-
Notifications
You must be signed in to change notification settings - Fork 709
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
Introduce a workflow updating the wishlist leaderboards #5085
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from github import Github | ||
import re | ||
import os | ||
from datetime import date | ||
|
||
g = Github(os.getenv("GH_TOKEN")) | ||
|
||
# Regex pattern to match wish format: | ||
wish_pattern = re.compile( | ||
r"I wish for:? (https://github\.com/([a-zA-Z0-9_.-]+)/([a-zA-Z0-9_.-]+)/issues/(\d+))" | ||
) | ||
|
||
wishlist_issue = g.get_repo(os.getenv("WISHLIST_REPOSITORY")).get_issue( | ||
int(os.getenv("WISHLIST_ISSUE_NUMBER")) | ||
) | ||
new_leaderboard = ( | ||
"| Feature Request | Summary | Votes | Status |\n| --- | --- | --- | --- |\n" | ||
) | ||
wishes = {} | ||
issue_details = {} | ||
|
||
for comment in wishlist_issue.get_comments(): | ||
# in the comment body, if there is a string `#(\d)`, replace it with | ||
# https://github.com/paritytech/polkadot-sdk/issues/(number) | ||
updated_body = re.sub( | ||
r"#(\d+)", r"https://github.com/paritytech/polkadot-sdk/issues/\1", comment.body | ||
) | ||
|
||
matches = wish_pattern.findall(updated_body) | ||
for match in matches: | ||
url, org, repo_name, issue_id = match | ||
issue_key = (url, org, repo_name, issue_id) | ||
if issue_key not in wishes: | ||
wishes[issue_key] = [] | ||
|
||
# Get the author and upvoters of the wish comment. | ||
wishes[issue_key].append(comment.user.id) | ||
wishes[issue_key].extend( | ||
[ | ||
reaction.user.id | ||
for reaction in comment.get_reactions() | ||
if reaction.content in ["+1", "heart", "rocket"] | ||
] | ||
) | ||
|
||
# Get upvoters of the desired issue. | ||
desired_issue = g.get_repo(f"{org}/{repo_name}").get_issue(int(issue_id)) | ||
wishes[issue_key].extend( | ||
[ | ||
reaction.user.id | ||
for reaction in desired_issue.get_reactions() | ||
if reaction.content in ["+1", "heart", "rocket"] | ||
] | ||
) | ||
issue_details[url] = [ | ||
desired_issue.title, | ||
"👾 Open" if desired_issue.state == "open" else "✅Closed", | ||
] | ||
|
||
# Count unique wishes - the author of the wish, upvoters of the wish, and upvoters of the desired issue. | ||
for key in wishes: | ||
wishes[key] = len(list(set(wishes[key]))) | ||
|
||
# Sort wishes by count and add to the markdown table | ||
sorted_wishes = sorted(wishes.items(), key=lambda x: x[1], reverse=True) | ||
for (url, _, _, _), count in sorted_wishes: | ||
[summary, status] = issue_details.get(url, "No summary available") | ||
new_leaderboard += f"| {url} | {summary} | {count} | {status} |\n" | ||
new_leaderboard += f"\n> Last updated: {date.today().strftime('%Y-%m-%d')}\n" | ||
print(new_leaderboard) | ||
|
||
new_content = re.sub( | ||
r"(\| Feature Request \|)(.*?)(> Last updated:)(.*?\n)", | ||
new_leaderboard, | ||
wishlist_issue.body, | ||
flags=re.DOTALL, | ||
) | ||
|
||
wishlist_issue.edit(body=new_content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Update wishlist leaderboard | ||
|
||
on: | ||
schedule: | ||
# Run every 3 hours | ||
- cron: '0 */3 * * *' | ||
|
||
permissions: | ||
contents: read | ||
issues: write | ||
|
||
jobs: | ||
update-wishlist-leaderboard: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install PyGithub | ||
- name: Update developer wishlist | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
WISHLIST_REPOSITORY: "paritytech/polkadot-sdk" | ||
WISHLIST_ISSUE_NUMBER: "3900" | ||
run: python .github/scripts/update-wishlist-leaderboard.py | ||
- name: Update user wishlist | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
WISHLIST_REPOSITORY: "paritytech/polkadot-sdk" | ||
WISHLIST_ISSUE_NUMBER: "3901" | ||
run: python .github/scripts/update-wishlist-leaderboard.py |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think every day is fine, but probably this is cheap af :D
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.
The job takes ~1 minute 15 secs to run.
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.
default
ubuntu-latest
are free for public repos