feat: attribute multiple issues addressed in a single PR in awards.csv (#2153)

This commit is contained in:
Bryan Mutai 2025-05-10 21:51:34 +03:00 committed by GitHub
parent f01a5fde00
commit faf11138c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 41 additions and 38 deletions

View File

@ -53,5 +53,5 @@ jobs:
branch: extend-awards/patch branch: extend-awards/patch
commit-message: Extending awards.csv commit-message: Extending awards.csv
title: Extending awards.csv title: Extending awards.csv
body: One or more PR's were merged that solve an issue(s) and awards.csv should be extended. Remembere to delete the branch after merging. body: One or more PR's were merged that solve an issue(s) and awards.csv should be extended. Remember to delete the branch after merging.
delete-branch: true delete-branch: true

View File

@ -15,15 +15,17 @@ def getIssue(n):
j = json.loads(r.text) j = json.loads(r.text)
return j return j
def findIssueInPR(j): def findIssuesInPR(j):
p = re.compile('(#|https://github.com/stackernews/stacker.news/issues/)([0-9]+)') p = re.compile('(#|https://github.com/stackernews/stacker.news/issues/)([0-9]+)')
issues = set()
for m in p.finditer(j['title']): for m in p.finditer(j['title']):
return m.group(2) issues.add(m.group(2))
if not 'body' in j or j['body'] is None: if not 'body' in j or j['body'] is None:
return return
for s in j['body'].split('\n'): for s in j['body'].split('\n'):
for m in p.finditer(s): for m in p.finditer(s):
return m.group(2) issues.add(m.group(2))
return list(issues)
def addAward(user, kind, pr, issue, difficulty, priority, count, amount): def addAward(user, kind, pr, issue, difficulty, priority, count, amount):
if amount >= 1000000 and amount % 1000000 == 0: if amount >= 1000000 and amount % 1000000 == 0:
@ -59,41 +61,42 @@ def countReviews(pr):
def checkPR(i): def checkPR(i):
pr = str(i['number']) pr = str(i['number'])
print('pr %s' % pr) print('pr %s' % pr)
n = findIssueInPR(i) issue_numbers = findIssuesInPR(i)
if not n: if not issue_numbers:
print('pr %s does not solve an issue' % pr) print('pr %s does not solve any issues' % pr)
return return
print('solves issue %s' % n) for n in issue_numbers:
j = getIssue(n) print('solves issue %s' % n)
difficulty = '' j = getIssue(n)
amount = 0 difficulty = ''
priority = '' amount = 0
multiplier = 1 priority = ''
for l in j['labels']: multiplier = 1
for d in difficulties: for l in j['labels']:
if l['name'] == 'difficulty:' + d: for d in difficulties:
difficulty = d if l['name'] == 'difficulty:' + d:
amount = difficulties[d] difficulty = d
for p in priorities: amount = difficulties[d]
if l['name'] == 'priority:' + p: for p in priorities:
priority = p if l['name'] == 'priority:' + p:
multiplier = priorities[p] priority = p
if amount * multiplier <= 0: multiplier = priorities[p]
print('issue gives no award') if amount * multiplier <= 0:
return print('issue gives no award')
count = countReviews(pr) continue
if count >= 10: count = countReviews(pr)
print('too many reviews, no award') if count >= 10:
return print('too many reviews, no award')
if count > 0: continue
print('%d reviews, %d%% reduction' % (count, count * 10)) if count > 0:
award = amount * multiplier * (10 - count) / 10 print('%d reviews, %d%% reduction' % (count, count * 10))
print('award is %d' % award) award = amount * multiplier * (10 - count) / 10
if i['user']['login'] not in ignored: print('award is %d' % award)
addAward(i['user']['login'], 'pr', '#' + pr, '#' + n, difficulty, priority, count, award) if i['user']['login'] not in ignored:
if j['user']['login'] not in ignored: addAward(i['user']['login'], 'pr', '#' + pr, '#' + n, difficulty, priority, count, award)
count = 0 if j['user']['login'] not in ignored:
addAward(j['user']['login'], 'issue', '#' + pr, '#' + n, difficulty, priority, count, int(award / 10)) count = 0
addAward(j['user']['login'], 'issue', '#' + pr, '#' + n, difficulty, priority, count, int(award / 10))
with open(fn, 'r') as f: with open(fn, 'r') as f:
for s in f: for s in f: