Skip to content

Commit 16f977b

Browse files
committed
Escape for multiline github output in get-prs.py
1 parent a9d3244 commit 16f977b

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

.github/workflows/watch-dependencies.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ jobs:
8383
# https://trstringer.com/github-actions-multiline-strings/#option-1---string-substitution
8484
run: |
8585
pip install PyGithub
86-
PR_LIST=$(./scripts/get-prs.py ${{matrix.repository}} ${{steps.local.outputs.tag}} ${{steps.latest.outputs.tag}})
87-
PR_LIST="${PR_LIST//$'\n'/'%0A'}"
86+
PR_LIST=$(./scripts/get-prs.py ${{matrix.repository}} ${{steps.local.outputs.tag}} ${{steps.latest.outputs.tag}} --github-action-escape)
8887
echo "::set-output name=prs::$PR_LIST"
8988
env:
9089
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -213,8 +212,7 @@ jobs:
213212
# https://trstringer.com/github-actions-multiline-strings/#option-1---string-substitution
214213
run: |
215214
pip install PyGithub
216-
PR_LIST=$(./scripts/get-prs.py ${{matrix.github_repo}} ${{steps.local.outputs.version}} ${{steps.latest.outputs.version}})
217-
PR_LIST="${PR_LIST//$'\n'/'%0A'}"
215+
PR_LIST=$(./scripts/get-prs.py ${{matrix.github_repo}} ${{steps.local.outputs.version}} ${{steps.latest.outputs.version}} --github-action-escape)
218216
echo "::set-output name=prs::$PR_LIST"
219217
env:
220218
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

scripts/get-prs.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ def extract_gitref(s):
2929
parser.add_argument("repo", help="The repository in format user/repo")
3030
parser.add_argument("start", help="commit or image/chart version from which to start")
3131
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+
)
3237

3338
args = parser.parse_args()
3439

@@ -44,5 +49,12 @@ def extract_gitref(s):
4449
s = gh.search_issues("", type="pr", repo=args.repo, sha=c.sha)
4550
prs.update(s)
4651

47-
for pr in sorted(prs):
48-
print(f"- [#{pr.number}]({pr.html_url}) {pr.title}")
52+
53+
pr_summaries = [
54+
f"- [#{pr.number}]({pr.html_url}) {pr.title}"
55+
for pr in sorted(prs, key=lambda pr: pr.number)
56+
]
57+
if args.github_action_escape:
58+
print("%0A".join(pr_summaries))
59+
else:
60+
print("\n".join(pr_summaries))

0 commit comments

Comments
 (0)