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(
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
79
def get_lp_bugs(lp, branch, tags):
66
return parser.parse_args(args)
69
def get_lp_bugs(lp, branch, with_ci=False):
80
70
"""Return a dict of blocker critical bug tasks for the branch."""
82
raise ValueError('tags must be a list of bug tags')
85
72
project = lp.projects['juju-core']
86
73
if branch == 'master':
90
77
target = project.getSeries(name=branch)
81
bug_tags = BUG_TAGS + ['ci']
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)
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)
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)