forked from OpenSCAP/openscap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove-milestones.py
executable file
·44 lines (30 loc) · 1.39 KB
/
move-milestones.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
import argparse as ap
import shared
def create_parser():
parser = ap.ArgumentParser()
parser.add_argument("old-version", type=shared.version_type)
parser.add_argument("new-version", type=shared.version_type)
shared.update_parser_with_common_stuff(parser)
return parser
def create_new_milestone(repo, name):
assert shared.get_milestone(repo, name) is None, \
f"There already is a milestone {name}"
return repo.create_milestone(name, "open")
def transfer_open_issues_and_prs_to_new_milestone(repo, old_milestone, new_milestone):
assert old_milestone.title != new_milestone.title, \
f"The new and old milestones have the same title '{new_milestone.title}'"
old_milestone_issues = repo.get_issues(milestone=old_milestone, state="open")
for issue in old_milestone_issues:
issue.edit(milestone=new_milestone)
def close_milestone(milestone):
milestone.edit(milestone.title, state="closed")
if __name__ == "__main__":
parser = create_parser()
args = parser.parse_args()
github = shared.get_github(args)
repo = shared.get_repo(github, args.owner)
old_milestone = shared.get_milestone(repo, vars(args)["old-version"])
new_milestone = create_new_milestone(repo, vars(args)["new-version"])
transfer_open_issues_and_prs_to_new_milestone(repo, old_milestone, new_milestone)
close_milestone(old_milestone)