Skip to content

Commit 2f5b421

Browse files
authored
Merge pull request #2348 from manics/dependencies-list-prs
Include list of merged PRs in dependency bumps for jupyterhub repos
2 parents 44a612d + a8cdd72 commit 2f5b421

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

.github/workflows/watch-dependencies.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ jobs:
7676
if: steps.local.outputs.tag != steps.latest.outputs.tag
7777
run: git --no-pager diff --color=always
7878

79+
- name: PR summary
80+
id: prsummary
81+
if: steps.local.outputs.tag != steps.latest.outputs.tag
82+
# Needs to be a single line string
83+
# https://trstringer.com/github-actions-multiline-strings/#option-1---string-substitution
84+
run: |
85+
pip install PyGithub
86+
PR_LIST=$(./scripts/get-prs.py ${{matrix.repository}} ${{steps.local.outputs.tag}} ${{steps.latest.outputs.tag}} --github-action-escape)
87+
echo "::set-output name=prs::$PR_LIST"
88+
env:
89+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
90+
7991
# ref: https://github.com/peter-evans/create-pull-request
8092
- name: Create a PR
8193
uses: peter-evans/[email protected]
@@ -93,6 +105,8 @@ jobs:
93105
body: |
94106
Updates mybinder to depend on the `${{ matrix.registry }}/${{ matrix.repository }}` image version `${{ steps.latest.outputs.tag }}` from version `${{ steps.local.outputs.tag }}`.
95107
108+
${{ steps.prsummary.outputs.prs }}
109+
96110
## Related
97111
98112
- Source code: ${{ matrix.source_url }}
@@ -119,30 +133,35 @@ jobs:
119133
chart_dep_app_changelog_url: "https://github.com/jupyterhub/binderhub/blob/master/CHANGES.md"
120134
chart_dep_source_url: "https://github.com/jupyterhub/binderhub/tree/master/helm-chart"
121135
chart_dep_devel_flag: "--devel"
136+
github_repo: jupyterhub/binderhub
122137

123138
- chart_dep_name: ingress-nginx
124139
chart_dep_chart_changelog_url: "https://github.com/kubernetes/ingress-nginx/tree/main/charts/ingress-nginx#upgrading-chart"
125140
chart_dep_app_changelog_url: "https://github.com/kubernetes/ingress-nginx/blob/master/Changelog.md"
126141
chart_dep_source_url: "https://github.com/kubernetes/ingress-nginx/tree/master/charts/ingress-nginx"
127142
chart_dep_devel_flag: ""
143+
github_repo: ""
128144

129145
- chart_dep_name: prometheus
130146
chart_dep_chart_changelog_url: "https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus#upgrading-chart"
131147
chart_dep_app_changelog_url: "https://github.com/prometheus/prometheus/blob/master/CHANGELOG.md"
132148
chart_dep_source_url: https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus
133149
chart_dep_devel_flag: ""
150+
github_repo: ""
134151

135152
- chart_dep_name: grafana
136153
chart_dep_chart_changelog_url: "https://github.com/grafana/helm-charts/tree/main/charts/grafana#upgrading-an-existing-release-to-a-new-major-version"
137154
chart_dep_app_changelog_url: "https://github.com/grafana/grafana/blob/master/CHANGELOG.md"
138155
chart_dep_source_url: "https://github.com/grafana/helm-charts/tree/main/charts/grafana"
139156
chart_dep_devel_flag: ""
157+
github_repo: ""
140158

141159
- chart_dep_name: cryptnono
142160
chart_dep_chart_changelog_url: ""
143161
chart_dep_app_changelog_url: ""
144162
chart_dep_source_url: "https://github.com/yuvipanda/cryptnono/"
145163
chart_dep_devel_flag: "--devel"
164+
github_repo: ""
146165

147166
steps:
148167
- uses: actions/checkout@v3
@@ -185,6 +204,18 @@ jobs:
185204
- name: git diff
186205
run: git --no-pager diff --color=always
187206

207+
- name: PR summary
208+
id: prsummary
209+
if: matrix.github_repo && (steps.local.outputs.version != steps.latest.outputs.version)
210+
# Needs to be a single line string
211+
# https://trstringer.com/github-actions-multiline-strings/#option-1---string-substitution
212+
run: |
213+
pip install PyGithub
214+
PR_LIST=$(./scripts/get-prs.py ${{matrix.github_repo}} ${{steps.local.outputs.version}} ${{steps.latest.outputs.version}} --github-action-escape)
215+
echo "::set-output name=prs::$PR_LIST"
216+
env:
217+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
218+
188219
# ref: https://github.com/peter-evans/create-pull-request
189220
- name: Create a PR
190221
uses: peter-evans/[email protected]
@@ -207,6 +238,8 @@ jobs:
207238
Chart.yaml's version | `${{ steps.local.outputs.version }}` | `${{ steps.latest.outputs.version }}`
208239
Chart.yaml's appVersion | `${{ steps.local.outputs.appVersion }}` | `${{ steps.latest.outputs.appVersion }}`
209240
241+
${{ steps.prsummary.outputs.prs }}
242+
210243
## Related
211244
212245
- Chart source code: ${{ matrix.chart_dep_source_url }}

scripts/get-prs.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
parser.add_argument(
33+
"--github-action-escape",
34+
action="store_true",
35+
help="Escape output for GitHub Action",
36+
)
37+
parser.add_argument(
38+
"--max-commits",
39+
type=int,
40+
default=100,
41+
help="Maximum number of commits to check",
42+
)
43+
44+
args = parser.parse_args()
45+
46+
gh = github.Github(token)
47+
r = gh.get_repo(args.repo)
48+
49+
start = extract_gitref(args.start)
50+
end = extract_gitref(args.end)
51+
52+
prs = set()
53+
git_compare = r.compare(start, end)
54+
commits = list(git_compare.commits)
55+
if len(commits) > args.max_commits:
56+
pr_summaries = [
57+
f"{len(commits)} commits between {start} and {end}, not searching for PRs"
58+
]
59+
else:
60+
for c in commits:
61+
prs.update(c.get_pulls())
62+
pr_summaries = [
63+
f"- [#{pr.number}]({pr.html_url}) {pr.title}"
64+
for pr in sorted(prs, key=lambda pr: pr.number)
65+
]
66+
67+
md = ["# PRs"] + pr_summaries + ["", f"{r.html_url}/compare/{start}...{end}"]
68+
if args.github_action_escape:
69+
print("%0A".join(md))
70+
else:
71+
print("\n".join(md))

0 commit comments

Comments
 (0)