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,10 +61,11 @@ 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
for n in issue_numbers:
print('solves issue %s' % n) print('solves issue %s' % n)
j = getIssue(n) j = getIssue(n)
difficulty = '' difficulty = ''
@ -80,11 +83,11 @@ def checkPR(i):
multiplier = priorities[p] multiplier = priorities[p]
if amount * multiplier <= 0: if amount * multiplier <= 0:
print('issue gives no award') print('issue gives no award')
return continue
count = countReviews(pr) count = countReviews(pr)
if count >= 10: if count >= 10:
print('too many reviews, no award') print('too many reviews, no award')
return continue
if count > 0: if count > 0:
print('%d reviews, %d%% reduction' % (count, count * 10)) print('%d reviews, %d%% reduction' % (count, count * 10))
award = amount * multiplier * (10 - count) / 10 award = amount * multiplier * (10 - count) / 10