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

[FEAT]: Require approval from someone other than the last pusher #1352

Closed
1 task done
tatutoivio-bf4d opened this issue Nov 8, 2022 · 7 comments · Fixed by #1407
Closed
1 task done

[FEAT]: Require approval from someone other than the last pusher #1352

tatutoivio-bf4d opened this issue Nov 8, 2022 · 7 comments · Fixed by #1407
Labels
Type: Feature New feature or request

Comments

@tatutoivio-bf4d
Copy link

Describe the need

I see that at least according to the branch_protection documentation of the currently latest version (5.7.0) the "Require approval from someone other than the last pusher" option isn't available for the required_pull_request_reviews parameter.

That boolean option would be very important for my use case, and its name could be e.g. require_non_last_pusher_approval.

SDK Version

No response

API Version

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@tatutoivio-bf4d tatutoivio-bf4d added Status: Triage This is being looked at and prioritized Type: Feature New feature or request labels Nov 8, 2022
@tatutoivio-bf4d
Copy link
Author

Looking at the GitHub API, I can see that the proper name for the option might rather be require_last_push_approval.

@fproulx-boostsecurity
Copy link

This is such an important improvement to branch protection. I hope this will go in soon.

@kfcampbell
Copy link
Member

I agree, this would be awesome to have! Do either of you have interest in opening a PR for this behavior?

@wwsean08
Copy link
Contributor

Looking into this, it looks like github.com/shurcooL/githubv4 will have to be updated first to support this new property unless I'm misinterpreting the code. I'm going to try and work on getting a PR against that repo this weekend to add the field. There are actually a couple of new fields missing which I'm going to try to get into the githubv4 library for branch protections. I'll post the PR link here if I'm able to get one opened over there since it's a pre-requisite for this work.

@wwsean08
Copy link
Contributor

Actually no need for me to open a PR, this one takes care of the necessary change, shurcooL/githubv4#107

@wwsean08
Copy link
Contributor

wwsean08 commented Nov 16, 2022

I've got a commit here that does all the work to add this option as well as the lock branch option since they were introduced at the same time. Because my test requires overriding the current version of the githubv4 library I haven't bothered opening a PR, but this should give someone a good start if someone else wants to take it up once the dependent change above is merged. I imagine you will be able to get away with leaving the go.mod at 1.16, but I had trouble which I think had to do with the go.mod (specifically golang.org/x/oauth2 v0.1.0) in the githubv4 repo which seemed to need a package introduced in 1.17, but I didn't dig too deep into the issue, so your results may vary.

If I'm able to open a PR once that (or another PR on githubv4 gets merged) I will, but I am not able to spend as much time on this as I would like so hopefully my code snippet above helps someone down the line. Below is the code I wrote to test and validate it so it should work along with a screenshot of the results:

terraform {
  required_providers {
    github = {
      source  = "integrations/github"
      version = "~> 5.0"
    }
  }
}

provider "github" {
  owner = "REDACTED"
}

data "github_repository" "repo" {
  full_name = "REDACTED/REDACTED"
}

resource "github_branch_protection" "protection" {
  repository_id              = data.github_repository.repo.node_id
  pattern                    = "test"
  lock_branch                = true
  required_pull_request_reviews {
    require_last_push_approval = true
  }
}

Screen Shot 2022-11-16 at 3 36 50 PM

@wwsean08
Copy link
Contributor

Good news, today a PR I opened that just updates the schema got merged 🎉 . Friday I will look to open a simplified version of my previous change as a PR to hopefully get this feature implemented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New feature or request
Projects
None yet
5 participants