Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b61b229
doc: fix PullRequestRefs comment
BagToad Feb 24, 2025
a8d01c7
feat: support `@{push}` revision syntax
BagToad Feb 25, 2025
6db9048
refactor: Refactor pr create
BagToad Feb 26, 2025
dc48625
test(pr create): test --head=<remote>:<branch>
BagToad Feb 27, 2025
cd67c2e
test(pr create): AT assert head repo and head ref
BagToad Feb 27, 2025
84a35ca
refactor: rename IsPushEnabled for clarity
BagToad Feb 27, 2025
1848beb
test(pr create): unset gh-resolved
BagToad Feb 28, 2025
10e3949
refactor(pr create): use prRefs.GetPRHeadLabel()
BagToad Feb 28, 2025
a5fe37f
test(pr create): add AT for remote:branch syntax
BagToad Feb 28, 2025
c3087cd
refactor(pr create): Refactor NewCreateContext
BagToad Mar 5, 2025
178fb40
refactor(pr create): Use PrRefs in CreateContext
BagToad Mar 5, 2025
c0c5d91
refactor(pr create): use GetPRHeadLabel()
BagToad Mar 5, 2025
f50dac5
docs(pr create): fix <repo_name>:<branch> desc.
BagToad Mar 5, 2025
9f1cb0c
refactor(pr create): simplify head remote logic
BagToad Mar 5, 2025
cf58910
refactor(pr create): named headRefName var
BagToad Mar 5, 2025
911079c
docs(pr create): add comments
BagToad Mar 5, 2025
ba6e2ec
test(pr create): skip tests that create forks
BagToad Mar 5, 2025
9b96e6c
doc(pr create): fix typo in test comments
BagToad Mar 6, 2025
da235b1
tests(pr create): remove irrelevant comments
BagToad Mar 6, 2025
1ce3d99
test(pr create): add logical spacing between operations
BagToad Mar 10, 2025
bab7dc6
test(pr create): update repo owner names in tests
BagToad Mar 10, 2025
54da786
fix(pr create): update error handling
BagToad Mar 10, 2025
e999976
refactor(pr create): add PullRequestRefs `HasHead`
BagToad Mar 10, 2025
d524cbd
docs(pr create): clarify comment on head branch syntax
BagToad Mar 10, 2025
e9e57f3
doc(pr create): fix typo in comments
BagToad Mar 10, 2025
6dae35b
test(finder): change assert to require
BagToad Mar 11, 2025
041f02c
docs(pr create): standard <user>:<branch> syntax
BagToad Mar 11, 2025
7bb5d71
doc(pr create): improve head repo resolution comments
BagToad Mar 11, 2025
15ea861
docs(pr create): help text, doc user:branch syntax
BagToad Mar 11, 2025
81d00a3
fix(pr create): use existing local variables
BagToad Mar 11, 2025
188e138
test(pr create): add AT for no local repo
BagToad Mar 11, 2025
bf7bf99
fix(pr create & stubs): handle exitcode in stubs
BagToad Mar 12, 2025
0611d9d
test(pr create): fix user:branch syntax AT
BagToad Mar 12, 2025
76de5f0
test(pr finder): run test in parallel
BagToad Mar 12, 2025
6004fc2
fix(pr create): use curly brace for vars in AT
BagToad Mar 12, 2025
bdfec50
fix(pr create): use REPO var in AT
BagToad Mar 12, 2025
339e1a2
docs(pr create): add link for user:branch syntax
BagToad Mar 12, 2025
028caa3
docs(pr create): clarify BaseRepo type in submitPR
BagToad Mar 12, 2025
ebd147b
Use verbose upstream setting
williammartin Mar 13, 2025
a9dbda6
Rework ref usage when finding and creating PRs
williammartin Apr 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ defer gh repo delete --yes ${ORG}/${REPO}

# Create a fork
exec gh repo fork ${ORG}/${REPO} --org ${ORG} --fork-name ${REPO}-fork
sleep 5

# Defer fork cleanup
defer gh repo delete --yes ${ORG}/${REPO}-fork
Expand Down
46 changes: 46 additions & 0 deletions acceptance/testdata/pr/pr-create-guesses-remote-from-sha.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
env REPO=${SCRIPT_NAME}-${RANDOM_STRING}
env FORK=${REPO}-fork

# Use gh as a credential helper
exec gh auth setup-git

