1
0
Fork 0
mirror of https://code.forgejo.org/actions/cascading-pr synced 2025-03-15 14:54:40 +01:00

update merge

This commit is contained in:
Earl Warren 2023-10-13 21:08:52 +02:00
parent c87d693481
commit b89d03dbb7
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
3 changed files with 43 additions and 9 deletions

View file

@ -108,6 +108,10 @@ function pr_head() {
pr $1 | jq --raw-output .head.ref pr $1 | jq --raw-output .head.ref
} }
function pr_merged() {
pr $1 | jq --raw-output .merged
}
function upsert_clone() { function upsert_clone() {
local direction=$1 branch=$2 clone=$3 local direction=$1 branch=$2 clone=$3
@ -154,7 +158,7 @@ function update() {
( (
cd $TMPDIR/origin cd $TMPDIR/origin
ls -l $TMPDIR/destination 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]} push destination ${options[destination_head]} ${options[destination_clone]}
} }
@ -188,9 +192,17 @@ function run() {
wait_destination_ci $(cat $TMPDIR/destination.sha) wait_destination_ci $(cat $TMPDIR/destination.sha)
;; ;;
closed) 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" log_info "PR is closed, close the cascade PR and remove the branch"
repo_login ${options[destination_repo]} repo_login ${options[destination_repo]}
close_pr destination close_pr destination
fi
;; ;;
*) *)
log_info "state '$state', do nothing" log_info "state '$state', do nothing"

View file

@ -1,5 +1,13 @@
#!/bin/bash #!/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

View file

@ -51,6 +51,12 @@ function close_pull_request() {
done 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() { 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 ${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 forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/repos/user1/originrepo/issues/$pr
@ -96,12 +102,20 @@ function run() {
push_self push_self
#
# create & close
#
create_pull_request 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) 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) wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/originrepo.sha)
} }