Add message if the pr is xl (#7)

This commit is contained in:
Rafa Gómez 2020-04-27 15:36:43 +02:00 committed by GitHub
parent 8cb2932588
commit 297d8199d5
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 8 deletions

View file

@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
name: Label the PR size
steps:
- uses: codelytv/pr-size-labeler@v1
- uses: codelytv/pr-size-labeler@message
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
xs_max_size: '10'
@ -15,3 +15,4 @@ jobs:
m_max_size: '200'
l_max_size: '450'
fail_if_xl: 'true'
message_if_xl: 'This PR is sooooo big!! 😳'

View file

@ -40,6 +40,7 @@ jobs:
m_max_size: '500'
l_max_size: '1000'
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.

View file

@ -24,6 +24,10 @@ inputs:
description: 'Fail if the PR is of xl size'
required: false
default: 'false'
message_if_xl:
description: 'Message to show if the PR is xl size'
required: false
default: ''
runs:
using: 'docker'
image: 'Dockerfile'
@ -34,6 +38,7 @@ runs:
- ${{ inputs.m_max_size }}
- ${{ inputs.l_max_size }}
- ${{ inputs.fail_if_xl }}
- ${{ inputs.message_if_xl }}
branding:
icon: 'tag'
icon: 'tag'
color: 'green'

View file

@ -9,7 +9,7 @@ github::calculate_total_modifications() {
local -r additions=$(echo "$body" | jq '.additions')
local -r deletions=$(echo "$body" | jq '.deletions')
echo $(( additions + deletions ))
echo $((additions + deletions))
}
github::add_label_to_pr() {
@ -39,3 +39,15 @@ github::format_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"
}

View file

@ -2,6 +2,7 @@
labeler::label() {
local -r fail_if_xl="$5"
local -r message_if_xl="$6"
local -r pr_number=$(github_actions::get_pr_number)
local -r total_modifications=$(github::calculate_total_modifications "$pr_number")
@ -14,9 +15,15 @@ labeler::label() {
github::add_label_to_pr "$pr_number" "$label_to_add"
if [ "$label_to_add" == "size/xl" ] && [ "$fail_if_xl" == "true" ]; then
echoerr "Pr is xl, please, short this!!"
exit 1
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!!"
exit 1
fi
fi
}

View file

@ -9,11 +9,11 @@ source "$PR_SIZE_LABELER_HOME/src/misc.sh"
main() {
ensure::env_variable_exist "GITHUB_REPOSITORY"
ensure::env_variable_exist "GITHUB_EVENT_PATH"
ensure::total_args 6 "$@"
ensure::total_args 7 "$@"
export GITHUB_TOKEN="$1"
labeler::label "$2" "$3" "$4" "$5" "$6"
labeler::label "$2" "$3" "$4" "$5" "$6" "$7"
exit $?
}