Skip to content

[DO NOT MERGE] [BUGFIX] v1.7.12 Last Agent's index correction process not enough #14861

[DO NOT MERGE] [BUGFIX] v1.7.12 Last Agent's index correction process not enough

[DO NOT MERGE] [BUGFIX] v1.7.12 Last Agent's index correction process not enough #14861

Workflow file for this run

#
# Copyright (C) 2019-2024 vdaas.org vald team <[email protected]>
#
# Licensed 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
#
# https://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
jobs:
dump-contexts-to-log:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/dump-context
triage:
name: Triage
runs-on: ubuntu-latest
if: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false) }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- name: Set Git config
run: |
git config --global --add safe.directory ${GITHUB_WORKSPACE}
- uses: actions/labeler@v5
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Add labels
run: |
pr_num=`cat $GITHUB_EVENT_PATH | jq -r ".number"`
branch_name=`cat $GITHUB_EVENT_PATH | jq -r ".pull_request.head.ref"`
type_labels=($(curl -s "https://api.github.com/repos/${REPOSITORY}/labels?per_page=5000" | jq -r ".[].name" | grep -e "^type/"))
send_labels=()
git fetch origin main
echo "branch name: " $branch_name
for label in ${type_labels[@]}
do
if [[ "${label#type/}" =~ "${branch_name%%/*}" ]] || [[ "${branch_name%%/*}" =~ "${label#type/}" ]]; then
send_labels+=(\"$label\")
fi
done
size=0
diff=`git diff --shortstat origin/main...${branch_name} ':!./*\.yaml' ':!./*\.yml' ':!./*\.svg' ':!./apis/*' ':!./design/*'`
if [ -n "$diff" ]; then
echo $diff
size=`echo $diff | awk '{print $4+$6}'`
fi
echo "pull request size: " $size
if [ $size -le 29 ]; then
send_labels+=(\"size/S\")
elif [ $size -le 99 ]; then
send_labels+=(\"size/M\")
elif [ $size -le 499 ]; then
send_labels+=(\"size/L\")
elif [ $size -le 999 ]; then
send_labels+=(\"size/XL\")
elif [ $size -le 4999 ]; then
send_labels+=(\"size/XXL\")
else
send_labels+=(\"size/XXXL\")
fi
if [ ${#send_labels[@]} -gt 0 ]; then
str="$(IFS=,; echo "${send_labels[*]}")"
data="{\"labels\": [$str]}"
echo "send data: " $data
curl --request POST \
--url "https://api.github.com/repos/${REPOSITORY}/issues/${pr_num}/labels" \
--header "authorization: Bearer ${GITHUB_TOKEN}" \
--header 'content-type: application/json' \
--data "$data"
fi
env:
REPOSITORY: ${{ github.repository }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
remove-duplication:
name: Remove duplication
needs:
- triage
runs-on: ubuntu-latest
steps:
- name: Remove duplication
run: |
declare -A SIZES
declare -A PRIORITIES
SIZES=(
["size/S"]=0
["size/M"]=30
["size/L"]=100
["size/XL"]=500
["size/XXL"]=1000
["size/XXXL"]=5000
)
PRIORITIES=(
["priority/low"]=10
["priority/medium"]=20
["priority/high"]=30
)
pr_num=`cat $GITHUB_EVENT_PATH | jq -r ".number"`
existing_labels=($(curl -s "https://api.github.com/repos/${REPOSITORY}/issues/${pr_num}/labels" | jq -r ".[].name"))
send_labels=()
size_label="size/S"
priority_label="priority/low"
for label in ${existing_labels[@]}
do
if [ "${label%%/*}" = "size" ]; then
if [ -z "${size_label}" ]; then
size_label=$label
else
c="${SIZES[$size_label]}"
s="${SIZES[$label]}"
if [ ! -z "${s}" ] && [ $c -lt $s ]; then
size_label=$label
fi
fi
elif [ "${label%%/*}" = "priority" ]; then
if [ -z "${priority_label}" ]; then
priority_label=$label
else
c="${PRIORITIES[$priority_label]}"
s="${PRIORITIES[$label]}"
if [ ! -z "${s}" ] && [ $c -lt $s ]; then
priority_label=$label
fi
fi
else
send_labels+=(\"$label\")
fi
if [ "${label}" = "type/security" ]; then
l="priority/high"
c="${PRIORITIES[$priority_label]}"
s="${PRIORITIES[$l]}"
if [ ! -z "${s}" ] && [ $c -lt $s ]; then
priority_label=$l
fi
elif [ "${label}" = "type/bug" ] || [ "${label}" = "type/feature" ]; then
l="priority/medium"
c="${PRIORITIES[$priority_label]}"
s="${PRIORITIES[$l]}"
if [ ! -z "${s}" ] && [ $c -lt $s ]; then
priority_label=$l
fi
fi
done
if [ ! -z "${size_label}" ]; then
send_labels+=(\"$size_label\")
fi
if [ ! -z "${priority_label}" ]; then
send_labels+=(\"$priority_label\")
fi
if [ ${#send_labels[@]} -gt 0 ]; then
str="$(IFS=,; echo "${send_labels[*]}")"
data="{\"labels\": [$str]}"
echo "send data: " $data
curl --request PUT \
--url "https://api.github.com/repos/${REPOSITORY}/issues/${pr_num}/labels" \
--header "authorization: Bearer ${GITHUB_TOKEN}" \
--header 'content-type: application/json' \
--data "$data"
fi
env:
REPOSITORY: ${{ github.repository }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}