forked from kubernetes/website
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a script util to check if a file is modified by an open PR (kuber…
- Loading branch information
1 parent
a7eeeb7
commit e9da053
Showing
1 changed file
with
70 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
|
||
import click | ||
import requests | ||
from jinja2 import Template | ||
|
||
|
||
@click.command() | ||
@click.argument("path") | ||
@click.option("--tags", | ||
multiple=True, | ||
help="Tags of PullRequest (Can be passed multiple times)") | ||
@click.option("--token", | ||
help="GitHub API token. (Default env variable GITHUB_TOKEN)", | ||
default=os.environ.get("GITHUB_TOKEN", "")) | ||
@click.option("--last-n-pr", | ||
help="Last n-th PullRequests", | ||
default=100) | ||
def main(tags, token, path, last_n_pr): | ||
""" | ||
Find what GitHub pull requests touch a given file. | ||
ex: | ||
./find_pr.py --tags "language/fr" "content/fr/_index.html" | ||
""" | ||
query = Template(""" | ||
query { | ||
repository(name: "website", owner: "kubernetes") { | ||
pullRequests({% if tags %}labels: [{% for tag in tags %}"{{ tag }}", {% endfor %}], {% endif %}last: {{ last_n_pr }}) { | ||
edges { | ||
node { | ||
title | ||
state | ||
url | ||
files (last: 100) { | ||
edges { | ||
node { | ||
path | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
""").render(tags=tags, last_n_pr=last_n_pr) | ||
r = requests.post("https://api.github.com/graphql", | ||
json={"query": query}, | ||
headers={ | ||
"Authorization": "token %s" % token, | ||
"Accept": "application/vnd.github.ocelot-preview+json", | ||
"Accept-Encoding": "gzip" | ||
}) | ||
reply = r.json() | ||
prs = reply['data']['repository']['pullRequests']['edges'] | ||
|
||
for pr in prs: | ||
files = pr["node"]["files"]["edges"] | ||
for f in files: | ||
if path == f["node"]["path"]: | ||
print("%s (%s)" % (pr["node"]["title"], pr["node"]["state"])) | ||
print(pr["node"]["url"]) | ||
print("----------------") | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |