Commit graph

212 commits

Author SHA1 Message Date
tommaso-moro
45d0ec0b51
address review comments
Co-authored-by: Sam Morrow <info@sam-morrow.com>
2026-04-15 16:01:26 +02:00
tommaso-moro
40b2a784e3
add core logic and improve test coverage 2026-04-15 15:45:49 +02:00
William Martin
4e68a61a58 Fix pr create when branch name contains slashes
Intentionally have not fixed remote names containing slashes because we
want to get a fix out for the vast majority failure case.
2025-04-24 15:14:49 +02:00
William Martin
a9dbda6913 Rework ref usage when finding and creating PRs 2025-04-15 13:38:10 -06:00
Kynan Ware
bf7bf99f54 fix(pr create & stubs): handle exitcode in stubs 2025-04-15 13:38:10 -06:00
Tyler McGoffin
e428b9c66c Remove unused ErrNoGitRepository error 2025-01-31 14:49:38 -08:00
Tyler McGoffin
058cb2c220 Refactor finder to work with URL selectors 2025-01-31 14:40:54 -08:00
Tyler McGoffin
e0f624ba24 Rename PRRefs to PullRequestRefs and PR comment cleanup 2025-01-29 11:56:31 -08:00
Tyler McGoffin
e31bfd0092 Cleaned up some naming and comments 2025-01-27 16:40:47 -08:00
Tyler McGoffin
62106dc800 Cleanup comment 2025-01-24 14:18:20 -08:00
Tyler McGoffin
cdead50d57 Moved remote.pushDefault out of ReadBranchConfig and into finder 2025-01-24 11:05:15 -08:00
Tyler McGoffin
e4d8ed0e60 Remove @{push} from branch config 2025-01-24 10:20:04 -08:00
Tyler McGoffin
5a8dd35ba7 Add PushDefault method to git client 2025-01-24 09:40:02 -08:00
Tyler McGoffin
41729b004d Refactor finder.Find and replace parseCurrentBranch with parsePRRefs
I've been struggling horribly to reason through all of this code, and
after much mental gymnastics I identified the culprit as the overloaded
"branch" string returned by parseCurrentBranch.

This value was either the name of the branch that the PR we're looking for
is associated with, or that name prepended with the owner's name and a :
if we're on a branch, so:

PR branch: featureBranch
branch == "featureBranch"

If on Fork belonging to "ForkOwner"
branch == "ForkOwner:featureBranch"

Since this extra information was bundled up into this single string, it
complicated the responsibilities of parseCurrentBranch's "branch" return
value. Thus, I've teased out "branch" into the new PRRefs struct:

type PRRefs struct{
	BranchName string
	HeadRepo ghrepo.Interface
	BaseRepo ghrepo.Interface
}

This allows the new parsePRRefs function to move all the previous
"branch" string's information into structured data, and allows for a new
method on PRRefs, GetPRLabel(), to create the string that "branch"
previously held to pass into its downstream consumer, namely
findForBranch.

This also allowed for better test coverage, directly connecting the PRRefs
fields to the values contained in the git config. Overall, I am now
confident that this is doing what its supposed to do with respect to my
understanding of the various central and triangular git workflows we are
addressing.
2025-01-23 15:25:28 -08:00
Frederick Zhang
aef2642581
fixup! Add comments and a bit of code cleanup 2025-01-16 15:07:33 +11:00
Tyler McGoffin
d289ddd617 Use PushRemoteURL instead of RemoteURL in prSelectorForCurrentBranch 2025-01-15 16:21:06 -08:00
Tyler McGoffin
4a9fd9508f Add comments and a bit of code cleanup 2025-01-15 16:13:03 -08:00
Tyler McGoffin
48e2681017 Merge branch 'trunk' into find-pr-by-rev-parse-push
A recent refactor caused the API for ReadBranchConfig to change, resulting
in changes for its consumers. Additionally, there was a large refactor of
the tests associated with ReadBranchConfig and its consumers to gain
confidence in this refactor. This commit attempts to resolve the
conflicts between the refactor and this effort as well as massage the
changes introduced here to reflect the refactor.

The refactor PR can be found here: https://github.com/cli/cli/pull/10197

I'll note that there are still a few failing tests in status_test.go. I
haven't had a chance to fully grok while they are failing, yet, and
suspect that some insights from the original PR author may be helpful
here.

Full disclaimer: I haven't verified any of this is working locally yet.
My primary motivation is to get these new changes working together in a
manner that unblocks further iteration on this effort.

* trunk: (79 commits)
  Enhance help docs on ext upgrade notices
  chore: fix some function names in comment
  Expand docs on cleaning extension update dir
  Simplifying cleanExtensionUpdateDir logic
  Separate logic for checking updates
  Capture greater detail on updaterEnabled
  Restore old error functionality of prSelectorForCurrentBranch
  Change error handling on ReadBranchConfig to respect git Exit Codes
  fix: add back colon that I removed
  fix: actually read how MaxFunc work and simplify the code
  fix: padded display
  Collapse dryrun checks in ext bin upgrade
  Bump github.com/mattn/go-colorable from 0.1.13 to 0.1.14
  Rename test user in tests
  Change pr number in test
  Surface and handle error from ReadBranchConfig in parseCurrentBranch
  Directly stub headBranchConfig in Test_tryDetermineTrackingRef
  Refactor error handling in ReadBranchConfig to avoid panic
  Refine error handling of ReadBranchConfig
  Add test for empty BranchConfig in prSelectorForCurrentBranch
  ...
