mirror of
https://code.forgejo.org/actions/cascading-pr.git
synced 2025-06-27 20:33:44 +00:00
do nothing if nothing is pushed
Fixes: https://code.forgejo.org/actions/cascading-pr/issues/6
This commit is contained in:
parent
bc706e42b6
commit
a449a6e6f5
6 changed files with 104 additions and 44 deletions
25
tests/originrepo-do-nothing/.forgejo/workflows/test.yml
Normal file
25
tests/originrepo-do-nothing/.forgejo/workflows/test.yml
Normal file
|
@ -0,0 +1,25 @@
|
|||
# SPDX-License-Identifier: MIT
|
||||
name: test
|
||||
on:
|
||||
pull_request:
|
||||
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-do-nothing
|
||||
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: /bin/true
|
||||
debug: true
|
1
tests/originrepo-do-nothing/README
Normal file
1
tests/originrepo-do-nothing/README
Normal file
|
@ -0,0 +1 @@
|
|||
originrepo
|
|
@ -7,7 +7,6 @@ destination_pr_json="$2"
|
|||
origin_pr_json="$3"
|
||||
|
||||
test -d $destination_checkout
|
||||
test -f $destination_pr_json
|
||||
test -f $origin_pr_json
|
||||
|
||||
date +%s > $destination_checkout/last
|
||||
|
|
70
tests/run.sh
70
tests/run.sh
|
@ -38,7 +38,7 @@ function user_token() {
|
|||
function user_secret() {
|
||||
local username=$1 name=$2 token=$3
|
||||
|
||||
user_curl $username api_json -X PUT --data '{"data":"'$token'"}' ${options[url]}/api/v1/repos/user1/originrepo/actions/secrets/$name
|
||||
user_curl $username api_json -X PUT --data '{"data":"'$token'"}' ${options[url]}/api/v1/user/actions/secrets/$name
|
||||
}
|
||||
|
||||
function user_create() {
|
||||
|
@ -60,27 +60,34 @@ function merge_pull_request() {
|
|||
done
|
||||
}
|
||||
|
||||
function has_cascade_pull_request() {
|
||||
pr_count=$(forgejo-curl.sh api_json ${options[url]}/api/v1/repos/user2/destinationrepo/pulls | jq '. | length')
|
||||
test $pr_count -gt 0
|
||||
}
|
||||
|
||||
function create_pull_request() {
|
||||
forgejo-curl.sh api_json ${options[url]}/api/v1/repos/user1/originrepo/pulls | jq --raw-output '.[] | .number' | while read pr ; do
|
||||
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/repos/user1/originrepo/issues/$pr
|
||||
local originrepo=$1
|
||||
|
||||
forgejo-curl.sh api_json ${options[url]}/api/v1/repos/user1/${originrepo}/pulls | jq --raw-output '.[] | .number' | while read pr ; do
|
||||
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/repos/user1/${originrepo}/issues/$pr
|
||||
done
|
||||
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/repos/user1/originrepo/branches/branch1 >& /dev/null || true
|
||||
forgejo-curl.sh api_json --data '{"new_branch_name":"branch1"}' ${options[url]}/api/v1/repos/user1/originrepo/branches
|
||||
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/repos/user1/${originrepo}/branches/branch1 >& /dev/null || true
|
||||
forgejo-curl.sh api_json --data '{"new_branch_name":"branch1"}' ${options[url]}/api/v1/repos/user1/${originrepo}/branches
|
||||
(
|
||||
cd $TMPDIR
|
||||
rm -fr originrepo
|
||||
git clone -b branch1 http://user1:admin1234@${options[host_port]}/user1/originrepo
|
||||
cd originrepo
|
||||
rm -fr ${originrepo}
|
||||
git clone -b branch1 http://user1:admin1234@${options[host_port]}/user1/${originrepo}
|
||||
cd ${originrepo}
|
||||
echo CONTENT > README
|
||||
git config user.email root@example.com
|
||||
git config user.name username
|
||||
git add .
|
||||
git commit -m 'update'
|
||||
git push origin branch1
|
||||
git rev-parse HEAD > ../originrepo.sha
|
||||
git rev-parse HEAD > ../${originrepo}.sha
|
||||
)
|
||||
|
||||
forgejo-curl.sh api_json --data '{"title":"PR","base":"main","head":"branch1"}' ${options[url]}/api/v1/repos/user1/originrepo/pulls
|
||||
forgejo-curl.sh api_json --data '{"title":"PR","base":"main","head":"branch1"}' ${options[url]}/api/v1/repos/user1/${originrepo}/pulls
|
||||
}
|
||||
|
||||
function finalize_options() {
|
||||
|
@ -143,34 +150,55 @@ function unit_retry() {
|
|||
grep --quiet 'retry failed' $TMPDIR/retry.log
|
||||
}
|
||||
|
||||
function integration() {
|
||||
function fixture() {
|
||||
local origin=$1
|
||||
local destination=$2
|
||||
|
||||
user_create user2 user2@example.com
|
||||
forgejo-test-helper.sh push tests/destinationrepo http://user2:admin1234@${options[host_port]} user2 destinationrepo
|
||||
forgejo-test-helper.sh push tests/${destination} http://user2:admin1234@${options[host_port]} user2 ${destination}
|
||||
|
||||
user_create user1 user1@example.com
|
||||
forgejo-test-helper.sh push tests/originrepo http://user1:admin1234@${options[host_port]} user1 originrepo cascading-pr
|
||||
forgejo-test-helper.sh push tests/${origin} http://user1:admin1234@${options[host_port]} user1 ${origin} cascading-pr
|
||||
user_secret user1 ORIGIN_TOKEN $(user_token user1 ORIGIN_TOKEN)
|
||||
user_secret user1 DESTINATION_TOKEN $(user_token user2 DESTINATION_TOKEN)
|
||||
|
||||
push_self
|
||||
}
|
||||
|
||||
#
|
||||
# create & close
|
||||
#
|
||||
create_pull_request
|
||||
function no_change_no_cascade_pr() {
|
||||
fixture originrepo-do-nothing destinationrepo
|
||||
|
||||
create_pull_request originrepo-do-nothing
|
||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo-do-nothing $(cat $TMPDIR/originrepo-do-nothing.sha)
|
||||
! has_cascade_pull_request
|
||||
}
|
||||
|
||||
function create_and_close() {
|
||||
fixture originrepo destinationrepo
|
||||
|
||||
create_pull_request originrepo
|
||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/originrepo.sha)
|
||||
has_cascade_pull_request
|
||||
close_pull_request
|
||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/originrepo.sha)
|
||||
}
|
||||
|
||||
#
|
||||
# create & merge
|
||||
#
|
||||
create_pull_request
|
||||
function create_and_merge() {
|
||||
fixture originrepo destinationrepo
|
||||
|
||||
create_pull_request originrepo
|
||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/originrepo.sha)
|
||||
has_cascade_pull_request
|
||||
merge_pull_request
|
||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/originrepo.sha)
|
||||
}
|
||||
|
||||
function integration() {
|
||||
no_change_no_cascade_pr
|
||||
create_and_close
|
||||
create_and_merge
|
||||
}
|
||||
|
||||
function unit() {
|
||||
unit_retry
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue