Skip to content

Commit

Permalink
Rename a function using - instead of _
Browse files Browse the repository at this point in the history
I know you already know this, but you can use `-` in function names.
In fact you can use just about any character that you could use in a
file name.

I often use ':' to namespace for a module.
Like this: `json:dump-to-file`

I find that avoiding underscores in function names leads to easier to
read code. Variables use _ and functions don't.
  • Loading branch information
ingydotnet committed Jan 29, 2023
1 parent fc6a012 commit f9e34bf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion _common
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ search_log() {
fi
}

label_on_issue() {
label-on-issue() {
local id=$1 search_term=$2 label=$3 restart=${4:-''} force_result=${5:-''}
local out=${out:?}
search_log "$id" "$search_term" "$out" || return
Expand Down
20 changes: 10 additions & 10 deletions openqa-label-known-issues
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,22 @@ label_on_issues_from_issue_tracker() {
if [[ $tracker == 'openqa-force-result' && $after =~ :force_result:([a-z_]+) ]]; then
force_result=${BASH_REMATCH[1]}
fi
label_on_issue "$id" "$search" "$label" "${after//*\":retry*/1}" "$force_result" && break
label-on-issue "$id" "$search" "$label" "${after//*\":retry*/1}" "$force_result" && break
fi
done
)
}

label_on_issues_without_tickets() {
if label_on_issue "$id" '([dD]ownload.*failed.*404)[\S\s]*Result: setup failure' 'label:non_existing asset, candidate for removal or wrong settings'; then return
elif label_on_issue "$id" 'File .*\.yaml.* does not exist at .*scheduler.pm' 'label:missing_schedule_file'; then return
elif label_on_issue "$id" 'Compilation failed in require at .*isotovideo line 28.' 'label:schedule_compilation_error'; then return
elif label_on_issue "$id" 'qemu-img: Could not open .*: No such file or directory' 'label:missing_asset'; then return
elif label_on_issue "$id" 'fatal: Remote branch .* not found' 'label:remote_branch_not_found, probably wrong custom git URL specified with branch'; then return
elif label_on_issue "$id" 'fatal: repository not found' 'label:remote_repo_not_found, probably wrong custom git URL specified'; then return
elif label_on_issue "$id" '(?s)Cloning git URL.*to use as test distribution.*(No scripts in|needledir not found)' 'label:remote_repo_invalid, probably wrong custom git URL specified'; then return
elif label_on_issue "$id" '(?s)Cloning git URL.*to use as test distribution.*(SCHEDULE.*not set|loadtest needs a script below)' 'label:remote_repo_schedule_not_found, probably wrong custom git URL + PRODUCTDIR specified'; then return
elif label_on_issue "$id" '\[error\] Failed to download' 'label:download_error potentially out-of-space worker?' 1; then return
if label-on-issue "$id" '([dD]ownload.*failed.*404)[\S\s]*Result: setup failure' 'label:non_existing asset, candidate for removal or wrong settings'; then return
elif label-on-issue "$id" 'File .*\.yaml.* does not exist at .*scheduler.pm' 'label:missing_schedule_file'; then return
elif label-on-issue "$id" 'Compilation failed in require at .*isotovideo line 28.' 'label:schedule_compilation_error'; then return
elif label-on-issue "$id" 'qemu-img: Could not open .*: No such file or directory' 'label:missing_asset'; then return
elif label-on-issue "$id" 'fatal: Remote branch .* not found' 'label:remote_branch_not_found, probably wrong custom git URL specified with branch'; then return
elif label-on-issue "$id" 'fatal: repository not found' 'label:remote_repo_not_found, probably wrong custom git URL specified'; then return
elif label-on-issue "$id" '(?s)Cloning git URL.*to use as test distribution.*(No scripts in|needledir not found)' 'label:remote_repo_invalid, probably wrong custom git URL specified'; then return
elif label-on-issue "$id" '(?s)Cloning git URL.*to use as test distribution.*(SCHEDULE.*not set|loadtest needs a script below)' 'label:remote_repo_schedule_not_found, probably wrong custom git URL + PRODUCTDIR specified'; then return
elif label-on-issue "$id" '\[error\] Failed to download' 'label:download_error potentially out-of-space worker?' 1; then return
fi
false
}
Expand Down
24 changes: 12 additions & 12 deletions test/01-label-known-issues.t
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,28 @@ try "search_log 123 'foo [z-a]' $logfile2"
is "$rc" 2 'search_log with invalid pattern'
has "$got" 'range out of order in character class' 'correct error message'

try-client-output label_on_issue 123 'foo.*bar' Label 1 softfailed
try-client-output label-on-issue 123 'foo.*bar' Label 1 softfailed
expected="client_call -X POST jobs/123/comments text=Label
client_call -X POST jobs/123/restart"
is "$rc" 0 'successful label_on_issue'
is "$got" "$expected" 'label_on_issue with restart and disabled force_result'
is "$rc" 0 'successful label-on-issue'
is "$got" "$expected" 'label-on-issue with restart and disabled force_result'

try-client-output enable_force_result=true label_on_issue 123 'foo.*bar' Label 1 softfailed
try-client-output enable_force_result=true label-on-issue 123 'foo.*bar' Label 1 softfailed
expected="client_call -X POST jobs/123/comments text=label:force_result:softfailed:Label
Label
client_call -X POST jobs/123/restart"
is "$rc" 0 'successful label_on_issue'
is "$got" "$expected" 'label_on_issue with restart and force_result'
is "$rc" 0 'successful label-on-issue'
is "$got" "$expected" 'label-on-issue with restart and force_result'

try-client-output label_on_issue 123 "foo.*bar" Label
try-client-output label-on-issue 123 "foo.*bar" Label
expected="client_call -X POST jobs/123/comments text=Label"
is "$rc" 0 'successful label_on_issue'
is "$got" "$expected" 'label_on_issue with restart and force_result'
is "$rc" 0 'successful label-on-issue'
is "$got" "$expected" 'label-on-issue with restart and force_result'

try-client-output "label_on_issue 123 'foo bar' Label"
is "$rc" 1 'label_on_issue did not find search term'
is "$got" "" 'label_on_issue with restart and force_result'
try-client-output "label-on-issue 123 'foo bar' Label"
is "$rc" 1 'label-on-issue did not find search term'
is "$got" "" 'label-on-issue with restart and force_result'

send-email() {
local mailto=$1 email=$2
Expand Down

0 comments on commit f9e34bf

Please sign in to comment.