-
Notifications
You must be signed in to change notification settings - Fork 1
/
github-issue
executable file
·314 lines (250 loc) · 10.5 KB
/
github-issue
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#!/usr/bin/python
import sys, re
from subprocess import Popen,PIPE
from github2.client import Github
def list_all(github, repo):
git_issues = github.issues.list(repo)
for git_issue in git_issues:
labels = ','.join(git_issue.labels)
summary = "%d [%s] %s" % (git_issue.number, labels, git_issue.title)
print " * %-90s Created: %s Modified: %s" % (summary, git_issue.created_at, git_issue.updated_at)
def list_tag(github, repo, tags):
for tag in tags:
git_issues = github.issues.list_by_label(repo, tag)
print "%s:" % tag
for git_issue in git_issues:
summary = "%d %s" % (git_issue.number, git_issue.title)
print " * %-90s Created: %s Modified: %s" % (summary, git_issue.created_at, git_issue.updated_at)
print " Total: %d" % (len(git_issues))
print ""
def list_tags(github, repo, detail=1):
tags = github.issues.list_labels(repo)
for tag in tags:
if detail:
git_issues = github.issues.list_by_label(repo, tag)
print " %15s %d" % (tag, len(git_issues))
else:
print " %s" % (tag)
print ""
def add_comment(github, repo, num, text):
git_issue = github.issues.comment(repo, num, text)
def issue_detail(github, repo, num):
git_issue = github.issues.show(repo, num)
print ""
if git_issue.labels:
labels = ', '.join(git_issue.labels)
labels = "%s, %s" % (git_issue.state, labels)
else:
labels = git_issue.state
summary = "%d [%s] %s" % (git_issue.number, labels, git_issue.title)
print " * %-90s" % (summary)
change='Modified'
when=git_issue.updated_at
if git_issue.state == "closed":
change='Closed'
when=git_issue.closed_at
print " Filed by: %s at %s (%s: %s)" % (git_issue.user, git_issue.created_at, change, when)
if git_issue.diff_url:
print " Diff: %s" % git_issue.diff_url
if git_issue.patch_url:
print " Patch: %s" % git_issue.patch_url
if git_issue.diff_url:
print " Pull: %s" % git_issue.pull_request_url
if git_issue.body:
print ""
for line in git_issue.body.split('\n'):
print " | %s" % line
comments = github.issues.comments(repo, num)
for comment in comments:
print ""
print " %s at %s" % (comment.user, comment.updated_at)
for line in comment.body.split('\n'):
print " > %s" % line
print ""
def bz_clone(repo, num, product, version, component):
git_issue = github.issues.show(repo, num)
text = "\n"
change='Modified'
when=git_issue.updated_at
if git_issue.state == "closed":
change='Closed'
when=git_issue.closed_at
text += "Filed by: %s at %s (%s: %s)\n" % (git_issue.user, git_issue.created_at, change, when)
if git_issue.labels:
text += "Labels: %s\n" % ', '.join(git_issue.labels)
if git_issue.patch_url:
text += "Patch: %s\n" % git_issue.patch_url
if git_issue.body:
text += "\n"
for line in git_issue.body.split('\n'):
text += "| %s\n" % line
comments = github.issues.comments(repo, num)
for comment in comments:
text += "\n"
text += "%s at %s\n" % (comment.user, comment.updated_at)
for line in comment.body.split('\n'):
text += "> %s\n" % line
text = re.sub("\'", "'\\''", text)
issue_url = 'https://github.com/%s/issues/%d' % (github_project, num)
cmd = "bugzilla new --product='%s' --version='%s' --component='%s' --url='%s' --summary='%s' --comment='%s'" % (product, version, component, issue_url, git_issue.title, text)
print cmd
proc = Popen(cmd, stdout = PIPE, stderr = PIPE, close_fds = True, shell = True)
if proc.stdout:
lines = proc.stdout.readlines()
proc.stdout.close()
for line in lines:
print line.strip()
if proc.stderr:
lines = proc.stderr.readlines()
proc.stderr.close()
for line in lines:
print "Err: %s" % line.strip()
rc = proc.wait()
if __name__ == '__main__':
# api settings for github
github_api_token = None
github_username = None
github_project = None
bz_product = None
bz_version = None
bz_component = None
action='list'
patch=None
tags=[]
untags=[]
issues=[]
skipthis=None
args=sys.argv[1:]
for i in range(0, len(args)):
if skipthis:
skipthis=None
continue
is_number = re.search("[0-9]+", args[i])
if args[i] == '-h' or args[i] == '--help' or args[i] == 'help':
print "github-issue - Tool for interacting with GitHub Issues from the command line"
print ""
print "Usage: github-issue [options] command [issues]"
print ""
print "Options:"
print " -u,--user - Your github username"
print " -t,--token - Your personal API token obtained from https://github.com/account/admin"
print " -r,--repo, --repository The github repository you wish to interact with"
print ""
print "Simple Commands:"
print " tags - List labels used by the project"
print " list - List all the project's open bugs"
print " start - Start working on the listed issue(s), sets a label called 'In Progress'"
print " close - Close the listed issue(s), unsets the 'In Progress' label"
print " clone-rhel - Clone the specified issue(s) to a bugzilla for RHEL 6"
print " clone-fedora - Clone the specified issue(s) to a bugzilla for Fedora 15"
print ""
print "Contextual Commands:"
print " b,bugs - Label issues with 'Bug', or list existing issues with that label if no issues are specified"
print " f,features - Label issues with 'Feature', or list existing issues with that label if no issues are specified"
print " t,tag text - Apply the specified label to specified issue(s), or list issues with that label otherwise"
print " May be specified multiple times"
print " u,untag text - Remove the specified label from specified issue(s)"
print " May be specified multiple times"
print ""
print "Example usage:"
print " alias g='github-issue -u your_github_username -t your_github_api_token -r ClusterLabs/pacemaker'"
print ""
print " g # List all open issues"
print " g bugs # List all open Bugs"
print " g show 1 # Show details of issue 1"
print " g tag 'My Label' 1 3 # Add 'My Label' to issues 1 and 3"
print " g tag 'My Label' # Shows all issues tagged with 'My Label'"
print " g untag 'Your Label' 3 # Remove 'My Label' from issue 3"
print ""
print "Notes:"
print " Requires: http://packages.python.org/github2/"
print ""
print ""
sys.exit(0)
if args[i] == '-u' or args[i] == '--user':
skipthis=1
github_username=args[i+1]
elif args[i] == '-t' or args[i] == '--token':
skipthis=1
github_api_token=args[i+1]
elif args[i] == '-r' or args[i] == '--repo' or args[i] == '--repository':
skipthis=1
github_project=args[i+1]
elif args[i] == 'b' or args[i] == 'bug' or args[i] == 'bugs' or args[i] == 'ack-bug' or args[i] == 'ack':
tags = []
tags.append('Bug')
untags.append('Feature')
action='tag'
elif args[i] == 'f' or args[i] == 'feature' or args[i] == 'features' or args[i] == 'ack-feature':
tags = []
tags.append('Feature')
untags.append('Bug')
action='tag'
elif args[i] == 'start':
tags.append('In Progress')
elif args[i] == 'close':
untags.append('In Progress')
action='close'
elif args[i] == 't' or args[i] == 'tag':
tags.append(args[i+1])
skipthis=1
elif args[i] == 'u' or args[i] == 'untag':
untags.append(args[i+1])
skipthis=1
elif args[i] == 'clone-fedora':
action='clone'
bz_product = 'Fedora'
bz_version = '15'
bz_component = 'pacemaker'
elif args[i] == 'clone-rhel':
action='clone'
bz_product = 'Red Hat Enterprise Linux 6'
bz_version = '6.2'
bz_component = 'pacemaker'
elif is_number:
issues.append(int(args[i]))
# Target shortcuts
elif args[i] == 'p' or args[i] == 'pcmk' or args[i] == 'pacemaker':
github_project='ClusterLabs/pacemaker'
else:
action=args[i]
if not(github_project):
print "You must specify a GitHub project to operate on"
sys.exit(1)
tags = set(tags)
untags = set(untags)
issues = set(issues)
github = Github(username=github_username, api_token=github_api_token)
if len(issues):
for issue in issues:
if action == 'close':
github.issues.close(github_project, issue)
elif action == 'reopen':
github.issues.reopen(github_project, issue)
elif action == 'show':
issue_detail(github, github_project, issue)
continue
elif action == 'clone':
bz_clone(github_project, issue, bz_product, bz_version, bz_component)
continue
elif action != 'list':
print "Unknown action: %s" % action
sys.exit(1)
for tag in tags:
github.issues.add_label(github_project, issue, tag)
if tag == "Bug" or tag == "Feature":
github.issues.add_label(github_project, issue, 'Accepted')
for tag in untags:
try:
github.issues.remove_label(github_project, issue, tag)
except:
pass
#github.issues.comment(github_project, num, """Some comment here""")
elif len(tags):
list_tag(github, github_project, tags)
elif action == 'list':
list_all(github, github_project)
elif action == 'tags':
list_tags(github, github_project)
else:
print "Unknown action: %s" % action