diff --git a/README.md b/README.md index 72fa05f..7c2caf0 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ jobs: Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size. github_api_url: 'api.github.com' + ignore_deleted: 'false' files_to_ignore: '' ``` @@ -62,6 +63,7 @@ jobs: - `fail_if_xl`: Set to `'true'` will report GitHub Workflow failure if the PR size is xl allowing to forbid PR merge - `message_if_xl`: Let the user(s) know that the PR exceeds the recommended size and what the consequences are - `github_api_url`: Override this parameter in order to use with your own GitHub Enterprise Server. Example: `'https://github.example.com/api/v3'` +- `ignore_deleted`: Set to `'true'` will ignore any deleted files when calculating the PR size. - `files_to_ignore`: Whitespace or newline separated list of files to ignore when calculating the PR size, regex match is supported. ### files_to_ignore Example: ```yml diff --git a/action.yml b/action.yml index 06be2ce..33f1447 100644 --- a/action.yml +++ b/action.yml @@ -55,6 +55,10 @@ inputs: description: 'URL to the API of your Github Server, only necessary for Github Enterprise customers' required: false default: 'https://api.github.com' + ignore_deleted: + description: 'Ignore deleted files when calculating the PR size' + required: false + default: 'false' files_to_ignore: description: 'Whitespace separated list of files to ignore when calculating the PR size (sum of changes)' required: false @@ -76,6 +80,7 @@ runs: - --xl_label=${{ inputs.xl_label }} - --fail_if_xl=${{ inputs.fail_if_xl }} - --message_if_xl="${{ inputs.message_if_xl }}" + - --ignore_deleted=${{ inputs.ignore_deleted }} - --files_to_ignore=${{ inputs.files_to_ignore }} branding: icon: 'tag' diff --git a/src/ensure.sh b/src/ensure.sh old mode 100644 new mode 100755 diff --git a/src/github.sh b/src/github.sh old mode 100644 new mode 100755 index 0934dc0..a43640f --- a/src/github.sh +++ b/src/github.sh @@ -5,8 +5,9 @@ GITHUB_API_HEADER="Accept: application/vnd.github.v3+json" github::calculate_total_modifications() { local -r pr_number="${1}" local -r files_to_ignore="${2}" + local -r ignore_deleted="${3}" - if [ -z "$files_to_ignore" ]; then + if [[ (-z "$files_to_ignore" && "$ignore_deleted" == 'false') ]]; then local -r body=$(curl -sSL -H "Authorization: token $GITHUB_TOKEN" -H "$GITHUB_API_HEADER" "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/pulls/$pr_number") local -r additions=$(echo "$body" | jq '.additions') @@ -20,6 +21,10 @@ github::calculate_total_modifications() { for file in $(echo "$body" | jq -r '.[] | @base64'); do local ignore_file=0 + if [[ ( "$ignore_deleted" == 'true' && "$(jq::base64 '.status')" == 'removed') ]]; then + echo "Ignoring deleted file: $(jq::base64 '.filename')" + continue + fi for file_to_ignore in $files_to_ignore; do if [ -z "$file_to_ignore" ]; then continue diff --git a/src/github_actions.sh b/src/github_actions.sh old mode 100644 new mode 100755 diff --git a/src/labeler.sh b/src/labeler.sh old mode 100644 new mode 100755 index dce7cc5..a37c001 --- a/src/labeler.sh +++ b/src/labeler.sh @@ -8,11 +8,13 @@ labeler::label() { local -r xl_label="${9}" local -r fail_if_xl="${10}" local -r message_if_xl="${11}" - local -r files_to_ignore="${12}" + local -r ignore_deleted="${12}" + local -r files_to_ignore="${13}" local -r pr_number=$(github_actions::get_pr_number) - local -r total_modifications=$(github::calculate_total_modifications "$pr_number" "$files_to_ignore") + local -r total_modifications=$(github::calculate_total_modifications "$pr_number" "$files_to_ignore" "$ignore_deleted") + log::message "Should ignore deleted files: $ignore_deleted" log::message "Total modifications (additions + deletions): $total_modifications" log::message "Ignoring files (if present): $files_to_ignore" diff --git a/src/main.sh b/src/main.sh old mode 100644 new mode 100755 index cb26580..1374367 --- a/src/main.sh +++ b/src/main.sh @@ -9,7 +9,7 @@ source "$PR_SIZE_LABELER_HOME/src/misc.sh" ##? Adds a size label to a GitHub Pull Request ##? ##? Usage: -##? main.sh --github_token= --xs_label=