From a69f5a0ce428f58a157a5f69da5656afbacbda26 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Tue, 24 Oct 2023 18:44:03 +0200 Subject: [PATCH] test PR from a fork Fixes: https://code.forgejo.org/actions/cascading-pr/issues/2 --- tests/originrepo/.forgejo/workflows/test.yml | 2 +- tests/run.sh | 78 +++++++++++++++----- 2 files changed, 59 insertions(+), 21 deletions(-) diff --git a/tests/originrepo/.forgejo/workflows/test.yml b/tests/originrepo/.forgejo/workflows/test.yml index ac8665a..4b7e008 100644 --- a/tests/originrepo/.forgejo/workflows/test.yml +++ b/tests/originrepo/.forgejo/workflows/test.yml @@ -1,7 +1,7 @@ # SPDX-License-Identifier: MIT name: test on: - pull_request: + pull_request_target: types: - opened - synchronize diff --git a/tests/run.sh b/tests/run.sh index 5ae2e6e..76f63d6 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -41,6 +41,15 @@ function user_secret() { user_curl $username api_json -X PUT --data '{"data":"'$token'"}' ${options[url]}/api/v1/user/actions/secrets/$name } +function orgs_delete() { + forgejo-curl.sh api_json ${options[url]}/api/v1/orgs | jq --raw-output '.[] | .name' | while read owner ; do + forgejo-curl.sh api_json ${options[url]}/api/v1/orgs/$owner/repos | jq --raw-output '.[] | .name' | while read repo ; do + forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/repos/$owner/$repo + done + forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/orgs/$owner + done +} + function user_create() { local username="$1" email="$2" forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/admin/users/$username?purge=true >& /dev/null || true @@ -65,29 +74,45 @@ function has_cascade_pull_request() { test $pr_count -gt 0 } -function create_pull_request() { - local originrepo=$1 +function create_branch1() { + local owner=$1 repo=$2 - 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/$owner/${repo}/branches/branch1 >& /dev/null || true + forgejo-curl.sh api_json --data '{"new_branch_name":"branch1"}' ${options[url]}/api/v1/repos/$owner/${repo}/branches ( cd $TMPDIR - rm -fr ${originrepo} - git clone -b branch1 http://user1:admin1234@${options[host_port]}/user1/${originrepo} - cd ${originrepo} + rm -fr ${repo} + git clone -b branch1 http://user1:admin1234@${options[host_port]}/$owner/${repo} + cd ${repo} 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 > ../${owner}-${repo}.sha ) +} - forgejo-curl.sh api_json --data '{"title":"PR","base":"main","head":"branch1"}' ${options[url]}/api/v1/repos/user1/${originrepo}/pulls +function create_pull_request() { + local baseowner=$1 headowner=$2 repo=$3 + + forgejo-curl.sh api_json ${options[url]}/api/v1/repos/$baseowner/${repo}/pulls | jq --raw-output '.[] | .number' | while read pr ; do + forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/repos/$baseowner/${repo}/issues/$pr + done + + create_branch1 $headowner $repo + + local head + if test $baseowner == $headowner; then + head=branch1 + else + head=$headowner:branch1 + fi + cat > $TMPDIR/data <