Commit graph

202 commits

Author SHA1 Message Date
Andy Feller
918cafc222 Deprecate ColorScheme.Gray for ColorScheme.Muted
This commit converts all of the places using ColorScheme.Gray and ColorScheme.Grayf to Muted and Mutedf.

There is a little extra tidying up with local variable names or converting code to use Mutedf format.
2025-04-06 10:18:48 -04:00
Andy Feller
bbb8213e9c Refactor commentable logic 2025-03-19 07:56:53 -04:00
Andy Feller
018b6d6d07 Initial pass fixing gh issue and gh pr comment
There is still a bit of work to get the gh pr comment tests in order, however this goes a way towards fixing the issue along with acceptance tests.

Also, it turns out some of the issue acceptance tests were really running `pr` tests.
2025-03-17 23:18:36 -04:00
William Martin
11b9496e17 Fix checkout when URL arg is from fork and cwd is upstream 2025-02-27 16:56:11 +01:00
latzskim
26414865c4 Address pr comments 2025-02-19 16:56:23 +01:00
latzskim
e516e5ed5d [gh issue/pr comment] Create a comment if no comment already 2025-02-12 21:04:22 +01:00
Kynan Ware
026672e79e
Merge branch 'trunk' into nil/fix-2329 2025-02-01 12:37:44 -07:00
nilvng
42c9d244f7 remove duplicated Prompter type 2025-02-01 11:45:37 +11:00
nilvng
7311b5cdd1 revert isEqualSet to private 2025-02-01 11:45:37 +11:00
Tyler McGoffin
877871f1e0 Address PR comments 2025-01-31 14:55:24 -08:00
Tyler McGoffin
601cf88852 Handle error from ParsePRRefs when the selector is provided 2025-01-31 14:40:54 -08:00
Tyler McGoffin
058cb2c220 Refactor finder to work with URL selectors 2025-01-31 14:40:54 -08:00
Tyler McGoffin
29e57ee8e7 Add tests for using the pr Finder outside of repo
This includes an acceptance test for `gh pr view` and a unit test on
`TestFind`
2025-01-31 14:22:02 -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
4382bdf072 Fix pr create tests
Due to the refactor of BranchConfig, the tests for `pr create` no longer
require a handful of stubbed git commands.

Additionally, I noticed some overlap between `pr create`'s existing logic
with the new finder code. I suspect that the finder's new ParsePRRefs
helper could be leveraged here as well, which would allow us to respect
non-centralized workflows pr create in the same way we are respecting them
in `gh pr view` and `gh pr status`
2025-01-24 14:01:44 -08:00
Tyler McGoffin
d684834ad9 Refactor pr status to use the ParsePRRefs helper on the Finder
There was a lot of copy-pasta code between the finder and pr status. After
some investigation it was clear that the prSelectorForCurrentBranch code
was really just a duplicate of the finder's code without actually making
the API call for the PR. Since the ParsePRRefs helper had already
extracted much of the logic for determining a PR's head ref branch, I was
able to reuse it in gh pr status with a small refactor.
2025-01-24 11:51:49 -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
William Martin
6355ed7c08 WIP: push default defaults to simple 2025-01-24 17:25:38 +01:00
William Martin
a72bef9b42 Error if push revision doesn't match a remote 2025-01-24 17:07:24 +01: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
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
e4f0b79173 Surface and handle error from ReadBranchConfig in parseCurrentBranch
I've only added the one test for parseCurrentBranch because the function
appears to be largely exercised by TestFind. There's definitely an
opportunity for a bigger refactor of the tests, here, but I want to avoid
scope creep as I propagate the ReadBranchConfig api changes throughout the
codebase
2025-01-09 12:46:55 -08:00
Tyler McGoffin
bf6fdbdfd2 Remove named returns from ReadBranchConfig and surface errors 2025-01-07 13:54:43 -08:00
Andy Feller
0006091d76
Fix up intra-org fork test setup
[1] 96ac8d6a2f
2025-01-07 10:22:51 +11: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
7fc35fd47d
Only find PRs w/ branch.<name>.merge if push.default = upstream/tracking
When push.default is not 'upstream' / 'tracking' (or 'nothing'), we can
expect local and remote branch names to be the same and solely rely on
@{push} or RemoteURL.

