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

check PR changed files count directly from get pull request endpoint #875

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

dblinkhorn
Copy link

Implements a fix for the checking of the files changed count for a PR. Now the check will be against the git pull request endpoint changed_files property rather than the list of files returned from the list pull request files endpoint.

@palantirtech
Copy link
Member

Thanks for your interest in palantir/policy-bot, @dblinkhorn! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request.

Copy link
Member

@bluekeyes bluekeyes left a comment

Choose a reason for hiding this comment

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

Thanks for submitting this! I think we can simplify the implementation by taking advantage of the fact that we already load the pull request object when creating the pull.Context

return ghc.files, nil
}

func (ghc *GitHubContext) ChangedFilesCount() (int, error) {
pullRequest, _, err := ghc.client.PullRequests.Get(ghc.ctx, ghc.owner, ghc.repo, ghc.number)
Copy link
Member

Choose a reason for hiding this comment

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

I shouldn't be necessary to add a new method to get the changed files from the pull request object because we load the pull request as part of creating the GitHubContext object. Instead, I think we need to extend the stored object to include this field:

  1. Modify the v4PullRequestStruct to include a new ChangedFiles field
  2. Update Locator.IsComplete to return false if the ChangedFiles field is missing or empty
  3. Update Locator.toV4 to se the new ChangedFiles field from the github.PullRequest object in the Locator

After that, you should be able to use ghc.pr.ChangedFiles to reference this in the ChangedFiles method

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.

3 participants