-
Notifications
You must be signed in to change notification settings - Fork 710
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ao-fix-backing-filtering-on-disputes
* master: (167 commits) Upgrade accidentally downgraded deps (#5365) [Pools] Fix issues with member migration to `DelegateStake` (#4822) Unify `no_genesis` check (#5360) [CI] Fix prdoc command (#5358) Beefy: add benchmarks for `report_fork_voting()` (#5188) Fix OurViewChange small race (#5356) Make ticket non-optional and add ensure_successful method to Consideration trait (#5359) [tests] dedup test code, add more tests, improve naming and docs (#5338) Stop running the wishlist workflow on forks (#5297) Migrate foreign assets v3::Location to v4::Location (#4129) Minor clean up (#5284) [Pools] Ensure members can always exit the pool gracefully (#4998) StorageWeightReclaim: set to node pov size if higher (#5281) [Bot] Add prdoc generation (#5331) Small nits found accidentally along the way (#5341) Create subsystem-benchmarks.yml (#5325) Bump libp2p-identity from 0.2.8 to 0.2.9 (#5232) Bump authoring duration for async backing to 2s. (#5195) Fix spelling issues (#5206) Bump the known_good_semver group across 1 directory with 3 updates (#5315) ...
- Loading branch information
Showing
1,093 changed files
with
32,091 additions
and
13,240 deletions.
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
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
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
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
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,112 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
Generate the PrDoc for a Pull Request with a specific number, audience and bump level. | ||
It downloads and parses the patch from the GitHub API to opulate the prdoc with all modified crates. | ||
This will delete any prdoc that already exists for the PR if `--force` is passed. | ||
Usage: | ||
python generate-prdoc.py --pr 1234 --audience "TODO" --bump "TODO" | ||
""" | ||
|
||
import argparse | ||
import os | ||
import re | ||
import sys | ||
import subprocess | ||
import toml | ||
import yaml | ||
import requests | ||
|
||
from github import Github | ||
import whatthepatch | ||
from cargo_workspace import Workspace | ||
|
||
# Download the patch and pass the info into `create_prdoc`. | ||
def from_pr_number(n, audience, bump, force): | ||
print(f"Fetching PR '{n}' from GitHub") | ||
g = Github() | ||
|
||
repo = g.get_repo("paritytech/polkadot-sdk") | ||
pr = repo.get_pull(n) | ||
|
||
patch_url = pr.patch_url | ||
patch = requests.get(patch_url).text | ||
|
||
create_prdoc(n, audience, pr.title, pr.body, patch, bump, force) | ||
|
||
def create_prdoc(pr, audience, title, description, patch, bump, force): | ||
path = f"prdoc/pr_{pr}.prdoc" | ||
|
||
if os.path.exists(path): | ||
if force == True: | ||
print(f"Overwriting existing PrDoc for PR {pr}") | ||
else: | ||
print(f"PrDoc already exists for PR {pr}. Use --force to overwrite.") | ||
sys.exit(1) | ||
else: | ||
print(f"No preexisting PrDoc for PR {pr}") | ||
|
||
prdoc = { "doc": [{}], "crates": [] } | ||
|
||
prdoc["title"] = title | ||
prdoc["doc"][0]["audience"] = audience | ||
prdoc["doc"][0]["description"] = description | ||
|
||
workspace = Workspace.from_path(".") | ||
|
||
modified_paths = [] | ||
for diff in whatthepatch.parse_patch(patch): | ||
modified_paths.append(diff.header.new_path) | ||
|
||
modified_crates = {} | ||
for p in modified_paths: | ||
# Go up until we find a Cargo.toml | ||
p = os.path.join(workspace.path, p) | ||
while not os.path.exists(os.path.join(p, "Cargo.toml")): | ||
p = os.path.dirname(p) | ||
|
||
with open(os.path.join(p, "Cargo.toml")) as f: | ||
manifest = toml.load(f) | ||
|
||
if not "package" in manifest: | ||
print(f"File was not in any crate: {p}") | ||
continue | ||
|
||
crate_name = manifest["package"]["name"] | ||
if workspace.crate_by_name(crate_name).publish: | ||
modified_crates[crate_name] = True | ||
else: | ||
print(f"Skipping unpublished crate: {crate_name}") | ||
|
||
print(f"Modified crates: {modified_crates.keys()}") | ||
|
||
for crate_name in modified_crates.keys(): | ||
entry = { "name": crate_name } | ||
|
||
if bump == 'silent' or bump == 'ignore' or bump == 'no change': | ||
entry["validate"] = False | ||
else: | ||
entry["bump"] = bump | ||
|
||
print(f"Adding crate {entry}") | ||
prdoc["crates"].append(entry) | ||
|
||
# write the parsed PR documentation back to the file | ||
with open(path, "w") as f: | ||
yaml.dump(prdoc, f) | ||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--pr", type=int, required=True) | ||
parser.add_argument("--audience", type=str, default="TODO") | ||
parser.add_argument("--bump", type=str, default="TODO") | ||
parser.add_argument("--force", type=str) | ||
return parser.parse_args() | ||
|
||
if __name__ == "__main__": | ||
args = parse_args() | ||
force = True if args.force.lower() == "true" else False | ||
print(f"Args: {args}, force: {force}") | ||
from_pr_number(args.pr, args.audience, args.bump, force) |
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|pull)/(\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) |
Oops, something went wrong.