This repository was archived by the owner on Aug 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathghq.py
More file actions
195 lines (163 loc) · 4.85 KB
/
ghq.py
File metadata and controls
195 lines (163 loc) · 4.85 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import sys, getopt
from github import Github
organizationName = "Symless"
errorCode = 1
def usage():
print "ghq.py\n\
-i get issues\n\
-p <project> -p <project>\n\
-m <milestone>\n\
-h html mode\n\
-l add links"
def main(argv):
try:
opts, args = getopt.getopt(argv, "ip:m:hl")
except:
print "Those args don't look right"
usage()
return errorCode
runGetIssues = False
projects = []
milestone = ""
htmlMode = False
addLinks = False
for opt, arg in opts:
if opt == '-i':
runGetIssues = True
elif opt == '-p':
projects.append(arg)
elif opt == '-m':
milestone = arg
elif opt == '-h':
htmlMode = True
elif opt == '-l':
addLinks = True
if runGetIssues:
return getIssues(projects, milestone, htmlMode, addLinks)
print "What do you want from me?"
usage()
return errorCode
def getIssues(projectNames, milestoneName, htmlMode, addLinks):
token = readGitHubToken()
if len(projectNames) <= 0:
print "Specify a project name with: -p <project> -p <project>"
return errorCode
if not milestoneName:
print "I need to know the milestone, use: -m <milestone>"
return errorCode
g = Github(token)
organization = g.get_organization(organizationName)
all = []
for projectName in projectNames:
print "Getting issues for " + milestoneName + " in " + projectName
try:
repo = organization.get_repo(projectName)
except Exception as e:
print "GitHub didn't like that project name, try one of these:"
for repo in organization.get_repos():
print repo.name
return errorCode
milestones = repo.get_milestones()
if not any(True for _ in milestones):
print "There are no open milestones"
return errorCode
milestone = None
for milestone_ in milestones:
if milestone_.title == milestoneName:
milestone = milestone_
if milestone:
print "Found your milestone: " + milestone.title
else:
print "Sorry, couldn't find that milestone, how about these?"
for milestone_ in milestones:
print milestone_.title
print "Note: your milestone has to be open"
return errorCode
issues = repo.get_issues(milestone, "all")
bugs = []
enhancements = []
features = []
others = []
print "Organizing issues into neat piles..."
for issue in issues:
added = 0
for label in issue.get_labels():
if label.name == "bug":
added = 1
bugs.append(issue)
elif label.name == "enhancement":
added = 1
enhancements.append(issue)
elif label.name == "feature":
added = 1
features.append(issue)
if added != 1:
others.append(issue)
preHeader = ""
postHeader = ""
preList = ""
postList = ""
preItem = "- "
postItem = ""
if htmlMode:
preHeader = "<p>"
postHeader = "</p>"
preList = "<ul>"
postList = "</ul>"
preItem = "<li>"
postItem = "</li>"
if len(bugs) != 0:
print "\n" + preHeader + "Bug fixes:" + postHeader
print preList
for bug in bugs:
item = getItem(bug, projectName, preItem, postItem, addLinks)
all.append(item)
print item
print postList
if len(enhancements) != 0:
print "\n" + preHeader + "Enhancements:" + postHeader
print preList
for enhancement in enhancements:
item = getItem(enhancement, projectName, preItem, postItem, addLinks)
all.append(item)
print item
print postList
if len(features) != 0:
print "\n" + preHeader + "Features:" + postHeader
print preList
for feature in features:
item = getItem(feature, projectName, preItem, postItem, addLinks)
all.append(item)
print item
print postList
if len(others) != 0:
print "\n" + preHeader + "Others:" + postHeader
print preList
for other in others:
item = getItem(other, projectName, preItem, postItem, addLinks)
all.append(item)
print item
print postList
print "\n\n#All issues\n"
for issue in all:
print issue
def getItem(bug, projectName, preItem, postItem, addLinks):
issueText = "#" + str(bug.number)
if addLinks:
issueText = (
"<a href=\"https://github.com/symless/" + projectName + "/issues/" +
str(bug.number) + "\" target=\"_blank\">" + issueText + "</a>")
return preItem + issueText + " " + bug.title + postItem
def readGitHubToken():
filename = "github-token"
try:
f = open(filename, "r")
except:
print (
"Please create a file called " + filename + " containing a GitHub token.\n"
"Tick the first `repo` option (yeah, a bit scary I suppose).\n"
"Here's some help: http://bit.ly/github-access-token")
sys.exit(errorCode)
return f.readline().strip()
if __name__ == "__main__":
main(sys.argv[1:])