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
commit-message: 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

View File

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