Skip to content

Workflow file for this run

# 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.
name: "Pull Request Labeler"
on:
pull_request_target:
types: [opened, reopened, synchronize]
jobs:
label_PRs:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- 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
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)
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