def main():
    """Main function"""
    args = _parse_args()

    if args.gerrit:
        args.gerrit = normalize_gerrit_name(args.gerrit)
    else:
        try:
            args.gerrit = find_gerrit_name()
        # pylint: disable=bare-except
        except:
            print('gerrit instance not found, use [-g GERRIT]')
            sys.exit(1)

    # Query change lists
    url_opener = create_url_opener_from_args(args)
    change_lists = query_change_lists(url_opener, args.gerrit, args.query,
                                      args.limits)

    # Download patch files
    num_changes = len(change_lists)
    num_changes_width = len(str(num_changes))
    for i, change in enumerate(change_lists, start=1):
        print('{:>{}}/{} | {} {}'.format(i, num_changes_width, num_changes,
                                         change['_number'], change['subject']))

        patch_file = get_patch(url_opener, args.gerrit, change['id'])
        with open('{}.patch'.format(change['_number']), 'wb') as output_file:
            output_file.write(patch_file)
Beispiel #2
0
def main():
    """Set review labels to selected change lists"""

    args = _parse_args()

    # Check the command line options
    if args.label is None and args.message is None and args.abandon is None:
        print('error: Either --label, --message, or --abandon must be ',
              'specified',
              file=sys.stderr)

    # Convert label arguments
    labels = _get_labels_from_args(args)

    # Load authentication credentials
    url_opener = create_url_opener_from_args(args)

    # Retrieve change lists
    change_lists = query_change_lists(url_opener, args.gerrit, args.query,
                                      args.limits)
    if not change_lists:
        print('error: No matching change lists.', file=sys.stderr)
        sys.exit(1)

    # Print matching lists
    _print_change_lists(change_lists, file=sys.stdout)

    # Confirm
    _confirm('Do you want to continue?')

    # Post review votes
    has_error = False
    for change in change_lists:
        if args.label or args.message:
            try:
                res_code, res_json = set_review(url_opener, args.gerrit,
                                                change['id'], labels,
                                                args.message)
            except HTTPError as error:
                res_code = error.code
                res_json = None

            if res_code != 200:
                has_error = True
                _report_error(change, res_code, res_json)

        if args.abandon:
            try:
                res_code, res_json = abandon(url_opener, args.gerrit,
                                             change['id'], args.abandon)
            except HTTPError as error:
                res_code = error.code
                res_json = None

            if res_code != 200:
                has_error = True
                _report_error(change, res_code, res_json)

    if has_error:
        sys.exit(1)
Beispiel #3
0
def main():
    """Set review labels to selected change lists"""

    args = _parse_args()

    # Convert label arguments
    labels = _get_labels_from_args(args)

    # Load authentication credentials
    url_opener = create_url_opener_from_args(args)

    # Retrieve change lists
    change_lists = query_change_lists(url_opener, args.gerrit, args.query,
                                      args.limits)
    if not change_lists:
        print('error: No matching change lists.', file=sys.stderr)
        sys.exit(1)

    # Print matching lists
    _print_change_lists(change_lists, file=sys.stdout)

    # Confirm
    _confirm('Do you want to continue?')

    # Post review votes
    has_error = False
    for change in change_lists:
        try:
            res_code, res_json = set_review(url_opener, args.gerrit,
                                            change['id'], labels, args.message)
        except HTTPError as e:
            res_code = e.code
            res_json = None

        if res_code != 200:
            has_error = True

            change_id = change['change_id']
            project = change['project']
            revision_sha1 = change['current_revision']
            revision = change['revisions'][revision_sha1]
            subject = revision['commit']['subject']

            print(_SEP_SPLIT, file=sys.stderr)
            print('Project:', project, file=sys.stderr)
            print('Change-Id:', change_id, file=sys.stderr)
            print('Subject:', subject, file=sys.stderr)
            print('HTTP status code:', res_code, file=sys.stderr)
            if res_json:
                print(_SEP, file=sys.stderr)
                json.dump(res_json,
                          sys.stderr,
                          indent=4,
                          separators=(', ', ': '))
                print(file=sys.stderr)
            print(_SEP_SPLIT, file=sys.stderr)

    if has_error:
        sys.exit(1)
