Skip to content

Commit 8b67d4e

Browse files
Rework ref usage when finding and creating PRs
1 parent 651370b commit 8b67d4e

28 files changed

+2227
-1083
lines changed

acceptance/testdata/pr/pr-checkout-with-url-from-fork.txtar

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ defer gh repo delete --yes ${ORG}/${REPO}
1212

1313
# Create a fork
1414
exec gh repo fork ${ORG}/${REPO} --org ${ORG} --fork-name ${REPO}-fork
15+
sleep 5
1516

1617
# Defer fork cleanup
1718
defer gh repo delete --yes ${ORG}/${REPO}-fork
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
env REPO=${SCRIPT_NAME}-${RANDOM_STRING}
2+
env FORK=${REPO}-fork
3+
4+
# Use gh as a credential helper
5+
exec gh auth setup-git
6+
7+
# Get the current username for the fork owner
8+
exec gh api user --jq .login
9+
stdout2env USER
10+
11+
# Create a repository with a file so it has a default branch
12+
exec gh repo create ${ORG}/${REPO} --add-readme --private
13+
14+
# Defer repo cleanup
15+
defer gh repo delete --yes ${ORG}/${REPO}
16+
17+
# Create a user fork of repository. This will be owned by USER.
18+
exec gh repo fork ${ORG}/${REPO} --fork-name ${FORK}
19+
sleep 5
20+
21+
# Defer repo cleanup of fork
22+
defer gh repo delete --yes ${USER}/${FORK}
23+
24+
# Retrieve fork repository information
25+
exec gh repo view ${USER}/${FORK} --json id --jq '.id'
26+
stdout2env FORK_ID
27+
28+
exec gh repo clone ${USER}/${FORK}
29+
cd ${FORK}
30+
31+
# Prepare a branch to commit
32+
exec git checkout -b feature-branch
33+
exec git commit --allow-empty -m 'Upstream Commit'
34+
exec git push upstream feature-branch
35+
36+
# Prepare an additional commit
37+
exec git commit --allow-empty -m 'Fork Commit'
38+
exec git push origin feature-branch
39+
40+
# Create the PR
41+
exec gh pr create --title 'Feature Title' --body 'Feature Body'
42+
stdout https://${GH_HOST}/${ORG}/${REPO}/pull/1
43+
44+
# Check the PR is indeed created
45+
exec gh pr view ${USER}:feature-branch --json headRefName,headRepository,baseRefName,isCrossRepository
46+
stdout {"baseRefName":"main","headRefName":"feature-branch","headRepository":{"id":"${FORK_ID}","name":"${FORK}"},"isCrossRepository":true}

acceptance/testdata/pr/pr-create-respects-branch-pushremote.txtar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ defer gh repo delete --yes ${ORG}/${REPO}
1919

2020
# Create a user fork of repository. This will be owned by USER.
2121
exec gh repo fork ${ORG}/${REPO} --fork-name ${FORK}
22+
sleep 5
2223

2324
# Defer repo cleanup of fork
2425
defer gh repo delete --yes ${USER}/${FORK}
2526

2627
# Retrieve fork repository information
27-
sleep 5
2828
exec gh repo view ${USER}/${FORK} --json id --jq '.id'
2929
stdout2env FORK_ID
3030

acceptance/testdata/pr/pr-create-respects-push-destination.txtar

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ defer gh repo delete --yes ${ORG}/${REPO}
1919

2020
# Create a user fork of repository. This will be owned by USER.
2121
exec gh repo fork ${ORG}/${REPO} --fork-name ${FORK}
22+
sleep 5
2223

2324
# Defer repo cleanup of fork
2425
defer gh repo delete --yes ${USER}/${FORK}
2526

2627
# Retrieve fork repository information
27-
sleep 5
2828
exec gh repo view ${USER}/${FORK} --json id --jq '.id'
2929
stdout2env FORK_ID
3030

@@ -50,4 +50,4 @@ stdout https://${GH_HOST}/${ORG}/${REPO}/pull/1
5050

5151
# Assert that the PR was created with the correct head repository and refs
5252
exec gh pr view --json headRefName,headRepository,baseRefName,isCrossRepository
53-
stdout {"baseRefName":"main","headRefName":"feature-branch","headRepository":{"id":"${FORK_ID}","name":"${FORK}"},"isCrossRepository":true}
53+
stdout {"baseRefName":"main","headRefName":"feature-branch","headRepository":{"id":"${FORK_ID}","name":"${FORK}"},"isCrossRepository":true}

acceptance/testdata/pr/pr-create-respects-remote-pushdefault.txtar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ defer gh repo delete --yes ${ORG}/${REPO}
1919

2020
# Create a user fork of repository. This will be owned by USER.
2121
exec gh repo fork ${ORG}/${REPO} --fork-name ${FORK}
22+
sleep 5
2223

2324
# Defer repo cleanup of fork
2425
defer gh repo delete --yes ${USER}/${FORK}
2526

2627
# Retrieve fork repository information
27-
sleep 5
2828
exec gh repo view ${USER}/${FORK} --json id --jq '.id'
2929
stdout2env FORK_ID
3030

