Beispiel #1
0
def create_or_update(args):
    "Creates or updates a code review case."

    creds = new_credentials_config()
    g = GitRepo()
    cr_data_file = get_cr_data_file(g)

    safe_create_code_review_data_file(cr_data_file)

    with CodeReviewConfiguration.persisting(cr_data_file) as data:
        if g.current_branch() in data.branches:
            cr_data = data.branches[g.current_branch()]
            if len(cr_data.commits) > 1 and g.sha('HEAD~') == cr_data.commits[-2]:
                # the last commit was amended, so replace it:
                if g.sha('HEAD') != cr_data.commits[-1]:
                    cr_data.commits[-1] = g.sha('HEAD')
            elif g.sha() not in cr_data.commits:
                cr_data.commits.append(g.sha())

            if len(cr_data.commits) >= 2:
                use_hash = str('..'.join([cr_data.commits[0][0:8], cr_data.commits[-1][0:8]]))
            else:
                use_hash = str(cr_data.commits[-1])

            logger.info('updating an existing code review.')
            update_code_review(cr_data, g, use_hash)
        else:
            data.set_branch(g.current_branch(), {'original_name': g.commit_messages()[0],
                                                 'commits': [g.sha('HEAD~'), g.sha()]})

            logger.info('creating new code review.')
            create_code_review(data, g, creds)
def close(args):
    "Removes a tracked code review."

    g = GitRepo()
    cr_data_file = get_cr_data_file(g)

    safe_create_code_review_data_file(cr_data_file)

    with CodeReviewConfiguration.persisting(cr_data_file) as data:
        branches = data.branches.keys()

        for to_delete in args._branch_name:
            if to_delete in branches:
                del data.branches[to_delete]
                logger.info('removed tracked code review for: ' + to_delete)
            else:
                logger.info("not tracking a code review for: " + to_delete)

            try:
                g.remove_branch(to_delete, args.force)
                logger.info('removed branch: ' + to_delete)
            except:
                logger.error('could not remove branch: ' + to_delete)
Beispiel #3
0
def create_or_update(args):
    "Creates or updates a code review case."

    creds = new_credentials_config()
    g = GitRepo()
    cr_data_file = get_cr_data_file(g)

    safe_create_code_review_data_file(cr_data_file)

    with CodeReviewConfiguration.persisting(cr_data_file) as data:
        if g.current_branch() in data.branches:
            cr_data = data.branches[g.current_branch()]
            if len(cr_data.commits) > 1 and g.sha(
                    'HEAD~') == cr_data.commits[-2]:
                # the last commit was amended, so replace it:
                if g.sha('HEAD') != cr_data.commits[-1]:
                    cr_data.commits[-1] = g.sha('HEAD')
            elif g.sha() not in cr_data.commits:
                cr_data.commits.append(g.sha())

            if len(cr_data.commits) >= 2:
                use_hash = str('..'.join(
                    [cr_data.commits[0][0:8], cr_data.commits[-1][0:8]]))
            else:
                use_hash = str(cr_data.commits[-1])

            logger.info('updating an existing code review.')
            update_code_review(cr_data, g, use_hash)
        else:
            data.set_branch(
                g.current_branch(), {
                    'original_name': g.commit_messages()[0],
                    'commits': [g.sha('HEAD~'), g.sha()]
                })

            logger.info('creating new code review.')
            create_code_review(data, g, creds)