Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

joshuabezaleel
Copy link

@joshuabezaleel joshuabezaleel commented Nov 15, 2019

Fixes #2193

  • Add check status for pull requests list on the command of hub pr list
  • Add query.go for constructing the particular GraphQL query using graphb.
  • Screenshot attached below.

image

I am so sorry beforehand if I got the design wrong in any way. Looking forward to the review! 馃檪

@joshuabezaleel joshuabezaleel force-pushed the checks-status-hub-pr-list branch 2 times, most recently from 762fe3c to 1091565 Compare Nov 15, 2019
Copy link
Member

@mislav mislav left a comment

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"
Copy link
Member

@mislav mislav Nov 16, 2019

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)
Copy link
Member

@mislav mislav Nov 16, 2019

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

Copy link
Author

@joshuabezaleel joshuabezaleel Dec 4, 2019

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? 馃榿

Copy link
Author

@joshuabezaleel joshuabezaleel Dec 8, 2019

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:

  1. Modify the flagPullRequestFormat and,
  2. 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)
Copy link
Member

@mislav mislav Nov 16, 2019

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)

Copy link
Author

@joshuabezaleel joshuabezaleel Dec 4, 2019

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"
Copy link
Member

@mislav mislav Nov 16, 2019

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.

Copy link
Author

@joshuabezaleel joshuabezaleel Dec 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we can 馃榿 . I just thought that there will be more GraphQL queries than only this one and it will be bloated for other developers if we are all using plain string but let's tackle that later. I am going to drop this dependency.

@joshuabezaleel
Copy link
Author

joshuabezaleel commented Dec 4, 2019

Hi @mislav , truly sorry for a really late reply 馃槥 .
First of all, I just want to say that I am blown away and thank you very much for the really kind 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.

  1. Wouldn't all GitHub repositories with CI installed will always have Status value but not always have Checks status value from GitHub Apps installed? and,
  2. I thought that if there are GitHub apps installed and it would return Checks value, the value of the Checks will always be the same and reflected by the Status value? So that it's sufficient to retrieve the Status value only.
  3. And if we are going to retrieve both of the two values from Status and also Checks, which value are we going to use? In case it would return different value.

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! 馃檪

@mislav
Copy link
Member

mislav commented Dec 4, 2019

I am really sorry beforehand if it's because I have a wrong understanding on this Status and Checks.

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:

  • Statuses were the original CI for GitHub
  • Checks are the new generation of Statuses and come from GitHub Apps
  • A repository can be configured with any combination of Checks and Statuses
  • Checks right now are complex to fetch over GraphQL.

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. 馃檱

@mislav
Copy link
Member

mislav commented Dec 4, 2019

@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

@mislav mislav force-pushed the checks-status-hub-pr-list branch from 4d24590 to 430a50c Compare Dec 15, 2019
@mislav
Copy link
Member

mislav commented Dec 16, 2019

I have pushed some changes, mainly to:

  • compose GraphQL requests directly without the graphb library - this utilizes the Client.GraphQL function that is new in master
  • restore default --format to original - I feel like this feature is still premature to be enabled by default
  • avoid fetching statuses via GraphQL unless %cs/%cC were explicitly specified via --format
  • support --limit values > 100

@joshuabezaleel Please review! 馃檱

I'm still not sure whether this feature is ready to merge, though:

  • It only fetches Statuses so far and not Checks (to reiterate: I will take on implementing Checks when I find time, so you don't have to worry about that);
  • It fetches pull requests double: once over REST (like before) and another time over GraphQL (to fetch Statuses). Ideally it would only fetch them once, so maybe we could switch to GraphQL entirely for the case when Statuses are needed.
  • --sort long-running is supported over REST API but not over GraphQL.

@XVilka

This comment has been minimized.

@XVilka
Copy link

XVilka commented Apr 14, 2020

Are there any updates regarding this PR? It needs to be rebased.

@mislav
Copy link
Member

mislav commented Apr 14, 2020

@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.

@mislav mislav force-pushed the checks-status-hub-pr-list branch from cfe1975 to 2725f45 Compare Apr 14, 2020
@dawsbot
Copy link

dawsbot commented Aug 12, 2020

I would really love this feature. Is anyone working on this still?

@mislav
Copy link
Member

mislav commented Aug 13, 2020

@dawsbot I haven't worked on it since my last comment, but since then there is a new GraphQL statusCheckRollup API that combines information about both Checks and Statuses and their resolution, so there's less work on the client to assemble this data. I plan to adopt it in this PR when I find time. Or, in the meantime, anyone is welcome to base their work off of my branch! 馃檱

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show the checks status in the hub pr list
4 participants