Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KAFKA-17542: Use actions/labeler for automatic PR labeling - part 2 #17260

Merged
merged 11 commits into from
Oct 4, 2024
Merged
37 changes: 36 additions & 1 deletion .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ name: "Pull Request Labeler"
on:
pull_request_target:
types: [opened, reopened, synchronize]


jobs:
label_PRs:
Expand All @@ -29,3 +28,39 @@ jobs:
- uses: actions/labeler@v5
with:
configuration-path: .github/configs/labeler.yml
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Compare trunk and PR
TaiJuWu marked this conversation as resolved.
Show resolved Hide resolved
env:
GH_TOKEN: ${{ github.token }}
run: |
BASE_COMMIT="${{ github.event.pull_request.base.sha }}"
HEAD_COMMIT="${{ github.event.pull_request.head.sha }}"

summary=$(git diff --stat $BASE_COMMIT $HEAD_COMMIT | tail -n 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it helps, but we can use the gh CLI here.

https://cli.github.com/manual/gh_pr_diff

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. It is very useful.

echo "summary $summary"

min_size=100
insertions=0
deletions=0

if [[ $summary =~ ([0-9]+)\ files?\ changed(,)?\ ([0-9]+)\ insertions?\(\+\)(,)?\ ([0-9]+)\ deletions?\(-\) ]]; then
files_changed=${BASH_REMATCH[1]}
insertions=${BASH_REMATCH[3]}
deletions=${BASH_REMATCH[5]}
elif [[ $summary =~ ([0-9]+)\ files?\ changed(,)?\ ([0-9]+)\ insertions?\(\+\) ]]; then
files_changed=${BASH_REMATCH[1]}
insertions=${BASH_REMATCH[3]}
elif [[ $summary =~ ([0-9]+)\ files?\ changed(,)?\ ([0-9]+)\ deletions?\(-\) ]]; then
files_changed=${BASH_REMATCH[1]}
deletions=${BASH_REMATCH[3]}
fi

total_changes=$((insertions + deletions))
if [ "$total_changes" -lt "$min_size" ]; then
gh api -H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/$GITHUB_REPOSITORY/issues/${{ github.event.number }}/labels -f "labels[]=mirror"
fi