Skip to content

Commit 5c8f0e6

Browse files
committed
Throttle automatic maintenance updates for Leap 16.X
* Implement checking for existing request on Gitea * Make decision whether to throttle per package and target (instead of checking the project as a whole and only the primary target) * See https://progress.opensuse.org/issues/191106
1 parent 11bd858 commit 5c8f0e6

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

os-autoinst-obs-auto-submit

Lines changed: 28 additions & 10 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+
git_user=${git_user:-os-autoinst-obs-workflow}
1617
XMLSTARLET=$(command -v xmlstarlet || true)
1718
[[ -n $XMLSTARLET ]] || (echo "Need xmlstarlet" >&2 && exit 1)
1819

@@ -175,6 +176,7 @@ update_package() {
175176
wait_for_package_build "$submit_target"
176177
for target in "${targets[@]}"; do
177178
[[ $target == none ]] && continue # allow specifying submit_target_extra=none for easier testing
179+
has_pending_submission "$package" "$target" && continue
178180
log-info "## Ready to submit $package to $target ##"
179181
local submit_cmd=make_obs_submit_request
180182
local args=("$package" "$target" "$version")
@@ -279,16 +281,33 @@ get_project_packages() {
279281
}
280282

281283
has_pending_submission() {
282-
log-info "has_pending_submission()"
283-
local requestlist
284-
# throttle number of submissions to allow only one SR within a certain number of days
285-
# note: Avoid using `grep --quiet` here to keep consuming input so osc does not run into "BrokenPipeError: [Errno 32] Broken pipe".
284+
local package=$1 target=$2
285+
local git_branch=${git_branches[$target]:-}
286+
local requestlist is_older_than_throttle_days
287+
log-info "has_pending_submission($package, $target)"
288+
289+
# throttle number of submissions to allow only one PR or SR within a certain number of days
286290
[[ $throttle_days == 0 ]] && return 0
287-
requestlist=$($osc request list --project "$dst_project" --type submit --state new,review --mine --days "$throttle_days")
288-
if echo "$requestlist" | grep 'Created by' > /dev/null; then
289-
log-info "Skipping submission, there is still a pending SR younger than $throttle_days days."
290-
echo "$requestlist"
291-
return 1
291+
if [[ $git_branch ]]; then
292+
# check for PR on Gitea
293+
is_older_than_throttle_days=$($git_obs -q api "repos/pool/$package/pulls?state=open&sort=recentupdate" \
294+
| jq --arg days "$throttle_days" \
295+
--arg target "$git_branch" \
296+
--arg login "$git_user" \
297+
'[.[] | select(.base.ref == $target) | select(.user.login == $login) | select(.updated_at | strptime("%Y-%m-%dT%H:%M:%S%z") | mktime > (now - ($days | tonumber) * 86400))] | length > 0')
298+
if [[ $is_older_than_throttle_days != false ]]; then
299+
log-info "Skipping submission, there is still a pending PR by $git_user targeting $git_branch younger than $throttle_days days."
300+
return 1
301+
fi
302+
else
303+
# check for SR on OBS
304+
# note: Avoid using `grep --quiet` here to keep consuming input so osc does not run into "BrokenPipeError: [Errno 32] Broken pipe".
305+
requestlist=$($osc request list --project "$target" --package "$package" --type submit --state new,review --mine --days "$throttle_days")
306+
if echo "$requestlist" | grep 'Created by' > /dev/null; then
307+
log-info "Skipping submission, there is still a pending SR younger than $throttle_days days."
308+
echo "$requestlist"
309+
return 1
310+
fi
292311
fi
293312
return 0
294313
}
@@ -306,7 +325,6 @@ submit() {
306325
cat job_post_skip_submission
307326
return 0
308327
fi
309-
has_pending_submission || return 0
310328
(
311329
cd "$TMPDIR"
312330
rc=0

test/08-auto-submit.t

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@ source os-autoinst-obs-auto-submit
2121
note "########### has_pending_submission"
2222

2323
throttle_days=0
24-
try has_pending_submission
24+
package=os-autoinst
25+
try has_pending_submission "$package" "$submit_target"
2526
is "$rc" 0 "returns 0 with throttle_days=0"
2627

2728
throttle_days=1
28-
try has_pending_submission
29+
try has_pending_submission "$package" "$submit_target"
2930
is "$rc" 1 "returns 1 with existing SRs"
3031
like "$got" "Created by: foo" "expected output"
3132

3233
_request_list() {
3334
echo ""
3435
}
35-
try has_pending_submission
36+
try has_pending_submission "$package" "$submit_target"
3637
is "$rc" 0 "returns 0 without existing SRs"
3738
like "$got" "info.*has_pending_submission" "no output"

0 commit comments

Comments
 (0)