From 5ad08f525cdd32d5cde61f02c2e704cb14829449 Mon Sep 17 00:00:00 2001 From: Lucas Martin-King Date: Fri, 28 Jul 2023 11:50:36 +1000 Subject: [PATCH 1/7] Correctly map `data.old_name` for audit entry events with action `repo.rename` --- github/github-accessors.go | 16 ++++++++-------- github/github-accessors_test.go | 20 ++++++++++---------- github/orgs_audit_log.go | 8 +++++++- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index 942ec6a96b..3b6ed0a421 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -1278,14 +1278,6 @@ func (a *AuditEntry) GetOAuthApplicationID() int64 { return *a.OAuthApplicationID } -// GetOldName returns the OldName field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetOldName() string { - if a == nil || a.OldName == nil { - return "" - } - return *a.OldName -} - // GetOldPermission returns the OldPermission field if it's non-nil, zero value otherwise. func (a *AuditEntry) GetOldPermission() string { if a == nil || a.OldPermission == nil { @@ -1598,6 +1590,14 @@ func (a *AuditEntry) GetWorkflowRunID() int64 { return *a.WorkflowRunID } +// GetOldName returns the OldName field if it's non-nil, zero value otherwise. +func (a *AuditEntryData) GetOldName() string { + if a == nil || a.OldName == nil { + return "" + } + return *a.OldName +} + // GetApp returns the App field. func (a *Authorization) GetApp() *AuthorizationApp { if a == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 4eafaf2522..419a83f06b 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -1514,16 +1514,6 @@ func TestAuditEntry_GetOAuthApplicationID(tt *testing.T) { a.GetOAuthApplicationID() } -func TestAuditEntry_GetOldName(tt *testing.T) { - var zeroValue string - a := &AuditEntry{OldName: &zeroValue} - a.GetOldName() - a = &AuditEntry{} - a.GetOldName() - a = nil - a.GetOldName() -} - func TestAuditEntry_GetOldPermission(tt *testing.T) { var zeroValue string a := &AuditEntry{OldPermission: &zeroValue} @@ -1914,6 +1904,16 @@ func TestAuditEntry_GetWorkflowRunID(tt *testing.T) { a.GetWorkflowRunID() } +func TestAuditEntryData_GetOldName(tt *testing.T) { + var zeroValue string + a := &AuditEntryData{OldName: &zeroValue} + a.GetOldName() + a = &AuditEntryData{} + a.GetOldName() + a = nil + a.GetOldName() +} + func TestAuthorization_GetApp(tt *testing.T) { a := &Authorization{} a.GetApp() diff --git a/github/orgs_audit_log.go b/github/orgs_audit_log.go index a86910533b..5af10f1f7e 100644 --- a/github/orgs_audit_log.go +++ b/github/orgs_audit_log.go @@ -78,7 +78,6 @@ type AuditEntry struct { Message *string `json:"message,omitempty"` Name *string `json:"name,omitempty"` OAuthApplicationID *int64 `json:"oauth_application_id,omitempty"` - OldName *string `json:"old_name,omitempty"` // The previous name of the repository, for a name change 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"` @@ -122,6 +121,13 @@ type AuditEntry struct { Visibility *string `json:"visibility,omitempty"` // The repository visibility, for example `public` or `private`. WorkflowID *int64 `json:"workflow_id,omitempty"` WorkflowRunID *int64 `json:"workflow_run_id,omitempty"` + + AuditEntryData `json:"data,omitempty"` +} + +// Some audit entries have additional information stuffed into a `data` field. +type AuditEntryData struct { + OldName *string `json:"old_name,omitempty"` // The previous name of the repository, for a name change } // GetAuditLog gets the audit-log entries for an organization. From 30c6cb989e70dda65c225de7f9f5e0fc734ec3f9 Mon Sep 17 00:00:00 2001 From: Lucas Martin-King Date: Fri, 28 Jul 2023 11:53:04 +1000 Subject: [PATCH 2/7] Update tests --- github/orgs_audit_log_test.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/github/orgs_audit_log_test.go b/github/orgs_audit_log_test.go index a5873ee4d3..5e50433e65 100644 --- a/github/orgs_audit_log_test.go +++ b/github/orgs_audit_log_test.go @@ -256,7 +256,6 @@ func TestAuditEntry_Marshal(t *testing.T) { LimitedAvailability: Bool(false), Message: String("m"), Name: String("n"), - OldName: String("on"), OldPermission: String("op"), OldUser: String("ou"), OpenSSHPublicKey: String("osshpk"), @@ -300,6 +299,9 @@ func TestAuditEntry_Marshal(t *testing.T) { Visibility: String("v"), WorkflowID: Int64(1), WorkflowRunID: Int64(1), + AuditEntryData: AuditEntryData{ + OldName: String("on"), + }, } want := `{ @@ -346,7 +348,6 @@ func TestAuditEntry_Marshal(t *testing.T) { "limited_availability": false, "message": "m", "name": "n", - "old_name": "on", "old_permission": "op", "old_user": "ou", "openssh_public_key": "osshpk", @@ -393,7 +394,10 @@ func TestAuditEntry_Marshal(t *testing.T) { "user_agent": "ua", "visibility": "v", "workflow_id": 1, - "workflow_run_id": 1 + "workflow_run_id": 1, + "data": { + "old_name": "on" + } }` testJSONMarshal(t, u, want) From ece58bf92bf66990084e1ef7419a3e1aa3e7706a Mon Sep 17 00:00:00 2001 From: Lucas Martin-King Date: Fri, 28 Jul 2023 23:13:12 +1000 Subject: [PATCH 3/7] Update github/orgs_audit_log.go Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- github/orgs_audit_log.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/orgs_audit_log.go b/github/orgs_audit_log.go index 5af10f1f7e..2b93c98fd5 100644 --- a/github/orgs_audit_log.go +++ b/github/orgs_audit_log.go @@ -125,7 +125,7 @@ type AuditEntry struct { AuditEntryData `json:"data,omitempty"` } -// Some audit entries have additional information stuffed into a `data` field. +// AuditEntryData represents additional information stuffed into a `data` field. type AuditEntryData struct { OldName *string `json:"old_name,omitempty"` // The previous name of the repository, for a name change } From 7bf719993e9e16efaaf1e70c4e2886f59cd9473b Mon Sep 17 00:00:00 2001 From: Lucas Martin-King Date: Fri, 28 Jul 2023 23:13:34 +1000 Subject: [PATCH 4/7] Update github/orgs_audit_log.go Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- github/orgs_audit_log.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/orgs_audit_log.go b/github/orgs_audit_log.go index 2b93c98fd5..9e534ac50c 100644 --- a/github/orgs_audit_log.go +++ b/github/orgs_audit_log.go @@ -122,7 +122,7 @@ type AuditEntry struct { WorkflowID *int64 `json:"workflow_id,omitempty"` WorkflowRunID *int64 `json:"workflow_run_id,omitempty"` - AuditEntryData `json:"data,omitempty"` + Data *AuditEntryData `json:"data,omitempty"` } // AuditEntryData represents additional information stuffed into a `data` field. From ccb4e751fd8ed287b77b25c883d51356c4447e3b Mon Sep 17 00:00:00 2001 From: Lucas Martin-King Date: Fri, 28 Jul 2023 23:38:26 +1000 Subject: [PATCH 5/7] Regenerate accessors --- github/github-accessors.go | 8 ++++++++ github/github-accessors_test.go | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/github/github-accessors.go b/github/github-accessors.go index 3b6ed0a421..356487e0e1 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -1134,6 +1134,14 @@ func (a *AuditEntry) GetCreatedAt() Timestamp { return *a.CreatedAt } +// GetData returns the Data field. +func (a *AuditEntry) GetData() *AuditEntryData { + if a == nil { + return nil + } + return a.Data +} + // GetDeployKeyFingerprint returns the DeployKeyFingerprint field if it's non-nil, zero value otherwise. func (a *AuditEntry) GetDeployKeyFingerprint() string { if a == nil || a.DeployKeyFingerprint == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 419a83f06b..40942da40b 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -1334,6 +1334,13 @@ func TestAuditEntry_GetCreatedAt(tt *testing.T) { a.GetCreatedAt() } +func TestAuditEntry_GetData(tt *testing.T) { + a := &AuditEntry{} + a.GetData() + a = nil + a.GetData() +} + func TestAuditEntry_GetDeployKeyFingerprint(tt *testing.T) { var zeroValue string a := &AuditEntry{DeployKeyFingerprint: &zeroValue} From e6e8a9dfc53da5fdaed09b6bcd5e12f97af37090 Mon Sep 17 00:00:00 2001 From: Lucas Martin-King Date: Fri, 28 Jul 2023 23:39:08 +1000 Subject: [PATCH 6/7] Fix tests --- github/orgs_audit_log_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/orgs_audit_log_test.go b/github/orgs_audit_log_test.go index 5e50433e65..2995de5023 100644 --- a/github/orgs_audit_log_test.go +++ b/github/orgs_audit_log_test.go @@ -299,7 +299,7 @@ func TestAuditEntry_Marshal(t *testing.T) { Visibility: String("v"), WorkflowID: Int64(1), WorkflowRunID: Int64(1), - AuditEntryData: AuditEntryData{ + Data: &AuditEntryData{ OldName: String("on"), }, } From 9f800d211910adf1b2d7783e7fcc118889861186 Mon Sep 17 00:00:00 2001 From: Lucas Martin-King Date: Sat, 29 Jul 2023 00:01:52 +1000 Subject: [PATCH 7/7] gofmt --- github/orgs_audit_log.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/orgs_audit_log.go b/github/orgs_audit_log.go index 9e534ac50c..d7de77127c 100644 --- a/github/orgs_audit_log.go +++ b/github/orgs_audit_log.go @@ -122,7 +122,7 @@ type AuditEntry struct { WorkflowID *int64 `json:"workflow_id,omitempty"` WorkflowRunID *int64 `json:"workflow_run_id,omitempty"` - Data *AuditEntryData `json:"data,omitempty"` + Data *AuditEntryData `json:"data,omitempty"` } // AuditEntryData represents additional information stuffed into a `data` field.