Пример #1
0
def log(connection, name=None, repo=None):
    """Returns log history of the given repository on the give system"""

    if repo is None:
        repo = Repository(connection, name)

    return repo.log()
Пример #2
0
def pull(connection, name=None, repo=None):
    """Pulls the given repository on the give system"""

    if repo is None:
        repo = Repository(connection, name)

    return repo.pull()
Пример #3
0
def checkout(connection, branch, name=None, repo=None):
    """Checks out the given branch in the given repository on the give system"""

    if repo is None:
        repo = Repository(connection, name)

    return repo.checkout(branch)
Пример #4
0
def checkout(connection, args):
    """git checkout <branch>
    """

    repo = Repository(connection, args.package)
    old_branch = repo.branch

    console = sap.cli.core.get_console()

    try:
        with sap.cli.helpers.ConsoleHeartBeat(console, args.heartbeat):
            response = sap.rest.gcts.simple.checkout(connection,
                                                     args.branch,
                                                     repo=repo)
    except GCTSRequestError as ex:
        dump_gcts_messages(sap.cli.core.get_console(), ex.messages)
        return 1

    console.printout(
        f'The repository "{args.package}" has been set to the branch "{args.branch}"'
    )
    console.printout(
        f'({old_branch}:{response["fromCommit"]}) -> ({args.branch}:{response["toCommit"]})'
    )
    return 0
Пример #5
0
def commit(connection, args):
    """git commit
    """

    console = sap.cli.core.get_console()
    repo = Repository(connection, args.package)

    try:
        with sap.cli.helpers.ConsoleHeartBeat(console, args.heartbeat):
            repo.commit_transport(args.corrnr, args.message
                                  or f'Transport {args.corrnr}',
                                  args.description)
    except GCTSRequestError as ex:
        dump_gcts_messages(sap.cli.core.get_console(), ex.messages)
        return 1

    console.printout(f'The transport "{args.corrnr}" has been committed')
    return 0
Пример #6
0
def fetch_repos(connection):
    """Returns list of repositories in the target systems defined by the given
       connection.
    """

    try:
        response = connection.get_json('repository')
    except HTTPRequestError as ex:
        raise exception_from_http_error(ex) from ex

    result = response.get('result', [])
    return [Repository(connection, repo['name'], data=repo) for repo in result]
Пример #7
0
def clone(connection,
          url,
          name,
          vsid='6IT',
          start_dir='src/',
          vcs_token=None,
          error_exists=True,
          role='SOURCE',
          typ='GITHUB'):
    """Creates and clones the repository in the target systems"""

    config = {}

    if start_dir:
        config['VCS_TARGET_DIR'] = start_dir

    if vcs_token:
        config['CLIENT_VCS_AUTH_TOKEN'] = vcs_token

    repo = Repository(connection, name)

    try:
        repo.create(url, vsid, config=config, role=role, typ=typ)
    except GCTSRepoAlreadyExistsError as ex:
        if error_exists:
            raise ex

        _mod_log().debug(ex)
        _mod_log().info(str(ex))

        repo.wipe_data()

    if not repo.is_cloned:
        repo.clone()
    else:
        _mod_log().info('Not cloning the repository "%s": already performed')

    return repo
Пример #8
0
def config(connection, args):
    """git config [-l] [<package>]
    """

    console = sap.cli.core.get_console()

    if args.list:
        repo = Repository(connection, args.package)

        try:
            configuration = repo.configuration
        except GCTSRequestError as ex:
            dump_gcts_messages(sap.cli.core.get_console(), ex.messages)
            return 1

        for key, value in configuration.items():
            console.printout(f'{key}={value}')

        return 0

    console.printerr(
        'Invalid command line options\nRun: sapcli gcts config --help')
    return 1
Пример #9
0
def delete(connection, name):
    """Deletes the given repository on the give system"""

    return Repository(connection, name).delete()
Пример #10
0
def set_url(connection, args):
    """Set repo URL"""

    repo = Repository(connection, args.package)
    sap.cli.core.printout(repo.set_url(args.url))