-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgengee-query
executable file
·248 lines (193 loc) · 9.25 KB
/
gengee-query
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import argparse
from collections import OrderedDict
from gengee import common, database, __version__ as version
from gengee.portage import *
from portage.versions import *
import prettytable
parser = argparse.ArgumentParser('gengee-query',description='Query the Gengee pull database')
parser.add_argument('-a', '--author', nargs='?', help="show open PR's for author, if empty show all authors", metavar='author', const="[all]", dest='author')
parser.add_argument('-c', '--conflict', help="show PR's referening the same files", action="store_true", dest='conflict')
parser.add_argument('-g', '--categories', help="sort all categories", action="store_true", dest='categories')
parser.add_argument('-l', '--label', nargs='?', help="show open PR's for label, if empty show all labels", metavar='label', const="[all]", dest='label')
parser.add_argument('-m', '--maintainer', nargs='?', help="show open PR's for maintainer, if empty show all maintainers", metavar='maintainer', const="[all]", dest='maintainer')
parser.add_argument('-o', '--outdated', help="show PR's that are outdated by current tree", action="store_true", dest='outdated')
parser.add_argument('-p', '--problem', help="show PR's that have some kind of problem", action="store_true", dest='problem')
parser.add_argument('-s', '--small', help="small QA fixes", action="store_true", dest='small')
formatgroup = parser.add_argument_group('format options')
formatgroup.add_argument('-f', '--format', choices=['html','ascii'], help="main operating mode, add or update stuff", default='ascii', dest='format')
args = parser.parse_args()
config = common.getConfig()
db = database.Database(config["dbpath"])
try:
db.read()
pulls = db.getPulls()
except Exception as e:
print(str(e))
exit()
if not common.checkCompatibleDatabase(version,db.db["version"]):
print("database outdated, update first")
exit()
if args.author == "[all]":
authors = {}
for pull in pulls:
if pull["user"] not in authors:
authors[pull["user"]] = 1
else:
authors[pull["user"]] += 1
sorted_authors = OrderedDict(sorted(authors.items(), key=lambda kv: kv[1]))
x = prettytable.PrettyTable(["author","count"])
for author in sorted_authors:
x.add_row([author,str(sorted_authors[author])])
common.printTable(x,args.format)
if args.author and args.author != "[all]":
x = prettytable.PrettyTable(["PR","title","comments"])
for pull in pulls:
if pull["user"] == args.author:
x.add_row([common.getPrValue(pull["number"],args.format),pull["title"],pull["comment_count"]])
common.printTable(x,args.format)
if args.categories:
categories = {}
for pull in pulls:
for package in pull["packages"]:
category = package.split("/")[0]
if category not in categories:
categories[category] = 1
else:
categories[category] += 1
sorted_categories = OrderedDict(sorted(categories.items(), key=lambda kv: kv[1]))
x = prettytable.PrettyTable(["category","count"])
for category in sorted_categories:
x.add_row([category,str(sorted_categories[category])])
common.printTable(x,args.format)
if args.conflict:
total_files = {}
for pull in pulls:
for file in pull["files"]:
if file not in total_files:
total_files[file] = []
total_files[file].append(pull)
else:
total_files[file].append(pull)
x = prettytable.PrettyTable(["PR","title","file","author"])
for file in total_files:
if len(total_files[file]) > 1:
filename = file
for pull in total_files[file]:
x.add_row([common.getPrValue(pull["number"],args.format),pull["title"],filename,pull["user"]])
filename = ""
common.printTable(x,args.format)
if args.label == "[all]":
labels = {}
for pull in pulls:
for label in pull["labels"]:
if label not in labels:
labels[label] = 1
else:
labels[label] += 1
sorted_labels = OrderedDict(sorted(labels.items(), key=lambda kv: kv[1]))
x = prettytable.PrettyTable(["label","count"])
for label in sorted_labels:
x.add_row([label,str(sorted_labels[label])])
common.printTable(x,args.format)
if args.label and args.label != "[all]":
x = prettytable.PrettyTable(["PR","title","comments"])
for pull in pulls:
if args.label in pull["labels"]:
x.add_row([common.getPrValue(pull["number"],args.format),pull["title"],pull["comment_count"]])
common.printTable(x,args.format)
if args.maintainer == "[all]":
maintainers = {}
for pull in pulls:
for maintainer in pull["maintainers"]:
if maintainer not in maintainers:
maintainers[maintainer] = 1
else:
maintainers[maintainer] += 1
sorted_maintainers = OrderedDict(sorted(maintainers.items(), key=lambda kv: kv[1]))
x = prettytable.PrettyTable(["maintainer","count"])
for maintainer in sorted_maintainers:
x.add_row([maintainer,str(sorted_maintainers[maintainer])])
common.printTable(x,args.format)
if args.maintainer and args.maintainer != "[all]":
x = prettytable.PrettyTable(["PR","title","comments"])
for pull in pulls:
if args.maintainer in pull["maintainers"]:
x.add_row([common.getPrValue(pull["number"],args.format),pull["title"],pull["comment_count"]])
common.printTable(x,args.format)
if args.outdated:
x = prettytable.PrettyTable(["PR","title","pull version","tree version"])
for pull in pulls:
# hard to determine what's happening in the PR with multiple packages, ebuilds or commits
if len(pull["ebuilds"]) != 1 or pull["commit_count"] > 1:
continue
if "do not merge" in pull["labels"]:
continue
package = pull["packages"][0]
ebuild = pull["ebuilds"][0]
current_ebuilds = getCurrentEbuilds(package)
# only add LAST RITED when not a new package
# when new package, it should go to the other checks
if not current_ebuilds and not "new package" in pull["labels"]:
x.add_row([common.getPrValue(pull["number"],args.format),pull["title"],ebuild,"LAST RITED"])
continue
if "bump" in pull["keywords"] and not "eapi" in pull["keywords"]:
for current_ebuild in current_ebuilds:
if current_ebuild[-4:] == "9999":
continue
try:
if pkgcmp(pkgsplit(ebuild),pkgsplit(current_ebuild)) <= 0:
x.add_row([common.getPrValue(pull["number"],args.format),pull["title"],ebuild,current_ebuild])
break
except:
pass
else:
for current_ebuild in current_ebuilds:
if current_ebuild[-4:] == "9999":
continue
try:
if pkgcmp(pkgsplit(ebuild),pkgsplit(current_ebuild)) < 0:
x.add_row([common.getPrValue(pull["number"],args.format),pull["title"],ebuild,current_ebuild])
break
except:
pass
common.printTable(x,args.format)
x = prettytable.PrettyTable(["PR","title","bugid","issue"])
for pull in pulls:
for bug in pull["bugs"]:
if pull["bugs"][bug] == "RESOLVED/FIXED":
x.add_row([common.getPrValue(pull["number"],args.format),pull["title"],"#" + bug,"PR references resolved fixed bug"])
common.printTable(x,args.format)
if args.problem:
x = prettytable.PrettyTable(["PR","title","problem"])
masked = getPackageMask()
for pull in pulls:
if "bump" in pull["keywords"] and not "eapi" in pull["keywords"] and pull["file_count"] < config["file_scan_max"] and not pull["manifest"]:
x.add_row([common.getPrValue(pull["number"],args.format),pull["title"],"version bump, but no manifest"])
for package in pull["packages"]:
if package in masked:
x.add_row([common.getPrValue(pull["number"],args.format),pull["title"],"package " + package + " in package.mask"])
summaries = []
for sha in pull["commits"]:
messagelines = pull["commits"][sha]["message"].splitlines()
summaries.append(messagelines[0])
if len(set(summaries)) < len(summaries):
x.add_row([common.getPrValue(pull["number"],args.format),pull["title"],"PR has multiple commits with same summary"])
# no reliable to retrieve
# if not pull["mergeable"]:
# x.add_row([common.getPrValue(pull["number"],args.format),pull["title"],"merge conflict"])
common.printTable(x,args.format)
if args.small:
x = prettytable.PrettyTable(["PR","title","comments"])
for pull in pulls:
if len(pull["packages"]) != 1:
continue
if ("bump" or "security" or "cross" ) in pull["keywords"]:
continue
if pull["manifest"]:
continue
if ("no signoff" or "do not merge") in pull["labels"]:
continue
x.add_row([common.getPrValue(pull["number"],args.format),pull["title"],pull["comment_count"]])
common.printTable(x,args.format)