def main():
    """Set review labels to selected change lists"""

    args = _parse_args()

    # Convert label arguments
    labels = _get_labels_from_args(args)

    # Load authentication credentials
    url_opener = create_url_opener_from_args(args)

    # Retrieve change lists
    change_lists = query_change_lists(
        url_opener, args.gerrit, args.query, args.limits)
    if not change_lists:
        print('error: No matching change lists.', file=sys.stderr)
        sys.exit(1)

    # Print matching lists
    _print_change_lists(change_lists, file=sys.stdout)

    # Confirm
    _confirm('Do you want to continue?')

    # Post review votes
    has_error = False
    for change in change_lists:
        try:
            res_code, res_json = set_review(
                url_opener, args.gerrit, change['id'], labels, args.message)
        except HTTPError as e:
            res_code = e.code
            res_json = None

        if res_code != 200:
            has_error = True

            change_id = change['change_id']
            project = change['project']
            revision_sha1 = change['current_revision']
            revision = change['revisions'][revision_sha1]
            subject = revision['commit']['subject']

            print(_SEP_SPLIT, file=sys.stderr)
            print('Project:', project, file=sys.stderr)
            print('Change-Id:', change_id, file=sys.stderr)
            print('Subject:', subject, file=sys.stderr)
            print('HTTP status code:', res_code, file=sys.stderr)
            if res_json:
                print(_SEP, file=sys.stderr)
                json.dump(res_json, sys.stderr, indent=4,
                          separators=(', ', ': '))
                print(file=sys.stderr)
            print(_SEP_SPLIT, file=sys.stderr)

    if has_error:
        sys.exit(1)
def main():
    """Set review labels to selected change lists"""

    # Parse and check the command line options
    args = _parse_args()
    if not _has_task(args):
        print('error: Either --label, --message, --abandon, --add-hashtag, '
              '--remove-hashtag, --set-topic, or --delete-topic must be ',
              'specified', file=sys.stderr)
        sys.exit(1)

    # Convert label arguments
    labels = _get_labels_from_args(args)

    # Load authentication credentials
    url_opener = create_url_opener_from_args(args)

    # Retrieve change lists
    change_lists = query_change_lists(
        url_opener, args.gerrit, args.query, args.limits)
    if not change_lists:
        print('error: No matching change lists.', file=sys.stderr)
        sys.exit(1)

    # Print matching lists
    _print_change_lists(change_lists, file=sys.stdout)

    # Confirm
    _confirm('Do you want to continue?')

    # Post review votes
    errors = {'num_errors': 0}
    for change in change_lists:
        if args.label or args.message:
            _do_task(change, set_review, url_opener, args.gerrit, change['id'],
                     labels, args.message, errors=errors)
        if args.add_hashtag or args.remove_hashtag:
            _do_task(change, set_hashtags, url_opener, args.gerrit,
                     change['id'], args.add_hashtag, args.remove_hashtag,
                     errors=errors)
        if args.set_topic:
            _do_task(change, set_topic, url_opener, args.gerrit, change['id'],
                     args.set_topic, errors=errors)
        if args.delete_topic:
            _do_task(change, delete_topic, url_opener, args.gerrit,
                     change['id'], expected_http_code=204, errors=errors)
        if args.abandon:
            _do_task(change, abandon, url_opener, args.gerrit, change['id'],
                     args.abandon, errors=errors)

    if errors['num_errors']:
        sys.exit(1)
Beispiel #6
0
def main():
    args = _parse_args()

    # Query change lists
    url_opener = create_url_opener_from_args(args)
    change_lists = query_change_lists(url_opener, args.gerrit, args.query,
                                      args.limits)

    # Download patch files
    num_changes = len(change_lists)
    num_changes_width = len(str(num_changes))
    for i, change in enumerate(change_lists, start=1):
        print('{:>{}}/{} | {} {}'.format(i, num_changes_width, num_changes,
                                         change['_number'], change['subject']))

        patch_file = get_patch(url_opener, args.gerrit, change['id'])
        with open('{}.patch'.format(change['_number']), 'wb') as output_file:
            output_file.write(patch_file)
def main():
    args = _parse_args()

    # Query change lists
    url_opener = create_url_opener_from_args(args)
    change_lists = query_change_lists(
        url_opener, args.gerrit, args.query, args.limits)

    # Download patch files
    num_changes = len(change_lists)
    num_changes_width = len(str(num_changes))
    for i, change in enumerate(change_lists, start=1):
        print('{:>{}}/{} | {} {}'.format(
                i, num_changes_width, num_changes, change['_number'],
                change['subject']))

        patch_file = get_patch(url_opener, args.gerrit, change['id'])
        with open('{}.patch'.format(change['_number']), 'wb') as output_file:
            output_file.write(patch_file)
def _get_change_lists_from_args(args):
    """Query the change lists by args."""
    url_opener = create_url_opener_from_args(args)
    return query_change_lists(url_opener, args.gerrit, args.query, args.limits)
Beispiel #9
0
def _get_change_lists_from_args(args):
    """Query the change lists by args."""
    url_opener = create_url_opener_from_args(args)
    return query_change_lists(url_opener, args.gerrit, args.query, args.limits)
