Skip to content

Commit 0476b3a

Browse files
authored
Merge pull request #483 from Martchus/leap-throttle
Allow configuring target-specific throttles
2 parents fd3b652 + 9e092c4 commit 0476b3a

File tree

2 files changed

+35
-19
lines changed

2 files changed

+35
-19
lines changed

os-autoinst-obs-auto-submit

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dry_run="${dry_run:-"0"}"
1313
osc_poll_interval="${osc_poll_interval:-2}"
1414
osc_build_start_poll_tries="${osc_build_start_poll_tries:-30}"
1515
throttle_days=${throttle_days:-2}
16+
throttle_days_leap_16=${throttle_days_leap_16:-7}
1617
git_user=${git_user:-os-autoinst-obs-workflow}
1718
XMLSTARLET=$(command -v xmlstarlet || true)
1819
[[ -n $XMLSTARLET ]] || (echo "Need xmlstarlet" >&2 && exit 1)
@@ -30,6 +31,11 @@ declare -A git_branches=(
3031
['openSUSE:Leap:16.0']=leap-16.0
3132
)
3233

34+
# allow specifying target-specific throttle variables
35+
declare -A throttle_variables=(
36+
['openSUSE:Leap:16.0']=throttle_days_leap_16
37+
)
38+
3339
encode_variable() {
3440
# https://stackoverflow.com/a/298258
3541
perl -MURI::Escape -e 'print uri_escape($ARGV[0])' "$1"
@@ -281,32 +287,33 @@ get_project_packages() {
281287
}
282288

283289
has_pending_submission() {
284-
[[ $throttle_days == 0 ]] && return 0
285-
286290
local package=$1 target=$2
287291
local git_branch=${git_branches[$target]:-}
292+
local throttle_variable=${throttle_variables[$target]:-throttle_days}
293+
local throttle_days_value=${!throttle_variable:-0}
288294
local requestlist recent_pr_url
295+
[[ $throttle_days_value == 0 ]] && return 0
289296
log-info "has_pending_submission($package, $target)"
290297

291298
# throttle number of submissions to allow only one PR or SR within a certain number of days
292299
if [[ $git_branch ]]; then
293300
# check for PR on Gitea
294301
recent_pr_url=$($git_obs -q api "repos/pool/$package/pulls?state=open&sort=recentupdate" 2> /dev/null \
295302
| jq --raw-output \
296-
--arg days "$throttle_days" \
303+
--arg days "$throttle_days_value" \
297304
--arg target "$git_branch" \
298305
--arg login "$git_user" \
299306
'[.[] | select(.base.ref == $target) | select(.user.login == $login) | select(.updated_at | strptime("%Y-%m-%dT%H:%M:%S%z") | mktime > (now - ($days | tonumber) * 86400)) | .html_url] | first')
300307
if [[ $recent_pr_url != null ]]; then
301-
log-info "Skipping submission, there is the still pending PR '$recent_pr_url' by $git_user targeting $git_branch younger than $throttle_days days."
308+
log-info "Skipping submission, there is the still pending PR '$recent_pr_url' by $git_user targeting $git_branch younger than $throttle_days_value days."
302309
return 1
303310
fi
304311
else
305312
# check for SR on OBS
306313
# note: Avoid using `grep --quiet` here to keep consuming input so osc does not run into "BrokenPipeError: [Errno 32] Broken pipe".
307-
requestlist=$($osc request list --project "$target" --package "$package" --type submit --state new,review --mine --days "$throttle_days")
308-
if echo "$requestlist" | grep 'Created by' > /dev/null; then
309-
log-info "Skipping submission, there is still a pending SR for package $package in project $target younger than $throttle_days days."
314+
requestlist=$($osc request list --project "$dst_project" --package "$package" --type submit,maintenance_incident --state new,review --days "$throttle_days_value")
315+
if echo "$requestlist" | grep --fixed-strings "$target" > /dev/null; then
316+
log-info "Skipping submission, there is still a pending SR for package $package in project $target younger than $throttle_days_value days."
310317
echo "$requestlist"
311318
return 1
312319
fi

test/08-auto-submit.t

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
#!/usr/bin/env bash
22

33
source test/init
4-
plan tests 11
4+
plan tests 13
55

66
mock_osc() {
77
local cmd=$1
88
local args=(${@:2})
9-
if [[ $cmd == 'request' && ${args[0]} == 'list' ]]; then
9+
if [[ $cmd == 'request' && ${args[0]} == 'list' && ${args[9]} == '--days' && ${args[10]} == "$throttle_days" ]]; then
1010
_request_list
1111
fi
1212
}
1313

14-
_request_list() {
15-
echo "Created by: foo"
16-
}
14+
_requests=(
15+
'submit: devel:openQA:tested/openQA@c0f8ee6a233ed250dbc54c19dee50118 -> openSUSE:Factory'
16+
'maintenance_incident: devel:openQA:tested/openQA@ae3d930a703dc411e249d644ad8b6802 -> openSUSE:Maintenance (release in openSUSE:Backports:SLE-15-SP6:Update)'
17+
)
18+
19+
_request_list() { echo "${_requests[@]}"; }
1720

1821
mock_git_obs() {
1922
if [[ $3 == 'repos/pool/openQA/pulls?state=open&sort=recentupdate' ]]; then
@@ -42,17 +45,17 @@ is "$rc" 0 "returns 0 with throttle_days=0"
4245

4346
throttle_days=1
4447
try has_pending_submission "$package" "$submit_target"
45-
is "$rc" 1 "returns 1 with existing SRs"
46-
like "$got" "Created by: foo" "expected output"
48+
is "$rc" 1 "returns 1 with existing SR"
49+
like "$got" "Skipping submission, there is still a pending SR for package os-autoinst" "expected output"
4750

48-
_request_list() {
49-
echo ""
50-
}
51+
_request_list() { echo; }
5152
try has_pending_submission "$package" "$submit_target"
5253
is "$rc" 0 "returns 0 without existing SRs"
5354
like "$got" "info.*has_pending_submission" "no output"
5455

5556
submit_target=openSUSE:Leap:16.0
57+
throttle_days=3 # expected to be ignored for openSUSE:Leap:16.0
58+
throttle_days_leap_16=1
5659
try has_pending_submission "$package" "$submit_target"
5760
is "$rc" 0 "returns 0 without existing PRs"
5861
like "$got" "info.*has_pending_submission\\($package, $submit_target\\)$" "no output (no PR)"
@@ -62,7 +65,13 @@ try has_pending_submission "$package" "$submit_target"
6265
is "$rc" 0 "returns 0 with existing PR older than throttle config of $throttle_days days"
6366
like "$got" "info.*has_pending_submission\\($package, $submit_target\\)$" "no output (old PR)"
6467

65-
throttle_days=3
68+
throttle_days_leap_16=3
6669
try has_pending_submission "$package" "$submit_target"
67-
is "$rc" 1 "returns 1 with existing PR recent than throttle config of $throttle_days days"
70+
is "$rc" 1 "returns 1 with existing PR that is more recent than throttle config of $throttle_days days"
6871
like "$got" "info.*Skipping submission.*pending PR.*https://foo/bar" "expected output (recent PR)"
72+
73+
_request_list() { echo "${_requests[@]}"; }
74+
submit_target=openSUSE:Backports:SLE-15-SP6:Update
75+
try has_pending_submission "$package" "$submit_target"
76+
is "$rc" 1 "returns 1 with existing maintenance incident that is more recent than throttle config of $throttle_days days"
77+
like "$got" "info.*Skipping submission.*pending SR"

0 commit comments

Comments
 (0)