-
Notifications
You must be signed in to change notification settings - Fork 104
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix invalidate_on_push, use GraphQL for timeline #37
Conversation
Previously, you could bypass the invalidate_on_push option by faking commit times. The v4 API exposes push times as a property, so switch to using that for timeline requests. This also simplifies loading commits, since it can be done in a single call now.
Make ResponsePlayer more flexible by introducing a matcher interface. Add an exact path matcher for the old behavior and a GraphQL matcher that parses queries and responds if the query contains a given node path prefix.
HasNextPage bool | ||
} | ||
Nodes []*timelineEvent | ||
} `graphql:"timeline(first: 100, after: $cursor)"` |
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.
Where does this 100
come from?
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's an arbitrary page size, but 100 is the maximum allowed by GitHub.
// Backfill this to all other commits for the purpose of sorting | ||
var lastPushed *time.Time | ||
for i := len(allEvents) - 1; i >= 0; i-- { | ||
if event := allEvents[i]; event.Type == "Commit" { |
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.
Should we use timelineevent#CreatedAt()
here?
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 don't think so - this loop fills in the underlying property that makes CreatedAt()
function correctly for commit events, so I think the clarity of using the low-level property is desired.
I just realized that with the addition of valid timestamps on everything, we can probably remove the |
Now that everything has timestamps, compare using those.
👍 |
The primary point of this PR is to fix a bug where commits are ordered by commit time (which is easily forged by clients) instead of push time. As a result, the
invalidate_on_push
option is currently a suggestion rather than a guarantee.To fix this, we need the
pushedDate
, which as far as I can tell is only exposed in the v4 GraphQL API. The second part of the PR convertspull.GitHubContext
to use GraphQL. This coincidentally cleans up some commit fetching logic, since we can get all the information at once now. Unfortunately, we still need the v3 client because PR file information is still in preview and even that isn't in GHE 2.15.x.The final part of this change is updating the tests to work with GraphQL. This required rewriting how our mock
http.Transport
worked.Some points for discussion:
I pass two clients around everywhere. Would it be better to define an aggregate struct?
All the testing tools are defined in the test package via
*_test.go
files. Should this be extracted to a real package? If so, where? I'm not sure it's mature enough to move togo-githubapp
.I pull in a GraphQL parsing library to implement the GraphQL matcher. This is potentially overkill. Is there another equally safe way to match on GraphQL query bodies?
Fixes #9.