mirror of
https://code.forgejo.org/actions/cascading-pr
synced 2025-03-15 06:46:59 +01:00
update merge
This commit is contained in:
parent
c87d693481
commit
b89d03dbb7
3 changed files with 43 additions and 9 deletions
|
@ -108,6 +108,10 @@ function pr_head() {
|
|||
pr $1 | jq --raw-output .head.ref
|
||||
}
|
||||
|
||||
function pr_merged() {
|
||||
pr $1 | jq --raw-output .merged
|
||||
}
|
||||
|
||||
function upsert_clone() {
|
||||
local direction=$1 branch=$2 clone=$3
|
||||
|
||||
|
@ -154,7 +158,7 @@ function update() {
|
|||
(
|
||||
cd $TMPDIR/origin
|
||||
ls -l $TMPDIR/destination
|
||||
${options[update]} $TMPDIR/destination
|
||||
${options[update]} $TMPDIR/destination $TMPDIR/destination-pr.json $TMPDIR/origin-pr.json
|
||||
)
|
||||
push destination ${options[destination_head]} ${options[destination_clone]}
|
||||
}
|
||||
|
@ -188,9 +192,17 @@ function run() {
|
|||
wait_destination_ci $(cat $TMPDIR/destination.sha)
|
||||
;;
|
||||
closed)
|
||||
if "$(pr_merged origin)"; then
|
||||
log_info "PR was merged, update the cascade PR"
|
||||
repo_login ${options[destination_repo]}
|
||||
pr origin
|
||||
pr destination
|
||||
update
|
||||
else
|
||||
log_info "PR is closed, close the cascade PR and remove the branch"
|
||||
repo_login ${options[destination_repo]}
|
||||
close_pr destination
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
log_info "state '$state', do nothing"
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
#!/bin/bash
|
||||
|
||||
destination="$1"
|
||||
set -ex
|
||||
|
||||
date +%s > $destination/last
|
||||
destination_checkout="$1"
|
||||
destination_pr_json="$2"
|
||||
origin_pr_json="$3"
|
||||
|
||||
test -d $destination_checkout
|
||||
test -f $destination_pr_json
|
||||
test -f $origin_pr_json
|
||||
|
||||
date +%s > $destination_checkout/last
|
||||
|
|
20
tests/run.sh
20
tests/run.sh
|
@ -51,6 +51,12 @@ function close_pull_request() {
|
|||
done
|
||||
}
|
||||
|
||||
function merge_pull_request() {
|
||||
forgejo-curl.sh api_json ${options[url]}/api/v1/repos/user1/originrepo/pulls | jq --raw-output '.[] | .number' | while read pr ; do
|
||||
forgejo-curl.sh api_json --data-raw '{"Do":"merge"}' ${options[url]}/api/v1/repos/user1/originrepo/pulls/$pr/merge
|
||||
done
|
||||
}
|
||||
|
||||
function create_pull_request() {
|
||||
forgejo-curl.sh api_json ${options[url]}/api/v1/repos/user1/originrepo/pulls | jq --raw-output '.[] | .number' | while read pr ; do
|
||||
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/repos/user1/originrepo/issues/$pr
|
||||
|
@ -96,12 +102,20 @@ function run() {
|
|||
|
||||
push_self
|
||||
|
||||
#
|
||||
# create & close
|
||||
#
|
||||
create_pull_request
|
||||
|
||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/originrepo.sha)
|
||||
close_pull_request
|
||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/originrepo.sha)
|
||||
|
||||
close_pull_request
|
||||
|
||||
#
|
||||
# create & merge
|
||||
#
|
||||
create_pull_request
|
||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/originrepo.sha)
|
||||
merge_pull_request
|
||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/originrepo.sha)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue