Ejemplo n.º 1
0
def main():
    description = ('Check if the owner of a change is a valid candidate as '
                   'described in the change')
    parser = argparse.ArgumentParser(description)
    parser.add_argument(dest='change_id', help=('A valid gerrit change ID'))
    parser.add_argument('--limit', dest='limit', type=int, default=1,
                        help=('How many validating changes to report.  '
                              'A negative value means report many.  '
                              'Default: %(default)s'))
    parser.add_argument('--tag', dest='tag', default=utils.conf['tag'],
                        help=('The governance tag to validate against.  '
                              'Default: %(default)s'))

    args = parser.parse_args()
    review = utils.get_reviews(args.change_id)[0]
    owner = review.get('owner', {})
    if args.limit < 0:
        args.limit = 100

    try:
        found = check_candidacy.check_candidacy_review(review['change_id'],
                                                       tag=args.tag,
                                                       review=review)
    except Exception as exc:
        print("[E] %s\n\n" % (exc))
    else:
        if found:
            print('SUCESS: %s is a valid candidate\n\n' % (owner['email']))
            return 0
        else:
            print('[E]: %s is not a valid candidate\n\n' % (owner['email']))
            return 1
Ejemplo n.º 2
0
def main():
    description = ('Check if the owner of a change is a valid candidate as '
                   'described in the change')
    parser = argparse.ArgumentParser(description)
    parser.add_argument(dest='change_id', help=('A valid gerrit change ID'))
    parser.add_argument('--limit', dest='limit', type=int, default=1,
                        help=('How many validating changes to report.  '
                              'A negative value means report many.  '
                              'Default: %(default)s'))
    parser.add_argument('--tag', dest='tag', default=utils.conf['tag'],
                        help=('The governance tag to validate against.  '
                              'Default: %(default)s'))
    parser.add_argument('-v', '--verbose', action="count", default=0,
                        help='Increase program verbosity')

    args = parser.parse_args()
    review = utils.get_reviews(args.change_id, verbose=args.verbose)[0]
    owner = review.get('owner', {})
    if args.limit < 0:
        args.limit = 100

    try:
        found = check_candidacy.check_candidacy_review(review['change_id'],
                                                       tag=args.tag,
                                                       review=review)
    except Exception as exc:
        print("[E] %s\n\n" % (exc))
    else:
        if found:
            print('SUCCESS: %s is a valid candidate\n\n' % (owner['email']))
            return 0
        else:
            print('[E]: %s is not a valid candidate\n\n' % (owner['email']))
            return 1
Ejemplo n.º 3
0
def check_candidate(project_name, email, projects, limit=1):
    def pretty_datetime(dt_str):
        dt = datetime.datetime.strptime(dt_str.split('.')[0],
                                        '%Y-%m-%d %H:%M:%S')
        return dt.strftime('%Y-%m-%d')

    found = 0
    branch = None
    timeframe = utils.conf['timeframe']

    if project_name in ['Stable branch maintenance']:
        project_list = projects.values()
        branch = '^stable/.*'
    else:
        project_list = [projects[project_name]]

    for project in project_list:
        for atc in project.get('extra-atcs', []):
            if (atc['email'] == email and utils.check_atc_date(atc)):
                print("%2d: Valid extra ATC record:\n\t%s" % (found, atc))
                found += 1
                if found >= limit:
                    return found

        for deliverable in project['deliverables'].values():
            for repo_name in deliverable["repos"]:
                query = ('is:merged after:"%s" before:"%s" '
                         'owner:%s project:%s' %
                         (utils.gerrit_datetime(timeframe['start']),
                          utils.gerrit_datetime(timeframe['end']),
                          email, repo_name))
                if branch:
                    query += (' branch:%s' % (branch))
                print('Checking %s for merged changes by %s' %
                      (repo_name, email))
                for review in utils.get_reviews(query):
                    url = ('%s/%s/commit/?id=%s' % (
                           utils.CGIT_URL, review['project'],
                           review['current_revision']))
                    print('%2d: %s %s' %
                          (found, pretty_datetime(review['submitted']),
                           url))
                    found += 1
                    if found >= limit:
                        return found
    return found
