feat: add regex match for files to ignore (#50)

This commit is contained in:
Changliang Wu 2023-01-31 22:31:23 +08:00 committed by GitHub
parent 54ef36785e
commit d269449310
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
3 changed files with 15 additions and 4 deletions

View file

@ -62,8 +62,16 @@ 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'`
- `files_to_ignore`: Whitespace separated list of files to ignore when calculating the PR size. Example: `'package-lock.json Pipfile.lock'`
- `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
files_to_ignore: 'package-lock.json *.lock'
# OR
files_to_ignore: |
"package-lock.json"
"*.lock"
"docs/*"
```
## 🤔 Basic concepts or assumptions
- PR size labeler consider as a change any kind of line addition, deletion, or modification

View file

@ -14,7 +14,7 @@ bash --version
source "$PR_SIZE_LABELER_HOME/src/main.sh"
for a in "${@}"; do
arg=$(echo "$a" | tr -d '\n'| sed "s/'//g"| sed "s///g")
arg=$(echo "$a" | tr '\n' ' ' | xargs echo | sed "s/'//g"| sed "s///g")
sanitizedArgs+=("$arg")
done

View file

@ -21,7 +21,10 @@ github::calculate_total_modifications() {
for file in $(echo "$body" | jq -r '.[] | @base64'); do
local ignore_file=0
for file_to_ignore in $files_to_ignore; do
if [ "$file_to_ignore" = "$(basename $(jq::base64 '.filename'))" ]; then
if [ -z "$file_to_ignore" ]; then
continue
fi
if [[ "$(jq::base64 '.filename')" == $file_to_ignore ]]; then
ignore_file=1
fi
done