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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalidate_on_push, use GraphQL for timeline #37

Merged
merged 8 commits into from
Dec 11, 2018

Conversation

bluekeyes
Copy link
Member

@bluekeyes bluekeyes commented Dec 6, 2018

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 converts pull.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?

    type Client struct {
      V3 *github.Client
      V4 *githubv4.Client
    }
  • 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 to go-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.

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.
@bluekeyes bluekeyes changed the title Fix invalidate_on_push, use GraphQL for timeline requests Fix invalidate_on_push, use GraphQL for timeline Dec 6, 2018
HasNextPage bool
}
Nodes []*timelineEvent
} `graphql:"timeline(first: 100, after: $cursor)"`
Copy link
Member

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?

Copy link
Member Author

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

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?

Copy link
Member Author

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.

@bluekeyes
Copy link
Member Author

I just realized that with the addition of valid timestamps on everything, we can probably remove the Order field from all of these types and use the times directly.

@ajlake
Copy link
Contributor

ajlake commented Dec 11, 2018

👍

@bluekeyes bluekeyes merged commit 564bcd8 into develop Dec 11, 2018
@bluekeyes bluekeyes deleted the bkeyes/v4-timeline branch December 11, 2018 23:59
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.

switch to using github api v4
3 participants