# Get the current username for the fork owner
exec gh api user --jq .login
stdout2env USER

# Create a repository with a file so it has a default branch
exec gh repo create ${ORG}/${REPO} --add-readme --private

# Defer repo cleanup
defer gh repo delete --yes ${ORG}/${REPO}

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

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

# Retrieve fork repository information
exec gh repo view ${USER}/${FORK} --json id --jq '.id'
stdout2env FORK_ID

exec gh repo clone ${USER}/${FORK}
cd ${FORK}

# Prepare a branch to commit
exec git checkout -b feature-branch
exec git commit --allow-empty -m 'Upstream Commit'
exec git push upstream feature-branch

# Prepare an additional commit
exec git commit --allow-empty -m 'Fork Commit'
exec git push origin feature-branch

# Create the PR
exec gh pr create --title 'Feature Title' --body 'Feature Body'
stdout https://${GH_HOST}/${ORG}/${REPO}/pull/1

# Check the PR is indeed created
exec gh pr view ${USER}:feature-branch --json headRefName,headRepository,baseRefName,isCrossRepository
stdout {"baseRefName":"main","headRefName":"feature-branch","headRepository":{"id":"${FORK_ID}","name":"${FORK}"},"isCrossRepository":true}
27 changes: 27 additions & 0 deletions acceptance/testdata/pr/pr-create-no-local-repo.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use gh as a credential helper
exec gh auth setup-git

# Setup environment variables used for testscript
env REPO=${SCRIPT_NAME}-${RANDOM_STRING}

# Create a repository with a file so it has a default branch
exec gh repo create ${ORG}/${REPO} --add-readme --private

# Defer repo cleanup
defer gh repo delete --yes ${ORG}/${REPO}

# Clone the repo
exec gh repo clone ${ORG}/${REPO}

# Prepare a branch to PR
cd ${REPO}
exec git checkout -b feature-branch
exec git commit --allow-empty -m 'Empty Commit'
exec git push -u origin feature-branch

# Leave the repo so there's no local repo
cd ${WORK}

# Create the PR
exec gh pr create --title 'Feature Title' --body 'Feature Body' --repo ${ORG}/${REPO} --head feature-branch
stdout https://${GH_HOST}/${ORG}/${REPO}/pull/1
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
skip 'it creates a fork owned by the user running the test'
Comment thread
andyfeller marked this conversation as resolved.

# Setup environment variables used for testscript
env REPO=${SCRIPT_NAME}-${RANDOM_STRING}
env FORK=${REPO}-fork

# Use gh as a credential helper
exec gh auth setup-git

# Get the current username for the fork owner
exec gh api user --jq .login
stdout2env USER

# Create a repository to act as upstream with a file so it has a default branch
exec gh repo create ${ORG}/${REPO} --add-readme --private

# Defer repo cleanup of upstream
defer gh repo delete --yes ${ORG}/${REPO}

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

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

# Retrieve fork repository information
exec gh repo view ${USER}/${FORK} --json id --jq '.id'
stdout2env FORK_ID

# Clone the repo
exec gh repo clone ${USER}/${FORK}
cd ${FORK}

# Prepare a branch where changes are pulled from the upstream default branch but pushed to fork
exec git checkout -b feature-branch
exec git branch --set-upstream-to upstream/main
exec git config branch.feature-branch.pushRemote origin
Comment thread
andyfeller marked this conversation as resolved.
exec git config unset remote.upstream.gh-resolved
exec git commit --allow-empty -m 'Empty Commit'
exec git push

# Create the PR spanning upstream and fork repositories
exec gh pr create --title 'Feature Title' --body 'Feature Body'
stdout https://${GH_HOST}/${ORG}/${REPO}/pull/1

# Assert that the PR was created with the correct head repository and refs
exec gh pr view --json headRefName,headRepository,baseRefName,isCrossRepository
stdout {"baseRefName":"main","headRefName":"feature-branch","headRepository":{"id":"${FORK_ID}","name":"${FORK}"},"isCrossRepository":true}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
skip 'it creates a fork owned by the user running the test'

# Setup environment variables used for testscript
env REPO=${SCRIPT_NAME}-${RANDOM_STRING}
env FORK=${REPO}-fork

# Use gh as a credential helper
exec gh auth setup-git

# Get the current username for the fork owner
exec gh api user --jq .login
stdout2env USER

