New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Checks status hub pr list #2361
base: master
Are you sure you want to change the base?
Checks status hub pr list #2361
Conversation
762fe3c
to
1091565
Compare
Nice going! This is a great start.
One thing you can do here is to construct the GraphQL query by hand instead of using the library. I think it would be simpler, and we avoid one extra dependency. I've left some notes about that.
Something that is missing from this implementation is that it only queries Statuses but not Checks. This might be a little confusing, but GitHub offers two different mechanisms to attach a success/failure status to commits and PRs: Statuses (legacy) and Checks (for GitHub Apps). Checks are more full-featured, but require access by separate APIs. Unfortunately, querying Checks is still a bit complicated over GraphQL, and there might be some API updates on our end to make it simpler, so I don't want you to worry about this now, as you already did a great job covering Statuses. When I find time, I can add Checks support on top of your Statuses implementation.
Great job! Thank you for working on this.
commands/pr.go
Outdated
| @@ -234,14 +238,25 @@ func listPulls(cmd *Command, args *Args) { | |||
| flagPullRequestLimit := args.Flag.Int("--limit") | |||
| flagPullRequestFormat := args.Flag.Value("--format") | |||
| if !args.Flag.HasReceived("--format") { | |||
| flagPullRequestFormat = "%pC%>(8)%i%Creset %t% l%n" | |||
| flagPullRequestFormat = "%pC%>(8)%i%Creset %t %cC%cs %l%n" | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we should change the default format string to include this just yet. Maybe it should remain opt-in? Anyway, you don't have to change this right away, let me think about this for a bit.
commands/pr.go
Outdated
| } | ||
|
|
||
| pulls, err := gh.FetchPullRequests(project, filters, flagPullRequestLimit, func(pr *github.PullRequest) bool { | ||
| return !(onlyMerged && pr.MergedAt.IsZero()) | ||
| }) | ||
| utils.Check(err) | ||
|
|
||
| checkStatus, err := gh.FetchPullRequestsCheckStatus(project, filters, flagPullRequestLimit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be ideal if we avoided making this extra API request unless the format flag listed that it wants these fields. I don't have a good idea how to do that yet (we don't have a mechanism to ask for which fields are listed in --format); just thinking out loud
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that this review and the previous review are talking on the same subject of whether we should make the status to be opted-in so that either the API call is executed and/or the format is changed when the user stated that they want to see the status in the --format input, right? Any further information on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any further info on this, @mislav ?
Should we implement Status in the form of --format flag option to then be able to:
- Modify the
flagPullRequestFormatand, - Also make the API request call to fetchStatus become optional
Looking forward to hearing from you!
github/client.go
Outdated
| return | ||
| } | ||
|
|
||
| response, err := api.PostJSONPreview(fmt.Sprintf("/graphql"), query, checksType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fmt.Sprintf("/graphql") can just be "graphql" (note that you should drop the leading / so this can work with GitHub Enterprise as well)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix this. Thank you!
github/query.go
Outdated
| import ( | ||
| "encoding/json" | ||
|
|
||
| "github.com/azaky/graphb" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we can avoid pulling in an extra dependency to construct the GraphQL query?
After all, the only thing we need to do is POST some JSON to the graphql endpoint. The JSON payload can be constructed like this:
variables := map[string]interface{}{
"state": "open",
}
payload := map[string]interface{}{
"variables": variables,
"query": `
query(...) {
repository(...) {
pullRequests(...) {
...
}
}
}`,
}
// later:
api.PostJSONPreview("/graphql", payload, checksType)I think it would be even simpler and more readable to write the query string by hand like that instead of using the library. In the future, when maintaining GraphQL queries becomes numerous and more cumbersome, we can consider using a library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, we can
|
Hi @mislav , truly sorry for a really late reply Yeah, I noticed it before that there are 2 ways of getting status which the first is Status and the second is Check, which is represented in the GraphQL query that you mentioned in the issue before, right? Thus if it's okay with you, I have several questions on this.
I am really sorry beforehand if it's because I have a wrong understanding on this Status and Checks. I will reply on the remaining reviews below. Looking forward to your reply and hope you have a great week ahead! |
No need to apologize, this stuff isn't really easy, and our documentation doesn't explain the differences between Statuses and Checks very well. Our GraphQL documentation for Checks is also lacking since that API is in preview phase. This is what it all comes down to:
For the simplicity of this PR, I would like you to focus on Statuses only, and I can then add Checks support as follow-up. |
|
@joshuabezaleel For an example of how to perform GraphQL queries in hub, here is a PR that adds some simple queries in a way that doesn't require an external library #2363 |
4d24590
to
430a50c
Compare
|
I have pushed some changes, mainly to:
@joshuabezaleel Please review! I'm still not sure whether this feature is ready to merge, though:
|
This comment has been minimized.
This comment has been minimized.
|
Are there any updates regarding this PR? It needs to be rebased. |
|
@XVilka @joshuabezaleel The GitHub API in the meantime had some updates to make querying Checks + Statuses easier! I plan to update this PR incorporating those changes when I find time. |
cfe1975
to
2725f45
Compare
|
I would really love this feature. Is anyone working on this still? |
|
@dawsbot I haven't worked on it since my last comment, but since then there is a new GraphQL |
Fixes #2193
hub pr listquery.gofor constructing the particular GraphQL query usinggraphb.I am so sorry beforehand if I got the design wrong in any way. Looking forward to the review!馃檪