2025-01-13 20:38:00 -08:00
Tyler McGoffin
322a43feff Change error handling on ReadBranchConfig to respect git Exit Codes 2025-01-10 09:59:21 -08:00
Tyler McGoffin
48d45d0b9d Refactor error handling in ReadBranchConfig to avoid panic 2025-01-09 11:45:45 -08:00
Tyler McGoffin
e1423cdbbf Refine error handling of ReadBranchConfig
cmd.Output() will return an error when the git command ran successfully
but had no output. To handle this, we can check Stderr, as we expect it to
be populated for any ExitErrors or otherwise when there is a command
failure.

This allows for propagation of this error handling up the call chain, so
we are now returning errors if the call to git fails instead of just
handing off an empty BranchConfig and suppressing the errors.

Additionally, I've removed some more naked returns that I found in
pkg/cmd/pr/create.go createRun
2025-01-09 11:45:15 -08:00
Tyler McGoffin
527d1db298 Add missing test for RemoteURL in parseBranchConfig 2025-01-08 14:24:20 -08:00
Tyler McGoffin
4575692ebf Remove private readBranchConfig method and remove parseBranchConfig from Client
I think I went too far with my previous refactor and am backing out of it.
Adding a private readBranchConfig method on the client wasn't providing
any real additional value, so I've put it back into ReadBranchConfig.

However, I think there is still value in having parseBranchConfig
(formerly createBranchConfig) as a separate util function, as it both
improves readability of ReadBranchConfig and makes parsing its purpose
easier through the bespoke tests for it.
2025-01-08 10:36:45 -08:00
Tyler McGoffin
0137150848 Refactor Test_readGitBranchConfig for easier parsing 2025-01-07 14:56:27 -08:00
Tyler McGoffin
f43da8ea9a Refactor ReadBranchConfig for test coverage of newly returned erros 2025-01-07 13:54:43 -08:00
Tyler McGoffin
bf6fdbdfd2 Remove named returns from ReadBranchConfig and surface errors 2025-01-07 13:54:43 -08:00
Frederick Zhang
4254818dbd
Find push remote using branch.<name>.pushRemote and remote.pushDefault
When using a push.default = current triangular workflow, apart from
using @{push} to determine the remote branch name, we should also follow
the

1. branch.<name>.pushRemote
2. remote.pushDefault
3. branch.<name>.remote

...list to determine which remote Git pushes to.
2025-01-07 10:22:39 +11:00
Frederick Zhang
0179381efd
Find PRs using @{push}
When using a push.default = current central workflow [1], we should use
@{push} instead to locate the remote branch.

In fact, @{push} covers most cases in push.default = upstream too. The
branch.<name>.merge is probably only needed when using RemoteURL and
different remote / local branch names.

[1] https://github.com/tpope/vim-fugitive/issues/1172#issuecomment-522301607
2025-01-07 10:18:01 +11:00
William Martin
8b5073d617 Move trackingRef into pr create package 2025-01-06 10:33:28 -06:00
William Martin
dc077dc09b Panic if tracking ref can't be reconstructed 2025-01-06 10:33:28 -06:00
William Martin
3ae4e5da20 Document and rework pr create tracking branch lookup 2025-01-06 10:33:28 -06:00
Caleb Brose
9d490547b8
Alternative: remove LocalBranch from BranchConfig 2025-01-03 20:39:12 +00:00
Caleb Brose
7a1052ca33
Set LocalBranch even if the git config fails 2025-01-03 20:35:48 +00:00
Heath Stewart
5da86e07e7
Merge changes from #10004
Merges changes from @williammartin including acceptance tests and word changes.

Co-authored-by: William Martin <williammartin@github.com>
2024-12-08 20:34:21 -08:00
Heath Stewart
88b96f411c
Set gh-merge-base from issue develop 2024-12-08 17:40:03 -08:00
Heath Stewart
3d139019f8
Open PR against gh-merge-base
Partly resolves issue #8979 by checking for a `gh-merge-base` branch tag and using that as though it were passed to `gh pr create --base`.
2024-12-08 17:40:00 -08:00
William Martin
694e565384 Fix PR checkout panic when base repo is not in remotes 2024-12-02 17:20:57 +01:00
bagtoad
76f1553fb9 Fix formatting in client_test.go comments for linter 2024-11-27 14:19:27 -07:00
William Martin
ec086a021b
Update git/client_test.go
Co-authored-by: Andy Feller <andyfeller@github.com>
2024-11-27 15:51:44 +01:00
William Martin
622e283d2b
Update git/client_test.go
Co-authored-by: Andy Feller <andyfeller@github.com>
2024-11-27 15:51:38 +01:00
William Martin
21a14a7d1a
Update git/client_test.go
Co-authored-by: Andy Feller <andyfeller@github.com>
2024-11-27 15:50:54 +01:00
William Martin
72a6fd00a4 Rename backwards compatible credentials pattern 2024-11-27 12:21:55 +01:00
William Martin
0b4f087b46 Fix CredentialPattern doc typos
Co-authored-by: Kynan Ware <47394200+BagToad@users.noreply.github.com>
2024-11-27 12:07:04 +01:00
William Martin
3773068f58 Remove TODOs 2024-11-27 12:06:17 +01:00
Tyler McGoffin
ad397bd0a6 Fix typos and add tests for CredentialPatternFrom* functions 2024-11-26 16:08:51 -08:00
William Martin
0db05ff022 Add SSH remote todo 2024-11-26 22:30:19 +01:00
William Martin
efd8ff6d46 General cleanup and docs 2024-11-26 22:30:11 +01:00
William Martin
6b7f1ff060 Allow client fetch to use insecure credentials pattern 2024-11-26 22:30:03 +01:00
William Martin
7affcadb5e Allow client push to use insecure credential pattern 2024-11-26 22:29:58 +01:00
William Martin
75712de712 Allow client pull to use insecure credential pattern 2024-11-26 22:29:51 +01:00