-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch-issues.py
97 lines (87 loc) · 3.24 KB
/
fetch-issues.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from datetime import date
import os
import re
from github import Github
import argparse
def comma_split(t):
return t.split(",")
CATEGORIES = {
"features": {"label": "Features", "marketing": True},
"bugs": {"label": "Bug fixes", "marketing": True},
"internals": {"label": "Internal tickets", "marketing": True},
}
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Github tool")
parser.add_argument(
"-m", dest="milestone", help="Name of the milestone", required=True
)
parser.add_argument(
"-r",
dest="repos",
type=comma_split,
help="Comma separated list of repositories",
required=True,
)
args = parser.parse_args()
if os.getenv("GITHUB_PERSONAL_ACCESS_TOKEN"):
g = Github(os.getenv("GITHUB_PERSONAL_ACCESS_TOKEN"))
else:
g = Github(os.getenv("GITHUB_USER"), os.getenv("GITHUB_PASSWORD"))
repos = [repo for repo in g.get_user().get_repos() if repo.full_name in args.repos]
issues = {category: [] for category in CATEGORIES}
print("### %s" % args.milestone)
print("")
print("*%s*" % date.today().strftime("%B %d %Y"))
print("")
print(
"**InUse** and **InLab** platforms have been upgraded to the version %s"
% args.milestone
)
print("")
for repo in repos:
milestones = [
milestone
for milestone in repo.get_milestones(state="all")
if milestone.title == args.milestone
]
if not milestones:
continue
milestone = milestones[0]
if milestone.description:
print(milestone.description.encode("utf8"))
print("")
for issue in repo.get_issues(milestone=milestone, state="all"):
if "/pull/" not in issue.html_url:
labels = [label.name for label in issue.labels]
if "structure" in labels:
issues["internals"].append(issue)
elif "bug" in labels:
issues["bugs"].append(issue)
elif "enhancement" or "feature" in labels:
issues["features"].append(issue)
else:
raise ValueError("Cannot find category for %s" % issue)
for category in ("features", "bugs", "internals"):
if not issues[category]:
continue
print("#### %s" % CATEGORIES[category]["label"])
print("")
for issue in issues[category]:
if category == "features":
print("##### %s" % issue.title)
print("")
print("[Link to github (#%s)](%s)" % (issue.number, issue.html_url))
else:
print("- [%s #%s](%s)" % (issue.title, issue.number, issue.html_url))
if CATEGORIES[category]["marketing"]:
for comment in issue.get_comments():
if re.match("[#]+ Marketing[\r\n]+", comment.body):
print("")
print(
re.sub(
"[#]+ Marketing[\r\n]+", "", comment.body.encode("utf8")
)
)
print("")
break
print("")