Repository: google/go-github
Pull request #2216 (2021-12-03 20:29:46)

Add BranchProtectionRuleEvent Installation field
Although it isn't yet documented at github, the BranchProtectionRuleEvent
includes an `installation` field which is crucial for letting Apps reacting to it
to authenticate their requests.

This PR adds that field the event type, along with an accessor for it.

Fixes: #2214.

nyarly: I've just added a CLA for this project.
gmlewis: @googlebot rescan
gmlewis: Thank you, @nyarly !
Please run `go generate ./...` and push (not force-push) the changed files to this PR, and the tests should then pass.
Hopefully @googlebot will also see your signed CLA by then.
codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/2216?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> Merging [#2216](https://codecov.io/gh/google/go-github/pull/2216?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (2f2e92d) into [master](https://codecov.io/gh/google/go-github/commit/f262aa132108bfd1f08436dfbb63a8c8b6d5d32b?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (f262aa1) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/google/go-github/pull/2216/graphs/tree.svg?width=650&height=150&src=pr&token=EgYjGjZlI0&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)](https://codecov.io/gh/google/go-github/pull/2216?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)

```diff
@@           Coverage Diff           @@
##           master    #2216   +/-   ##
=======================================
  Coverage   97.81%   97.81%           
=======================================
  Files         112      112           
  Lines       10117    10117           
=======================================
  Hits         9896     9896           
  Misses        154      154           
  Partials       67       67           
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/2216?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) | Coverage Δ | |
|---|---|---|
| [github/event\_types.go](https://codecov.io/gh/google/go-github/pull/2216/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL2V2ZW50X3R5cGVzLmdv) | `100.00% <ø> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/google/go-github/pull/2216?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/google/go-github/pull/2216?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Last update [f262aa1...2f2e92d](https://codecov.io/gh/google/go-github/pull/2216?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).


Patch:
diff --git a/github/event_types.go b/github/event_types.go
index 5c811158..f63c8040 100644
--- a/github/event_types.go
+++ b/github/event_types.go
@@ -20,12 +20,13 @@ type RequestedAction struct {
 //
 // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#branch_protection_rule
 type BranchProtectionRuleEvent struct {
-	Action  *string               `json:"action,omitempty"`
-	Rule    *BranchProtectionRule `json:"rule,omitempty"`
-	Changes *ProtectionChanges    `json:"changes,omitempty"`
-	Repo    *Repository           `json:"repository,omitempty"`
-	Org     *Organization         `json:"organization,omitempty"`
-	Sender  *User                 `json:"sender,omitempty"`
+	Action       *string               `json:"action,omitempty"`
+	Rule         *BranchProtectionRule `json:"rule,omitempty"`
+	Changes      *ProtectionChanges    `json:"changes,omitempty"`
+	Repo         *Repository           `json:"repository,omitempty"`
+	Org          *Organization         `json:"organization,omitempty"`
+	Sender       *User                 `json:"sender,omitempty"`
+	Installation *Installation         `json:"installation,omitempty"`
 }
 
 // CheckRunEvent is triggered when a check run is "created", "completed", or "rerequested".
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 8c6ebdad..166e2ad5 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -1604,6 +1604,14 @@ func (b *BranchProtectionRuleEvent) GetChanges() *ProtectionChanges {
 	return b.Changes
 }
 
+// GetInstallation returns the Installation field.
+func (b *BranchProtectionRuleEvent) GetInstallation() *Installation {
+	if b == nil {
+		return nil
+	}
+	return b.Installation
+}
+
 // GetOrg returns the Org field.
 func (b *BranchProtectionRuleEvent) GetOrg() *Organization {
 	if b == nil {


Test patch:
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index 246190dc..fa4dc56c 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -1928,6 +1928,13 @@ func TestBranchProtectionRuleEvent_GetChanges(tt *testing.T) {
 	b.GetChanges()
 }
 
+func TestBranchProtectionRuleEvent_GetInstallation(tt *testing.T) {
+	b := &BranchProtectionRuleEvent{}
+	b.GetInstallation()
+	b = nil
+	b.GetInstallation()
+}
+
 func TestBranchProtectionRuleEvent_GetOrg(tt *testing.T) {
 	b := &BranchProtectionRuleEvent{}
 	b.GetOrg()
diff --git a/scrape/testdata/access-restrictions-disabled.html b/scrape/testdata/access-restrictions-disabled.html
index 97e81339..a5fbe34c 100644
--- a/scrape/testdata/access-restrictions-disabled.html
+++ b/scrape/testdata/access-restrictions-disabled.html
@@ -2,16 +2,16 @@
      Some extraneous markup removed to keep the file size smaller -->
 <html lang="en">
   <body class="logged-in env-production min-width-lg">
-    
+
   <div class="application-main " data-commit-hovercards-enabled>
       <main id="js-pjax-container" data-pjax-container>
-        
+
 <div itemscope itemtype="http://schema.org/Organization">
 
   <div class="container-lg px-3 d-flex">
 
     <div class="col-9">
-      
+
   <div class="boxed-group oauth-application-whitelist ">
     <h3>Third-party application access policy</h3>
     <div class="boxed-group-inner">
diff --git a/scrape/testdata/access-restrictions-enabled.html b/scrape/testdata/access-restrictions-enabled.html
index 39ef4b4c..4b8d1db8 100644
--- a/scrape/testdata/access-restrictions-enabled.html
+++ b/scrape/testdata/access-restrictions-enabled.html
@@ -2,10 +2,10 @@
      Some extraneous markup removed to keep the file size smaller -->
 <html lang="en">
   <body class="logged-in env-production min-width-lg">
-    
+
   <div class="application-main " data-commit-hovercards-enabled>
       <main id="js-pjax-container" data-pjax-container>
-        
+
 
 
 <div itemscope itemtype="http://schema.org/Organization">
@@ -13,7 +13,7 @@
   <div class="container-lg px-3 d-flex">
 
     <div class="col-9">
-      
+
   <div class="boxed-group oauth-application-whitelist is-selectable">
     <h3>Third-party application access policy</h3>
     <div class="boxed-group-inner">
@@ -23,24 +23,24 @@
         <p>
           Only approved applications can access data in this organization. Applications owned by <strong>google-test</strong> always have access.
         </p>
-        
+
 <details
   class="details-reset details-overlay details-overlay-dark lh-default text-gray-dark d-inline-block text-left"
   >
   <summary
       class="btn btn-danger"
-     
-      
-      
-      
+
+
+
+
       >
-    
+
     Remove restrictions
   </summary>
   <details-dialog
     aria-label="Are you sure?"
     class="Box Box--overlay d-flex flex-column anim-fade-in fast "
-    
+
     >
     <div class="Box-header">
       <button class="Box-btn-octicon btn-octicon float-right" type="button" aria-label="Close dialog" data-close-dialog>
@@ -48,7 +48,7 @@
       </button>
       <h3 class="Box-title ">Are you sure?</h3>
     </div>
-    
+
           <div class="flash flash-full flash-warn">
             You’re about to remove all third-party application restrictions. Please read this carefully.
           </div>
@@ -69,7 +69,7 @@
           <ul class="boxed-group-list">
             <li>
               <div class="float-right request-indicator">
-                Approval requested by <a class="requestor" href="/willnorris">willnorris</a> &#8212; 
+                Approval requested by <a class="requestor" href="/willnorris">willnorris</a> &#8212;
                 <a href="/orgs/google-test/policies/applications/22222">Review</a>
               </div>
               <img class="avatar float-left" src="https://avatars3.githubusercontent.com/oa/22222?s=40&amp;u=90a5890234f8061be4c6c0b29b4fa7594f2ba2d7&amp;v=4" height="20" width="20" alt="" />