~andrewjbeach/juju-ci-tools/make-local-patcher

« back to all changes in this revision

Viewing changes to check_blockers.py

  • Committer: Aaron Bentley
  • Date: 2015-07-27 19:19:56 UTC
  • mto: This revision was merged to the branch mainline in revision 1048.
  • Revision ID: aaron.bentley@canonical.com-20150727191956-uz4gdxuv28qhvv94
Use per-client JUJU_HOME.

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
 
    if branch.startswith('1.'):
86
 
        # Historic Juju 1.x
87
 
        project = lp.projects['juju-core']
88
 
    else:
89
 
        # Juju 2.x.
90
 
        project = lp.projects['juju']
 
72
    project = lp.projects['juju-core']
91
73
    if branch == 'master':
92
74
        # Lp implicitly assigns bugs to trunk, which is not a series query.
93
75
        target = project
95
77
        target = project.getSeries(name=branch)
96
78
    if not target:
97
79
        return bugs
 
80
    if with_ci:
 
81
        bug_tags = BUG_TAGS + ['ci']
 
82
    else:
 
83
        bug_tags = BUG_TAGS
98
84
    bug_tasks = target.searchTasks(
99
85
        status=BUG_STATUSES, importance=BUG_IMPORTANCES,
100
86
        tags=bug_tags, tags_combinator='All')
133
119
    """Update the critical blocker+ci bugs for the branch to Fix Released."""
134
120
    changes = []
135
121
    for bug_id, bug_task in bugs.items():
136
 
        if 'intermittent-failure' in bug_task.bug.tags:
137
 
            changes.append('Skipping intermittent-failure %s' % bug_task.title)
138
 
            continue
139
122
        changes.append('Updated %s' % bug_task.title)
140
123
        bug_task.status = 'Fix Released'
141
124
        if not dry_run:
153
136
    args = parse_args(argv)
154
137
    lp = get_lp('check_blockers', credentials_file=args.credentials_file)
155
138
    if args.command == 'check':
156
 
        bugs = get_lp_bugs(lp, args.branch, ['blocker'])
157
 
        code, reason = get_reason(bugs, args)
158
 
        print(reason)
159
 
    if args.command == 'block-ci-testing':
160
 
        bugs = get_lp_bugs(lp, args.branch, ['block-ci-testing'])
 
139
        bugs = get_lp_bugs(lp, args.branch, with_ci=False)
161
140
        code, reason = get_reason(bugs, args)
162
141
        print(reason)
163
142
    elif args.command == 'update':
164
 
        bugs = get_lp_bugs(lp, args.branch, ['blocker', 'ci'])
 
143
        bugs = get_lp_bugs(lp, args.branch, with_ci=True)
165
144
        code, changes = update_bugs(
166
145
            bugs, args.branch, args.build, dry_run=args.dry_run)
167
146
        print(changes)