Skip to content

Commit d3b6a63

Browse files
committed
Add script to summarise PRs between a range of git-refs
1 parent 868e24b commit d3b6a63

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

scripts/get-prs.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python
2+
import os
3+
import re
4+
from argparse import ArgumentParser
5+
6+
import github
7+
8+
9+
def extract_gitref(s):
10+
"""
11+
Extract git ref from a container registry tag or Helm chart version
12+
13+
Examples:
14+
- 2022.02.0 -> 2022.02.0
15+
- 2022.02.0-90.g0345a86 -> 0345a86
16+
- 0.2.0 -> 0.2.0
17+
- 0.2.0-n1011.hb49edf6 -> b49edf6
18+
- 0.2.0-0.dev.git.2752.h3450e52 -> 3450e52
19+
"""
20+
m = re.match(r"[\d\.]+-[\w\.]+[gh]([0-9a-f]+)", s)
21+
if m:
22+
return m.group(1)
23+
return s
24+
25+
26+
token = os.getenv("GITHUB_TOKEN")
27+
28+
parser = ArgumentParser(description="Summarise PRs from a repo")
29+
parser.add_argument("repo", help="The repository in format user/repo")
30+
parser.add_argument("start", help="commit or image/chart version from which to start")
31+
parser.add_argument("end", help="commit or image/chart version to which to end")
32+
33+
args = parser.parse_args()
34+
35+
gh = github.Github(token)
36+
r = gh.get_repo(args.repo)
37+
38+
start = extract_gitref(args.start)
39+
end = extract_gitref(args.end)
40+
41+
prs = set()
42+
git_compare = r.compare(start, end)
43+
for c in git_compare.commits:
44+
s = gh.search_issues("", type="pr", repo=args.repo, sha=c.sha)
45+
prs.update(s)
46+
47+
for pr in sorted(prs):
48+
print(f"- [#{pr.number}]({pr.html_url}) {pr.title}")

0 commit comments

Comments
 (0)