Пример #1
0
    def resolve_commit(self, commit_identifier: Optional[str]) -> str:
        if not commit_identifier:
            try:
                commit_identifier = git.get_current_commit(
                    self.project.directory)
            except NoGitRepo:
                warn(
                    'The directory is not a Git repository. \n'
                    'Would you like to just run using the latest commit known by Valohai?'
                )
                if not click.confirm('Use latest commit?', default=True):
                    raise click.Abort()

        if commit_identifier and commit_identifier.startswith('~'):
            # Assume ad-hoc commits are qualified already
            return commit_identifier

        try:
            commit_obj = self.project.resolve_commit(
                commit_identifier=commit_identifier)
        except KeyError:
            warn(
                f'Commit {commit_identifier} is not known for the project. Have you pushed it?'
            )
            raise click.Abort()
        except IndexError:
            warn('No commits are known for the project.')
            raise click.Abort()

        resolved_commit_identifier: str = commit_obj['identifier']
        if not commit_identifier:
            click.echo(f'Resolved to commit {resolved_commit_identifier}',
                       err=True)

        return resolved_commit_identifier
Пример #2
0
def test_get_current_commit(tmpdir):
    dir = str(tmpdir)
    check_call('git init', cwd=dir, shell=True)
    check_call('git config user.name Robot', cwd=dir, shell=True)
    check_call('git config user.email [email protected]', cwd=dir, shell=True)
    tmpdir.join('test').write_text('test', 'utf8')
    check_call('git add .', cwd=dir, shell=True)
    check_call('git commit -mtest', cwd=dir, shell=True)
    assert len(get_current_commit(dir)) == 40
Пример #3
0
def get_git_commit(project: Project) -> Optional[str]:
    try:
        return git.get_current_commit(project.directory)
    except NoGitRepo:
        warn(
            'The directory is not a Git repository. \n'
            'Would you like to just run using the latest commit known by Valohai?'
        )
        if not click.confirm('Use latest commit?', default=True):
            raise click.Abort()
        return None
Пример #4
0
    def resolve_commit(self, commit):
        if not commit:
            commit = git.get_current_commit(self.project.directory)

        commits = request(
            'get', '/api/v0/projects/{id}/commits/'.format(
                id=self.project.id)).json()
        by_identifier = {c['identifier']: c for c in commits}
        if commit not in by_identifier:
            warn(
                'Commit {commit} is not known for the project. Have you pushed it?'
                .format(commit=commit))
            raise click.Abort()

        return commit
Пример #5
0
def commits():
    """
    List the commits for the linked project.
    """
    project = get_project(require=True)
    commits_data = request(
        'get', '/api/v0/projects/{id}/commits/'.format(id=project.id)).json()
    try:
        current_commit = get_current_commit(project.directory)
    except:
        current_commit = None

    # Filter out ad-hoc executions (and remove the adhocness marker)
    commits_data = [
        commit for commit in commits_data if not commit.pop('adhoc', False)
    ]

    # Mark the current commit
    for commit in commits_data:
        if commit['identifier'] == current_commit:
            commit['identifier'] += ' (current)'

    print_table(commits_data)