Ejemplo n.º 4
0
def check_candidate(project_name, email, projects, limit=1, verbose=0):
    def pretty_datetime(dt_str):
        dt = datetime.datetime.strptime(
            dt_str.split('.')[0], '%Y-%m-%d %H:%M:%S')
        return dt.strftime('%Y-%m-%d')

    found = 0
    branch = None
    timeframe = utils.conf['timeframe']
    owner = utils.get_gerrit_account(email)['username']

    if project_name in ['Stable branch maintenance']:
        project_list = projects.values()
        branch = '^stable/.*'
    else:
        project_list = [projects[project_name]]

    for project in project_list:
        for atc in project.get('extra-atcs', []):
            if (atc['email'] == email and utils.check_atc_date(atc)):
                print("%2d: Valid extra ATC record:\n\t%s" % (found, atc))
                found += 1
                if found >= limit:
                    return found

        for deliverable in project['deliverables'].values():
            for repo_name in deliverable["repos"]:
                query = ('is:merged after:"%s" before:"%s" '
                         'owner:%s project:%s' %
                         (utils.gerrit_datetime(timeframe['start']),
                          utils.gerrit_datetime(
                              timeframe['end']), owner, repo_name))
                if branch:
                    query += (' branch:%s' % (branch))
                if verbose >= 1:
                    print('Checking %s for merged changes by %s' %
                          (repo_name, email))
                for review in utils.get_reviews(query, verbose=verbose):
                    print('Found: %s/%s merged on %s to %s for %s' %
                          (utils.GERRIT_BASE, review['_number'],
                           pretty_datetime(
                               review['submitted']), repo_name, project_name))
                    found += 1
                    if found >= limit:
                        return found
    return found
Ejemplo n.º 5
0
def check_candidate(project_name, email, projects, limit=1):
    def pretty_datetime(dt_str):
        dt = datetime.datetime.strptime(
            dt_str.split('.')[0], '%Y-%m-%d %H:%M:%S')
        return dt.strftime('%Y-%m-%d')

    found = 0
    branch = None
    timeframe = utils.conf['timeframe']

    if project_name in ['Stable branch maintenance']:
        project_list = projects.values()
        branch = '^stable/.*'
    else:
        project_list = [projects[project_name]]

    for project in project_list:
        for atc in project.get('extra-atcs', []):
            if (atc['email'] == email and utils.check_atc_date(atc)):
                print("%2d: Valid extra ATC record:\n\t%s" % (found, atc))
                found += 1
                if found >= limit:
                    return found

        for deliverable in project['deliverables'].values():
            for repo_name in deliverable["repos"]:
                query = ('is:merged after:"%s" before:"%s" '
                         'owner:%s project:%s' %
                         (utils.gerrit_datetime(timeframe['start']),
                          utils.gerrit_datetime(
                              timeframe['end']), email, repo_name))
                if branch:
                    query += (' branch:%s' % (branch))
                print('Checking %s for merged changes by %s' %
                      (repo_name, email))
                for review in utils.get_reviews(query):
                    url = ('%s/%s/commit/?id=%s' %
                           (utils.CGIT_URL, review['project'],
                            review['current_revision']))
                    print('%2d: %s %s' %
                          (found, pretty_datetime(review['submitted']), url))
                    found += 1
                    if found >= limit:
                        return found
    return found
Ejemplo n.º 6
0
def check_candidacy_review(change_id, limit=1, tag=utils.conf['tag'],
                           review=None):
    projects = utils.get_projects(tag=tag)
    # If there is more than one review that matches this change_id then all
    # bets are off
    review = review or utils.get_reviews(change_id)[0]
    email = review.get('owner', {}).get('email')
    found = 0

    for filename in utils.candidate_files(review):
        _, series, project_name, candidate_file = filename.split(os.sep)
        if project_name != 'TC':
            project_name = utils.dir2name(project_name, projects)

        found += check_candidate(project_name, email, projects,
                                 limit=(limit-found))
        if found >= limit:
            return True

    return found > 0
Ejemplo n.º 7
0
def check_candidacy_review(change_id,
                           limit=1,
                           tag=utils.PROJECTS_TAG,
                           review=None):
    projects = utils.get_projects(tag=tag)
    # If there is more than one review that matches this change_id then all
    # bets are off
    review = review or utils.get_reviews(change_id)[0]
    email = review.get('owner', {}).get('email')
    found = 0

    for filename in utils.candidate_files(review):
        _, series, project_name, candidate_file = filename.split(os.sep)
        if project_name != 'TC':
            project_name = utils.dir2name(project_name, projects)

        found += check_candidate(project_name,
                                 email,
                                 projects,
                                 limit=(limit - found))
        if found >= limit:
            return True

    return found > 0
def get_reviews():
    return utils.get_reviews(
        'is:open project:%s file:^%s/%s/.*' %
        (utils.ELECTION_REPO, utils.CANDIDATE_PATH, utils.conf['release']))
Ejemplo n.º 9
0
def get_reviews():
    return utils.get_reviews('is:open project:%s file:^%s/%s/.*' %
                             (utils.ELECTION_REPO, utils.CANDIDATE_PATH,
                              utils.conf['release']))
Ejemplo n.º 10
0
def get_reviews():
    return utils.get_reviews(
        'is:open project:%s file:^%s/%s/.*' %
        (utils.ELECTION_REPO, utils.CANDIDATE_PATH, utils.SERIES_NAME))