allow running on a ref instead of a PR

When running from a PR, the ref is the head of the PR in the origin
repository. The PR is used to:

* display comments about the location of the destination PR
* asynchronously close / merge the destination PR when something
  happens in the origin PR

When only the ref is available, the destination PR must be closed and
the corresponding branch destroyed immediately after it concludes
because there is no convenient way to know what or when something
else will happen.
This commit is contained in:
Earl Warren 2024-01-02 18:39:58 +01:00
parent 0e9a4e846b
commit 0c3c8b591b
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
12 changed files with 326 additions and 85 deletions

View file

@ -197,3 +197,47 @@ function wait_status() {
return 1
fi
}
function sanity_check_pr_or_ref() {
local pr="$1" ref="$2"
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
log_error "one of --origin-pr or --origin-ref must be set"
return 2
fi
}
function set_origin_head() {
local pr="${options[origin_pr]}"
local ref="${options[origin_ref]}"
sanity_check_pr_or_ref "$pr" "$ref"
if test "$pr"; then
options[origin_head]=refs/pull/$pr/head
origin_sanity_check
else
options[origin_head]=$ref
fi
}
function origin_has_pr() {
test "${options[origin_pr]}"
}
function set_destination_head() {
local pr="${options[origin_pr]}"
local ref="${options[origin_ref]}"
sanity_check_pr_or_ref "$pr" "$ref"
if $(origin_has_pr); then
options[destination_head]=${options[prefix]}-$pr
else
options[destination_head]=${options[prefix]}-$ref
fi
}