def review_url(review_n, gerrit_query=None, verbose=False):
    if not review_n:
        return None
    if not gerrit_query:
        gerrit_host, gerrit_port = guess.gerrit_from_repo()
        gerrit_query = GerritQuery(gerrit_host, gerrit_port, log_cmd=verbose)
    review = gerrit_query(review_n) or {}
    return review.get('url')
Exemple #2
0
def review_url(review_n, gerrit_query=None, verbose=False):
    if not review_n:
        return None
    if not gerrit_query:
        gerrit_host, gerrit_port = guess.gerrit_from_repo()
        gerrit_query = GerritQuery(gerrit_host, gerrit_port, log_cmd=verbose)
    review = gerrit_query(review_n) or {}
    return review.get('url')
Exemple #3
0
def fetch_patches_branch(local_patches_branch,
                         gerrit_patches_chain,
                         force=False):
    review_n = _review_number(gerrit_patches_chain)
    gerrit_host, gerrit_port = guess.gerrit_from_repo()
    query = GerritQuery(gerrit_host, gerrit_port)
    review = query('--current-patch-set', review_n)
    current_ps = review.get('currentPatchSet', {})
    patchset_n = current_ps.get('number')
    if not patchset_n:
        raise exception.CantGuess(
            msg='Failed to determine current patch set for review: %s' %
            gerrit_patches_chain)
    gerrit_ref = _review_ref(review_n, patchset_n)
    git('fetch', 'patches', gerrit_ref)

    approvals = current_ps.get('approvals', [])
    jenkins = [
        a for a in approvals if a.get('type') == 'Verified'
        and a.get('by', {}).get('username') == 'jenkins'
    ]
    code_reviews = [
        int(a.get('Value', 0)) for a in approvals
        if a.get('type') == 'Code-Review'
    ]
    if not jenkins:
        verified = 0
    else:
        verified = int(jenkins[0]['value'])
    if verified != 1:
        if force:
            log.warn("Ref %s has not been validated by CI." %
                     gerrit_patches_chain)
            helpers.confirm("Do you want to continue anyway?",
                            default_yes=False)
        else:
            raise exception.UnverifiedPatch()
    if any(cr < 0 for cr in code_reviews):
        log.warn("Ref %s has at least one negative review." %
                 gerrit_patches_chain)
        helpers.confirm("Do you want to continue anyway?", default_yes=False)

    git('update-ref', 'refs/heads/%s' % local_patches_branch, 'FETCH_HEAD')
def fetch_patches_branch(local_patches_branch, gerrit_patches_chain,
                         force=False):
    review_n = _review_number(gerrit_patches_chain)
    gerrit_host, gerrit_port = guess.gerrit_from_repo()
    query = GerritQuery(gerrit_host, gerrit_port)
    review = query('--current-patch-set', review_n)
    current_ps = review.get('currentPatchSet', {})
    patchset_n = current_ps.get('number')
    if not patchset_n:
        raise exception.CantGuess(
            msg='Failed to determine current patch set for review: %s'
                % gerrit_patches_chain)
    gerrit_ref = _review_ref(review_n, patchset_n)
    git('fetch', 'patches', gerrit_ref)

    approvals = current_ps.get('approvals', [])
    jenkins = [a for a in approvals
               if a.get('type') == 'Verified'
               and a.get('by', {}).get('username') == 'jenkins']
    code_reviews = [int(a.get('Value', 0)) for a in approvals
                    if a.get('type') == 'Code-Review']
    if not jenkins:
        verified = 0
    else:
        verified = int(jenkins[0]['value'])
    if verified != 1:
        if force:
            log.warn(
                "Ref %s has not been validated by CI." % gerrit_patches_chain)
            helpers.confirm("Do you want to continue anyway?",
                            default_yes=False)
        else:
            raise exception.UnverifiedPatch()
    if any(cr < 0 for cr in code_reviews):
        log.warn(
            "Ref %s has at least one negative review." % gerrit_patches_chain)
        helpers.confirm("Do you want to continue anyway?",
                        default_yes=False)

    git('update-ref', 'refs/heads/%s' % local_patches_branch,
        'FETCH_HEAD')