chore: shmft (#36)
Some checks are pending
integration / integration (push) Waiting to run

Reviewed-on: https://code.forgejo.org/actions/cascading-pr/pulls/36
Co-authored-by: Earl Warren <contact@earl-warren.org>
Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
Earl Warren 2025-07-20 05:38:43 +00:00 committed by earl-warren
parent 98b48e57d7
commit 06248c771c
No known key found for this signature in database
GPG key ID: F128CBE6AB3A7201
5 changed files with 526 additions and 518 deletions

View file

@ -1,3 +1,10 @@
root = true
[*]
tab_width: 8
indent_style = space
indent_size = 4
tab_width = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

View file

@ -21,7 +21,7 @@ DEBUG=false
: ${RETRY_DELAYS:=1 1 5 5 15 30}
function dependencies() {
if ! which jq curl > /dev/null ; then
if ! which jq curl >/dev/null; then
apt-get update -qq
apt-get -qq install -y jq curl
fi
@ -30,17 +30,17 @@ function dependencies() {
function retry() {
rm -f $TMPDIR/retry.{out,attempt,err}
local success=false
for delay in $RETRY_DELAYS ; do
if "$@" > $TMPDIR/retry.attempt 2>> $TMPDIR/retry.err ; then
for delay in $RETRY_DELAYS; do
if "$@" >$TMPDIR/retry.attempt 2>>$TMPDIR/retry.err; then
success=true
break
fi
cat $TMPDIR/retry.{err,attempt} >> $TMPDIR/retry.out
cat $TMPDIR/retry.{err,attempt} >>$TMPDIR/retry.out
cat $TMPDIR/retry.{err,attempt} >&2
echo waiting $delay "$@" >&2
sleep $delay
done
if $success ; then
if $success; then
cat $TMPDIR/retry.attempt
return 0
else
@ -70,7 +70,7 @@ function log_error() {
}
function log_verbose() {
if $VERBOSE ; then
if $VERBOSE; then
log_info "$@"
fi
}
@ -81,7 +81,7 @@ function log_info() {
function fatal_error() {
log_error "$@"
if $EXIT_ON_ERROR ; then
if $EXIT_ON_ERROR; then
exit 1
else
return 1
@ -91,10 +91,10 @@ function fatal_error() {
function stash_debug() {
echo start $SELF
mkdir -p $TMPDIR
> $TMPDIR/run.out
>$TMPDIR/run.out
tail --follow $TMPDIR/run.out | sed --unbuffered -n -e "/^$PREFIX/s/^$PREFIX //p" &
pid=$!
if ! $SELF --debug "$@" >& $TMPDIR/run.out ; then
if ! $SELF --debug "$@" >&$TMPDIR/run.out; then
kill $pid
cat $TMPDIR/run.out
echo fail $SELF
@ -142,9 +142,9 @@ function check_status() {
local expected_status="$3"
local expected_description="$4"
get_status $api $sha > $TMPDIR/status.json
local status="$(jq --raw-output .state < $TMPDIR/status.json)"
local description="$(jq --raw-output .statuses[0].description < $TMPDIR/status.json)"
get_status $api $sha >$TMPDIR/status.json
local status="$(jq --raw-output .state <$TMPDIR/status.json)"
local description="$(jq --raw-output .statuses[0].description <$TMPDIR/status.json)"
if test "$status" = "$expected_status" && test -z "$expected_description" -o "$description" = "$expected_description"; then
echo OK
elif test "$status" = "failure" -o "$status" = "success"; then
@ -168,8 +168,8 @@ function wait_running() {
function wait_log() {
local sha="$1" expected_status="$2" expected_description="$3"
local status="$(jq --raw-output .state < $TMPDIR/status.json)"
local description="$(jq --raw-output .statuses[0].description < $TMPDIR/status.json)"
local status="$(jq --raw-output .state <$TMPDIR/status.json)"
local description="$(jq --raw-output .statuses[0].description <$TMPDIR/status.json)"
if test "$expected_description"; then
expected_description=" '$expected_description'"
fi
@ -183,13 +183,13 @@ function wait_status() {
local description="$4"
for i in $(seq $LOOPS); do
if test $(check_status "$api" "$sha" "$status" "$description") != RETRY ; then
if test $(check_status "$api" "$sha" "$status" "$description") != RETRY; then
break
fi
wait_log "$sha" "$status" "$description"
sleep $LOOP_DELAY
done
if test $(check_status "$api" "$sha" "$status" "$description") = "OK" ; then
if test $(check_status "$api" "$sha" "$status" "$description") = "OK"; then
log_info "$sha status OK"
else
get_status $api $sha | jq .statuses
@ -201,11 +201,11 @@ function wait_status() {
function sanity_check_pr_or_ref() {
local pr="$1" ref="$2"
if test "$pr" -a "$ref" ; then
if test "$pr" -a "$ref"; then
log_error "--origin-pr $pr and --origin-ref $ref are mutually exclusive"
return 1
fi
if test -z "$pr" -a -z "$ref" ; then
if test -z "$pr" -a -z "$ref"; then
log_error "one of --origin-pr or --origin-ref must be set"
return 2
fi

View file

@ -5,7 +5,7 @@ set -e
set -o posix
SELF=${BASH_SOURCE[0]}
SELF_DIR="$( cd "$( dirname "$SELF" )" && pwd )"
SELF_DIR="$(cd "$(dirname "$SELF")" && pwd)"
source $SELF_DIR/cascading-pr-lib.sh
trap "rm -fr $TMPDIR" EXIT
@ -29,19 +29,19 @@ function repo_curl() {
function default_branch() {
local direction=$1
repo_curl ${options[${direction}_repo]} api_json ${options[${direction}_api]} > $TMPDIR/$direction.json
jq --raw-output .default_branch < $TMPDIR/$direction.json
repo_curl ${options[${direction}_repo]} api_json ${options[${direction}_api]} >$TMPDIR/$direction.json
jq --raw-output .default_branch <$TMPDIR/$direction.json
}
function destination_updated_at() {
local api
if ${options[destination_is_fork]} ; then
repo_curl ${options[destination_repo]} api_json ${options[destination_fork_api]} > $TMPDIR/updated_at.json
if ${options[destination_is_fork]}; then
repo_curl ${options[destination_repo]} api_json ${options[destination_fork_api]} >$TMPDIR/updated_at.json
else
repo_curl ${options[destination_repo]} api_json ${options[destination_api]} > $TMPDIR/updated_at.json
repo_curl ${options[destination_repo]} api_json ${options[destination_api]} >$TMPDIR/updated_at.json
fi
jq --raw-output .updated_at < $TMPDIR/updated_at.json
jq --raw-output .updated_at <$TMPDIR/updated_at.json
}
function delete_branch_destination() {
@ -49,12 +49,12 @@ function delete_branch_destination() {
local repo=${options[destination_repo]}
local api=${options[destination_api]}
if ${options[destination_is_fork]} ; then
if ${options[destination_is_fork]}; then
repo=${options[destination_fork_repo]}
api=${options[destination_fork_api]}
fi
if ! repo_curl ${options[destination_repo]} api_json $api/branches/$branch >& /dev/null ; then
if ! repo_curl ${options[destination_repo]} api_json $api/branches/$branch >&/dev/null; then
log_info "branch $branch does not exists in $repo"
return
fi
@ -67,7 +67,7 @@ function pr_origin_comment_body() {
}
function comment_origin_pr() {
cat > $TMPDIR/data <<EOF
cat >$TMPDIR/data <<EOF
{
"body":"$(pr_origin_comment_body)"
}
@ -95,13 +95,13 @@ function upsert_destination_pr() {
log_info "an open PR already exists $url"
return
fi
if ${options[destination_is_fork]} ; then
if ${options[destination_is_fork]}; then
head="$(owner ${options[destination_fork_repo]}):${options[destination_head]}"
else
head=${options[destination_head]}
fi
local title=$(pr_destination_title)
cat > $TMPDIR/data <<EOF
cat >$TMPDIR/data <<EOF
{
"title":"$(pr_destination_title)",
"body":"$(pr_destination_body)",
@ -109,7 +109,7 @@ function upsert_destination_pr() {
"head":"$head"
}
EOF
retry repo_curl ${options[destination_repo]} api_json --data @$TMPDIR/data ${options[destination_api]}/pulls > $TMPDIR/destination-pr.json
retry repo_curl ${options[destination_repo]} api_json --data @$TMPDIR/data ${options[destination_api]}/pulls >$TMPDIR/destination-pr.json
log_info "PR created $(pr_url destination)"
}
@ -127,12 +127,12 @@ function close_pr() {
}
function pr_get_origin() {
repo_curl ${options[origin_repo]} api_json ${options[origin_api]}/pulls/${options[origin_pr]} > $TMPDIR/origin-pr.json
repo_curl ${options[origin_repo]} api_json ${options[origin_api]}/pulls/${options[origin_pr]} >$TMPDIR/origin-pr.json
}
function pr_get_destination() {
local title=$(pr_destination_title)
repo_curl ${options[destination_repo]} api --get --data state=open --data type=pulls --data-urlencode q="$title" ${options[destination_api]}/issues | jq --raw-output .[0] > $TMPDIR/destination-pr.json
repo_curl ${options[destination_repo]} api --get --data state=open --data type=pulls --data-urlencode q="$title" ${options[destination_api]}/issues | jq --raw-output .[0] >$TMPDIR/destination-pr.json
}
function pr_get() {
@ -191,7 +191,7 @@ function git_checkout() {
(
cd $TMPDIR/$direction
if [[ "$ref" =~ ^refs/ ]] ; then
if [[ "$ref" =~ ^refs/ ]]; then
git fetch --update-head-ok ${remote} +$ref:$ref
else
ref=${remote}/$ref
@ -213,7 +213,7 @@ function git_reset_branch() {
local direction=$1 remote=$2 branch=$3
(
cd $TMPDIR/$direction
if git ls-remote --exit-code --heads ${remote} $branch ; then
if git ls-remote --exit-code --heads ${remote} $branch; then
git fetch --quiet ${remote} $branch
git reset --hard ${remote}/$branch
fi
@ -222,7 +222,7 @@ function git_reset_branch() {
function sha_pushed() {
local direction=$1
if test -f $TMPDIR/$direction.sha ; then
if test -f $TMPDIR/$direction.sha; then
cat $TMPDIR/$direction.sha
fi
}
@ -243,7 +243,7 @@ function push() {
local before=$(destination_updated_at)
sleep 1 # the resolution of the update time is one second
git push --force ${remote} prbranch:$branch
git rev-parse HEAD > ../destination.sha
git rev-parse HEAD >../destination.sha
retry destination_updated_at_changed "$before"
local after=$(destination_updated_at)
log_info "pushed"
@ -260,20 +260,20 @@ function wait_destination_ci() {
}
function upsert_fork() {
if repo_curl ${options[destination_repo]} api_json ${options[destination_fork_api]} > $TMPDIR/fork.json 2> /dev/null ; then
if test "$(jq --raw-output .fork < $TMPDIR/fork.json)" != true ; then
if repo_curl ${options[destination_repo]} api_json ${options[destination_fork_api]} >$TMPDIR/fork.json 2>/dev/null; then
if test "$(jq --raw-output .fork <$TMPDIR/fork.json)" != true; then
log_error "the destination fork already exists but is not a fork ${options[destination_fork]}"
return 1
fi
local forked_from_repo=$(jq --raw-output .parent.full_name < $TMPDIR/fork.json)
if test "$forked_from_repo" != "${options[destination_repo]}" ; then
local forked_from_repo=$(jq --raw-output .parent.full_name <$TMPDIR/fork.json)
if test "$forked_from_repo" != "${options[destination_repo]}"; then
log_error "${options[destination_fork]} must be a fork of ${options[destination_repo]} but is a fork of $forked_from_repo instead"
return 1
fi
else
local fork_owner=$(owner ${options[destination_fork_repo]})
local data="{}"
if repo_curl ${options[destination_repo]} api_json ${options[destination_url]}/api/v1/orgs/${fork_owner} >& /dev/null ; then
if repo_curl ${options[destination_repo]} api_json ${options[destination_url]}/api/v1/orgs/${fork_owner} >&/dev/null; then
data='{"organization":"'$fork_owner'"}'
fi
repo_curl ${options[destination_repo]} api_json --data "$data" ${options[destination_url]}/api/v1/repos/${options[destination_repo]}/forks
@ -297,7 +297,7 @@ function checkout() {
# fork
#
local head_remote=origin
if ${options[destination_is_fork]} ; then
if ${options[destination_is_fork]}; then
upsert_fork
git_remote destination fork ${options[destination_fetch_fork]}
head_remote=fork
@ -308,7 +308,7 @@ function checkout() {
function update() {
(
local update=${options[update]}
if ! [[ "$update" =~ ^/ ]] ; then
if ! [[ "$update" =~ ^/ ]]; then
local d
if $(origin_has_pr) && $(pr_from_fork origin); then
local default_branch=$(default_branch origin)
@ -330,7 +330,7 @@ function update() {
$update $TMPDIR/destination $TMPDIR/destination-pr.json $TMPDIR/origin $origin_info
)
local remote_head=origin
if ${options[destination_is_fork]} ; then
if ${options[destination_is_fork]}; then
remote_head=fork
fi
push $remote_head ${options[destination_head]}
@ -340,15 +340,15 @@ function set_git_url() {
local direction=$1 name=$2 repo=$3
local token=${options[${direction}_token]}
if [[ "$token" =~ ^@ ]] ; then
if [[ "$token" =~ ^@ ]]; then
local file=${token##@}
(
echo -n ${options[${direction}_scheme]}://any:
cat $file
echo @${options[${direction}_host_port]}/$repo
) > $TMPDIR/$direction.git-credentials
) >$TMPDIR/$direction.git-credentials
else
echo ${options[${direction}_scheme]}://any:${options[${direction}_token]}@${options[${direction}_host_port]}/$repo > $TMPDIR/$direction.git-credentials
echo ${options[${direction}_scheme]}://any:${options[${direction}_token]}@${options[${direction}_host_port]}/$repo >$TMPDIR/$direction.git-credentials
fi
options[$name]=${options[${direction}_scheme]}://${options[${direction}_host_port]}/$repo
}
@ -409,17 +409,17 @@ function run_origin_ref() {
checkout
update
local sha=$(sha_pushed destination)
if test "$sha" ; then
if test "$sha"; then
upsert_destination_pr
local status
if wait_destination_ci "$sha" ; then
if wait_destination_ci "$sha"; then
log_info "cascade PR status successful"
status=0
else
log_info "cascade PR status failed"
status=1
fi
if "${options[close]}" ; then
if "${options[close]}"; then
log_info "close the cascade PR and remove the branch"
close_pr
fi
@ -436,7 +436,7 @@ function run_origin_pr() {
checkout
update
local sha=$(sha_pushed destination)
if test "$sha" ; then
if test "$sha"; then
upsert_destination_pr
comment_origin_pr
wait_destination_ci "$sha"
@ -444,7 +444,7 @@ function run_origin_pr() {
;;
closed)
if "$(pr_merged origin)"; then
if "${options[close]}" ; then
if "${options[close]}"; then
log_info "PR is merged, close the cascade PR and remove the branch"
close_pr
else
@ -552,7 +552,7 @@ function main() {
dependencies
if echo "${@}" | grep --quiet -e '--debug' ; then
if echo "${@}" | grep --quiet -e '--debug'; then
main "${@}"
else
stash_debug "${@}"

View file

@ -2,7 +2,7 @@
# SPDX-License-Identifier: MIT
VERSION=1.0.0
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SELF_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VERBOSE=false
DEBUG=false
: ${EXIT_ON_ERROR:=true}
@ -28,7 +28,7 @@ function log_error() {
}
function log_verbose() {
if $VERBOSE ; then
if $VERBOSE; then
log "$@"
fi
}
@ -39,7 +39,7 @@ function log_info() {
function fatal_error() {
log_error "$@"
if $EXIT_ON_ERROR ; then
if $EXIT_ON_ERROR; then
exit 1
else
return 1
@ -66,32 +66,35 @@ function login_api() {
local user="$1" password="$2" token="$3" scopes="${4:-[\"all\"]}" url="$5"
dot_ensure
if test -s $DOT/token ; then
if test -s $DOT/token; then
log_info "already logged in, ignored"
return
fi
if test -z "$token" ; then
if test -z "$token"; then
log_verbose curl -sS -X DELETE --user "${user}:${password}" "${url}/api/v1/users/$user/tokens/${TOKEN_NAME}" -o /dev/null -w "%{http_code}"
local basic="${user:-unknown}:${password:-unknown}"
local status=$(curl -sS -X DELETE --user "${basic}" "${url}/api/v1/users/$user/tokens/${TOKEN_NAME}" -o /dev/null -w "%{http_code}")
if test "${status}" != 404 -a "${status}" != 204 ; then
if test "${status}" != 404 -a "${status}" != 204; then
fatal_error permission denied, the user or password are probably incorrect, try again with --verbose
return 1
fi
token=$(client $HEADER_JSON --user "${basic}" --data-raw '{"name":"'${TOKEN_NAME}'","scopes":'${scopes}'}' "${url}/api/v1/users/${user}/tokens" | jq --raw-output .sha1)
fi
if [[ "$token" =~ ^@ ]] ; then
if [[ "$token" =~ ^@ ]]; then
cp "${token##@}" $DOT/token
else
echo "$token" > $DOT/token
echo "$token" >$DOT/token
fi
( echo -n "Authorization: token " ; cat $DOT/token ) > $DOT/header-token
(
echo -n "Authorization: token "
cat $DOT/token
) >$DOT/header-token
#
# Verify it works
#
local status=$(api -w "%{http_code}" -o /dev/null "${url}/api/v1/user")
if test "${status}" != 200 ; then
if test "${status}" != 200; then
fatal_error "${url}/api/v1/user returns status code '${status}', the token is invalid, $0 logout and login again"
return 1
fi
@ -99,7 +102,7 @@ function login_api() {
function client() {
log_verbose curl --cookie $DOT/cookies -f -sS "$@"
if ! curl --cookie $DOT/cookies -f -sS "$@" ; then
if ! curl --cookie $DOT/cookies -f -sS "$@"; then
fatal_error
fi
}
@ -111,7 +114,7 @@ function web() {
function client_update_cookies() {
log_verbose curl --cookie-jar $DOT/cookies --cookie $DOT/cookies -w "%{http_code}" -f -sS "$@"
local status=$(curl --cookie-jar $DOT/cookies --cookie $DOT/cookies -w "%{http_code}" -f -sS "$@")
if ! test "${status}" = 200 -o "${status}" = 303 ; then
if ! test "${status}" = 200 -o "${status}" = 303; then
fatal_error
fi
}
@ -119,7 +122,7 @@ function client_update_cookies() {
function login_client() {
local user="$1" password="$2" url="$3"
if test -z "$password" ; then
if test -z "$password"; then
log_verbose "no password, web will not be authenticated"
return
fi
@ -138,14 +141,14 @@ function login_client() {
#
client_update_cookies -o /dev/null "${url}/user/login"
local csrf=$(sed -n -e '/csrf/s/.*csrf\t//p' $DOT/cookies)
echo "X-Csrf-Token: $csrf" > $DOT/header-csrf
echo "X-Csrf-Token: $csrf" >$DOT/header-csrf
#
# Verify it works
#
local status=$(web -o /dev/null -w "%{http_code}" "${url}/user/settings")
if test "${status}" != 200 ; then
if test "${status}" != 200; then
grep -C 1 flash-error $DOT/login.html
if ${DEBUG} ; then
if ${DEBUG}; then
cat $DOT/login.html
fi
fatal_error login failed, the user or password are probably incorrect, try again with --verbose
@ -160,12 +163,11 @@ function login() {
function logout() {
rm -f $DOT/*
if test -d $DOT ; then
if test -d $DOT; then
rmdir $DOT
fi
}
function usage() {
cat >&2 <<EOF
forgejo-curl.sh - thin curl wrapper that helps with Forgejo authentication
@ -327,7 +329,7 @@ function main() {
echo "forgejo-curl.sh version $VERSION"
return 0
;;
--help|*)
--help | *)
usage
return 1
;;

View file

@ -4,7 +4,7 @@
set -e
set -o posix
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SELF_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TMPDIR=/tmp/cascading-pr-test
export LOOP_DELAY=5
mkdir -p $TMPDIR
@ -44,8 +44,8 @@ function user_secret() {
}
function orgs_delete() {
forgejo-curl.sh api_json ${options[url]}/api/v1/orgs | jq --raw-output '.[] | .name' | while read owner ; do
forgejo-curl.sh api_json ${options[url]}/api/v1/orgs/$owner/repos | jq --raw-output '.[] | .name' | while read repo ; do
forgejo-curl.sh api_json ${options[url]}/api/v1/orgs | jq --raw-output '.[] | .name' | while read owner; do
forgejo-curl.sh api_json ${options[url]}/api/v1/orgs/$owner/repos | jq --raw-output '.[] | .name' | while read repo; do
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/repos/$owner/$repo
done
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/orgs/$owner
@ -55,7 +55,7 @@ function orgs_delete() {
function user_create() {
local username="$1" email="$2"
log_verbose "(re)create user $username"
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/admin/users/$username?purge=true >& /dev/null || true
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/admin/users/$username?purge=true >&/dev/null || true
forgejo-curl.sh api_json --data '{"username":"'$username'","email":"'$email'","password":"'${options[password]}'","must_change_password":false}' ${options[url]}/api/v1/admin/users
user_login $username
}
@ -64,7 +64,7 @@ function close_pull_request() {
local repo=$1
log_verbose "close all pull requests in user1/$repo"
forgejo-curl.sh api_json ${options[url]}/api/v1/repos/user1/${repo}/pulls | jq --raw-output '.[] | .number' | while read pr ; do
forgejo-curl.sh api_json ${options[url]}/api/v1/repos/user1/${repo}/pulls | jq --raw-output '.[] | .number' | while read pr; do
forgejo-curl.sh api_json -X PATCH --data '{"state":"closed"}' ${options[url]}/api/v1/repos/user1/${repo}/issues/$pr
done
}
@ -73,7 +73,7 @@ function merge_pull_request() {
local repo=$1
log_verbose "merge all pull requests in user1/$repo"
forgejo-curl.sh api_json ${options[url]}/api/v1/repos/user1/${repo}/pulls | jq --raw-output '.[] | .number' | while read pr ; do
forgejo-curl.sh api_json ${options[url]}/api/v1/repos/user1/${repo}/pulls | jq --raw-output '.[] | .number' | while read pr; do
forgejo-curl.sh api_json --data '{"Do":"merge"}' ${options[url]}/api/v1/repos/user1/${repo}/pulls/$pr/merge
done
}
@ -120,15 +120,15 @@ function create_branch1() {
local owner=$1 repo=$2 modify=$3
log_verbose "(re)create branch1 in $owner/$repo"
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/repos/$owner/${repo}/branches/branch1 >& /dev/null || true
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/repos/$owner/${repo}/branches/branch1 >&/dev/null || true
forgejo-curl.sh api_json --data '{"new_branch_name":"branch1"}' ${options[url]}/api/v1/repos/$owner/${repo}/branches
(
cd $TMPDIR
rm -fr ${repo}
git clone -b branch1 http://user1:admin1234@${options[host_port]}/$owner/${repo}
cd ${repo}
echo CONTENT > README
if test "$modify" ; then
echo CONTENT >README
if test "$modify"; then
log_verbose "modify branch1 in $owner/$repo with $modify"
$modify
fi
@ -137,19 +137,18 @@ function create_branch1() {
git add .
git commit -m 'update'
git push origin branch1
git rev-parse HEAD > ../${owner}-${repo}.sha
git rev-parse HEAD >../${owner}-${repo}.sha
)
}
function delete_pull_requests() {
local owner=$1 repo=$2
forgejo-curl.sh api_json ${options[url]}/api/v1/repos/$owner/${repo}/pulls | jq --raw-output '.[] | .number' | while read pr ; do
forgejo-curl.sh api_json ${options[url]}/api/v1/repos/$owner/${repo}/pulls | jq --raw-output '.[] | .number' | while read pr; do
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/repos/$owner/${repo}/issues/$pr
done
}
function create_pull_request() {
local baseowner=$1 headowner=$2 repo=$3
@ -159,7 +158,7 @@ function create_pull_request() {
else
head=$headowner:branch1
fi
cat > $TMPDIR/data <<EOF
cat >$TMPDIR/data <<EOF
{"title":"PR","base":"main","head":"$head"}
EOF
log_verbose "create pull request in $baseowner/$repo from $head"
@ -184,9 +183,9 @@ function unit_finalize_options() {
function unit_retry_fail() {
local file=$1
local value=$(cat $file)
expr $value - 1 > $file
expr $value - 1 >$file
echo RESULT
if test $value -gt 0 ; then
if test $value -gt 0; then
return 1
else
return 0
@ -201,25 +200,25 @@ function unit_retry() {
#
# Succeeds after two tries
#
echo 2 > $TMPDIR/unit_retry_two
if ! RETRY_DELAYS='1 1 1 1' retry unit_retry_fail $two > $TMPDIR/retry.test-result 2> $TMPDIR/retry.test-log ; then
echo 2 >$TMPDIR/unit_retry_two
if ! RETRY_DELAYS='1 1 1 1' retry unit_retry_fail $two >$TMPDIR/retry.test-result 2>$TMPDIR/retry.test-log; then
cat $TMPDIR/retry.test-result $TMPDIR/retry.test-log
return 1
fi
test "$(cat $TMPDIR/retry.test-result)" = "RESULT"
if test "$(grep -c '^waiting 1 unit_retry_fail' $TMPDIR/retry.test-log)" != 2 ; then
if test "$(grep -c '^waiting 1 unit_retry_fail' $TMPDIR/retry.test-log)" != 2; then
cat $TMPDIR/retry.test-log
return 1
fi
#
# Succeeds immediately
#
if ! RETRY_DELAYS='1' retry unit_retry_fail $two > $TMPDIR/retry.test-result 2> $TMPDIR/retry.test-log ; then
if ! RETRY_DELAYS='1' retry unit_retry_fail $two >$TMPDIR/retry.test-result 2>$TMPDIR/retry.test-log; then
cat $TMPDIR/retry.test-result $TMPDIR/retry.test-log
return 1
fi
test "$(cat $TMPDIR/retry.test-result)" = "RESULT"
if test "$(grep -c 'waiting 1 unit_retry_fail' $TMPDIR/retry.test-log)" != 0 ; then
if test "$(grep -c 'waiting 1 unit_retry_fail' $TMPDIR/retry.test-log)" != 0; then
cat $TMPDIR/retry.test-log
return 1
fi
@ -228,14 +227,14 @@ function unit_retry() {
# Verify the output is only the output of the last run and is not polluted by
# unrelated output
#
echo 2 > $TMPDIR/unit_retry_two
echo 2 >$TMPDIR/unit_retry_two
test "$(RETRY_DELAYS='1 1 1' retry unit_retry_fail $two)" = "RESULT"
#
# Fails after one try
#
echo 2 > $TMPDIR/unit_retry_two
if RETRY_DELAYS='1' retry unit_retry_fail $two > $TMPDIR/retry.test-result 2> $TMPDIR/retry.test-log ; then
echo 2 >$TMPDIR/unit_retry_two
if RETRY_DELAYS='1' retry unit_retry_fail $two >$TMPDIR/retry.test-result 2>$TMPDIR/retry.test-log; then
cat $TMPDIR/retry.test-result $TMPDIR/retry.test-log
return 1
fi
@ -323,11 +322,11 @@ function create_and_close() {
}
function taint_update() {
if ! test -f upgraded ; then
if ! test -f upgraded; then
echo upgraded file not found
return 1
fi
echo 'TAINTED' > upgraded
echo 'TAINTED' >upgraded
}
function create_from_origin_fork_and_close() {
@ -423,14 +422,14 @@ function run() {
shift
echo "Start running $fun ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
if $DEBUG ; then
if $DEBUG; then
$fun "$@"
else
mkdir -p $TMPDIR
> $TMPDIR/$fun.out
>$TMPDIR/$fun.out
tail --follow $TMPDIR/$fun.out | sed --unbuffered -n -e "/^$PREFIX/s/^$PREFIX //p" &
pid=$!
if ! ${BASH_SOURCE[0]} --debug ${options[args]} $fun "$@" >& $TMPDIR/$fun.out ; then
if ! ${BASH_SOURCE[0]} --debug ${options[args]} $fun "$@" >&$TMPDIR/$fun.out; then
kill $pid
cat $TMPDIR/$fun.out
echo Failure running $fun