WIP: Show pull requests against branches#2781
Conversation
8357475 to
cd8cfbd
Compare
|
Oooh, very nice! A few thoughts after trying it (very briefly though, so I might be missing a lot of things):
|
It needs remotes to map from PRs back to branches i.e. the PR has an owner e.g. 'jesseduffield') and the remote has a URL (e.g.
No need to apologise, I've been thinking the same thing. I wish there was a way to pass multiple branch heads to gh or to the graphql endpoint (gh is just a way of talking to graphql) but from what I've seen and tried, there's not. We could try a parallelised approach of shelling out to a bunch of gh processes at once but it would probably be rate limited.
I agree, and it shouldn't be hard to support that.
Yep currently it's just for display but I like your idea. |
cd8cfbd to
39bd87d
Compare
134a144 to
319ca04
Compare
319ca04 to
bcb7011
Compare
|
|
||
| func fetchPullRequestsQuery(branches []string, owner string, repo string) string { | ||
| var queries []string | ||
| for i, branch := range branches { |
There was a problem hiding this comment.
You can do this in one request (not sure about the length limits for the query) with:
query {
search(first:3, query:"head:gh-integration-3 head:integration-tests-on-windows repo:jesseduffield/lazygit", type: ISSUE) {
nodes {
... on PullRequest {
url
}
}
}
}which returns:
{
"data": {
"search": {
"nodes": [
{
"url": "https://github.com/jesseduffield/lazygit/pull/2781"
},
{
"url": "https://github.com/jesseduffield/lazygit/pull/2648"
}
]
}
}
}There was a problem hiding this comment.
@dlvhdr Interesting, playing with this now. I'm new to GraphQL and all this stuff.
May I ask a few questions?
- What are some criteria for which is better? When I tried both versions using a list of 10 branches, they both took roughly the same time (a bit over 500ms).
- When you say "one request", then the original version is also just one request (i.e. one http call). It just has a bunch of subqueries, and I couldn't find a lot of information about what these even are or how they work. (But I didn't try hard.) Ok, so this wasn't a question. 😄
- Why does this even work? The github documentation says that when you put multiple things into a search query, it ANDs them together by default, so I would have expected that you need
query:"(head:gh-integration-3 OR head:integration-tests-on-windows) repo:jesseduffield/lazygit". Does github have the DWIM logic to synthesize the right boolean operator based on what field types you search for?
There was a problem hiding this comment.
Oh then I must have been mistaken.. Seems pretty much identical.
Regarding the 3rd point I couldn't find the documentation for it, but I swear it exists.
Anyway if you use https://docs.github.com/en/graphql/overview/explorer and provide this query, it works:
query FetchSponsors {
search(query:"is:pr repo:dlvhdr/gh-dash repo:jesseduffield/lazygit", type:ISSUE, first: 10) {
nodes {
... on PullRequest {
title
repository {
nameWithOwner
}
}
}
}
}Maybe github does an implicit OR if an AND doesn't make sense.
|
Is there a plan to make gh pr usable in LG, or only the external view? I would love to see it allow us to use 'gh pr create/edit/etc'.. if lg could add in support for the gh command for prs... it would be amazing and make it so i dont even have to leave my nvim/lg setup xD |
|
@Daemoen You can easily do this as a customCommand. For example, for creating a PR on the current branch: |
|
Could we show a list of pull requests and their titles? I would actually use this instead of the branch view most of the time. This way I wouldn't need to remember the name of the branch or the PR number. I just need the (human readable) title. This would also be useful for code review. Currently I have to go to GitHub, copy the branch name, and checkout the branch, whereas with this workflow I could just directly checkout the PR inside of lazygit. The branch name is an implementation detail. |
a8edf26 to
843d19a
Compare
dfc47fb to
335cbf7
Compare
335cbf7 to
35fc12e
Compare
35fc12e to
834b0f1
Compare
834b0f1 to
62cf0ac
Compare
I don't know what I'm doing here, but this seems to be needed to make it work for me.
62cf0ac to
620ff4b
Compare
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesFootnotes
|
- Fix "if if" typo in enableGithubCli config description - Guard nerd font icons in PR state badges and main view display behind icons.IsIconEnabled() so non-nerd-font users see plain text - Add tests for GenerateGithubPullRequestMap and getRepoInfoFromURL - Update branch display test expectations for new icon column - Fix integration tests that matched "* branchname" patterns (now need to account for icon column between recency and name) - Remove commented-out dead code in branches.go - Regenerate docs and schema with corrected config description Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
They aren't going to change when you check out a branch, and they take a long time to fetch.
620ff4b to
5d45212
Compare
|
Pushed some more commits. Functionality-wise this is good enough for me to merge (though I would need to do another review of the code) |
|
Nice, good to see some work on this. I was meaning to come back to this myself too, but never found the time. I have been using it locally for a long time now, and love it. However, I'm afraid I don't think I agree it's good enough to merge. The biggest open problems off the top of my head are:
|
Some branch names are re-used across PRs, so now we sort PRs by newest-first when fetching so we don't get stale PRs.
We now auto-select a remote if: * it's the only remote * it's named origin Otherwise we prompt the user to specify the remote they want to use.
I've got it sorting by newest first now when fetching PRs. Picking the newest should be fine.
Now it selects the one repo if there's only one, otherwise 'origin', otherwise prompts the user and I've got a title on the prompt now. I think this works well. |
If you check out a new branch via the remote branches tab you'd want to see its status
If the user has
ghinstalled and it's on version 2 or greater, we'll refresh pull requests at the same time we run a backgroundgit fetch.There are a lot of touch points here:
ghis written in Go and we could avoid an external dependency by using theghcode directly, however doing so would mean taking on the burden of handling things like authentication, which would increase the scope quite a bit. Given that pulling pull requests takes a while (3.5s for me), the extra cost of shelling out toghis negligible in comparisongithub.com. Gh itself looks at the configured hosts file to see if there is an authentication setup for any host. We should do the same.go run scripts/cheatsheet/main.go generate)docs/Config.md) have been updated if necessary