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

Version selection refactor, logging, schema previews, and more #1

Merged
merged 1 commit into from
Aug 27, 2019

Conversation

christophermancini
Copy link
Contributor

@christophermancini christophermancini commented Aug 1, 2019

The initial scope of this PR was to not use CommittedDate for filtering PRs that will not be included as new versions. This has clearly been identified as a source for missing PRs in Issue #26. This modified approach looks at the PR UpdatedAt field instead. This field is updated every time there is a new commit and shifts the filtering from the code to the GraphQL engine, improving performance even further.

How it works, is that the version information pushed back to concourse contains the PR #, the head ref sha, and the PR UpdatedAt (UpdatedDate). Every resource check operation will take the updated value from the most recent version in Concourse to filter the list of PRs queried. We end up with only PRs that are open and have been updated since the last time we checked. We also use the updated value from Concourse to filter the TimelineItems connection, only receiving events & objects attached to the PR since we last checked. This allows us to expand our methods of filtering down the PR versions we return to Concourse.

You can read more about the filtering options in the changes to the README of this PR.

Other noteworthy changes include:

  • added support for some schema previews
  • added support to trigger a build via a PR comment containing [build ci | ci build]
  • updated the files API request to use the V4 GraphQL interface instead of V3 Rest
  • added logging to /tmp/github-pr-resource.log on the containers which can be accessed via hijacking the check, get, or put steps for a pipeline
  • updated path filtering to use a Glob library instead of filepath.Match which doesn't adhere to glob standards and is not deterministic (e.g. acts differently on different operating systems)
  • decoupled internal PullRequest struct from the GitHub PullRequestObject
  • added environment variable interpolation to the context parameter on status put

We used a GraphQL query like the following to experiment and come up with this solution:

query ($c: String, $q: String!, $s: DateTime!) {
  search(query: $q, type: ISSUE, first: 100, after: $c) {
    edges {
      node {
        ... on PullRequest {
          id
          number
          title
          url
          baseRefName
          headRefName
          isCrossRepository
          createdAt
          updatedAt
          headRef {
            id
            name
            target {
              __typename
              ... on Commit {
                oid
                abbreviatedOid
                authoredDate
                committedDate
                pushedDate
                message
                author {
                  date
                  email
                  name
                  user {
                    login
                  }
                }
              }
            }
          }
          files(first: 100) {
            edges {
              cursor
              node {
                path
              }
            }
          }
          repository {
            url
          }
          timelineItems(last: 100, since: $s) {
            edges {
              cursor
              node {
                __typename
                ... on BaseRefChangedEvent {
                  id
                  createdAt
                }
                ... on HeadRefForcePushedEvent {
                  id
                  createdAt
                }
                ... on ReopenedEvent {
                  id
                  createdAt
                }
                ... on IssueComment {
                  id
                  createdAt
                  bodyText
                }
                ... on PullRequestCommit {
                  id
                  commit {
                    oid
                    abbreviatedOid
                    authoredDate
                    committedDate
                    pushedDate
                    message
                    author {
                      date
                      email
                      name
                      user {
                        login
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    pageInfo {
      endCursor
      hasNextPage
    }
  }
}

Sample variables:

{"c":null,"q":"is:pr is:open repo:digitalocean/concourse updated:\u003e2019-07-22T17:18:11-04:00","s":"2019-07-22T17:18:11-04:00"}

@christophermancini christophermancini force-pushed the lost_commits branch 2 times, most recently from 8e1252e to aaa9833 Compare August 1, 2019 18:44
@christophermancini christophermancini force-pushed the lost_commits branch 6 times, most recently from 5c7398e to 95720c7 Compare August 2, 2019 04:02
@christophermancini christophermancini changed the title modify datetime exclusion of versions Modify version selection Aug 5, 2019
@christophermancini christophermancini force-pushed the lost_commits branch 2 times, most recently from a67d164 to 5f049e3 Compare August 7, 2019 21:07
@aliculPix4D
Copy link

Hi, can you please give us some more information when are you planning to merge this PR or the current status? Thank you.

@christophermancini
Copy link
Contributor Author

Hi @aliculPix4D, thanks for reaching out. I am getting close to having something that is worth merging. Just need to do a bit more testing and polish it up. Then I will squash, have some other folks test it, then merge to our fork. We will give it a little while running internally (maybe two weeks) before submitting it upstream in a pull request.

@bhcleek
Copy link
Contributor

bhcleek commented Aug 21, 2019

Will this end up triggering builds of a PR every time there's any action on the PR (e.g. comments, reviews, title changes, etc.)?

@christophermancini
Copy link
Contributor Author

christophermancini commented Aug 21, 2019

@bhcleek nah, I recently added a section to the README covering how the search and filtering works, you can see it here:
https://github.com/digitalocean/github-pr-resource/pull/1/files#diff-04c6e90faac2675aa89e2176d2eec7d8R55

@christophermancini christophermancini force-pushed the lost_commits branch 2 times, most recently from 9c874ff to e962567 Compare August 21, 2019 23:27
@christophermancini christophermancini changed the title Modify version selection Version selection refactor, logging, schema previews, and more Aug 22, 2019
* `pullrequest.HeadRefForcePushed` which will include PRs where a [HeadRefForcePushed](https://developer.github.com/v4/object/headrefforcepushedevent) occurred
* `pullrequest.Reopened` which will include PRs where a [BaseRefChanged](https://developer.github.com/v4/object/reopenedevent) occurred
* `pullrequest.BuildCI` which will include PRs with a new comment containing `[build ci|ci build]`
* `pullrequest.NewCommits` which will include PRs with a new commit since the last `updated` timestamp of the last check
Copy link

Choose a reason for hiding this comment

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

Rather than include this list, can we just link to some godoc? This type of documentation is a prime example of "a lie waiting to happen" - it's too far from the code to expect anyone to remember to update it when they change the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, however, I wanted it documented on the README for now because all of this work is in a feature branch and I am not sure it will ever get merged back upstream. Once we merge it to the master branch, I will replace it to a link to GoDoc.

check.go Outdated
pulls, err = manager.GetLatestOpenPullRequest()
} else {
pulls, err = manager.ListOpenPullRequests(request.Version.UpdatedDate)
}
Copy link

Choose a reason for hiding this comment

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

You know else statements are bad go 😜

This is another case where the var pulls []pullrequest.PullRequest followed by assignment inside branching logic suggests that what you really want is a function call:

func findPulls(since time.Time) ([]pullrequest.PullRequest, error) {
    if since.IsZero() {
        return manager.GetLatestOpenPullRequest()
    }
    return manager.ListOpenPullRequests(since)
}

func Check(request CheckRequest, manager Github) (CheckResponse, error) {
    var response CheckResponse
    pulls, err := findPulls(request.Version.UpdatedDate)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, when I wrote it and looked at it, I could hear you in the back of my head... Thanks for the sample fix. Will update it. :)

@bhcleek
Copy link
Contributor

bhcleek commented Aug 22, 2019

@christophermancini this PR is huge. Are there particular concerns that you'd like to me focus on?

@christophermancini
Copy link
Contributor Author

christophermancini commented Aug 23, 2019 via email

goal was to make version selection more robust, easier
to test and reduce the chance legitimate versions
are missed by concourse

* add support for schema previews
* add support to trigger pr via comment
* convert files to use graphql api
* logging
* use glob path filtering
* decouple internal PullRequest from GitHub PullRequestObject
* add env var support to context param
* add head short ref to metadata
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.

None yet

6 participants