~abentley/juju-ci-tools/client-from-config-4

« back to all changes in this revision

Viewing changes to check_blockers.py

  • Committer: Martin Packman
  • Date: 2015-12-16 03:59:38 UTC
  • mto: This revision was merged to the branch mainline in revision 1200.
  • Revision ID: martin.packman@canonical.com-20151216035938-881wbry7ezh8he5m
Add missing template test file

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
    subparsers = parser.add_subparsers(help='sub-command help', dest="command")
52
52
    check_parser = subparsers.add_parser(
53
53
        'check', help='Check if merges are blocked for a branch.')
54
 
    check_parser.add_argument(
55
 
        'branch', default='master', nargs='?', type=str.lower,
56
 
        help='The branch to merge into.')
 
54
    check_parser.add_argument('branch', default='master', nargs='?',
 
55
                              help='The branch to merge into.')
57
56
    check_parser.add_argument('pull_request', default=None, nargs='?',
58
57
                              help='The pull request to be merged')
59
 
    block_ci_testing_parser = subparsers.add_parser(
60
 
        'block-ci-testing',
61
 
        help='Check if ci testing is blocked for the branch.')
62
 
    block_ci_testing_parser.add_argument(
63
 
        'branch', type=str.lower, help='The branch to merge into.')
64
58
    update_parser = subparsers.add_parser(
65
59
        'update', help='Update blocking for a branch that passed CI.')
66
60
    update_parser.add_argument(
67
61
        '-d', '--dry-run', action='store_true', default=False,
68
62
        help='Do not make changes.')
69
 
    update_parser.add_argument(
70
 
        'branch', type=str.lower, help='The branch that passed.')
 
63
    update_parser.add_argument('branch', help='The branch that passed.')
71
64
    update_parser.add_argument(
72
65
        'build', help='The build-revision build number.')
73
 
    args = parser.parse_args(args)
74
 
    if not getattr(args, 'pull_request', None):
75
 
        args.pull_request = None
76
 
    return args
77
 
 
78
 
 
79
 
def get_lp_bugs(lp, branch, tags):
 
66
    return parser.parse_args(args)
 
67
 
 
68
 
 
69
def get_lp_bugs(lp, branch, with_ci=False):
80
70
    """Return a dict of blocker critical bug tasks for the branch."""
81
 
    if not tags:
82
 
        raise ValueError('tags must be a list of bug tags')
83
 
    bug_tags = tags
84
71
    bugs = {}
85
72
    project = lp.projects['juju-core']
86
73
    if branch == 'master':
90
77
        target = project.getSeries(name=branch)
91
78
    if not target:
92
79
        return bugs
 
80
    if with_ci:
 
81
        bug_tags = BUG_TAGS + ['ci']
 
82
    else:
 
83
        bug_tags = BUG_TAGS
93
84
    bug_tasks = target.searchTasks(
94
85
        status=BUG_STATUSES, importance=BUG_IMPORTANCES,
95
86
        tags=bug_tags, tags_combinator='All')
145
136
    args = parse_args(argv)
146
137
    lp = get_lp('check_blockers', credentials_file=args.credentials_file)
147
138
    if args.command == 'check':
148
 
        bugs = get_lp_bugs(lp, args.branch, ['blocker'])
149
 
        code, reason = get_reason(bugs, args)
150
 
        print(reason)
151
 
    if args.command == 'block-ci-testing':
152
 
        bugs = get_lp_bugs(lp, args.branch, ['block-ci-testing'])
 
139
        bugs = get_lp_bugs(lp, args.branch, with_ci=False)
153
140
        code, reason = get_reason(bugs, args)
154
141
        print(reason)
155
142
    elif args.command == 'update':
156
 
        bugs = get_lp_bugs(lp, args.branch, ['blocker', 'ci'])
 
143
        bugs = get_lp_bugs(lp, args.branch, with_ci=True)
157
144
        code, changes = update_bugs(
158
145
            bugs, args.branch, args.build, dry_run=args.dry_run)
159
146
        print(changes)