1
0
Fork 0
mirror of https://code.forgejo.org/actions/cascading-pr synced 2025-03-14 22:36:58 +01:00

Merge pull request 'always push what has been changed at destination' (#15) from earl-warren/cascading-pr:wip-race into main

Reviewed-on: https://code.forgejo.org/actions/cascading-pr/pulls/15
Reviewed-by: dachary <dachary@noreply.code.forgejo.org>
This commit is contained in:
earl-warren 2023-12-23 23:27:15 +00:00
commit 0e9a4e846b

View file

@ -33,11 +33,15 @@ function default_branch() {
jq --raw-output .default_branch < $TMPDIR/$direction.json
}
function updated_at() {
local direction=$1
function destination_updated_at() {
local api
repo_curl ${options[${direction}_repo]} api_json ${options[${direction}_api]} > $TMPDIR/$direction.json
jq --raw-output .updated_at < $TMPDIR/$direction.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
fi
jq --raw-output .updated_at < $TMPDIR/updated_at.json
}
function exists_branch() {
@ -218,17 +222,25 @@ function sha_pushed() {
fi
}
function destination_updated_at_changed() {
local before="$1"
local after="$(destination_updated_at)"
test "$before" != "$after"
}
function push() {
local direction=$1 remote=$2 branch=$3
local remote=$1 branch=$2
(
cd $TMPDIR/$direction
cd $TMPDIR/destination
git add .
if git commit -m 'cascading-pr update'; then
local updated_at=$(updated_at $direction)
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 > ../$direction.sha
retry test "$updated_at" != "$(updated_at $direction)"
git rev-parse HEAD > ../destination.sha
retry destination_updated_at_changed "$before"
local after=$(destination_updated_at)
log_info "pushed"
else
log_info "nothing to push"
@ -310,7 +322,7 @@ function update() {
if ${options[destination_is_fork]} ; then
remote_head=fork
fi
push destination $remote_head ${options[destination_head]}
push $remote_head ${options[destination_head]}
}
function set_git_url() {