# Create a repository to act as upstream with a file so it has a default branch
exec gh repo create ${ORG}/${REPO} --add-readme --private

# Defer repo cleanup of upstream
defer gh repo delete --yes ${ORG}/${REPO}

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

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

# Retrieve fork repository information
exec gh repo view ${USER}/${FORK} --json id --jq '.id'
stdout2env FORK_ID

# Clone the repo
exec gh repo clone ${USER}/${FORK}
cd ${FORK}

# Configure default push behavior so local and remote branches will be the same
exec git config push.default current
Comment thread
andyfeller marked this conversation as resolved.

# Prepare a branch where changes are pulled from the default branch instead of remote branch of same name
exec git checkout -b feature-branch
Comment thread
williammartin marked this conversation as resolved.
exec git branch --set-upstream-to origin/main
exec git rev-parse --abbrev-ref feature-branch@{upstream}
stdout origin/main
exec git config unset remote.upstream.gh-resolved
Comment thread
BagToad marked this conversation as resolved.
exec git commit --allow-empty -m 'Empty Commit'
exec git push

# Create the PR
exec gh pr create --title 'Feature Title' --body 'Feature Body'
stdout https://${GH_HOST}/${ORG}/${REPO}/pull/1

# Assert that the PR was created with the correct head repository and refs
exec gh pr view --json headRefName,headRepository,baseRefName,isCrossRepository
stdout {"baseRefName":"main","headRefName":"feature-branch","headRepository":{"id":"${FORK_ID}","name":"${FORK}"},"isCrossRepository":true}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
skip 'it creates a fork owned by the user running the test'

# Setup environment variables used for testscript
env REPO=${SCRIPT_NAME}-${RANDOM_STRING}
env FORK=${REPO}-fork

# Use gh as a credential helper
exec gh auth setup-git

# Get the current username for the fork owner
exec gh api user --jq .login
stdout2env USER

# Create a repository to act as upstream with a file so it has a default branch
exec gh repo create ${ORG}/${REPO} --add-readme --private

# Defer repo cleanup of upstream
defer gh repo delete --yes ${ORG}/${REPO}

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

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

# Retrieve fork repository information
exec gh repo view ${USER}/${FORK} --json id --jq '.id'
stdout2env FORK_ID

# Clone the repo
exec gh repo clone ${USER}/${FORK}
cd ${FORK}

# Prepare a branch where changes are pulled from the upstream default branch but pushed to fork
exec git checkout -b feature-branch
exec git branch --set-upstream-to upstream/main
exec git config remote.pushDefault origin
Comment thread
andyfeller marked this conversation as resolved.
exec git config unset remote.upstream.gh-resolved
exec git commit --allow-empty -m 'Empty Commit'
exec git push

# Create the PR spanning upstream and fork repositories
exec gh pr create --title 'Feature Title' --body 'Feature Body'
stdout https://${GH_HOST}/${ORG}/${REPO}/pull/1

# Assert that the PR was created with the correct head repository and refs
exec gh pr view --json headRefName,headRepository,baseRefName,isCrossRepository
stdout {"baseRefName":"main","headRefName":"feature-branch","headRepository":{"id":"${FORK_ID}","name":"${FORK}"},"isCrossRepository":true}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Setup environment variables used for testscript
env REPO=${SCRIPT_NAME}-${RANDOM_STRING}

# Use gh as a credential helper
exec gh auth setup-git

# Create a repository with a file so it has a default branch
exec gh repo create ${ORG}/${REPO} --add-readme --private

# Defer repo cleanup of repo
defer gh repo delete --yes ${ORG}/${REPO}
exec gh repo view ${ORG}/${REPO} --json id --jq '.id'
stdout2env REPO_ID

# Clone the repo
exec gh repo clone ${ORG}/${REPO}
cd ${REPO}

# Configure default push behavior so local and remote branches have to be the same
exec git config push.default simple
Comment thread
BagToad marked this conversation as resolved.

# Prepare a branch where changes are pulled from the default branch instead of remote branch of same name
exec git checkout -b feature-branch
exec git branch --set-upstream-to origin/main
exec git commit --allow-empty -m 'Empty Commit'
exec git push origin feature-branch

# Create the PR
exec gh pr create --title 'Feature Title' --body 'Feature Body'
stdout https://${GH_HOST}/${ORG}/${REPO}/pull/1

