Repository: google/go-github
Pull request #2670 (2023-02-22 20:02:21)

Add Permission, OldPermission to AuditEntry type
Fixes https://github.com/google/go-github/issues/2669

# Changes

- Add marshalling of the `old_permission` and `permission` fields in the response of `GET /orgs/:org/audit-log` to the `AuditEntry` type as `AuditEntry.OldPermission` and `AuditEntry.Permission`.

google-cla[bot]: Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this [failed invocation](https://github.com/google/go-github/pull/2670/checks?check_run_id=11530525237) of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.
Archetypically: > Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).
> 
> View this [failed invocation](https://github.com/google/go-github/pull/2670/checks?check_run_id=11530525237) of the CLA check for more information.
> 
> For the most up to date status, view the checks section at the bottom of the pull request.

Signed CLA.
codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/2670?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> Merging [#2670](https://codecov.io/gh/google/go-github/pull/2670?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (9c96a43) into [master](https://codecov.io/gh/google/go-github/commit/b9cb801b8aa1f2e928a13e579e8a58fc0667a053?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (b9cb801) will **not change** coverage.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##           master    #2670   +/-   ##
=======================================
  Coverage   98.05%   98.05%           
=======================================
  Files         131      131           
  Lines       11442    11442           
=======================================
  Hits        11219    11219           
  Misses        152      152           
  Partials       71       71           
```


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

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)


Patch:
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 7036a9a6..59a59a4e 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -1222,6 +1222,14 @@ func (a *AuditEntry) GetName() string {
 	return *a.Name
 }
 
+// GetOldPermission returns the OldPermission field if it's non-nil, zero value otherwise.
+func (a *AuditEntry) GetOldPermission() string {
+	if a == nil || a.OldPermission == nil {
+		return ""
+	}
+	return *a.OldPermission
+}
+
 // GetOldUser returns the OldUser field if it's non-nil, zero value otherwise.
 func (a *AuditEntry) GetOldUser() string {
 	if a == nil || a.OldUser == nil {
@@ -1246,6 +1254,14 @@ func (a *AuditEntry) GetOrg() string {
 	return *a.Org
 }
 
+// GetPermission returns the Permission field if it's non-nil, zero value otherwise.
+func (a *AuditEntry) GetPermission() string {
+	if a == nil || a.Permission == nil {
+		return ""
+	}
+	return *a.Permission
+}
+
 // GetPreviousVisibility returns the PreviousVisibility field if it's non-nil, zero value otherwise.
 func (a *AuditEntry) GetPreviousVisibility() string {
 	if a == nil || a.PreviousVisibility == nil {
diff --git a/github/orgs_audit_log.go b/github/orgs_audit_log.go
index be5fd24d..700c233c 100644
--- a/github/orgs_audit_log.go
+++ b/github/orgs_audit_log.go
@@ -63,8 +63,10 @@ type AuditEntry struct {
 	Message               *string     `json:"message,omitempty"`
 	Name                  *string     `json:"name,omitempty"`
 	OldUser               *string     `json:"old_user,omitempty"`
+	OldPermission         *string     `json:"old_permission,omitempty"` // The permission level for membership changes, for example `admin` or `read`.
 	OpenSSHPublicKey      *string     `json:"openssh_public_key,omitempty"`
 	Org                   *string     `json:"org,omitempty"`
+	Permission            *string     `json:"permission,omitempty"` // The permission level for membership changes, for example `admin` or `read`.
 	PreviousVisibility    *string     `json:"previous_visibility,omitempty"`
 	ReadOnly              *string     `json:"read_only,omitempty"`
 	Repo                  *string     `json:"repo,omitempty"`


Test patch:
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index 6590ff99..7239698a 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -1447,6 +1447,16 @@ func TestAuditEntry_GetName(tt *testing.T) {
 	a.GetName()
 }
 
+func TestAuditEntry_GetOldPermission(tt *testing.T) {
+	var zeroValue string
+	a := &AuditEntry{OldPermission: &zeroValue}
+	a.GetOldPermission()
+	a = &AuditEntry{}
+	a.GetOldPermission()
+	a = nil
+	a.GetOldPermission()
+}
+
 func TestAuditEntry_GetOldUser(tt *testing.T) {
 	var zeroValue string
 	a := &AuditEntry{OldUser: &zeroValue}
@@ -1477,6 +1487,16 @@ func TestAuditEntry_GetOrg(tt *testing.T) {
 	a.GetOrg()
 }
 
+func TestAuditEntry_GetPermission(tt *testing.T) {
+	var zeroValue string
+	a := &AuditEntry{Permission: &zeroValue}
+	a.GetPermission()
+	a = &AuditEntry{}
+	a.GetPermission()
+	a = nil
+	a.GetPermission()
+}
+
 func TestAuditEntry_GetPreviousVisibility(tt *testing.T) {
 	var zeroValue string
 	a := &AuditEntry{PreviousVisibility: &zeroValue}
diff --git a/github/orgs_audit_log_test.go b/github/orgs_audit_log_test.go
index 1f060072..be636156 100644
--- a/github/orgs_audit_log_test.go
+++ b/github/orgs_audit_log_test.go
@@ -34,6 +34,8 @@ func TestOrganizationService_GetAuditLog(t *testing.T) {
         "created_at": 1615077308538,
         "head_sha": "5acdeadbeef64d1a62388e901e5cdc9358644b37",
         "conclusion": "success",
+        "old_permission": "read",
+        "permission": "admin",
         "actor": "testactor",
         "completed_at": "2021-03-07T00:35:08.000Z",
         "@timestamp": 1615077308538,
@@ -80,7 +82,9 @@ func TestOrganizationService_GetAuditLog(t *testing.T) {
 			HeadBranch:    String("master"),
 			HeadSHA:       String("5acdeadbeef64d1a62388e901e5cdc9358644b37"),
 			Name:          String("Code scanning - action"),
+			OldPermission: String("read"),
 			Org:           String("o"),
+			Permission:    String("admin"),
 			Repo:          String("o/blue-crayon-1"),
 			StartedAt:     &Timestamp{startedAt},
 			WorkflowID:    Int64(123456),
@@ -199,9 +203,11 @@ func TestAuditEntry_Marshal(t *testing.T) {
 		LimitedAvailability:   Bool(false),
 		Message:               String("m"),
 		Name:                  String("n"),
+		OldPermission:         String("op"),
 		OldUser:               String("ou"),
 		OpenSSHPublicKey:      String("osshpk"),
 		Org:                   String("o"),
+		Permission:            String("p"),
 		PreviousVisibility:    String("pv"),
 		ReadOnly:              String("ro"),
 		Repo:                  String("r"),
@@ -268,9 +274,11 @@ func TestAuditEntry_Marshal(t *testing.T) {
 		"limited_availability": false,
 		"message": "m",
 		"name": "n",
+		"old_permission": "op",
 		"old_user": "ou",
 		"openssh_public_key": "osshpk",
 		"org": "o",
+		"permission": "p",
 		"previous_visibility": "pv",
 		"read_only": "ro",
 		"repo": "r",