mirror of
https://code.forgejo.org/actions/cascading-pr
synced 2025-03-15 14:54:40 +01:00
test PR from a fork
Fixes: https://code.forgejo.org/actions/cascading-pr/issues/2
This commit is contained in:
parent
5c0fc66c82
commit
a69f5a0ce4
2 changed files with 59 additions and 21 deletions
|
@ -1,7 +1,7 @@
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
name: test
|
name: test
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request_target:
|
||||||
types:
|
types:
|
||||||
- opened
|
- opened
|
||||||
- synchronize
|
- synchronize
|
||||||
|
|
78
tests/run.sh
78
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
|
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() {
|
function user_create() {
|
||||||
local username="$1" email="$2"
|
local username="$1" email="$2"
|
||||||
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/admin/users/$username?purge=true >& /dev/null || true
|
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
|
test $pr_count -gt 0
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_pull_request() {
|
function create_branch1() {
|
||||||
local originrepo=$1
|
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/$owner/${repo}/branches/branch1 >& /dev/null || true
|
||||||
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/repos/user1/${originrepo}/issues/$pr
|
forgejo-curl.sh api_json --data '{"new_branch_name":"branch1"}' ${options[url]}/api/v1/repos/$owner/${repo}/branches
|
||||||
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
|
|
||||||
(
|
(
|
||||||
cd $TMPDIR
|
cd $TMPDIR
|
||||||
rm -fr ${originrepo}
|
rm -fr ${repo}
|
||||||
git clone -b branch1 http://user1:admin1234@${options[host_port]}/user1/${originrepo}
|
git clone -b branch1 http://user1:admin1234@${options[host_port]}/$owner/${repo}
|
||||||
cd ${originrepo}
|
cd ${repo}
|
||||||
echo CONTENT > README
|
echo CONTENT > README
|
||||||
git config user.email root@example.com
|
git config user.email root@example.com
|
||||||
git config user.name username
|
git config user.name username
|
||||||
git add .
|
git add .
|
||||||
git commit -m 'update'
|
git commit -m 'update'
|
||||||
git push origin branch1
|
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 <<EOF
|
||||||
|
{"title":"PR","base":"main","head":"$head"}
|
||||||
|
EOF
|
||||||
|
forgejo-curl.sh api_json --data @$TMPDIR/data ${options[url]}/api/v1/repos/$baseowner/${repo}/pulls
|
||||||
}
|
}
|
||||||
|
|
||||||
function finalize_options() {
|
function finalize_options() {
|
||||||
|
@ -154,11 +179,14 @@ function fixture() {
|
||||||
local origin=$1
|
local origin=$1
|
||||||
local destination=$2
|
local destination=$2
|
||||||
|
|
||||||
|
orgs_delete
|
||||||
user_create user2 user2@example.com
|
user_create user2 user2@example.com
|
||||||
forgejo-test-helper.sh push tests/${destination} http://user2:admin1234@${options[host_port]} user2 ${destination}
|
forgejo-test-helper.sh push tests/${destination} http://user2:admin1234@${options[host_port]} user2 ${destination}
|
||||||
|
|
||||||
user_create user1 user1@example.com
|
user_create user1 user1@example.com
|
||||||
forgejo-test-helper.sh push tests/${origin} http://user1:admin1234@${options[host_port]} user1 ${origin} cascading-pr
|
forgejo-test-helper.sh push tests/${origin} http://user1:admin1234@${options[host_port]} user1 ${origin} cascading-pr
|
||||||
|
user_curl user1 api_json --data '{"username":"fork-org"}' ${options[url]}/api/v1/orgs
|
||||||
|
user_curl user1 api_json --data '{"organization":"fork-org"}' ${options[url]}/api/v1/repos/user1/${origin}/forks
|
||||||
user_secret user1 ORIGIN_TOKEN $(user_token user1 ORIGIN_TOKEN)
|
user_secret user1 ORIGIN_TOKEN $(user_token user1 ORIGIN_TOKEN)
|
||||||
user_secret user1 DESTINATION_TOKEN $(user_token user2 DESTINATION_TOKEN)
|
user_secret user1 DESTINATION_TOKEN $(user_token user2 DESTINATION_TOKEN)
|
||||||
|
|
||||||
|
@ -168,29 +196,39 @@ function fixture() {
|
||||||
function no_change_no_cascade_pr() {
|
function no_change_no_cascade_pr() {
|
||||||
fixture originrepo-do-nothing destinationrepo
|
fixture originrepo-do-nothing destinationrepo
|
||||||
|
|
||||||
create_pull_request originrepo-do-nothing
|
create_pull_request user1 user1 originrepo-do-nothing
|
||||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo-do-nothing $(cat $TMPDIR/originrepo-do-nothing.sha)
|
wait_success ${options[url]}/api/v1/repos/user1/originrepo-do-nothing $(cat $TMPDIR/user1-originrepo-do-nothing.sha)
|
||||||
! has_cascade_pull_request
|
! has_cascade_pull_request
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_and_close() {
|
function create_and_close() {
|
||||||
fixture originrepo destinationrepo
|
fixture originrepo destinationrepo
|
||||||
|
|
||||||
create_pull_request originrepo
|
create_pull_request user1 user1 originrepo
|
||||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/originrepo.sha)
|
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/user1-originrepo.sha)
|
||||||
has_cascade_pull_request
|
has_cascade_pull_request
|
||||||
close_pull_request
|
close_pull_request
|
||||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/originrepo.sha)
|
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/user1-originrepo.sha)
|
||||||
|
}
|
||||||
|
|
||||||
|
function create_from_fork_and_close() {
|
||||||
|
fixture originrepo destinationrepo
|
||||||
|
|
||||||
|
create_pull_request user1 fork-org originrepo
|
||||||
|
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/fork-org-originrepo.sha)
|
||||||
|
has_cascade_pull_request
|
||||||
|
close_pull_request
|
||||||
|
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/fork-org-originrepo.sha)
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_and_merge() {
|
function create_and_merge() {
|
||||||
fixture originrepo destinationrepo
|
fixture originrepo destinationrepo
|
||||||
|
|
||||||
create_pull_request originrepo
|
create_pull_request user1 user1 originrepo
|
||||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/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
|
||||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/originrepo.sha)
|
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/user1-originrepo.sha)
|
||||||
}
|
}
|
||||||
|
|
||||||
function integration() {
|
function integration() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue