mirror of
https://code.forgejo.org/actions/cascading-pr.git
synced 2025-04-21 08:28:44 +00: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:
commit
0e9a4e846b
1 changed files with 22 additions and 10 deletions
|
@ -33,11 +33,15 @@ function default_branch() {
|
||||||
jq --raw-output .default_branch < $TMPDIR/$direction.json
|
jq --raw-output .default_branch < $TMPDIR/$direction.json
|
||||||
}
|
}
|
||||||
|
|
||||||
function updated_at() {
|
function destination_updated_at() {
|
||||||
local direction=$1
|
local api
|
||||||
|
|
||||||
repo_curl ${options[${direction}_repo]} api_json ${options[${direction}_api]} > $TMPDIR/$direction.json
|
if ${options[destination_is_fork]} ; then
|
||||||
jq --raw-output .updated_at < $TMPDIR/$direction.json
|
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() {
|
function exists_branch() {
|
||||||
|
@ -218,17 +222,25 @@ function sha_pushed() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function destination_updated_at_changed() {
|
||||||
|
local before="$1"
|
||||||
|
local after="$(destination_updated_at)"
|
||||||
|
test "$before" != "$after"
|
||||||
|
}
|
||||||
|
|
||||||
function push() {
|
function push() {
|
||||||
local direction=$1 remote=$2 branch=$3
|
local remote=$1 branch=$2
|
||||||
|
|
||||||
(
|
(
|
||||||
cd $TMPDIR/$direction
|
cd $TMPDIR/destination
|
||||||
git add .
|
git add .
|
||||||
if git commit -m 'cascading-pr update'; then
|
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 push --force ${remote} prbranch:$branch
|
||||||
git rev-parse HEAD > ../$direction.sha
|
git rev-parse HEAD > ../destination.sha
|
||||||
retry test "$updated_at" != "$(updated_at $direction)"
|
retry destination_updated_at_changed "$before"
|
||||||
|
local after=$(destination_updated_at)
|
||||||
log_info "pushed"
|
log_info "pushed"
|
||||||
else
|
else
|
||||||
log_info "nothing to push"
|
log_info "nothing to push"
|
||||||
|
@ -310,7 +322,7 @@ function update() {
|
||||||
if ${options[destination_is_fork]} ; then
|
if ${options[destination_is_fork]} ; then
|
||||||
remote_head=fork
|
remote_head=fork
|
||||||
fi
|
fi
|
||||||
push destination $remote_head ${options[destination_head]}
|
push $remote_head ${options[destination_head]}
|
||||||
}
|
}
|
||||||
|
|
||||||
function set_git_url() {
|
function set_git_url() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue