Skip to content

Commit 9333224

Browse files
authored
Improve PR number parsing resiliency (#9860)
This sort of thing failed before, because there were two PR numbers in the title: * [Fix lint error from #9854 (#9856)](fba7990) Now it won't
1 parent 2bebafe commit 9333224

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

.github/workflows/auto_docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
GH_TOKEN: ${{ secrets.RERUN_BOT_TOKEN }}
3535
run: |
3636
commit_message=$(git log --pretty=format:%s -n 1 ${{ github.sha }})
37-
pr_number=$(echo $commit_message | grep -oP '(?<=#)\d+')
37+
pr_number=$(python3 scripts/ci/parse_pr_number.py "$commit_message")
3838
3939
result=$(gh pr view $pr_number --json labels | jq -r 'any(.labels[].name; . == "deploy docs")')
4040
echo "result=$result" >> $GITHUB_OUTPUT

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
rerun_cpp/docs/**/*
22

33
rerun_py/docs/templates/**
4+
rerun_py/site/**
45

56
rerun_js/web-viewer/re_viewer_bg.js
67
rerun_js/web-viewer/re_viewer.js

scripts/ci/parse_pr_number.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python3
2+
3+
from __future__ import annotations
4+
5+
import argparse
6+
import sys
7+
8+
9+
def parse_pr_number(commit_message: str) -> int:
10+
first_line = commit_message.splitlines()[0]
11+
start_idx = first_line.rfind("(#")
12+
if start_idx == -1:
13+
raise Exception("failed to parse PR number: no PR number in commit message, expected to find '(#1234)'")
14+
start_idx += 2 # trim '(#'
15+
16+
end_idx = first_line.find(")", start_idx)
17+
if end_idx == -1:
18+
raise Exception("failed to parse PR number: unclosed parenthesis, expected to find '(#1234)'")
19+
# end idx is exclusive, no need to trim
20+
21+
digits = first_line[start_idx:end_idx]
22+
return int(digits)
23+
24+
25+
def main() -> None:
26+
parser = argparse.ArgumentParser()
27+
parser.add_argument("commit_message", type=str)
28+
29+
args, unknown = parser.parse_known_args()
30+
for arg in unknown:
31+
print(f"Unknown argument: {arg}")
32+
33+
pr_number = parse_pr_number(args.commit_message)
34+
sys.stdout.write(str(pr_number))
35+
sys.stdout.flush()
36+
37+
38+
if __name__ == "__main__":
39+
main()

0 commit comments

Comments
 (0)