mirror of
https://code.forgejo.org/actions/cascading-pr.git
synced 2025-06-28 04:43:44 +00:00
draft implementation
This commit is contained in:
parent
ec542726c8
commit
fc026df37e
2 changed files with 135 additions and 6 deletions
|
@ -48,9 +48,64 @@ function upsert_pr() {
|
|||
log_info "PR created $url"
|
||||
}
|
||||
|
||||
function upsert_clone() {
|
||||
local direction=$1 branch=$2 clone=$3
|
||||
|
||||
local fetch=true
|
||||
if ! test -d $TMPDIR/$direction; then
|
||||
git clone $clone -b $branch $TMPDIR/$direction
|
||||
fetch=false
|
||||
fi
|
||||
(
|
||||
cd $TMPDIR/$direction
|
||||
if $fetch; then
|
||||
git fetch $direction
|
||||
fi
|
||||
git config user.email cascading-pr@example.com
|
||||
git config user.name cascading-pr
|
||||
)
|
||||
}
|
||||
|
||||
function push() {
|
||||
local direction=$1 branch=$2 clone=$3
|
||||
|
||||
(
|
||||
cd $TMPDIR/$direction
|
||||
if git diff; then
|
||||
log_info "nothing to push"
|
||||
else
|
||||
git add .
|
||||
git commit -m 'cascading-pr update'
|
||||
git push --force-push origin $branch
|
||||
git rev-parse HEAD > ../$direction.sha
|
||||
log_info "pushed"
|
||||
fi
|
||||
)
|
||||
}
|
||||
|
||||
function wait_destination_ci() {
|
||||
local sha="$1"
|
||||
local repo_api=${options[destination_url]}/api/v1/repos/${options[destination_repo]}
|
||||
wait_success $repo_api $sha
|
||||
}
|
||||
|
||||
function update() {
|
||||
upsert_clone origin ${options[origin_head]} ${options[origin_clone]}
|
||||
upsert_clone destination ${options[destination_head]} ${options[destination_clone]}
|
||||
(
|
||||
cd $TMPDIR/origin
|
||||
${options[update]} $TMPDIR/destination
|
||||
)
|
||||
push destination ${options[destination_clone]}
|
||||
}
|
||||
|
||||
function finalize_options() {
|
||||
options[origin_scheme]=$(scheme ${options[origin_url]})
|
||||
options[origin_host_port]=$(host_port ${options[origin_url]})
|
||||
options[origin_clone]=${options[origin_scheme]}://:${options[origin_token]}@${options[origin_host_port]}/${options[origin_repo]}
|
||||
options[destination_scheme]=$(scheme ${options[destination_url]})
|
||||
options[destination_host_port]=$(host_port ${options[destination_url]})
|
||||
options[destination_clone]=${options[destination_scheme]}://:${options[destination_token]}@${options[destination_host_port]}/${options[destination_repo]}
|
||||
options[destination_base]=${options[destination_branch]}
|
||||
: ${options[prefix]:=${options[origin_repo]}}
|
||||
options[destination_head]=${options[prefix]}-${options[origin_pr]}
|
||||
|
@ -61,12 +116,8 @@ function run() {
|
|||
upsert_branch
|
||||
upsert_pr
|
||||
repo_login ${options[origin_repo]}
|
||||
|
||||
# open a PR on destination
|
||||
# checkout the head of the PR
|
||||
# update the PR
|
||||
# force-push the head
|
||||
# wait on the status of the tip of the head
|
||||
update
|
||||
wait_destination_ci $(cat $TMPDIR/destination.sha)
|
||||
}
|
||||
|
||||
function main() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue