-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-to-github-migration replace roundup summary script #91738
base: main
Are you sure you want to change the base?
Changes from all commits
df0c68e
d1d7faf
beface5
dd3d022
24b5b8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import json | ||
import os | ||
from datetime import date, timedelta | ||
from typing import Iterable | ||
|
||
import requests | ||
|
||
ISSUE_ENDPOINT = "https://github.com/python/cpython/issues" | ||
SEARCH_ENDPOINT = "https://api.github.com/search/issues" | ||
GRAPHQL_ENDPOINT = "https://api.github.com/graphql" | ||
MAILGUN_ENDPOINT = "https://api.mailgun.net/v3/mg.python.org" | ||
|
||
|
||
def get_issue_counts(token: str) -> tuple[int, int]: | ||
"""use the GraphQL API to get the number of opened and closed issues | ||
without having to query every single issue and count them.""" | ||
data = { | ||
"query": """ | ||
{ | ||
repository(owner: "python", name: "cpython") { | ||
open: issues(states: OPEN) { totalCount } | ||
closed: issues(states: CLOSED) { totalCount } | ||
} | ||
} | ||
""" | ||
} | ||
response = requests.post(GRAPHQL_ENDPOINT, json=data, headers={ | ||
"Authorization": f"Bearer {token}", | ||
"accept": "application/vnd.github.v3+json" | ||
}) | ||
repo = response.json()["data"]["repository"] | ||
open = repo["open"]["totalCount"] | ||
closed = repo["closed"]["totalCount"] | ||
return open, closed | ||
|
||
def get_issues(filters: Iterable[str], token: str, all_: bool = True): | ||
"""return a list of results from the Github search API""" | ||
# TODO: if there are more than 100 issues, we need to include pagination | ||
# this doesn't occur very often, but it should still be included just incase. | ||
data = {"query": f""" | ||
{{ | ||
search(query:"{' '.join(filters)}" type: ISSUE first: 100) | ||
{{ | ||
pageInfo {{ hasNextPage endCursor startCursor }} | ||
nodes {{ | ||
... on Issue {{ | ||
title number author {{ login }} closedAt createdAt | ||
}} | ||
}} | ||
}} | ||
}} | ||
"""} | ||
response = requests.post(GRAPHQL_ENDPOINT, json=data, headers={ | ||
"Authorization": f"Bearer {token}", | ||
"accept": "application/vnd.github.v3+json" | ||
}) | ||
return response.json()["data"]["search"]["nodes"] | ||
|
||
def send_report(payload: str, token: str) -> int: | ||
"""send the report using the Mailgun API""" | ||
params = { | ||
"from": "Cpython Issues <[email protected]>", | ||
"to": "", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be configured before merge. |
||
"subject": "Summary of Python tracker Issues", | ||
"template": "issue-tracker-template", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note To Self: Ensure template name matches when added to Mailgun. |
||
"o:tracking-clicks": "no", | ||
"h:X-Mailgun-Variables": payload, | ||
} | ||
response = requests.post( | ||
MAILGUN_ENDPOINT, | ||
auth=("api", token), | ||
json=params) | ||
return response.status_code | ||
|
||
if __name__ == '__main__': | ||
date_from = date.today() - timedelta(days=7) | ||
github_token = os.environ.get("github_api_token") | ||
mailgun_token = os.environ.get("mailgun_api_key") | ||
|
||
total_open, total_closed = get_issue_counts(github_token) | ||
closed = get_issues(("repo:python/cpython", f"closed:>{date_from}", "type:issue"), github_token) | ||
opened = get_issues(("repo:python/cpython", "state:open", f"created:>{date_from}", "type:issue"), github_token) | ||
most_discussed = get_issues( | ||
("repo:python/cpython", "state:open", "type:issue", "sort:comments"), | ||
github_token, | ||
False) | ||
no_comments = get_issues( | ||
("repo:python/cpython", "state:open", "type:issue", "comments:0", "sort:updated"), | ||
github_token, | ||
False) | ||
|
||
payload = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This payload appears to be missing the following keys to render the proposed template:
|
||
"opened_issues": opened, | ||
"closed_issues": closed, | ||
"most_discussed": most_discussed[:10], | ||
"no_comments": no_comments[:15], | ||
"total_open": total_open, | ||
"total_closed": total_closed, | ||
"week_delta": len(opened) - len(closed), | ||
} | ||
status_code = send_report(json.dumps(payload), mailgun_token) | ||
if status_code == 200: | ||
print("successfully sent email") | ||
else: | ||
# in this case, fail the GitHub action | ||
print("failed to send email", status_code) | ||
exit(1) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: weekly-summary | ||
|
||
on: | ||
schedule: | ||
- cron: "15 19 * * FRI" | ||
|
||
jobs: | ||
roundup-summary: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
issues: read | ||
steps: | ||
- name: checkout repo | ||
uses: actions/checkout@v2 | ||
- name: setup python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.10.1 | ||
- name: install deps | ||
run: pip install requests | ||
- name: execute script | ||
run: | | ||
python -u ./.github/actions/roundup_summary.py | ||
env: | ||
github_api_token: ${{ secrets.GITHUB_TOKEN }} | ||
mailgun_api_key: ${{ secrets.PSF_MAILGUN_KEY }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this TODO be addressed before merge? If not is there something we should put in place to make clear that there weren't magically just 100 issues a given week?