From 297d8199d51077325aa131435fe7e91e83a02c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=20G=C3=B3mez?= Date: Mon, 27 Apr 2020 15:36:43 +0200 Subject: [PATCH] Add message if the pr is xl (#7) --- .github/workflows/labeler.yml | 3 ++- README.md | 1 + action.yml | 7 ++++++- src/github.sh | 14 +++++++++++++- src/labeler.sh | 13 ++++++++++--- src/main.sh | 4 ++-- 6 files changed, 34 insertions(+), 8 deletions(-) diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index 017664e..681bb34 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -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!! 😳' diff --git a/README.md b/README.md index f3119bc..365a57e 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/action.yml b/action.yml index c0e6420..1a5c07b 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/src/github.sh b/src/github.sh index 3a79a65..3a40c23 100644 --- a/src/github.sh +++ b/src/github.sh @@ -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" +} diff --git a/src/labeler.sh b/src/labeler.sh index f64b0d1..aa5f161 100644 --- a/src/labeler.sh +++ b/src/labeler.sh @@ -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 } diff --git a/src/main.sh b/src/main.sh index bce88f9..e2df2d0 100644 --- a/src/main.sh +++ b/src/main.sh @@ -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 $? }