mirror of
https://code.forgejo.org/actions/cascading-pr
synced 2025-03-15 06:46:59 +01:00
improve the readability of API calls
This commit is contained in:
parent
e445a531fa
commit
28c365c695
1 changed files with 16 additions and 3 deletions
|
@ -42,7 +42,13 @@ function upsert_branch() {
|
||||||
log_info "branch ${options[destination_head]} already exists"
|
log_info "branch ${options[destination_head]} already exists"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
repo_curl ${options[destination_repo]} api_json --data-raw '{"new_branch_name":"'${options[destination_head]}'","old_branch_name":"'${options[destination_base]}'"}' ${options[destination_api]}/branches
|
cat > $TMPDIR/data <<EOF
|
||||||
|
{
|
||||||
|
"new_branch_name":"${options[destination_head]}",
|
||||||
|
"old_branch_name":"${options[destination_base]}"
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
repo_curl ${options[destination_repo]} api_json --data @$TMPDIR/data ${options[destination_api]}/branches
|
||||||
log_info "branch ${options[destination_head]} created"
|
log_info "branch ${options[destination_head]} created"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +64,14 @@ function upsert_pr() {
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
local title=$(pr_destination_title)
|
local title=$(pr_destination_title)
|
||||||
retry repo_curl ${options[destination_repo]} api_json --data-raw '{"title":"'"$title"'","base":"'${options[destination_base]}'","head":"'${options[destination_head]}'"}' ${options[destination_api]}/pulls > $TMPDIR/destination-pr.json
|
cat > $TMPDIR/data <<EOF
|
||||||
|
{
|
||||||
|
"title":"$title",
|
||||||
|
"base":"${options[destination_base]}",
|
||||||
|
"head":"${options[destination_head]}"
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
retry repo_curl ${options[destination_repo]} api_json --data @$TMPDIR/data ${options[destination_api]}/pulls > $TMPDIR/destination-pr.json
|
||||||
log_info "PR created $(pr_url destination)"
|
log_info "PR created $(pr_url destination)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +81,7 @@ function close_pr() {
|
||||||
if test "$(pr_state ${direction})" = "open"; then
|
if test "$(pr_state ${direction})" = "open"; then
|
||||||
log_info "closing $(pr_url ${direction})"
|
log_info "closing $(pr_url ${direction})"
|
||||||
local number=$(pr_number $direction)
|
local number=$(pr_number $direction)
|
||||||
repo_curl ${options[${direction}_repo]} api_json -X PATCH --data-raw '{"state":"closed"}' ${options[${direction}_api]}/issues/$number
|
repo_curl ${options[${direction}_repo]} api_json -X PATCH --data '{"state":"closed"}' ${options[${direction}_api]}/issues/$number
|
||||||
delete_branch $(pr_head ${direction})
|
delete_branch $(pr_head ${direction})
|
||||||
else
|
else
|
||||||
log_info "no open PR found"
|
log_info "no open PR found"
|
||||||
|
|
Loading…
Add table
Reference in a new issue