File tree Expand file tree Collapse file tree 6 files changed +42
-8
lines changed Expand file tree Collapse file tree 6 files changed +42
-8
lines changed Original file line number Diff line number Diff line change @@ -52,14 +52,17 @@ jobs:
52
52
Please make sure you are NOT addressing multiple issues with one PR.
53
53
Note this PR might be rejected due to its size.’
54
54
github_api_url : ' api.github.com'
55
+ files_to_ignore : ' '
55
56
` ` `
56
57
57
58
## 🎛️ Available parameters
58
59
59
60
- ` *_label` (`xs_label`, `s_label`…): Adjust size label names
60
61
- `*_max_size` (`xs_max_size`, `s_max_size`…) : Adjust which amount of changes you consider appropriate for each size based on your project context
61
62
- `fail_if_xl` : Set to `'true'` will report GitHub Workflow failure if the PR size is xl allowing to forbid PR merge
63
+ - `message_if_xl` : Let the user(s) know that the PR exceeds the recommended size and what the consequences are
62
64
- `github_api_url` : Override this parameter in order to use with your own GitHub Enterprise Server. Example: `'https://github.example.com/api/v3'`
65
+ - `files_to_ignore` : Whitespace separated list of files to ignore when calculating the PR size. Example: `'package-lock.json Pipfile.lock'`
63
66
64
67
# # 🤔 Basic concepts or assumptions
65
68
Original file line number Diff line number Diff line change @@ -55,6 +55,10 @@ inputs:
55
55
description : ' URL to the API of your Github Server, only necessary for Github Enterprise customers'
56
56
required : false
57
57
default : ' https://api.github.com'
58
+ files_to_ignore :
59
+ description : ' Whitespace separated list of files to ignore when calculating the PR size (sum of changes)'
60
+ required : false
61
+ default : ' '
58
62
runs :
59
63
using : ' docker'
60
64
image : ' Dockerfile'
72
76
- --xl_label=${{ inputs.xl_label }}
73
77
- --fail_if_xl=${{ inputs.fail_if_xl }}
74
78
- --message_if_xl="${{ inputs.message_if_xl }}"
79
+ - --files_to_ignore=${{ inputs.files_to_ignore }}
75
80
branding :
76
81
icon : ' tag'
77
82
color : ' green'
Original file line number Diff line number Diff line change 3
3
GITHUB_API_HEADER=" Accept: application/vnd.github.v3+json"
4
4
5
5
github::calculate_total_modifications () {
6
- local -r body=$( curl -sSL -H " Authorization: token $GITHUB_TOKEN " -H " $GITHUB_API_HEADER " " $GITHUB_API_URL /repos/$GITHUB_REPOSITORY /pulls/$1 " )
6
+ local -r pr_number=" ${1} "
7
+ local -r files_to_ignore=" ${2} "
8
+
9
+ if [ -z " $files_to_ignore " ]; then
10
+ local -r body=$( curl -sSL -H " Authorization: token $GITHUB_TOKEN " -H " $GITHUB_API_HEADER " " $GITHUB_API_URL /repos/$GITHUB_REPOSITORY /pulls/$pr_number " )
11
+
12
+ local -r additions=$( echo " $body " | jq ' .additions' )
13
+ local -r deletions=$( echo " $body " | jq ' .deletions' )
14
+
15
+ echo $(( additions + deletions))
16
+ else
17
+ local -r body=$( curl -sSL -H " Authorization: token $GITHUB_TOKEN " -H " $GITHUB_API_HEADER " " $GITHUB_API_URL /repos/$GITHUB_REPOSITORY /pulls/$pr_number /files?per_page=100" )
7
18
8
- local -r additions=$( echo " $body " | jq ' .additions' )
9
- local -r deletions=$( echo " $body " | jq ' .deletions' )
19
+ local changes=0
20
+ for file in $( echo " $body " | jq -r ' .[] | @base64' ) ; do
21
+ for file_to_ignore in $files_to_ignore ; do
22
+ if [ " $file_to_ignore " != " $( basename $( jq::base64 ' .filename' ) ) " ]; then
23
+ total_changes=$( jq::base64 ' .changes' )
24
+ (( changes += total_changes))
25
+ fi
26
+ done
27
+ done
10
28
11
- echo $(( additions + deletions))
29
+ echo $changes
30
+ fi
12
31
}
13
32
14
33
github::add_label_to_pr () {
Original file line number Diff line number Diff line change @@ -8,11 +8,13 @@ labeler::label() {
8
8
local -r xl_label=" ${9} "
9
9
local -r fail_if_xl=" ${10} "
10
10
local -r message_if_xl=" ${11} "
11
+ local -r files_to_ignore=" ${12} "
11
12
12
13
local -r pr_number=$( github_actions::get_pr_number)
13
- local -r total_modifications=$( github::calculate_total_modifications " $pr_number " )
14
+ local -r total_modifications=$( github::calculate_total_modifications " $pr_number " " $files_to_ignore " )
14
15
15
- log::message " Total modifications: $total_modifications "
16
+ log::message " Total modifications (additions + deletions): $total_modifications "
17
+ log::message " Ignoring files (if present): $files_to_ignore "
16
18
17
19
local -r label_to_add=$( labeler::label_for " $total_modifications " " $@ " )
18
20
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ source "$PR_SIZE_LABELER_HOME/src/misc.sh"
9
9
# #? Adds a size label to a GitHub Pull Request
10
10
# #?
11
11
# #? Usage:
12
- # #? main.sh --github_token=<token> --xs_label=<label> --xs_max_size=<size> --s_label=<label> --s_max_size=<size> --m_label=<label> --m_max_size=<size> --l_label=<label> --l_max_size=<size> --xl_label=<label> --fail_if_xl=<false> --message_if_xl=<message> --github_api_url=<url>
12
+ # #? main.sh --github_token=<token> --xs_label=<label> --xs_max_size=<size> --s_label=<label> --s_max_size=<size> --m_label=<label> --m_max_size=<size> --l_label=<label> --l_max_size=<size> --xl_label=<label> --fail_if_xl=<false> --message_if_xl=<message> --github_api_url=<url> --files_to_ignore=<files>
13
13
main () {
14
14
eval " $( /root/bin/docpars -h " $( grep " ^##?" " $PR_SIZE_LABELER_HOME /src/main.sh" | cut -c 5-) " : " $@ " ) "
15
15
@@ -30,7 +30,8 @@ main() {
30
30
" $l_max_size " \
31
31
" $xl_label " \
32
32
" $fail_if_xl " \
33
- " $message_if_xl "
33
+ " $message_if_xl " \
34
+ " $files_to_ignore "
34
35
35
36
exit $?
36
37
}
Original file line number Diff line number Diff line change @@ -25,3 +25,7 @@ coll::map() {
25
25
str::quote () {
26
26
echo " \" $1 \" "
27
27
}
28
+
29
+ jq::base64 () {
30
+ echo " $file " | base64 -d | jq -r " $1 "
31
+ }
You can’t perform that action at this time.
0 commit comments