acceptance/testdata/pr/pr-create-respects-user-colon-branch-syntax.txtar

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ defer gh repo delete --yes ${ORG}/${REPO}
1919

2020
# Create a user fork of repository. This will be owned by USER.
2121
exec gh repo fork ${ORG}/${REPO} --fork-name ${FORK}
22+
sleep 5
2223

2324
# Defer repo cleanup of fork
2425
defer gh repo delete --yes ${USER}/${FORK}
2526

2627
# Retrieve fork repository information
27-
sleep 5
2828
exec gh repo view ${USER}/${FORK} --json id --jq '.id'
2929
stdout2env FORK_ID
3030

31-
# Clone the repo
31+
# Clone the fork
3232
exec gh repo clone ${USER}/${FORK}
3333
cd ${FORK}
3434

acceptance/testdata/pr/pr-create-without-upstream-config.txtar

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
# This test is the same as pr-create-basic, except that the git push doesn't include the -u argument
22
# This causes a git config read to fail during gh pr create, but it should not be fatal
33

4+
env REPO=${SCRIPT_NAME}-${RANDOM_STRING}
5+
46
# Use gh as a credential helper
57
exec gh auth setup-git
68

79
# Create a repository with a file so it has a default branch
8-
exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private
10+
exec gh repo create ${ORG}/${REPO} --add-readme --private
911

1012
# Defer repo cleanup
11-
defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING
13+
defer gh repo delete --yes ${ORG}/${REPO}
1214

1315
# Clone the repo
14-
exec gh repo clone $ORG/$SCRIPT_NAME-$RANDOM_STRING
16+
exec gh repo clone ${ORG}/${REPO}
1517

1618
# Prepare a branch to PR
17-
cd $SCRIPT_NAME-$RANDOM_STRING
19+
cd ${REPO}
1820
exec git checkout -b feature-branch
1921
exec git commit --allow-empty -m 'Empty Commit'
2022
exec git push origin feature-branch
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
skip 'it creates a fork owned by the user running the test'
2+
3+
# Setup environment variables used for testscript
4+
env REPO=${SCRIPT_NAME}-${RANDOM_STRING}
5+
env FORK=${REPO}-fork
6+
7+
# Use gh as a credential helper
8+
exec gh auth setup-git
9+
10+
# Get the current username for the fork owner
11+
exec gh api user --jq .login
12+
stdout2env USER
13+
14+
# Create a repository to act as upstream with a file so it has a default branch
15+
exec gh repo create ${ORG}/${REPO} --add-readme --private
16+
17+
# Defer repo cleanup of upstream
18+
defer gh repo delete --yes ${ORG}/${REPO}
19+
20+
# Create a user fork of repository. This will be owned by USER.
21+
exec gh repo fork ${ORG}/${REPO} --fork-name ${FORK}
22+
sleep 5
23+
24+
# Defer repo cleanup of fork
25+
defer gh repo delete --yes ${USER}/${FORK}
26+
27+
# Retrieve fork repository information
28+
exec gh repo view ${USER}/${FORK} --json id --jq '.id'
29+
stdout2env FORK_ID
30+
31+
# Clone the repo
32+
exec gh repo clone ${USER}/${FORK}
33+
cd ${FORK}
34+
35+
# Prepare a branch where changes are pulled from the upstream default branch but pushed to fork
36+
exec git checkout -b feature-branch
37+
exec git commit --allow-empty -m 'Empty Commit'
38+
exec git push -u origin feature-branch
39+
40+
# Create the PR spanning upstream and fork repositories
41+
exec gh pr create --title 'Feature Title' --body 'Feature Body'
42+
stdout https://${GH_HOST}/${ORG}/${REPO}/pull/1
43+
44+
# Assert that the PR was created with the correct head repository and refs
45+
exec gh pr status
46+
! stdout 'There is no pull request associated with'

acceptance/testdata/pr/pr-view-same-org-fork.txtar

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ stdout2env REPO_ID
1515

1616
# Create a fork in the same org
1717
exec gh repo fork ${ORG}/${REPO} --org ${ORG} --fork-name ${FORK}
18+
sleep 5
1819

1920
# Defer repo cleanup of fork
2021
defer gh repo delete --yes ${ORG}/${FORK}
21-
sleep 1
22+
2223
exec gh repo view ${ORG}/${FORK} --json id --jq '.id'
2324
stdout2env FORK_ID
2425

acceptance/testdata/pr/pr-view-status-respects-branch-pushremote.txtar

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ stdout2env REPO_ID
1515

1616
# Create a user fork of repository as opposed to private organization fork
1717
exec gh repo fork ${ORG}/${REPO} --org ${ORG} --fork-name ${FORK}
18+
sleep 5
1819

1920
# Defer repo cleanup of fork
2021
defer gh repo delete --yes ${ORG}/${FORK}
21-
sleep 5
22+
2223
exec gh repo view ${ORG}/${FORK} --json id --jq '.id'
2324
stdout2env FORK_ID
2425

0 commit comments

Comments
 (0)