# Assert that the PR was created with the correct head repository and refs
exec gh pr view --json headRefName,headRepository,baseRefName,isCrossRepository
stdout {"baseRefName":"main","headRefName":"feature-branch","headRepository":{"id":"${REPO_ID}","name":"${REPO}"},"isCrossRepository":false}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
skip 'it creates a fork owned by the user running the test'

# Setup environment variables used for testscript
env REPO=${SCRIPT_NAME}-${RANDOM_STRING}
env FORK=${REPO}-fork

# Use gh as a credential helper
exec gh auth setup-git

# Get the current username for the fork owner
exec gh api user --jq .login
stdout2env USER

# Create a repository to act as upstream with a file so it has a default branch
exec gh repo create ${ORG}/${REPO} --add-readme --private

# Defer repo cleanup of upstream
defer gh repo delete --yes ${ORG}/${REPO}

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

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

# Retrieve fork repository information
exec gh repo view ${USER}/${FORK} --json id --jq '.id'
stdout2env FORK_ID

# Clone the fork
exec gh repo clone ${USER}/${FORK}
cd ${FORK}

# Prepare a branch where changes are pulled from the upstream default branch but pushed to fork
exec git checkout -b feature-branch
exec git branch --set-upstream-to upstream/main
exec git commit --allow-empty -m 'Empty Commit'
exec git push origin feature-branch

# Create the PR spanning upstream and fork repositories
exec gh pr create --title 'Feature Title' --body 'Feature Body' --head ${USER}:feature-branch
stdout https://${GH_HOST}/${ORG}/${REPO}/pull/1

# Assert that the PR was created with the correct head repository and refs
exec gh pr view ${USER}:feature-branch --json headRefName,headRepository,baseRefName,isCrossRepository
stdout {"baseRefName":"main","headRefName":"feature-branch","headRepository":{"id":"${FORK_ID}","name":"${FORK}"},"isCrossRepository":true}
10 changes: 6 additions & 4 deletions acceptance/testdata/pr/pr-create-without-upstream-config.txtar
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# This test is the same as pr-create-basic, except that the git push doesn't include the -u argument
# This causes a git config read to fail during gh pr create, but it should not be fatal

env REPO=${SCRIPT_NAME}-${RANDOM_STRING}

# Use gh as a credential helper
exec gh auth setup-git

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

# Defer repo cleanup
defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING
defer gh repo delete --yes ${ORG}/${REPO}

# Clone the repo
exec gh repo clone $ORG/$SCRIPT_NAME-$RANDOM_STRING
exec gh repo clone ${ORG}/${REPO}

# Prepare a branch to PR
cd $SCRIPT_NAME-$RANDOM_STRING
cd ${REPO}
exec git checkout -b feature-branch
exec git commit --allow-empty -m 'Empty Commit'
exec git push origin feature-branch
Expand Down
46 changes: 46 additions & 0 deletions acceptance/testdata/pr/pr-status-respects-cross-org.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
skip 'it creates a fork owned by the user running the test'

# Setup environment variables used for testscript
env REPO=${SCRIPT_NAME}-${RANDOM_STRING}
env FORK=${REPO}-fork

# Use gh as a credential helper
exec gh auth setup-git

# Get the current username for the fork owner
exec gh api user --jq .login
stdout2env USER

# Create a repository to act as upstream with a file so it has a default branch
exec gh repo create ${ORG}/${REPO} --add-readme --private

# Defer repo cleanup of upstream
defer gh repo delete --yes ${ORG}/${REPO}

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

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

# Retrieve fork repository information
exec gh repo view ${USER}/${FORK} --json id --jq '.id'
stdout2env FORK_ID

# Clone the repo
exec gh repo clone ${USER}/${FORK}
cd ${FORK}

# Prepare a branch where changes are pulled from the upstream default branch but pushed to fork
exec git checkout -b feature-branch
exec git commit --allow-empty -m 'Empty Commit'
exec git push -u origin feature-branch

# Create the PR spanning upstream and fork repositories
exec gh pr create --title 'Feature Title' --body 'Feature Body'
stdout https://${GH_HOST}/${ORG}/${REPO}/pull/1

# Assert that the PR was created with the correct head repository and refs
exec gh pr status
! stdout 'There is no pull request associated with'
Loading
Loading