Skip to content

Commit 9206828

Browse files
committed
added one-off (?) for creativecommons/tech-support#785
1 parent 155c272 commit 9206828

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

move_closed_issues.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Move closed Issues out of Backlog and into Active Sprint: Done.
4+
"""
5+
# Standard library
6+
import os
7+
import sys
8+
import traceback
9+
10+
# Third-party
11+
import github
12+
13+
GITHUB_TOKEN = os.environ["ADMIN_GITHUB_TOKEN"]
14+
15+
16+
class ScriptError(Exception):
17+
def __init__(self, message, code=None):
18+
self.code = code if code else 1
19+
message = "({}) {}".format(self.code, message)
20+
super(ScriptError, self).__init__(message)
21+
22+
23+
def main():
24+
backlog = None
25+
active_sprint = None
26+
done = None
27+
github_client = github.Github(GITHUB_TOKEN)
28+
cc = github_client.get_organization("creativecommons")
29+
30+
for project in cc.get_projects():
31+
if project.name == "Active Sprint":
32+
active_sprint = project
33+
elif project.name == "Backlog":
34+
backlog = project
35+
36+
for column in active_sprint.get_columns():
37+
if column.name == "Done":
38+
done = column
39+
break
40+
41+
for column in backlog.get_columns():
42+
print(f"{backlog.name}: {column.name}")
43+
for card in column.get_cards():
44+
if not card.content_url or "/issues/" not in card.content_url:
45+
continue
46+
content = card.get_content(content_type="Issue")
47+
if content.state != "closed":
48+
continue
49+
print(f" {content.title}")
50+
try:
51+
done.create_card(content_id=content.id, content_type="Issue")
52+
print(f" -> added to Active Sprint: {done.name}")
53+
except github.GithubException as e:
54+
if e.data["errors"][0]["message"] != (
55+
"Project already has the associated issue"
56+
):
57+
raise
58+
card.delete()
59+
print(f" -> removed.")
60+
61+
62+
if __name__ == "__main__":
63+
try:
64+
main()
65+
except SystemExit as e:
66+
sys.exit(e.code)
67+
except KeyboardInterrupt:
68+
print("INFO (130) Halted via KeyboardInterrupt.", file=sys.stderr)
69+
sys.exit(130)
70+
except ScriptError:
71+
error_type, error_value, error_traceback = sys.exc_info()
72+
print("ERROR {}".format(error_value), file=sys.stderr)
73+
sys.exit(error_value.code)
74+
except Exception:
75+
print("ERROR (1) Unhandled exception:", file=sys.stderr)
76+
print(traceback.print_exc(), file=sys.stderr)
77+
sys.exit(1)

0 commit comments

Comments
 (0)