Skip to content

GHE 2.20 compatibility for pr commands - #2035

Merged
mislav merged 7 commits into
trunkfrom
ghe-2.20-compat
Oct 6, 2020
Merged

GHE 2.20 compatibility for pr commands#2035
mislav merged 7 commits into
trunkfrom
ghe-2.20-compat

Conversation

@mislav

@mislav mislav commented Sep 30, 2020

Copy link
Copy Markdown
Contributor

Fixes

  • gh pr status
  • gh pr view
  • gh pr create

for GHE versions where statusCheckRollup or reviewDecision are unavailable.

To avoid the overhead of GraphQL schema introspection queries every time, their result is cached on disk per-host for 24 hours.

Fixes #1709, closes #1102

… GHE

We first ask the GHE server for whether it supports these fields.
It looks like GHE v2.20 does not support `@me` in search yet.
This speeds up `pr`-related commands for GHE by caching schema
introspection queries for 24h.
@gibfahn

gibfahn commented Oct 1, 2020

Copy link
Copy Markdown

Built this locally, confirmed that gh pr status, gh pr view, and gh pr create work with this change.

mislav added 2 commits October 1, 2020 19:18
I have no idea what's going on there, so I'll just give up the streaming
approach and read the entire contents of the cache file to memory.

https://github.com/cli/cli/pull/2035/checks?check_run_id=1194798056
Comment thread api/cache.go Outdated
bodyCopy := &bytes.Buffer{}
defer req.Body.Close()
_, err := io.Copy(h, io.TeeReader(req.Body, bodyCopy))
req.Body = ioutil.NopCloser(bodyCopy)

@samcoe samcoe Oct 2, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, what is the purpose of this line, and the similar line in writeCache?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The caching layer is essentially a middleware. This method needs to read the entire request body to compute the signature of the request, but then req.Body would have already been exhausted from this point onward and nothing else could read from it. This code essentially "rewinds" an io.Reader by replacing it with another Reader that can be read again from the start.

Maybe I should wrap this in a named helper function so the intent of the logic is clearer 👍

Comment thread api/queries_pr.go
}
`

if currentUsername == "@me" && ghinstance.IsEnterprise(repo.RepoHost()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a reason why we only want to evaluate this on GHES?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes: we know that github.com already supports @me and thus we can avoid an overhead of the extra request. I'm not sure which GHE version adds support for @me, but I have confirmed that GHE v2.20 doesn't.

- make thread-safe
- only cache GET, HEAD, and GraphQL requests
- only cache non-5xx, non-403 responses
- include `Accept` and `Authorization` headers in cache key
@vilmibm
vilmibm self-requested a review October 5, 2020 16:02

@vilmibm vilmibm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I found the caching stuff easy to follow and it seemed good to me; the resulting complexity for checking feature support isn't so bad. Thanks!

@mislav
mislav merged commit 115357c into trunk Oct 6, 2020
@mislav
mislav deleted the ghe-2.20-compat branch October 6, 2020 10:50
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.

GraphQL error with pr commands on GHE v2.20

4 participants