mirror of
https://code.forgejo.org/actions/cascading-pr.git
synced 2025-06-28 04:43:44 +00:00
do nothing if nothing is pushed
Fixes: https://code.forgejo.org/actions/cascading-pr/issues/6
This commit is contained in:
parent
bc706e42b6
commit
a449a6e6f5
6 changed files with 104 additions and 44 deletions
|
@ -43,7 +43,7 @@ function delete_branch() {
|
|||
}
|
||||
|
||||
function pr_origin_comment_body() {
|
||||
echo "cascading-pr created at ${options[destination_url]}/${options[destination_repo]}/pulls/$(pr_number destination)"
|
||||
echo "cascading-pr updated at ${options[destination_url]}/${options[destination_repo]}/pulls/$(pr_number destination)"
|
||||
}
|
||||
|
||||
function comment_origin_pr() {
|
||||
|
@ -121,31 +121,39 @@ function pr_get_destination() {
|
|||
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() {
|
||||
function pr_get() {
|
||||
local direction=$1
|
||||
if ! test -f $TMPDIR/${direction}-pr.json; then
|
||||
pr_get_$direction
|
||||
fi
|
||||
cat $TMPDIR/${direction}-pr.json
|
||||
}
|
||||
|
||||
function pr() {
|
||||
cat $TMPDIR/$1-pr.json
|
||||
}
|
||||
|
||||
function pr_state() {
|
||||
pr_get $1
|
||||
pr $1 | jq --raw-output .state
|
||||
}
|
||||
|
||||
function pr_url() {
|
||||
pr_get $1
|
||||
pr $1 | jq --raw-output .url
|
||||
}
|
||||
|
||||
function pr_number() {
|
||||
pr_get $1
|
||||
pr $1 | jq --raw-output .number
|
||||
}
|
||||
|
||||
function pr_head() {
|
||||
pr_get $1
|
||||
pr $1 | jq --raw-output .head.ref
|
||||
}
|
||||
|
||||
function pr_merged() {
|
||||
pr_get $1
|
||||
pr $1 | jq --raw-output .merged
|
||||
}
|
||||
|
||||
|
@ -168,6 +176,13 @@ function upsert_clone() {
|
|||
)
|
||||
}
|
||||
|
||||
function sha_pushed() {
|
||||
local direction=$1
|
||||
if test -f $TMPDIR/$direction.sha ; then
|
||||
cat $TMPDIR/$direction.sha
|
||||
fi
|
||||
}
|
||||
|
||||
function push() {
|
||||
local direction=$1 branch=$2 clone=$3
|
||||
|
||||
|
@ -176,11 +191,11 @@ function push() {
|
|||
git add .
|
||||
if git commit -m 'cascading-pr update'; then
|
||||
git push --force origin $branch
|
||||
git rev-parse HEAD > ../$direction.sha
|
||||
log_info "pushed"
|
||||
else
|
||||
log_info "nothing to push"
|
||||
fi
|
||||
git rev-parse HEAD > ../$direction.sha
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -240,18 +255,21 @@ function run() {
|
|||
log_info "PR is open, update or create the cascade branch and PR"
|
||||
repo_login ${options[destination_repo]}
|
||||
upsert_destination_branch
|
||||
upsert_destination_pr
|
||||
repo_login ${options[origin_repo]}
|
||||
comment_origin_pr
|
||||
update
|
||||
wait_destination_ci $(cat $TMPDIR/destination.sha)
|
||||
local sha=$(sha_pushed destination)
|
||||
if test "$sha" ; then
|
||||
upsert_destination_pr
|
||||
repo_login ${options[origin_repo]}
|
||||
comment_origin_pr
|
||||
wait_destination_ci "$sha"
|
||||
fi
|
||||
;;
|
||||
closed)
|
||||
if "$(pr_merged origin)"; then
|
||||
log_info "PR was merged, update the cascade PR"
|
||||
repo_login ${options[destination_repo]}
|
||||
pr origin
|
||||
pr destination
|
||||
pr_get origin
|
||||
pr_get destination
|
||||
update
|
||||
else
|
||||
log_info "PR is closed, close the cascade PR and remove the branch"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue