Skip to content

Commit e65922c

Browse files
authored
Update autolabeler again again (#1870)
- fix breakage when diff contains very long line (#1861) - unhardcode repository - add more logging
1 parent 4fbdb18 commit e65922c

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

.github/workflows/label.yml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
label-pull-request:
1313
runs-on: ubuntu-latest
1414

15-
# This workflow is not useful to forks without significantly updating the workflow script.
15+
# Disabled by default for forks since this is probably not useful.
1616
if: ${{ github.repository == 'TurboWarp/extensions' }}
1717

1818
permissions:
@@ -34,21 +34,27 @@ jobs:
3434
got_any_specific_label=false
3535
3636
if [[ "$BASE_REF" == "master" ]]; then
37+
echo "Downloading pull request diff"
38+
3739
# Download just the diff so it is harder to accidentally run any code from the pull request.
38-
gh pr diff --repo TurboWarp/extensions "$PR_NUMBER" > pr.diff
40+
gh pr diff --repo "$GH_REPO" "$PR_NUMBER" | tee pr.diff
3941
40-
# Note that pcregrep exits with success on any match, failure on no match
41-
if pcregrep -M "^--- /dev/null\n\+\+\+ b/extensions/" pr.diff; then
42+
# Note that pcregrep exits with success on any match, failure on no match or internal buffer overflow.
43+
# To avoid errors on big diffs like compressed SVGs, increase the internal buffer size dramatically.
44+
# This is pretty big and uses ~50MB of RAM but the machines can fit that just fine.
45+
if pcregrep --buffer-size 16777216 -M "^--- /dev/null\n\+\+\+ b/extensions/" pr.diff; then
4246
# Example:
4347
# --- /dev/null
4448
# +++ b/extensions/DangoCat/extension.js
45-
gh pr edit --repo TurboWarp/extensions "$PR_NUMBER" --add-label "$LABEL_NEW_EXTENSION"
49+
echo "Adding label: $LABEL_NEW_EXTENSION"
50+
gh pr edit --repo "$GH_REPO" "$PR_NUMBER" --add-label "$LABEL_NEW_EXTENSION"
4651
got_any_specific_label=true
47-
elif pcregrep "^\+\+\+ b/extensions/" pr.diff; then
52+
elif pcregrep --buffer-size 16777216 "^\+\+\+ b/extensions/" pr.diff; then
4853
# Example:
4954
# --- a/extensions/DangoCat/extension.js
5055
# +++ b/extensions/DangoCat/extension.js
51-
gh pr edit --repo TurboWarp/extensions "$PR_NUMBER" --add-label "$LABEL_CHANGE_EXTENSION"
56+
echo "Adding label: $LABEL_CHANGE_EXTENSION"
57+
gh pr edit --repo "$GH_REPO" "$PR_NUMBER" --add-label "$LABEL_CHANGE_EXTENSION"
5258
got_any_specific_label=true
5359
fi
5460
else
@@ -57,9 +63,11 @@ jobs:
5763
5864
# Any PR that didn't get a specific label will go into other, for a human to look at.
5965
if [[ "$got_any_specific_label" == "false" ]]; then
60-
gh pr edit --repo TurboWarp/extensions "$PR_NUMBER" --add-label "$LABEL_OTHER"
66+
echo "Adding label: $LABEL_OTHER"
67+
gh pr edit --repo "$GH_REPO" "$PR_NUMBER" --add-label "$LABEL_OTHER"
6168
fi
6269
env:
6370
PR_NUMBER: "${{ github.event.number }}"
6471
BASE_REF: "${{ github.base_ref }}"
6572
GH_TOKEN: "${{ github.token }}"
73+
GH_REPO: "${{ github.repository }}"

0 commit comments

Comments
 (0)