def main():
    """Set review labels to selected change lists"""

    # Parse and check the command line options
    args = _parse_args()
    if not _has_task(args):
        print(
            'error: Either --label, --message, --abandon, --add-hashtag, '
            '--remove-hashtag, --set-topic, or --delete-topic must be ',
            'specified',
            file=sys.stderr)
        sys.exit(1)

    # Convert label arguments
    labels = _get_labels_from_args(args)

    # Load authentication credentials
    url_opener = create_url_opener_from_args(args)

    # Retrieve change lists
    change_lists = query_change_lists(url_opener, args.gerrit, args.query,
                                      args.limits)
    if not change_lists:
        print('error: No matching change lists.', file=sys.stderr)
        sys.exit(1)

    # Print matching lists
    _print_change_lists(change_lists, file=sys.stdout)

    # Confirm
    _confirm('Do you want to continue?')

    # Post review votes
    errors = {'num_errors': 0}
    for change in change_lists:
        if args.label or args.message:
            _do_task(change,
                     set_review,
                     url_opener,
                     args.gerrit,
                     change['id'],
                     labels,
                     args.message,
                     errors=errors)
        if args.add_hashtag or args.remove_hashtag:
            _do_task(change,
                     set_hashtags,
                     url_opener,
                     args.gerrit,
                     change['id'],
                     args.add_hashtag,
                     args.remove_hashtag,
                     errors=errors)
        if args.set_topic:
            _do_task(change,
                     set_topic,
                     url_opener,
                     args.gerrit,
                     change['id'],
                     args.set_topic,
                     errors=errors)
        if args.delete_topic:
            _do_task(change,
                     delete_topic,
                     url_opener,
                     args.gerrit,
                     change['id'],
                     expected_http_code=204,
                     errors=errors)
        if args.abandon:
            _do_task(change,
                     abandon,
                     url_opener,
                     args.gerrit,
                     change['id'],
                     args.abandon,
                     errors=errors)

    if errors['num_errors']:
        sys.exit(1)
Beispiel #11
0
def main():
    """Set review labels to selected change lists"""

    # Parse and check the command line options
    args = _parse_args()

    if args.gerrit:
        args.gerrit = normalize_gerrit_name(args.gerrit)
    else:
        try:
            args.gerrit = find_gerrit_name()
        # pylint: disable=bare-except
        except:
            print('gerrit instance not found, use [-g GERRIT]')
            sys.exit(1)

    if not _has_task(args):
        print(
            'error: Either --label, --message, --submit, --abandon, --restore, '
            '--add-hashtag, --remove-hashtag, --set-topic, --delete-topic, '
            '--add-reviewer or --delete-reviewer must be specified',
            file=sys.stderr)
        sys.exit(1)

    # Convert label arguments
    labels = _get_labels_from_args(args)

    # Convert reviewer arguments
    new_reviewers = [{'reviewer': name} for name in args.add_reviewer]

    # Load authentication credentials
    url_opener = create_url_opener_from_args(args)

    # Retrieve change lists
    change_lists = query_change_lists(url_opener, args.gerrit, args.query,
                                      args.limits)
    if not change_lists:
        print('error: No matching change lists.', file=sys.stderr)
        sys.exit(1)

    # Print matching lists
    _print_change_lists(change_lists, file=sys.stdout)

    # Confirm
    _confirm('Do you want to continue?')

    # Post review votes
    errors = {'num_errors': 0}
    for change in change_lists:
        if args.label or args.message:
            _do_task(change,
                     set_review,
                     url_opener,
                     args.gerrit,
                     change['id'],
                     labels,
                     args.message,
                     errors=errors)
        if args.add_hashtag or args.remove_hashtag:
            _do_task(change,
                     set_hashtags,
                     url_opener,
                     args.gerrit,
                     change['id'],
                     args.add_hashtag,
                     args.remove_hashtag,
                     errors=errors)
        if args.set_topic:
            _do_task(change,
                     set_topic,
                     url_opener,
                     args.gerrit,
                     change['id'],
                     args.set_topic,
                     errors=errors)
        if args.delete_topic:
            _do_task(change,
                     delete_topic,
                     url_opener,
                     args.gerrit,
                     change['id'],
                     expected_http_code=204,
                     errors=errors)
        if args.submit:
            _do_task(change,
                     submit,
                     url_opener,
                     args.gerrit,
                     change['id'],
                     errors=errors)
        if args.abandon:
            _do_task(change,
                     abandon,
                     url_opener,
                     args.gerrit,
                     change['id'],
                     args.abandon,
                     errors=errors)
        if args.restore:
            _do_task(change,
                     restore,
                     url_opener,
                     args.gerrit,
                     change['id'],
                     errors=errors)
        if args.add_reviewer:
            _do_task(change,
                     add_reviewers,
                     url_opener,
                     args.gerrit,
                     change['id'],
                     new_reviewers,
                     errors=errors)
        for name in args.delete_reviewer:
            _do_task(change,
                     delete_reviewer,
                     url_opener,
                     args.gerrit,
                     change['id'],
                     name,
                     expected_http_code=204,
                     errors=errors)

    if errors['num_errors']:
        sys.exit(1)