This fixes the wrong error message 'no pull requests found for branch
"<target branch>"' when the local branch is not pushed in the
push.default = simple / current and upstream = <target branch> setup.
2025-01-07 10:18:07 +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
nilvng
91b3b99b76 issue #2329: create shared PRLister 2024-12-15 17:53:00 +11:00
Nilln
de13d7b721
Merge branch 'trunk' into nil/fix-2329 2024-12-14 11:03:22 +11:00
William Martin
d662226ae4 Name conditionals in PR finder 2024-12-13 14:33:33 +01:00
William Martin
96ac8d6a2f Support pr view for intra-org forks 2024-12-13 14:27:41 +01:00
nilvng
5109336963 issue #2329: include PR status in the prompt's options 2024-12-09 21:22:00 +11:00
nilvng
409e3ca08c issue #2329: simplify the UI of the prompt
This commit reverts the previous color changes in the prompt UI. While color highlighting could potentially improve the visual appealing of the prompt
using the existing color library (mguz/ansi) with the prompt library (AlecAivazis/survey) caused unintended side effects.
It reset the bold text style for the selected option. We decide to that
bold text style would have a higher priority than the color text ,for
three reasons:
1. To maintain consistency with other prompts in the UI and prioritize accessibility
2. While color can enhance the user experience, according to Primer Design Guidelines, color should not be relied upon to convey essential information.
3. visual indicator of the selected option, especially crucial when dealing with long PR titles or branch names.

As a future improvement, we may consider a separate issue or PR to address the color library issue and explore controlled color usage in prompts. This could potentially allow for more nuanced visual differentiation while avoiding unintended style resets.

Co-authored-by: Kynan Ware <47394200+BagToad@users.noreply.github.com>
2024-12-06 19:59:46 +11:00
nilvng
36eaf14857 issue #2329: improve UI/UX
Improve the interactive PR selection UI by
- prefix the PR number with hashcode #
- perserve the text formatting (bold) upon an option is hovered
- add the PR head label

Technical changes:
- Replace \033[0m with \033[39m for maintaining text formatting
2024-11-17 23:47:36 +11:00
nilvng
1832c1a767 issue #2329: fix the linting issue 2024-11-17 14:58:38 +11:00
Nillin
49b10b745d
Merge branch 'trunk' into nil/fix-2329 2024-11-17 13:47:29 +11:00
nilvng
2eaab56912 chore: tidy up 2024-11-07 10:20:23 +11:00
nilvng
a780b488a3 fix: ignore template flag 2024-11-07 10:20:23 +11:00
nilvng
7d7c240f4b feat: let user select pr to checkout 2024-11-03 11:38:58 +11:00
Tyler McGoffin
14acbe00a9 Remove . from test case for TestTitleSurvey 2024-10-17 14:45:35 -07:00
Tyler McGoffin
13ab02729b Clean up Title Survey empty title message code 2024-10-17 14:40:17 -07:00
Tyler McGoffin
4df2e7be63 Remove comment 2024-10-15 12:16:20 -07:00
Tyler McGoffin
dcbd1b728c Add test coverage for TitleSurvey change 2024-10-08 16:32:50 -07:00
Tyler McGoffin
be3b6cbd8d Make the X in the error message red and print with io writer 2024-10-08 16:03:14 -07:00
Tyler McGoffin
5fc311374a Add handling of empty titles for Issues and PRs
Currently, the prompter doesn't enforce the requirement of a title for PR
and Issue creation. However, that creates the UX where a user can enter a
blank title, spend time filling out a detailed body, then fail to create
the issue or pr when the request is sent to the api because the title is
blank. This attempts to handle that before sending a request to the api,
enforcing that, when prompting, the title of an issue is not blank.
2024-10-04 10:08:48 -07:00
benebsiny
e18c002283 Deduplicate the initialization of editor mode 2024-08-08 18:07:52 +08:00
notomo
0d37174076 Add editor hint message 2024-07-09 21:01:50 +09:00