mirror of
https://code.forgejo.org/actions/cascading-pr.git
synced 2025-06-27 20:33:44 +00:00
add a test for forked destination
This commit is contained in:
parent
dd5427bc63
commit
a98dc1dffc
6 changed files with 91 additions and 24 deletions
|
@ -1,6 +1,6 @@
|
|||
# SPDX-License-Identifier: MIT
|
||||
name: test
|
||||
on: [pull_request]
|
||||
on: [pull_request_target]
|
||||
jobs:
|
||||
test:
|
||||
runs-on: docker
|
||||
|
|
26
tests/origin-fork-destination/.forgejo/workflows/test.yml
Normal file
26
tests/origin-fork-destination/.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/origin-fork-destination
|
||||
origin-token: ${{ secrets.ORIGIN_TOKEN }}
|
||||
origin-pr: ${{ github.event.pull_request.number }}
|
||||
destination-url: ${{ env.GITHUB_SERVER_URL }}
|
||||
destination-repo: user2/destinationrepo
|
||||
destination-fork-repo: user3/destinationrepo
|
||||
destination-branch: main
|
||||
destination-token: ${{ secrets.DESTINATION_TOKEN }}
|
||||
update: ./upgraded
|
||||
debug: true
|
1
tests/origin-fork-destination/README
Normal file
1
tests/origin-fork-destination/README
Normal file
|
@ -0,0 +1 @@
|
|||
originrepo
|
14
tests/origin-fork-destination/upgraded
Executable file
14
tests/origin-fork-destination/upgraded
Executable file
|
@ -0,0 +1,14 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -ex
|
||||
|
||||
destination_checkout="$1"
|
||||
destination_pr_json="$2"
|
||||
origin_checkout="$3"
|
||||
origin_pr_json="$4"
|
||||
|
||||
test -d $destination_checkout
|
||||
test -d $origin_checkout
|
||||
test -f $origin_pr_json
|
||||
|
||||
date +%s > $destination_checkout/last
|
50
tests/run.sh
50
tests/run.sh
|
@ -58,8 +58,10 @@ function user_create() {
|
|||
}
|
||||
|
||||
function close_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 PATCH --data '{"state":"closed"}' ${options[url]}/api/v1/repos/user1/originrepo/issues/$pr
|
||||
local repo=$1
|
||||
|
||||
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 -X PATCH --data '{"state":"closed"}' ${options[url]}/api/v1/repos/user1/${repo}/issues/$pr
|
||||
done
|
||||
}
|
||||
|
||||
|
@ -194,21 +196,25 @@ function fixture() {
|
|||
local destination=$2
|
||||
|
||||
orgs_delete
|
||||
|
||||
user_create user3 user3@example.com
|
||||
user_curl user3 api_json --data '{"username":"destination-fork"}' ${options[url]}/api/v1/orgs
|
||||
|
||||
user_create user2 user2@example.com
|
||||
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/${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_curl user1 api_json --data '{"username":"origin-fork"}' ${options[url]}/api/v1/orgs
|
||||
user_curl user1 api_json --data '{"organization":"origin-fork"}' ${options[url]}/api/v1/repos/user1/${origin}/forks
|
||||
user_secret user1 ORIGIN_TOKEN $(user_token user1 ORIGIN_TOKEN)
|
||||
user_secret user1 DESTINATION_TOKEN $(user_token user2 DESTINATION_TOKEN)
|
||||
|
||||
push_self
|
||||
}
|
||||
|
||||
function no_change_no_cascade_pr() {
|
||||
fixture originrepo-do-nothing destinationrepo
|
||||
user_secret user1 DESTINATION_TOKEN $(user_token user2 DESTINATION_TOKEN)
|
||||
|
||||
create_pull_request_case1 user1 user1 originrepo-do-nothing
|
||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo-do-nothing $(cat $TMPDIR/user1-originrepo-do-nothing.sha)
|
||||
|
@ -217,11 +223,12 @@ function no_change_no_cascade_pr() {
|
|||
|
||||
function create_and_close() {
|
||||
fixture originrepo destinationrepo
|
||||
user_secret user1 DESTINATION_TOKEN $(user_token user2 DESTINATION_TOKEN)
|
||||
|
||||
create_pull_request_case1 user1 user1 originrepo
|
||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/user1-originrepo.sha)
|
||||
has_cascade_pull_request
|
||||
close_pull_request
|
||||
close_pull_request originrepo
|
||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/user1-originrepo.sha)
|
||||
}
|
||||
|
||||
|
@ -233,23 +240,26 @@ function taint_update() {
|
|||
echo 'TAINTED' > upgraded
|
||||
}
|
||||
|
||||
function create_from_fork_and_close() {
|
||||
function create_from_origin_fork_and_close() {
|
||||
fixture originrepo destinationrepo
|
||||
user_secret user1 DESTINATION_TOKEN $(user_token user2 DESTINATION_TOKEN)
|
||||
|
||||
delete_pull_requests user1 originrepo
|
||||
create_branch1 fork-org originrepo taint_update
|
||||
create_pull_request user1 fork-org originrepo
|
||||
create_branch1 origin-fork originrepo taint_update
|
||||
create_pull_request user1 origin-fork originrepo
|
||||
|
||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/fork-org-originrepo.sha)
|
||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/origin-fork-originrepo.sha)
|
||||
has_cascade_pull_request
|
||||
close_pull_request
|
||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/fork-org-originrepo.sha)
|
||||
close_pull_request originrepo
|
||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/origin-fork-originrepo.sha)
|
||||
}
|
||||
|
||||
function create_and_merge() {
|
||||
fixture originrepo destinationrepo
|
||||
user_secret user1 DESTINATION_TOKEN $(user_token user2 DESTINATION_TOKEN)
|
||||
|
||||
create_pull_request_case1 user1 user1 originrepo
|
||||
|
||||
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/user1-originrepo.sha)
|
||||
has_cascade_pull_request
|
||||
merge_pull_request originrepo
|
||||
|
@ -257,10 +267,24 @@ function create_and_merge() {
|
|||
has_cascade_pull_request
|
||||
}
|
||||
|
||||
function create_in_destination_fork_and_close() {
|
||||
fixture origin-fork-destination destinationrepo
|
||||
user_secret user1 DESTINATION_TOKEN $(user_token user3 DESTINATION_TOKEN)
|
||||
|
||||
create_pull_request_case1 user1 user1 origin-fork-destination
|
||||
|
||||
wait_success ${options[url]}/api/v1/repos/user1/origin-fork-destination $(cat $TMPDIR/user1-origin-fork-destination.sha)
|
||||
has_cascade_pull_request
|
||||
close_pull_request origin-fork-destination
|
||||
wait_success ${options[url]}/api/v1/repos/user1/origin-fork-destination $(cat $TMPDIR/user1-origin-fork-destination.sha)
|
||||
}
|
||||
|
||||
function create_and_merge_close() {
|
||||
fixture originrepo-close-merge destinationrepo
|
||||
user_secret user1 DESTINATION_TOKEN $(user_token user2 DESTINATION_TOKEN)
|
||||
|
||||
create_pull_request_case1 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
|
||||
|
@ -269,7 +293,7 @@ function create_and_merge_close() {
|
|||
}
|
||||
|
||||
function integration() {
|
||||
for t in no_change_no_cascade_pr create_from_fork_and_close create_and_close create_and_merge create_and_merge_close; do
|
||||
for t in create_in_destination_fork_and_close no_change_no_cascade_pr create_from_origin_fork_and_close create_and_close create_and_merge create_and_merge_close; do
|
||||
log_info "running $t"
|
||||
$t
|
||||
done
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue