mirror of
https://github.com/CodelyTV/pr-size-labeler.git
synced 2025-02-21 12:31:01 -05:00
Add message if the pr is xl (#7)
This commit is contained in:
parent
8cb2932588
commit
297d8199d5
6 changed files with 34 additions and 8 deletions
3
.github/workflows/labeler.yml
vendored
3
.github/workflows/labeler.yml
vendored
|
@ -7,7 +7,7 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: Label the PR size
|
name: Label the PR size
|
||||||
steps:
|
steps:
|
||||||
- uses: codelytv/pr-size-labeler@v1
|
- uses: codelytv/pr-size-labeler@message
|
||||||
with:
|
with:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
xs_max_size: '10'
|
xs_max_size: '10'
|
||||||
|
@ -15,3 +15,4 @@ jobs:
|
||||||
m_max_size: '200'
|
m_max_size: '200'
|
||||||
l_max_size: '450'
|
l_max_size: '450'
|
||||||
fail_if_xl: 'true'
|
fail_if_xl: 'true'
|
||||||
|
message_if_xl: 'This PR is sooooo big!! 😳'
|
||||||
|
|
|
@ -40,6 +40,7 @@ jobs:
|
||||||
m_max_size: '500'
|
m_max_size: '500'
|
||||||
l_max_size: '1000'
|
l_max_size: '1000'
|
||||||
fail_if_xl: 'false'
|
fail_if_xl: 'false'
|
||||||
|
message_if_xl: 'This PR is sooooo big!! 😳'
|
||||||
```
|
```
|
||||||
|
|
||||||
> If you want, you can customize all `*_max_size` with the size that fits in your project.
|
> If you want, you can customize all `*_max_size` with the size that fits in your project.
|
||||||
|
|
|
@ -24,6 +24,10 @@ inputs:
|
||||||
description: 'Fail if the PR is of xl size'
|
description: 'Fail if the PR is of xl size'
|
||||||
required: false
|
required: false
|
||||||
default: 'false'
|
default: 'false'
|
||||||
|
message_if_xl:
|
||||||
|
description: 'Message to show if the PR is xl size'
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
runs:
|
runs:
|
||||||
using: 'docker'
|
using: 'docker'
|
||||||
image: 'Dockerfile'
|
image: 'Dockerfile'
|
||||||
|
@ -34,6 +38,7 @@ runs:
|
||||||
- ${{ inputs.m_max_size }}
|
- ${{ inputs.m_max_size }}
|
||||||
- ${{ inputs.l_max_size }}
|
- ${{ inputs.l_max_size }}
|
||||||
- ${{ inputs.fail_if_xl }}
|
- ${{ inputs.fail_if_xl }}
|
||||||
|
- ${{ inputs.message_if_xl }}
|
||||||
branding:
|
branding:
|
||||||
icon: 'tag'
|
icon: 'tag'
|
||||||
color: 'green'
|
color: 'green'
|
||||||
|
|
|
@ -9,7 +9,7 @@ github::calculate_total_modifications() {
|
||||||
local -r additions=$(echo "$body" | jq '.additions')
|
local -r additions=$(echo "$body" | jq '.additions')
|
||||||
local -r deletions=$(echo "$body" | jq '.deletions')
|
local -r deletions=$(echo "$body" | jq '.deletions')
|
||||||
|
|
||||||
echo $(( additions + deletions ))
|
echo $((additions + deletions))
|
||||||
}
|
}
|
||||||
|
|
||||||
github::add_label_to_pr() {
|
github::add_label_to_pr() {
|
||||||
|
@ -39,3 +39,15 @@ github::format_labels() {
|
||||||
|
|
||||||
coll::join_by "," "${splitted_quoted_labels[@]/#/}"
|
coll::join_by "," "${splitted_quoted_labels[@]/#/}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
github::comment() {
|
||||||
|
local -r comment=$1
|
||||||
|
|
||||||
|
curl -sSL \
|
||||||
|
-H "Authorization: token $GITHUB_TOKEN" \
|
||||||
|
-H "$GITHUB_API_HEADER" \
|
||||||
|
-X POST \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "{\"body\":\"$comment\"}" \
|
||||||
|
"$GITHUB_API_URI/repos/$GITHUB_REPOSITORY/issues/$pr_number/comments"
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
labeler::label() {
|
labeler::label() {
|
||||||
local -r fail_if_xl="$5"
|
local -r fail_if_xl="$5"
|
||||||
|
local -r message_if_xl="$6"
|
||||||
|
|
||||||
local -r pr_number=$(github_actions::get_pr_number)
|
local -r pr_number=$(github_actions::get_pr_number)
|
||||||
local -r total_modifications=$(github::calculate_total_modifications "$pr_number")
|
local -r total_modifications=$(github::calculate_total_modifications "$pr_number")
|
||||||
|
@ -14,10 +15,16 @@ labeler::label() {
|
||||||
|
|
||||||
github::add_label_to_pr "$pr_number" "$label_to_add"
|
github::add_label_to_pr "$pr_number" "$label_to_add"
|
||||||
|
|
||||||
if [ "$label_to_add" == "size/xl" ] && [ "$fail_if_xl" == "true" ]; then
|
if [ "$label_to_add" == "size/xl" ]; then
|
||||||
|
if [ -n "$message_if_xl" ]; then
|
||||||
|
github::comment "$message_if_xl"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$fail_if_xl" == "true" ]; then
|
||||||
echoerr "Pr is xl, please, short this!!"
|
echoerr "Pr is xl, please, short this!!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
labeler::label_for() {
|
labeler::label_for() {
|
||||||
|
|
|
@ -9,11 +9,11 @@ source "$PR_SIZE_LABELER_HOME/src/misc.sh"
|
||||||
main() {
|
main() {
|
||||||
ensure::env_variable_exist "GITHUB_REPOSITORY"
|
ensure::env_variable_exist "GITHUB_REPOSITORY"
|
||||||
ensure::env_variable_exist "GITHUB_EVENT_PATH"
|
ensure::env_variable_exist "GITHUB_EVENT_PATH"
|
||||||
ensure::total_args 6 "$@"
|
ensure::total_args 7 "$@"
|
||||||
|
|
||||||
export GITHUB_TOKEN="$1"
|
export GITHUB_TOKEN="$1"
|
||||||
|
|
||||||
labeler::label "$2" "$3" "$4" "$5" "$6"
|
labeler::label "$2" "$3" "$4" "$5" "$6" "$7"
|
||||||
|
|
||||||
exit $?
|
exit $?
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue