Skip to content

Commit

Permalink
move to script
Browse files Browse the repository at this point in the history
  • Loading branch information
TaiJuWu committed Sep 30, 2024
1 parent e99939f commit 5ebbf25
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
32 changes: 32 additions & 0 deletions .github/scripts/label_minor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

pr_diff=$(gh pr diff $PR_NUM -R $GITHUB_REPOSITORY)

min_size=100
insertions=$(printf "$pr_diff" | grep '^+' | wc -l)
deletions=$(printf "$pr_diff" | grep '^-' | wc -l)

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/$PR_NUM/labels -f "labels[]=minor"
else
gh api -X Delete -H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/$GITHUB_REPOSITORY/issues/$PR_NUM/labels -f "labels[]=minor"
fi
16 changes: 4 additions & 12 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,14 @@ jobs:
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: actions/labeler@v5
with:
configuration-path: .github/configs/labeler.yml
- name: check MINOR label
env:
GH_TOKEN: ${{ github.token }}
PR_NUM: ${{github.event.number}}
run: |
pr_diff=$(gh pr diff ${{ github.event.number }} -R $GITHUB_REPOSITORY)
min_size=100
insertions=$(printf "$pr_diff" | grep '^+' | wc -l)
deletions=$(printf "$pr_diff" | grep '^-' | wc -l)
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[]=MINOR"
fi
./.github/scripts/label_minor.sh $GH_TOKEN $

0 comments on commit 5ebbf25

Please sign in to comment.