Skip to content

Commit

Permalink
Merge pull request #301 from marketulinek/marketulinek/generate-grant…
Browse files Browse the repository at this point in the history
…s-edit

Marketulinek/generate grants edit
  • Loading branch information
honzajavorek committed Nov 11, 2022
2 parents c993efd + f442406 commit 60fee83
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions _scripts/generate_grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,45 @@ def get_votes(reactions, voted_at, board_history=None):
yield {'name': name, 'text': text}


def get_lock_date(events):
for event in reversed(events):
if event['event'] == 'locked':
return to_date(event['created_at'])


if __name__ == '__main__':
res = requests.get(GITHUB_API_URL, headers=GITHUB_API_HEADERS,
params={'per_page': 100, 'state': 'closed'})
res.raise_for_status()

grants = []
for issue in res.json():
voted_at = to_date(issue['closed_at'])

res = requests.get(issue['reactions']['url'],
headers=GITHUB_API_HEADERS)
res.raise_for_status()
votes = list(get_votes(res.json(), voted_at))

labels = [label['name'] for label in issue['labels']]
if 'approved' not in labels and 'rejected' not in labels:
# skip unlabeled, e.g. https://github.com/pyvec/money/issues/1
continue

if issue['locked']:
res = requests.get(issue['events_url'],
headers=GITHUB_API_HEADERS,
params={'per_page': 100})
res.raise_for_status()

if res.headers.get('link'):
raise NotImplementedError(f"The number of events of issue #{issue['number']} "
"is paginated and this code isn't yet designed "
"to handle this!")
else:
voted_at = get_lock_date(res.json())
else:
voted_at = to_date(issue['closed_at'])

res = requests.get(issue['reactions']['url'],
headers=GITHUB_API_HEADERS)
res.raise_for_status()
votes = list(get_votes(res.json(), voted_at))

grants.append({
'title': issue['title'],
'description': remove_comments(issue['body']),
Expand Down

0 comments on commit 60fee83

Please sign in to comment.