mirror of
https://code.forgejo.org/actions/cascading-pr.git
synced 2025-04-21 08:28:44 +00:00
close-merge input
Fixes: https://code.forgejo.org/actions/cascading-pr/issues/7
This commit is contained in:
parent
f8a65b3d9f
commit
5caaedbc52
7 changed files with 80 additions and 9 deletions
|
@ -46,6 +46,7 @@ pushed as a new commit in the PR.
|
||||||
| destination-token | a token with write permission on destination-repo | `true` | |
|
| destination-token | a token with write permission on destination-repo | `true` | |
|
||||||
| update | path to the script to update the content of the cascading PR | `true` | |
|
| update | path to the script to update the content of the cascading PR | `true` | |
|
||||||
| prefix | prefix of the cascading PR created on destination-repo (default to {origin-repo}) | `false` | |
|
| prefix | prefix of the cascading PR created on destination-repo (default to {origin-repo}) | `false` | |
|
||||||
|
| close-merge | if true the cascading PR will be closed and the branch deleted when the PR is merged | `false` | false |
|
||||||
| verbose | if true print verbose information | `false` | false |
|
| verbose | if true print verbose information | `false` | false |
|
||||||
| debug | if true print debug information | `false` | false |
|
| debug | if true print debug information | `false` | false |
|
||||||
<!-- action-docs-inputs -->
|
<!-- action-docs-inputs -->
|
||||||
|
|
|
@ -60,6 +60,9 @@ inputs:
|
||||||
required: true
|
required: true
|
||||||
prefix:
|
prefix:
|
||||||
description: 'prefix of the cascading PR created on destination-repo (default to {origin-repo})'
|
description: 'prefix of the cascading PR created on destination-repo (default to {origin-repo})'
|
||||||
|
close-merge:
|
||||||
|
description: 'if true the cascading PR will be closed and the branch deleted when the PR is merged'
|
||||||
|
default: false
|
||||||
verbose:
|
verbose:
|
||||||
description: 'if true print verbose information'
|
description: 'if true print verbose information'
|
||||||
default: false
|
default: false
|
||||||
|
@ -97,4 +100,5 @@ runs:
|
||||||
--destination-branch "${{ inputs.destination-branch }}" \
|
--destination-branch "${{ inputs.destination-branch }}" \
|
||||||
--update "${{ inputs.update }}" \
|
--update "${{ inputs.update }}" \
|
||||||
--prefix "${{ inputs.prefix }}" \
|
--prefix "${{ inputs.prefix }}" \
|
||||||
|
--close-merge "${{ inputs.close-merge }}" \
|
||||||
run
|
run
|
||||||
|
|
|
@ -241,6 +241,7 @@ function finalize_options() {
|
||||||
options[destination_base]=${options[destination_branch]}
|
options[destination_base]=${options[destination_branch]}
|
||||||
: ${options[prefix]:=${options[origin_repo]}}
|
: ${options[prefix]:=${options[origin_repo]}}
|
||||||
options[destination_head]=${options[prefix]}-${options[origin_pr]}
|
options[destination_head]=${options[prefix]}-${options[origin_pr]}
|
||||||
|
: ${options[close_merge]:=false}
|
||||||
}
|
}
|
||||||
|
|
||||||
function run() {
|
function run() {
|
||||||
|
@ -262,11 +263,17 @@ function run() {
|
||||||
;;
|
;;
|
||||||
closed)
|
closed)
|
||||||
if "$(pr_merged origin)"; then
|
if "$(pr_merged origin)"; then
|
||||||
log_info "PR was merged, update the cascade PR"
|
if "${options[close_merge]}" ; then
|
||||||
repo_login ${options[destination_repo]}
|
log_info "PR is merged, close the cascade PR and remove the branch"
|
||||||
pr_get origin
|
repo_login ${options[destination_repo]}
|
||||||
pr_get destination
|
close_pr
|
||||||
update
|
else
|
||||||
|
log_info "PR was merged, update the cascade PR"
|
||||||
|
repo_login ${options[destination_repo]}
|
||||||
|
pr_get origin
|
||||||
|
pr_get destination
|
||||||
|
update
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
log_info "PR is closed, close the cascade PR and remove the branch"
|
log_info "PR is closed, close the cascade PR and remove the branch"
|
||||||
repo_login ${options[destination_repo]}
|
repo_login ${options[destination_repo]}
|
||||||
|
@ -340,6 +347,11 @@ function main() {
|
||||||
options[prefix]=$1
|
options[prefix]=$1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--close-merge)
|
||||||
|
shift
|
||||||
|
options[close_merge]=$1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
finalize_options
|
finalize_options
|
||||||
"${1:-run}"
|
"${1:-run}"
|
||||||
|
|
26
tests/originrepo-close-merge/.forgejo/workflows/test.yml
Normal file
26
tests/originrepo-close-merge/.forgejo/workflows/test.yml
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
name: test
|
||||||
|
on:
|
||||||
|
pull_request_target:
|
||||||
|
types:
|
||||||
|
- opened
|
||||||
|
- synchronize
|
||||||
|
- closed
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: docker
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: SELF@vTest
|
||||||
|
with:
|
||||||
|
origin-url: ${{ env.GITHUB_SERVER_URL }}
|
||||||
|
origin-repo: user1/originrepo-close-merge
|
||||||
|
origin-token: ${{ secrets.ORIGIN_TOKEN }}
|
||||||
|
origin-pr: ${{ github.event.pull_request.number }}
|
||||||
|
destination-url: ${{ env.GITHUB_SERVER_URL }}
|
||||||
|
destination-repo: user2/destinationrepo
|
||||||
|
destination-branch: main
|
||||||
|
destination-token: ${{ secrets.DESTINATION_TOKEN }}
|
||||||
|
update: ./upgraded
|
||||||
|
close-merge: true
|
||||||
|
debug: true
|
1
tests/originrepo-close-merge/README
Normal file
1
tests/originrepo-close-merge/README
Normal file
|
@ -0,0 +1 @@
|
||||||
|
originrepo
|
12
tests/originrepo-close-merge/upgraded
Executable file
12
tests/originrepo-close-merge/upgraded
Executable file
|
@ -0,0 +1,12 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
destination_checkout="$1"
|
||||||
|
destination_pr_json="$2"
|
||||||
|
origin_pr_json="$3"
|
||||||
|
|
||||||
|
test -d $destination_checkout
|
||||||
|
test -f $origin_pr_json
|
||||||
|
|
||||||
|
date +%s > $destination_checkout/last
|
23
tests/run.sh
23
tests/run.sh
|
@ -64,13 +64,15 @@ function close_pull_request() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function merge_pull_request() {
|
function merge_pull_request() {
|
||||||
forgejo-curl.sh api_json ${options[url]}/api/v1/repos/user1/originrepo/pulls | jq --raw-output '.[] | .number' | while read pr ; do
|
local repo=$1
|
||||||
forgejo-curl.sh api_json --data '{"Do":"merge"}' ${options[url]}/api/v1/repos/user1/originrepo/pulls/$pr/merge
|
|
||||||
|
forgejo-curl.sh api_json ${options[url]}/api/v1/repos/user1/${repo}/pulls | jq --raw-output '.[] | .number' | while read pr ; do
|
||||||
|
forgejo-curl.sh api_json --data '{"Do":"merge"}' ${options[url]}/api/v1/repos/user1/${repo}/pulls/$pr/merge
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function has_cascade_pull_request() {
|
function has_cascade_pull_request() {
|
||||||
pr_count=$(forgejo-curl.sh api_json ${options[url]}/api/v1/repos/user2/destinationrepo/pulls | jq '. | length')
|
pr_count=$(forgejo-curl.sh api_json ${options[url]}/api/v1/repos/user2/destinationrepo/pulls | jq '[ .[] | select(.state == "open") ] | length')
|
||||||
test $pr_count -gt 0
|
test $pr_count -gt 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,8 +229,20 @@ function create_and_merge() {
|
||||||
create_pull_request user1 user1 originrepo
|
create_pull_request user1 user1 originrepo
|
||||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/user1-originrepo.sha)
|
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/user1-originrepo.sha)
|
||||||
has_cascade_pull_request
|
has_cascade_pull_request
|
||||||
merge_pull_request
|
merge_pull_request originrepo
|
||||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/user1-originrepo.sha)
|
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/user1-originrepo.sha)
|
||||||
|
has_cascade_pull_request
|
||||||
|
}
|
||||||
|
|
||||||
|
function create_and_merge_close() {
|
||||||
|
fixture originrepo-close-merge destinationrepo
|
||||||
|
|
||||||
|
create_pull_request user1 user1 originrepo-close-merge
|
||||||
|
wait_success ${options[url]}/api/v1/repos/user1/originrepo-close-merge $(cat $TMPDIR/user1-originrepo-close-merge.sha)
|
||||||
|
has_cascade_pull_request
|
||||||
|
merge_pull_request originrepo-close-merge
|
||||||
|
wait_success ${options[url]}/api/v1/repos/user1/originrepo-close-merge $(cat $TMPDIR/user1-originrepo-close-merge.sha)
|
||||||
|
! has_cascade_pull_request
|
||||||
}
|
}
|
||||||
|
|
||||||
function integration() {
|
function integration() {
|
||||||
|
@ -236,6 +250,7 @@ function integration() {
|
||||||
create_from_fork_and_close
|
create_from_fork_and_close
|
||||||
create_and_close
|
create_and_close
|
||||||
create_and_merge
|
create_and_merge
|
||||||
|
create_and_merge_close
|
||||||
}
|
}
|
||||||
|
|
||||||
function unit() {
|
function unit() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue