diff --git a/github/enterprise_audit_log_test.go b/github/enterprise_audit_log_test.go index 2e91346ebf3..0d9e44a3eb6 100644 --- a/github/enterprise_audit_log_test.go +++ b/github/enterprise_audit_log_test.go @@ -11,8 +11,6 @@ import ( "net/http" "testing" "time" - - "github.com/google/go-cmp/cmp" ) func TestEnterpriseService_GetAuditLog(t *testing.T) { @@ -54,34 +52,31 @@ func TestEnterpriseService_GetAuditLog(t *testing.T) { if err != nil { t.Errorf("Enterprise.GetAuditLog returned error: %v", err) } - startedAt, _ := time.Parse(time.RFC3339, "2021-03-07T00:33:04.000Z") - completedAt, _ := time.Parse(time.RFC3339, "2021-03-07T00:35:08.000Z") timestamp := time.Unix(0, 1615077308538*1e6) - want := []*AuditEntry{ { - Timestamp: &Timestamp{timestamp}, - DocumentID: String("beeZYapIUe-wKg5-beadb33"), - Action: String("workflows.completed_workflow_run"), - Actor: String("testactor"), - CompletedAt: &Timestamp{completedAt}, - Conclusion: String("success"), - CreatedAt: &Timestamp{timestamp}, - Event: String("schedule"), - HeadBranch: String("master"), - HeadSHA: String("5acdeadbeef64d1a62388e901e5cdc9358644b37"), - Name: String("Code scanning - action"), - Org: String("o"), - Repo: String("o/blue-crayon-1"), - StartedAt: &Timestamp{startedAt}, - WorkflowID: Int64(123456), - WorkflowRunID: Int64(628312345), + Timestamp: &Timestamp{timestamp}, + DocumentID: String("beeZYapIUe-wKg5-beadb33"), + Action: String("workflows.completed_workflow_run"), + Actor: String("testactor"), + CreatedAt: &Timestamp{timestamp}, + Org: String("o"), + AdditionalFields: map[string]interface{}{ + "completed_at": "2021-03-07T00:35:08.000Z", + "conclusion": "success", + "event": "schedule", + "head_branch": "master", + "head_sha": "5acdeadbeef64d1a62388e901e5cdc9358644b37", + "name": "Code scanning - action", + "repo": "o/blue-crayon-1", + "started_at": "2021-03-07T00:33:04.000Z", + "workflow_id": float64(123456), + "workflow_run_id": float64(628312345), + }, }, } - if !cmp.Equal(auditEntries, want) { - t.Errorf("Enterprise.GetAuditLog return \ngot: %+v,\nwant:%+v", auditEntries, want) - } + assertNoDiff(t, want, auditEntries) const methodName = "GetAuditLog" testBadOptions(t, methodName, func() (err error) { diff --git a/github/github-accessors.go b/github/github-accessors.go index 02d1212cd9b..f41409f9e6c 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -1070,22 +1070,6 @@ func (a *AuditEntry) GetAction() string { return *a.Action } -// GetActive returns the Active field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetActive() bool { - if a == nil || a.Active == nil { - return false - } - return *a.Active -} - -// GetActiveWas returns the ActiveWas field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetActiveWas() bool { - if a == nil || a.ActiveWas == nil { - return false - } - return *a.ActiveWas -} - // GetActor returns the Actor field if it's non-nil, zero value otherwise. func (a *AuditEntry) GetActor() string { if a == nil || a.Actor == nil { @@ -1094,12 +1078,12 @@ func (a *AuditEntry) GetActor() string { return *a.Actor } -// GetActorIP returns the ActorIP field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetActorIP() string { - if a == nil || a.ActorIP == nil { - return "" +// GetActorID returns the ActorID field if it's non-nil, zero value otherwise. +func (a *AuditEntry) GetActorID() int64 { + if a == nil || a.ActorID == nil { + return 0 } - return *a.ActorIP + return *a.ActorID } // GetActorLocation returns the ActorLocation field. @@ -1110,14 +1094,6 @@ func (a *AuditEntry) GetActorLocation() *ActorLocation { return a.ActorLocation } -// GetBlockedUser returns the BlockedUser field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetBlockedUser() string { - if a == nil || a.BlockedUser == nil { - return "" - } - return *a.BlockedUser -} - // GetBusiness returns the Business field if it's non-nil, zero value otherwise. func (a *AuditEntry) GetBusiness() string { if a == nil || a.Business == nil { @@ -1126,52 +1102,12 @@ func (a *AuditEntry) GetBusiness() string { return *a.Business } -// GetCancelledAt returns the CancelledAt field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetCancelledAt() Timestamp { - if a == nil || a.CancelledAt == nil { - return Timestamp{} - } - return *a.CancelledAt -} - -// GetCompletedAt returns the CompletedAt field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetCompletedAt() Timestamp { - if a == nil || a.CompletedAt == nil { - return Timestamp{} - } - return *a.CompletedAt -} - -// GetConclusion returns the Conclusion field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetConclusion() string { - if a == nil || a.Conclusion == nil { - return "" - } - return *a.Conclusion -} - -// GetConfig returns the Config field. -func (a *AuditEntry) GetConfig() *HookConfig { - if a == nil { - return nil - } - return a.Config -} - -// GetConfigWas returns the ConfigWas field. -func (a *AuditEntry) GetConfigWas() *HookConfig { - if a == nil { - return nil - } - return a.ConfigWas -} - -// GetContentType returns the ContentType field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetContentType() string { - if a == nil || a.ContentType == nil { - return "" +// GetBusinessID returns the BusinessID field if it's non-nil, zero value otherwise. +func (a *AuditEntry) GetBusinessID() int64 { + if a == nil || a.BusinessID == nil { + return 0 } - return *a.ContentType + return *a.BusinessID } // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. @@ -1182,22 +1118,6 @@ 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 { - return "" - } - return *a.DeployKeyFingerprint -} - // GetDocumentID returns the DocumentID field if it's non-nil, zero value otherwise. func (a *AuditEntry) GetDocumentID() string { if a == nil || a.DocumentID == nil { @@ -1206,38 +1126,6 @@ func (a *AuditEntry) GetDocumentID() string { return *a.DocumentID } -// GetEmoji returns the Emoji field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetEmoji() string { - if a == nil || a.Emoji == nil { - return "" - } - return *a.Emoji -} - -// GetEnvironmentName returns the EnvironmentName field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetEnvironmentName() string { - if a == nil || a.EnvironmentName == nil { - return "" - } - return *a.EnvironmentName -} - -// GetEvent returns the Event field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetEvent() string { - if a == nil || a.Event == nil { - return "" - } - return *a.Event -} - -// GetExplanation returns the Explanation field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetExplanation() string { - if a == nil || a.Explanation == nil { - return "" - } - return *a.Explanation -} - // GetExternalIdentityNameID returns the ExternalIdentityNameID field if it's non-nil, zero value otherwise. func (a *AuditEntry) GetExternalIdentityNameID() string { if a == nil || a.ExternalIdentityNameID == nil { @@ -1254,14 +1142,6 @@ func (a *AuditEntry) GetExternalIdentityUsername() string { return *a.ExternalIdentityUsername } -// GetFingerprint returns the Fingerprint field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetFingerprint() string { - if a == nil || a.Fingerprint == nil { - return "" - } - return *a.Fingerprint -} - // GetHashedToken returns the HashedToken field if it's non-nil, zero value otherwise. func (a *AuditEntry) GetHashedToken() string { if a == nil || a.HashedToken == nil { @@ -1270,118 +1150,6 @@ func (a *AuditEntry) GetHashedToken() string { return *a.HashedToken } -// GetHeadBranch returns the HeadBranch field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetHeadBranch() string { - if a == nil || a.HeadBranch == nil { - return "" - } - return *a.HeadBranch -} - -// GetHeadSHA returns the HeadSHA field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetHeadSHA() string { - if a == nil || a.HeadSHA == nil { - return "" - } - return *a.HeadSHA -} - -// GetHookID returns the HookID field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetHookID() int64 { - if a == nil || a.HookID == nil { - return 0 - } - return *a.HookID -} - -// GetIsHostedRunner returns the IsHostedRunner field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetIsHostedRunner() bool { - if a == nil || a.IsHostedRunner == nil { - return false - } - return *a.IsHostedRunner -} - -// GetJobName returns the JobName field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetJobName() string { - if a == nil || a.JobName == nil { - return "" - } - return *a.JobName -} - -// GetJobWorkflowRef returns the JobWorkflowRef field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetJobWorkflowRef() string { - if a == nil || a.JobWorkflowRef == nil { - return "" - } - return *a.JobWorkflowRef -} - -// GetLimitedAvailability returns the LimitedAvailability field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetLimitedAvailability() bool { - if a == nil || a.LimitedAvailability == nil { - return false - } - return *a.LimitedAvailability -} - -// GetMessage returns the Message field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetMessage() string { - if a == nil || a.Message == nil { - return "" - } - return *a.Message -} - -// GetName returns the Name field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetName() string { - if a == nil || a.Name == nil { - return "" - } - return *a.Name -} - -// GetOAuthApplicationID returns the OAuthApplicationID field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetOAuthApplicationID() int64 { - if a == nil || a.OAuthApplicationID == nil { - return 0 - } - return *a.OAuthApplicationID -} - -// 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 { - return "" - } - return *a.OldUser -} - -// GetOpenSSHPublicKey returns the OpenSSHPublicKey field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetOpenSSHPublicKey() string { - if a == nil || a.OpenSSHPublicKey == nil { - return "" - } - return *a.OpenSSHPublicKey -} - -// GetOperationType returns the OperationType field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetOperationType() string { - if a == nil || a.OperationType == nil { - return "" - } - return *a.OperationType -} - // GetOrg returns the Org field if it's non-nil, zero value otherwise. func (a *AuditEntry) GetOrg() string { if a == nil || a.Org == nil { @@ -1398,182 +1166,6 @@ func (a *AuditEntry) GetOrgID() int64 { return *a.OrgID } -// 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 { - return "" - } - return *a.PreviousVisibility -} - -// GetProgrammaticAccessType returns the ProgrammaticAccessType field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetProgrammaticAccessType() string { - if a == nil || a.ProgrammaticAccessType == nil { - return "" - } - return *a.ProgrammaticAccessType -} - -// GetPullRequestID returns the PullRequestID field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetPullRequestID() int64 { - if a == nil || a.PullRequestID == nil { - return 0 - } - return *a.PullRequestID -} - -// GetPullRequestTitle returns the PullRequestTitle field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetPullRequestTitle() string { - if a == nil || a.PullRequestTitle == nil { - return "" - } - return *a.PullRequestTitle -} - -// GetPullRequestURL returns the PullRequestURL field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetPullRequestURL() string { - if a == nil || a.PullRequestURL == nil { - return "" - } - return *a.PullRequestURL -} - -// GetReadOnly returns the ReadOnly field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetReadOnly() string { - if a == nil || a.ReadOnly == nil { - return "" - } - return *a.ReadOnly -} - -// GetReferrer returns the Referrer field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetReferrer() string { - if a == nil || a.Referrer == nil { - return "" - } - return *a.Referrer -} - -// GetRepo returns the Repo field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetRepo() string { - if a == nil || a.Repo == nil { - return "" - } - return *a.Repo -} - -// GetRepository returns the Repository field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetRepository() string { - if a == nil || a.Repository == nil { - return "" - } - return *a.Repository -} - -// GetRepositoryPublic returns the RepositoryPublic field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetRepositoryPublic() bool { - if a == nil || a.RepositoryPublic == nil { - return false - } - return *a.RepositoryPublic -} - -// GetRunAttempt returns the RunAttempt field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetRunAttempt() int64 { - if a == nil || a.RunAttempt == nil { - return 0 - } - return *a.RunAttempt -} - -// GetRunnerGroupID returns the RunnerGroupID field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetRunnerGroupID() int64 { - if a == nil || a.RunnerGroupID == nil { - return 0 - } - return *a.RunnerGroupID -} - -// GetRunnerGroupName returns the RunnerGroupName field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetRunnerGroupName() string { - if a == nil || a.RunnerGroupName == nil { - return "" - } - return *a.RunnerGroupName -} - -// GetRunnerID returns the RunnerID field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetRunnerID() int64 { - if a == nil || a.RunnerID == nil { - return 0 - } - return *a.RunnerID -} - -// GetRunnerName returns the RunnerName field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetRunnerName() string { - if a == nil || a.RunnerName == nil { - return "" - } - return *a.RunnerName -} - -// GetRunNumber returns the RunNumber field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetRunNumber() int64 { - if a == nil || a.RunNumber == nil { - return 0 - } - return *a.RunNumber -} - -// GetSourceVersion returns the SourceVersion field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetSourceVersion() string { - if a == nil || a.SourceVersion == nil { - return "" - } - return *a.SourceVersion -} - -// GetStartedAt returns the StartedAt field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetStartedAt() Timestamp { - if a == nil || a.StartedAt == nil { - return Timestamp{} - } - return *a.StartedAt -} - -// GetTargetLogin returns the TargetLogin field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetTargetLogin() string { - if a == nil || a.TargetLogin == nil { - return "" - } - return *a.TargetLogin -} - -// GetTargetVersion returns the TargetVersion field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetTargetVersion() string { - if a == nil || a.TargetVersion == nil { - return "" - } - return *a.TargetVersion -} - -// GetTeam returns the Team field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetTeam() string { - if a == nil || a.Team == nil { - return "" - } - return *a.Team -} - // GetTimestamp returns the Timestamp field if it's non-nil, zero value otherwise. func (a *AuditEntry) GetTimestamp() Timestamp { if a == nil || a.Timestamp == nil { @@ -1598,38 +1190,6 @@ func (a *AuditEntry) GetTokenScopes() string { return *a.TokenScopes } -// GetTopic returns the Topic field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetTopic() string { - if a == nil || a.Topic == nil { - return "" - } - return *a.Topic -} - -// GetTransportProtocol returns the TransportProtocol field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetTransportProtocol() int { - if a == nil || a.TransportProtocol == nil { - return 0 - } - return *a.TransportProtocol -} - -// GetTransportProtocolName returns the TransportProtocolName field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetTransportProtocolName() string { - if a == nil || a.TransportProtocolName == nil { - return "" - } - return *a.TransportProtocolName -} - -// GetTriggerID returns the TriggerID field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetTriggerID() int64 { - if a == nil || a.TriggerID == nil { - return 0 - } - return *a.TriggerID -} - // GetUser returns the User field if it's non-nil, zero value otherwise. func (a *AuditEntry) GetUser() string { if a == nil || a.User == nil { @@ -1638,52 +1198,12 @@ func (a *AuditEntry) GetUser() string { return *a.User } -// GetUserAgent returns the UserAgent field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetUserAgent() string { - if a == nil || a.UserAgent == nil { - return "" - } - return *a.UserAgent -} - -// GetVisibility returns the Visibility field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetVisibility() string { - if a == nil || a.Visibility == nil { - return "" - } - return *a.Visibility -} - -// GetWorkflowID returns the WorkflowID field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetWorkflowID() int64 { - if a == nil || a.WorkflowID == nil { +// GetUserID returns the UserID field if it's non-nil, zero value otherwise. +func (a *AuditEntry) GetUserID() int64 { + if a == nil || a.UserID == nil { return 0 } - return *a.WorkflowID -} - -// GetWorkflowRunID returns the WorkflowRunID field if it's non-nil, zero value otherwise. -func (a *AuditEntry) GetWorkflowRunID() int64 { - if a == nil || a.WorkflowRunID == nil { - return 0 - } - return *a.WorkflowRunID -} - -// GetOldLogin returns the OldLogin field if it's non-nil, zero value otherwise. -func (a *AuditEntryData) GetOldLogin() string { - if a == nil || a.OldLogin == nil { - return "" - } - return *a.OldLogin -} - -// 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 + return *a.UserID } // GetApp returns the App field. @@ -14478,22 +13998,6 @@ func (p *Plan) GetSpace() int { return *p.Space } -// GetCode returns the Code field if it's non-nil, zero value otherwise. -func (p *PolicyOverrideReason) GetCode() string { - if p == nil || p.Code == nil { - return "" - } - return *p.Code -} - -// GetMessage returns the Message field if it's non-nil, zero value otherwise. -func (p *PolicyOverrideReason) GetMessage() string { - if p == nil || p.Message == nil { - return "" - } - return *p.Message -} - // GetConfigURL returns the ConfigURL field if it's non-nil, zero value otherwise. func (p *PreReceiveHook) GetConfigURL() string { if p == nil || p.ConfigURL == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 6ae89e454a6..5b0b9911bdb 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -1263,26 +1263,6 @@ func TestAuditEntry_GetAction(tt *testing.T) { a.GetAction() } -func TestAuditEntry_GetActive(tt *testing.T) { - var zeroValue bool - a := &AuditEntry{Active: &zeroValue} - a.GetActive() - a = &AuditEntry{} - a.GetActive() - a = nil - a.GetActive() -} - -func TestAuditEntry_GetActiveWas(tt *testing.T) { - var zeroValue bool - a := &AuditEntry{ActiveWas: &zeroValue} - a.GetActiveWas() - a = &AuditEntry{} - a.GetActiveWas() - a = nil - a.GetActiveWas() -} - func TestAuditEntry_GetActor(tt *testing.T) { var zeroValue string a := &AuditEntry{Actor: &zeroValue} @@ -1293,14 +1273,14 @@ func TestAuditEntry_GetActor(tt *testing.T) { a.GetActor() } -func TestAuditEntry_GetActorIP(tt *testing.T) { - var zeroValue string - a := &AuditEntry{ActorIP: &zeroValue} - a.GetActorIP() +func TestAuditEntry_GetActorID(tt *testing.T) { + var zeroValue int64 + a := &AuditEntry{ActorID: &zeroValue} + a.GetActorID() a = &AuditEntry{} - a.GetActorIP() + a.GetActorID() a = nil - a.GetActorIP() + a.GetActorID() } func TestAuditEntry_GetActorLocation(tt *testing.T) { @@ -1310,16 +1290,6 @@ func TestAuditEntry_GetActorLocation(tt *testing.T) { a.GetActorLocation() } -func TestAuditEntry_GetBlockedUser(tt *testing.T) { - var zeroValue string - a := &AuditEntry{BlockedUser: &zeroValue} - a.GetBlockedUser() - a = &AuditEntry{} - a.GetBlockedUser() - a = nil - a.GetBlockedUser() -} - func TestAuditEntry_GetBusiness(tt *testing.T) { var zeroValue string a := &AuditEntry{Business: &zeroValue} @@ -1330,58 +1300,14 @@ func TestAuditEntry_GetBusiness(tt *testing.T) { a.GetBusiness() } -func TestAuditEntry_GetCancelledAt(tt *testing.T) { - var zeroValue Timestamp - a := &AuditEntry{CancelledAt: &zeroValue} - a.GetCancelledAt() - a = &AuditEntry{} - a.GetCancelledAt() - a = nil - a.GetCancelledAt() -} - -func TestAuditEntry_GetCompletedAt(tt *testing.T) { - var zeroValue Timestamp - a := &AuditEntry{CompletedAt: &zeroValue} - a.GetCompletedAt() - a = &AuditEntry{} - a.GetCompletedAt() - a = nil - a.GetCompletedAt() -} - -func TestAuditEntry_GetConclusion(tt *testing.T) { - var zeroValue string - a := &AuditEntry{Conclusion: &zeroValue} - a.GetConclusion() - a = &AuditEntry{} - a.GetConclusion() - a = nil - a.GetConclusion() -} - -func TestAuditEntry_GetConfig(tt *testing.T) { - a := &AuditEntry{} - a.GetConfig() - a = nil - a.GetConfig() -} - -func TestAuditEntry_GetConfigWas(tt *testing.T) { - a := &AuditEntry{} - a.GetConfigWas() - a = nil - a.GetConfigWas() -} - -func TestAuditEntry_GetContentType(tt *testing.T) { - var zeroValue string - a := &AuditEntry{ContentType: &zeroValue} - a.GetContentType() +func TestAuditEntry_GetBusinessID(tt *testing.T) { + var zeroValue int64 + a := &AuditEntry{BusinessID: &zeroValue} + a.GetBusinessID() a = &AuditEntry{} - a.GetContentType() + a.GetBusinessID() a = nil - a.GetContentType() + a.GetBusinessID() } func TestAuditEntry_GetCreatedAt(tt *testing.T) { @@ -1394,23 +1320,6 @@ 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} - a.GetDeployKeyFingerprint() - a = &AuditEntry{} - a.GetDeployKeyFingerprint() - a = nil - a.GetDeployKeyFingerprint() -} - func TestAuditEntry_GetDocumentID(tt *testing.T) { var zeroValue string a := &AuditEntry{DocumentID: &zeroValue} @@ -1421,46 +1330,6 @@ func TestAuditEntry_GetDocumentID(tt *testing.T) { a.GetDocumentID() } -func TestAuditEntry_GetEmoji(tt *testing.T) { - var zeroValue string - a := &AuditEntry{Emoji: &zeroValue} - a.GetEmoji() - a = &AuditEntry{} - a.GetEmoji() - a = nil - a.GetEmoji() -} - -func TestAuditEntry_GetEnvironmentName(tt *testing.T) { - var zeroValue string - a := &AuditEntry{EnvironmentName: &zeroValue} - a.GetEnvironmentName() - a = &AuditEntry{} - a.GetEnvironmentName() - a = nil - a.GetEnvironmentName() -} - -func TestAuditEntry_GetEvent(tt *testing.T) { - var zeroValue string - a := &AuditEntry{Event: &zeroValue} - a.GetEvent() - a = &AuditEntry{} - a.GetEvent() - a = nil - a.GetEvent() -} - -func TestAuditEntry_GetExplanation(tt *testing.T) { - var zeroValue string - a := &AuditEntry{Explanation: &zeroValue} - a.GetExplanation() - a = &AuditEntry{} - a.GetExplanation() - a = nil - a.GetExplanation() -} - func TestAuditEntry_GetExternalIdentityNameID(tt *testing.T) { var zeroValue string a := &AuditEntry{ExternalIdentityNameID: &zeroValue} @@ -1481,16 +1350,6 @@ func TestAuditEntry_GetExternalIdentityUsername(tt *testing.T) { a.GetExternalIdentityUsername() } -func TestAuditEntry_GetFingerprint(tt *testing.T) { - var zeroValue string - a := &AuditEntry{Fingerprint: &zeroValue} - a.GetFingerprint() - a = &AuditEntry{} - a.GetFingerprint() - a = nil - a.GetFingerprint() -} - func TestAuditEntry_GetHashedToken(tt *testing.T) { var zeroValue string a := &AuditEntry{HashedToken: &zeroValue} @@ -1501,146 +1360,6 @@ func TestAuditEntry_GetHashedToken(tt *testing.T) { a.GetHashedToken() } -func TestAuditEntry_GetHeadBranch(tt *testing.T) { - var zeroValue string - a := &AuditEntry{HeadBranch: &zeroValue} - a.GetHeadBranch() - a = &AuditEntry{} - a.GetHeadBranch() - a = nil - a.GetHeadBranch() -} - -func TestAuditEntry_GetHeadSHA(tt *testing.T) { - var zeroValue string - a := &AuditEntry{HeadSHA: &zeroValue} - a.GetHeadSHA() - a = &AuditEntry{} - a.GetHeadSHA() - a = nil - a.GetHeadSHA() -} - -func TestAuditEntry_GetHookID(tt *testing.T) { - var zeroValue int64 - a := &AuditEntry{HookID: &zeroValue} - a.GetHookID() - a = &AuditEntry{} - a.GetHookID() - a = nil - a.GetHookID() -} - -func TestAuditEntry_GetIsHostedRunner(tt *testing.T) { - var zeroValue bool - a := &AuditEntry{IsHostedRunner: &zeroValue} - a.GetIsHostedRunner() - a = &AuditEntry{} - a.GetIsHostedRunner() - a = nil - a.GetIsHostedRunner() -} - -func TestAuditEntry_GetJobName(tt *testing.T) { - var zeroValue string - a := &AuditEntry{JobName: &zeroValue} - a.GetJobName() - a = &AuditEntry{} - a.GetJobName() - a = nil - a.GetJobName() -} - -func TestAuditEntry_GetJobWorkflowRef(tt *testing.T) { - var zeroValue string - a := &AuditEntry{JobWorkflowRef: &zeroValue} - a.GetJobWorkflowRef() - a = &AuditEntry{} - a.GetJobWorkflowRef() - a = nil - a.GetJobWorkflowRef() -} - -func TestAuditEntry_GetLimitedAvailability(tt *testing.T) { - var zeroValue bool - a := &AuditEntry{LimitedAvailability: &zeroValue} - a.GetLimitedAvailability() - a = &AuditEntry{} - a.GetLimitedAvailability() - a = nil - a.GetLimitedAvailability() -} - -func TestAuditEntry_GetMessage(tt *testing.T) { - var zeroValue string - a := &AuditEntry{Message: &zeroValue} - a.GetMessage() - a = &AuditEntry{} - a.GetMessage() - a = nil - a.GetMessage() -} - -func TestAuditEntry_GetName(tt *testing.T) { - var zeroValue string - a := &AuditEntry{Name: &zeroValue} - a.GetName() - a = &AuditEntry{} - a.GetName() - a = nil - a.GetName() -} - -func TestAuditEntry_GetOAuthApplicationID(tt *testing.T) { - var zeroValue int64 - a := &AuditEntry{OAuthApplicationID: &zeroValue} - a.GetOAuthApplicationID() - a = &AuditEntry{} - a.GetOAuthApplicationID() - a = nil - a.GetOAuthApplicationID() -} - -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} - a.GetOldUser() - a = &AuditEntry{} - a.GetOldUser() - a = nil - a.GetOldUser() -} - -func TestAuditEntry_GetOpenSSHPublicKey(tt *testing.T) { - var zeroValue string - a := &AuditEntry{OpenSSHPublicKey: &zeroValue} - a.GetOpenSSHPublicKey() - a = &AuditEntry{} - a.GetOpenSSHPublicKey() - a = nil - a.GetOpenSSHPublicKey() -} - -func TestAuditEntry_GetOperationType(tt *testing.T) { - var zeroValue string - a := &AuditEntry{OperationType: &zeroValue} - a.GetOperationType() - a = &AuditEntry{} - a.GetOperationType() - a = nil - a.GetOperationType() -} - func TestAuditEntry_GetOrg(tt *testing.T) { var zeroValue string a := &AuditEntry{Org: &zeroValue} @@ -1661,226 +1380,6 @@ func TestAuditEntry_GetOrgID(tt *testing.T) { a.GetOrgID() } -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} - a.GetPreviousVisibility() - a = &AuditEntry{} - a.GetPreviousVisibility() - a = nil - a.GetPreviousVisibility() -} - -func TestAuditEntry_GetProgrammaticAccessType(tt *testing.T) { - var zeroValue string - a := &AuditEntry{ProgrammaticAccessType: &zeroValue} - a.GetProgrammaticAccessType() - a = &AuditEntry{} - a.GetProgrammaticAccessType() - a = nil - a.GetProgrammaticAccessType() -} - -func TestAuditEntry_GetPullRequestID(tt *testing.T) { - var zeroValue int64 - a := &AuditEntry{PullRequestID: &zeroValue} - a.GetPullRequestID() - a = &AuditEntry{} - a.GetPullRequestID() - a = nil - a.GetPullRequestID() -} - -func TestAuditEntry_GetPullRequestTitle(tt *testing.T) { - var zeroValue string - a := &AuditEntry{PullRequestTitle: &zeroValue} - a.GetPullRequestTitle() - a = &AuditEntry{} - a.GetPullRequestTitle() - a = nil - a.GetPullRequestTitle() -} - -func TestAuditEntry_GetPullRequestURL(tt *testing.T) { - var zeroValue string - a := &AuditEntry{PullRequestURL: &zeroValue} - a.GetPullRequestURL() - a = &AuditEntry{} - a.GetPullRequestURL() - a = nil - a.GetPullRequestURL() -} - -func TestAuditEntry_GetReadOnly(tt *testing.T) { - var zeroValue string - a := &AuditEntry{ReadOnly: &zeroValue} - a.GetReadOnly() - a = &AuditEntry{} - a.GetReadOnly() - a = nil - a.GetReadOnly() -} - -func TestAuditEntry_GetReferrer(tt *testing.T) { - var zeroValue string - a := &AuditEntry{Referrer: &zeroValue} - a.GetReferrer() - a = &AuditEntry{} - a.GetReferrer() - a = nil - a.GetReferrer() -} - -func TestAuditEntry_GetRepo(tt *testing.T) { - var zeroValue string - a := &AuditEntry{Repo: &zeroValue} - a.GetRepo() - a = &AuditEntry{} - a.GetRepo() - a = nil - a.GetRepo() -} - -func TestAuditEntry_GetRepository(tt *testing.T) { - var zeroValue string - a := &AuditEntry{Repository: &zeroValue} - a.GetRepository() - a = &AuditEntry{} - a.GetRepository() - a = nil - a.GetRepository() -} - -func TestAuditEntry_GetRepositoryPublic(tt *testing.T) { - var zeroValue bool - a := &AuditEntry{RepositoryPublic: &zeroValue} - a.GetRepositoryPublic() - a = &AuditEntry{} - a.GetRepositoryPublic() - a = nil - a.GetRepositoryPublic() -} - -func TestAuditEntry_GetRunAttempt(tt *testing.T) { - var zeroValue int64 - a := &AuditEntry{RunAttempt: &zeroValue} - a.GetRunAttempt() - a = &AuditEntry{} - a.GetRunAttempt() - a = nil - a.GetRunAttempt() -} - -func TestAuditEntry_GetRunnerGroupID(tt *testing.T) { - var zeroValue int64 - a := &AuditEntry{RunnerGroupID: &zeroValue} - a.GetRunnerGroupID() - a = &AuditEntry{} - a.GetRunnerGroupID() - a = nil - a.GetRunnerGroupID() -} - -func TestAuditEntry_GetRunnerGroupName(tt *testing.T) { - var zeroValue string - a := &AuditEntry{RunnerGroupName: &zeroValue} - a.GetRunnerGroupName() - a = &AuditEntry{} - a.GetRunnerGroupName() - a = nil - a.GetRunnerGroupName() -} - -func TestAuditEntry_GetRunnerID(tt *testing.T) { - var zeroValue int64 - a := &AuditEntry{RunnerID: &zeroValue} - a.GetRunnerID() - a = &AuditEntry{} - a.GetRunnerID() - a = nil - a.GetRunnerID() -} - -func TestAuditEntry_GetRunnerName(tt *testing.T) { - var zeroValue string - a := &AuditEntry{RunnerName: &zeroValue} - a.GetRunnerName() - a = &AuditEntry{} - a.GetRunnerName() - a = nil - a.GetRunnerName() -} - -func TestAuditEntry_GetRunNumber(tt *testing.T) { - var zeroValue int64 - a := &AuditEntry{RunNumber: &zeroValue} - a.GetRunNumber() - a = &AuditEntry{} - a.GetRunNumber() - a = nil - a.GetRunNumber() -} - -func TestAuditEntry_GetSourceVersion(tt *testing.T) { - var zeroValue string - a := &AuditEntry{SourceVersion: &zeroValue} - a.GetSourceVersion() - a = &AuditEntry{} - a.GetSourceVersion() - a = nil - a.GetSourceVersion() -} - -func TestAuditEntry_GetStartedAt(tt *testing.T) { - var zeroValue Timestamp - a := &AuditEntry{StartedAt: &zeroValue} - a.GetStartedAt() - a = &AuditEntry{} - a.GetStartedAt() - a = nil - a.GetStartedAt() -} - -func TestAuditEntry_GetTargetLogin(tt *testing.T) { - var zeroValue string - a := &AuditEntry{TargetLogin: &zeroValue} - a.GetTargetLogin() - a = &AuditEntry{} - a.GetTargetLogin() - a = nil - a.GetTargetLogin() -} - -func TestAuditEntry_GetTargetVersion(tt *testing.T) { - var zeroValue string - a := &AuditEntry{TargetVersion: &zeroValue} - a.GetTargetVersion() - a = &AuditEntry{} - a.GetTargetVersion() - a = nil - a.GetTargetVersion() -} - -func TestAuditEntry_GetTeam(tt *testing.T) { - var zeroValue string - a := &AuditEntry{Team: &zeroValue} - a.GetTeam() - a = &AuditEntry{} - a.GetTeam() - a = nil - a.GetTeam() -} - func TestAuditEntry_GetTimestamp(tt *testing.T) { var zeroValue Timestamp a := &AuditEntry{Timestamp: &zeroValue} @@ -1911,46 +1410,6 @@ func TestAuditEntry_GetTokenScopes(tt *testing.T) { a.GetTokenScopes() } -func TestAuditEntry_GetTopic(tt *testing.T) { - var zeroValue string - a := &AuditEntry{Topic: &zeroValue} - a.GetTopic() - a = &AuditEntry{} - a.GetTopic() - a = nil - a.GetTopic() -} - -func TestAuditEntry_GetTransportProtocol(tt *testing.T) { - var zeroValue int - a := &AuditEntry{TransportProtocol: &zeroValue} - a.GetTransportProtocol() - a = &AuditEntry{} - a.GetTransportProtocol() - a = nil - a.GetTransportProtocol() -} - -func TestAuditEntry_GetTransportProtocolName(tt *testing.T) { - var zeroValue string - a := &AuditEntry{TransportProtocolName: &zeroValue} - a.GetTransportProtocolName() - a = &AuditEntry{} - a.GetTransportProtocolName() - a = nil - a.GetTransportProtocolName() -} - -func TestAuditEntry_GetTriggerID(tt *testing.T) { - var zeroValue int64 - a := &AuditEntry{TriggerID: &zeroValue} - a.GetTriggerID() - a = &AuditEntry{} - a.GetTriggerID() - a = nil - a.GetTriggerID() -} - func TestAuditEntry_GetUser(tt *testing.T) { var zeroValue string a := &AuditEntry{User: &zeroValue} @@ -1961,64 +1420,14 @@ func TestAuditEntry_GetUser(tt *testing.T) { a.GetUser() } -func TestAuditEntry_GetUserAgent(tt *testing.T) { - var zeroValue string - a := &AuditEntry{UserAgent: &zeroValue} - a.GetUserAgent() - a = &AuditEntry{} - a.GetUserAgent() - a = nil - a.GetUserAgent() -} - -func TestAuditEntry_GetVisibility(tt *testing.T) { - var zeroValue string - a := &AuditEntry{Visibility: &zeroValue} - a.GetVisibility() - a = &AuditEntry{} - a.GetVisibility() - a = nil - a.GetVisibility() -} - -func TestAuditEntry_GetWorkflowID(tt *testing.T) { +func TestAuditEntry_GetUserID(tt *testing.T) { var zeroValue int64 - a := &AuditEntry{WorkflowID: &zeroValue} - a.GetWorkflowID() + a := &AuditEntry{UserID: &zeroValue} + a.GetUserID() a = &AuditEntry{} - a.GetWorkflowID() + a.GetUserID() a = nil - a.GetWorkflowID() -} - -func TestAuditEntry_GetWorkflowRunID(tt *testing.T) { - var zeroValue int64 - a := &AuditEntry{WorkflowRunID: &zeroValue} - a.GetWorkflowRunID() - a = &AuditEntry{} - a.GetWorkflowRunID() - a = nil - a.GetWorkflowRunID() -} - -func TestAuditEntryData_GetOldLogin(tt *testing.T) { - var zeroValue string - a := &AuditEntryData{OldLogin: &zeroValue} - a.GetOldLogin() - a = &AuditEntryData{} - a.GetOldLogin() - a = nil - a.GetOldLogin() -} - -func TestAuditEntryData_GetOldName(tt *testing.T) { - var zeroValue string - a := &AuditEntryData{OldName: &zeroValue} - a.GetOldName() - a = &AuditEntryData{} - a.GetOldName() - a = nil - a.GetOldName() + a.GetUserID() } func TestAuthorization_GetApp(tt *testing.T) { @@ -16949,26 +16358,6 @@ func TestPlan_GetSpace(tt *testing.T) { p.GetSpace() } -func TestPolicyOverrideReason_GetCode(tt *testing.T) { - var zeroValue string - p := &PolicyOverrideReason{Code: &zeroValue} - p.GetCode() - p = &PolicyOverrideReason{} - p.GetCode() - p = nil - p.GetCode() -} - -func TestPolicyOverrideReason_GetMessage(tt *testing.T) { - var zeroValue string - p := &PolicyOverrideReason{Message: &zeroValue} - p.GetMessage() - p = &PolicyOverrideReason{} - p.GetMessage() - p = nil - p.GetMessage() -} - func TestPreReceiveHook_GetConfigURL(tt *testing.T) { var zeroValue string p := &PreReceiveHook{ConfigURL: &zeroValue} diff --git a/github/github_test.go b/github/github_test.go index 4d672f6096f..45ac57c0019 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -275,6 +275,13 @@ func testErrorResponseForStatusCode(t *testing.T, code int) { } } +func assertNoDiff(t *testing.T, want, got interface{}) { + t.Helper() + if diff := cmp.Diff(want, got); diff != "" { + t.Errorf("diff mismatch (-want +got):\n%v", diff) + } +} + func assertNilError(t *testing.T, err error) { t.Helper() if err != nil { diff --git a/github/orgs_audit_log.go b/github/orgs_audit_log.go index aa3591359ef..28ac079bb3b 100644 --- a/github/orgs_audit_log.go +++ b/github/orgs_audit_log.go @@ -7,6 +7,7 @@ package github import ( "context" + "encoding/json" "fmt" ) @@ -34,104 +35,94 @@ type ActorLocation struct { CountryCode *string `json:"country_code,omitempty"` } -// PolicyOverrideReason contains user-supplied information about why a policy was overridden. -type PolicyOverrideReason struct { - Code *string `json:"code,omitempty"` - Message *string `json:"message,omitempty"` -} - // AuditEntry describes the fields that may be represented by various audit-log "action" entries. +// There are many other fields that may be present depending on the action. You can access those +// in AdditionalFields. // For a list of actions see - https://docs.github.com/github/setting-up-and-managing-organizations-and-teams/reviewing-the-audit-log-for-your-organization#audit-log-actions type AuditEntry struct { - ActorIP *string `json:"actor_ip,omitempty"` - Action *string `json:"action,omitempty"` // The name of the action that was performed, for example `user.login` or `repo.create`. - Active *bool `json:"active,omitempty"` - ActiveWas *bool `json:"active_was,omitempty"` - Actor *string `json:"actor,omitempty"` // The actor who performed the action. - ActorLocation *ActorLocation `json:"actor_location,omitempty"` - BlockedUser *string `json:"blocked_user,omitempty"` - Business *string `json:"business,omitempty"` - CancelledAt *Timestamp `json:"cancelled_at,omitempty"` - CompletedAt *Timestamp `json:"completed_at,omitempty"` - Conclusion *string `json:"conclusion,omitempty"` - Config *HookConfig `json:"config,omitempty"` - ConfigWas *HookConfig `json:"config_was,omitempty"` - ContentType *string `json:"content_type,omitempty"` - CreatedAt *Timestamp `json:"created_at,omitempty"` - DeployKeyFingerprint *string `json:"deploy_key_fingerprint,omitempty"` - DocumentID *string `json:"_document_id,omitempty"` - Emoji *string `json:"emoji,omitempty"` - EnvironmentName *string `json:"environment_name,omitempty"` - Event *string `json:"event,omitempty"` - Events []string `json:"events,omitempty"` - EventsWere []string `json:"events_were,omitempty"` - Explanation *string `json:"explanation,omitempty"` - ExternalIdentityNameID *string `json:"external_identity_nameid,omitempty"` - ExternalIdentityUsername *string `json:"external_identity_username,omitempty"` - Fingerprint *string `json:"fingerprint,omitempty"` - HashedToken *string `json:"hashed_token,omitempty"` - HeadBranch *string `json:"head_branch,omitempty"` - HeadSHA *string `json:"head_sha,omitempty"` - HookID *int64 `json:"hook_id,omitempty"` - IsHostedRunner *bool `json:"is_hosted_runner,omitempty"` - JobName *string `json:"job_name,omitempty"` - JobWorkflowRef *string `json:"job_workflow_ref,omitempty"` - LimitedAvailability *bool `json:"limited_availability,omitempty"` - Message *string `json:"message,omitempty"` - Name *string `json:"name,omitempty"` - OAuthApplicationID *int64 `json:"oauth_application_id,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"` - OperationType *string `json:"operation_type,omitempty"` - Org *string `json:"org,omitempty"` - OrgID *int64 `json:"org_id,omitempty"` - OverriddenCodes []string `json:"overridden_codes,omitempty"` - Permission *string `json:"permission,omitempty"` // The permission level for membership changes, for example `admin` or `read`. - PreviousVisibility *string `json:"previous_visibility,omitempty"` - ProgrammaticAccessType *string `json:"programmatic_access_type,omitempty"` - PullRequestID *int64 `json:"pull_request_id,omitempty"` - PullRequestTitle *string `json:"pull_request_title,omitempty"` - PullRequestURL *string `json:"pull_request_url,omitempty"` - ReadOnly *string `json:"read_only,omitempty"` - Reasons []*PolicyOverrideReason `json:"reasons,omitempty"` - Referrer *string `json:"referrer,omitempty"` - Repo *string `json:"repo,omitempty"` - Repository *string `json:"repository,omitempty"` - RepositoryPublic *bool `json:"repository_public,omitempty"` - RunAttempt *int64 `json:"run_attempt,omitempty"` - RunnerGroupID *int64 `json:"runner_group_id,omitempty"` - RunnerGroupName *string `json:"runner_group_name,omitempty"` - RunnerID *int64 `json:"runner_id,omitempty"` - RunnerLabels []string `json:"runner_labels,omitempty"` - RunnerName *string `json:"runner_name,omitempty"` - RunNumber *int64 `json:"run_number,omitempty"` - SecretsPassed []string `json:"secrets_passed,omitempty"` - SourceVersion *string `json:"source_version,omitempty"` - StartedAt *Timestamp `json:"started_at,omitempty"` - TargetLogin *string `json:"target_login,omitempty"` - TargetVersion *string `json:"target_version,omitempty"` - Team *string `json:"team,omitempty"` - Timestamp *Timestamp `json:"@timestamp,omitempty"` // The time the audit log event occurred, given as a [Unix timestamp](http://en.wikipedia.org/wiki/Unix_time). - TokenID *int64 `json:"token_id,omitempty"` - TokenScopes *string `json:"token_scopes,omitempty"` - Topic *string `json:"topic,omitempty"` - TransportProtocolName *string `json:"transport_protocol_name,omitempty"` // A human readable name for the protocol (for example, HTTP or SSH) used to transfer Git data. - TransportProtocol *int `json:"transport_protocol,omitempty"` // The type of protocol (for example, HTTP=1 or SSH=2) used to transfer Git data. - TriggerID *int64 `json:"trigger_id,omitempty"` - User *string `json:"user,omitempty"` // The user that was affected by the action performed (if available). - UserAgent *string `json:"user_agent,omitempty"` - 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"` - - Data *AuditEntryData `json:"data,omitempty"` + Action *string `json:"action,omitempty"` // The name of the action that was performed, for example `user.login` or `repo.create`. + Actor *string `json:"actor,omitempty"` // The actor who performed the action. + ActorID *int64 `json:"actor_id,omitempty"` + ActorLocation *ActorLocation `json:"actor_location,omitempty"` + Business *string `json:"business,omitempty"` + BusinessID *int64 `json:"business_id,omitempty"` + CreatedAt *Timestamp `json:"created_at,omitempty"` + DocumentID *string `json:"_document_id,omitempty"` + ExternalIdentityNameID *string `json:"external_identity_nameid,omitempty"` + ExternalIdentityUsername *string `json:"external_identity_username,omitempty"` + HashedToken *string `json:"hashed_token,omitempty"` + Org *string `json:"org,omitempty"` + OrgID *int64 `json:"org_id,omitempty"` + Timestamp *Timestamp `json:"@timestamp,omitempty"` // The time the audit log event occurred, given as a [Unix timestamp](http://en.wikipedia.org/wiki/Unix_time). + TokenID *int64 `json:"token_id,omitempty"` + TokenScopes *string `json:"token_scopes,omitempty"` + User *string `json:"user,omitempty"` // The user that was affected by the action performed (if available). + UserID *int64 `json:"user_id,omitempty"` + + // Some events types have a data field that contains additional information about the event. + Data map[string]interface{} `json:"data,omitempty"` + + // All fields that are not explicitly defined in the struct are captured here. + AdditionalFields map[string]interface{} `json:"-"` +} + +func (a *AuditEntry) UnmarshalJSON(data []byte) error { + type entryAlias AuditEntry + var v entryAlias + if err := json.Unmarshal(data, &v); err != nil { + return err + } + + rawDefinedFields, err := json.Marshal(v) + if err != nil { + return err + } + definedFields := map[string]interface{}{} + if err := json.Unmarshal(rawDefinedFields, &definedFields); err != nil { + return err + } + + if err := json.Unmarshal(data, &v.AdditionalFields); err != nil { + return err + } + + for key, val := range v.AdditionalFields { + if _, ok := definedFields[key]; ok || val == nil { + delete(v.AdditionalFields, key) + } + } + + *a = AuditEntry(v) + if len(v.AdditionalFields) == 0 { + a.AdditionalFields = nil + } + return nil } -// 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 - OldLogin *string `json:"old_login,omitempty"` // The previous name of the organization, for a name change +func (a *AuditEntry) MarshalJSON() ([]byte, error) { + type entryAlias AuditEntry + v := entryAlias(*a) + defBytes, err := json.Marshal(v) + if err != nil { + return nil, err + } + if len(a.AdditionalFields) == 0 { + return defBytes, err + } + resMap := map[string]interface{}{} + if err := json.Unmarshal(defBytes, &resMap); err != nil { + return nil, err + } + for key, val := range a.AdditionalFields { + if val == nil { + continue + } + if _, ok := resMap[key]; ok { + return nil, fmt.Errorf("unexpected field in AdditionalFields: %v", key) + } + resMap[key] = val + } + return json.Marshal(resMap) } // GetAuditLog gets the audit-log entries for an organization. diff --git a/github/orgs_audit_log_test.go b/github/orgs_audit_log_test.go index 1a82471face..7c8de74c650 100644 --- a/github/orgs_audit_log_test.go +++ b/github/orgs_audit_log_test.go @@ -12,8 +12,6 @@ import ( "strings" "testing" "time" - - "github.com/google/go-cmp/cmp" ) func TestOrganizationService_GetAuditLog(t *testing.T) { @@ -24,46 +22,43 @@ func TestOrganizationService_GetAuditLog(t *testing.T) { testMethod(t, r, "GET") fmt.Fprint(w, `[ - { + { + "@timestamp": 1615077308538, + "_document_id": "beeZYapIUe-wKg5-beadb33", + "action": "workflows.completed_workflow_run", + "active": true, + "actor": "testactor", "actor_ip": "10.0.0.1", "actor_location": { "country_code": "US" }, - "active": true, - "workflow_id": 123456, - "head_branch": "master", - "org": "o", - "trigger_id": null, - "repo": "o/blue-crayon-1", - "created_at": 1615077308538, + "cancelled_at": "2021-03-07T00:35:08.000Z", + "completed_at": "2021-03-07T00:35:08.000Z", + "conclusion": "success", + "config": { + "content_type": "json", + "insecure_ssl": "0", + "url": "https://example.com/deadbeef-new-hook" + }, + "created_at": 1615077308538, + "event": "schedule", + "events": ["code_scanning_alert"], "hashed_token": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=", - "head_sha": "5acdeadbeef64d1a62388e901e5cdc9358644b37", - "conclusion": "success", - "old_permission": "read", - "permission": "admin", - "actor": "testactor", - "completed_at": "2021-03-07T00:35:08.000Z", - "@timestamp": 1615077308538, - "name": "Code scanning - action", - "action": "workflows.completed_workflow_run", - "started_at": "2021-03-07T00:33:04.000Z", - "event": "schedule", - "workflow_run_id": 628312345, - "_document_id": "beeZYapIUe-wKg5-beadb33", - "run_attempt": 1, - "run_number": 1, - "token_id": 1, - "token_scopes": "gist,repo:read", - "topic": "cp1-iad.ingest.github.actions.v0.WorkflowUpdate", + "head_branch": "master", + "head_sha": "5acdeadbeef64d1a62388e901e5cdc9358644b37", "job_workflow_ref": "testorg/testrepo/.github/workflows/testjob.yml@refs/pull/1/merge", + "name": "Code scanning - action", "oauth_application_id": 1, + "old_permission": "read", + "org": "o", "org_id": 1, - "pull_request_id": 1, - "pull_request_title": "a pr title", - "pull_request_url": "https://github.com/testorg/testrepo/pull/1", "overridden_codes": [ "review_policy_not_satisfied" ], + "permission": "admin", + "pull_request_id": 1, + "pull_request_title": "a pr title", + "pull_request_url": "https://github.com/testorg/testrepo/pull/1", "reasons": [ { "code": "a code", @@ -71,14 +66,19 @@ func TestOrganizationService_GetAuditLog(t *testing.T) { } ], "programmatic_access_type": "GitHub App server-to-server token", + "referrer": "a referrer", + "repo": "o/blue-crayon-1", + "run_attempt": 1, + "run_number": 1, + "started_at": "2021-03-07T00:33:04.000Z", + "token_id": 1, + "token_scopes": "gist,repo:read", + "topic": "cp1-iad.ingest.github.actions.v0.WorkflowUpdate", + "trigger_id": null, "user_agent": "a user agent", - "config": { - "content_type": "json", - "insecure_ssl": "0", - "url": "https://example.com/deadbeef-new-hook" - }, - "events": ["code_scanning_alert"] - }]`) + "workflow_id": 123456, + "workflow_run_id": 628312345 + }]`) }) ctx := context.Background() getOpts := GetAuditLogOptions{ @@ -91,8 +91,6 @@ func TestOrganizationService_GetAuditLog(t *testing.T) { if err != nil { t.Errorf("Organizations.GetAuditLog returned error: %v", err) } - startedAt, _ := time.Parse(time.RFC3339, "2021-03-07T00:33:04.000Z") - completedAt, _ := time.Parse(time.RFC3339, "2021-03-07T00:35:08.000Z") timestamp := time.Unix(0, 1615077308538*1e6) want := []*AuditEntry{ @@ -101,56 +99,58 @@ func TestOrganizationService_GetAuditLog(t *testing.T) { DocumentID: String("beeZYapIUe-wKg5-beadb33"), Action: String("workflows.completed_workflow_run"), Actor: String("testactor"), - ActorIP: String("10.0.0.1"), ActorLocation: &ActorLocation{ CountryCode: String("US"), }, - Active: Bool(true), - CompletedAt: &Timestamp{completedAt}, - Conclusion: String("success"), - CreatedAt: &Timestamp{timestamp}, - Event: String("schedule"), - HashedToken: String("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="), - HeadBranch: String("master"), - HeadSHA: String("5acdeadbeef64d1a62388e901e5cdc9358644b37"), - JobWorkflowRef: String("testorg/testrepo/.github/workflows/testjob.yml@refs/pull/1/merge"), - Name: String("Code scanning - action"), - OAuthApplicationID: Int64(1), - OldPermission: String("read"), - Org: String("o"), - OrgID: Int64(1), - OverriddenCodes: []string{"review_policy_not_satisfied"}, - Permission: String("admin"), - ProgrammaticAccessType: String("GitHub App server-to-server token"), - PullRequestID: Int64(1), - PullRequestTitle: String("a pr title"), - PullRequestURL: String("https://github.com/testorg/testrepo/pull/1"), - Reasons: []*PolicyOverrideReason{{ - Code: String("a code"), - Message: String("a message"), - }}, - Repo: String("o/blue-crayon-1"), - RunAttempt: Int64(1), - RunNumber: Int64(1), - StartedAt: &Timestamp{startedAt}, - TokenID: Int64(1), - TokenScopes: String("gist,repo:read"), - Topic: String("cp1-iad.ingest.github.actions.v0.WorkflowUpdate"), - UserAgent: String("a user agent"), - WorkflowID: Int64(123456), - WorkflowRunID: Int64(628312345), - Events: []string{"code_scanning_alert"}, - Config: &HookConfig{ - ContentType: String("json"), - InsecureSSL: String("0"), - URL: String("https://example.com/deadbeef-new-hook"), + CreatedAt: &Timestamp{timestamp}, + HashedToken: String("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="), + Org: String("o"), + OrgID: Int64(1), + TokenID: Int64(1), + TokenScopes: String("gist,repo:read"), + AdditionalFields: map[string]interface{}{ + "actor_ip": "10.0.0.1", + "active": true, + "cancelled_at": "2021-03-07T00:35:08.000Z", + "completed_at": "2021-03-07T00:35:08.000Z", + "conclusion": "success", + "event": "schedule", + "head_branch": "master", + "head_sha": "5acdeadbeef64d1a62388e901e5cdc9358644b37", + "job_workflow_ref": "testorg/testrepo/.github/workflows/testjob.yml@refs/pull/1/merge", + "name": "Code scanning - action", + "oauth_application_id": float64(1), + "old_permission": "read", + "overridden_codes": []interface{}{"review_policy_not_satisfied"}, + "permission": "admin", + "programmatic_access_type": "GitHub App server-to-server token", + "pull_request_id": float64(1), + "pull_request_title": "a pr title", + "pull_request_url": "https://github.com/testorg/testrepo/pull/1", + "reasons": []interface{}{map[string]interface{}{ + "code": "a code", + "message": "a message", + }}, + "referrer": "a referrer", + "repo": "o/blue-crayon-1", + "run_attempt": float64(1), + "run_number": float64(1), + "started_at": "2021-03-07T00:33:04.000Z", + "topic": "cp1-iad.ingest.github.actions.v0.WorkflowUpdate", + "user_agent": "a user agent", + "workflow_id": float64(123456), + "workflow_run_id": float64(628312345), + "events": []interface{}{"code_scanning_alert"}, + "config": map[string]interface{}{ + "content_type": "json", + "insecure_ssl": "0", + "url": "https://example.com/deadbeef-new-hook", + }, }, }, } - if !cmp.Equal(auditEntries, want) { - t.Errorf("Organizations.GetAuditLog return \ngot: %+v,\nwant:%+v", auditEntries, want) - } + assertNoDiff(t, want, auditEntries) // assert query string has lower case params requestedQuery := resp.Request.URL.RawQuery @@ -224,86 +224,95 @@ func TestAuditEntry_Marshal(t *testing.T) { u := &AuditEntry{ Action: String("a"), - Active: Bool(false), - ActiveWas: Bool(false), Actor: String("ac"), - ActorIP: String("aip"), ActorLocation: &ActorLocation{CountryCode: String("alcc")}, - BlockedUser: String("bu"), Business: String("b"), - CancelledAt: &Timestamp{referenceTime}, - CompletedAt: &Timestamp{referenceTime}, - Conclusion: String("c"), - Config: &HookConfig{URL: String("s")}, - ConfigWas: &HookConfig{URL: String("s")}, - ContentType: String("ct"), CreatedAt: &Timestamp{referenceTime}, - DeployKeyFingerprint: String("dkf"), DocumentID: String("did"), - Emoji: String("e"), - EnvironmentName: String("en"), - Event: String("e"), - Events: []string{"s"}, - EventsWere: []string{"s"}, - Explanation: String("e"), ExternalIdentityNameID: String("ein"), ExternalIdentityUsername: String("eiu"), - Fingerprint: String("f"), HashedToken: String("ht"), - HeadBranch: String("hb"), - HeadSHA: String("hsha"), - HookID: Int64(1), - IsHostedRunner: Bool(false), - JobName: String("jn"), - LimitedAvailability: Bool(false), - Message: String("m"), - Name: String("n"), - OldPermission: String("op"), - OldUser: String("ou"), - OpenSSHPublicKey: String("osshpk"), Org: String("o"), OrgID: Int64(1), - Permission: String("p"), - PreviousVisibility: String("pv"), - ProgrammaticAccessType: String("pat"), - PullRequestID: Int64(1), - PullRequestTitle: String("prt"), - PullRequestURL: String("pru"), - Reasons: []*PolicyOverrideReason{{ - Code: String("c"), - Message: String("m"), - }}, - ReadOnly: String("ro"), - Repo: String("r"), - Repository: String("repo"), - RepositoryPublic: Bool(false), - RunAttempt: Int64(1), - RunnerGroupID: Int64(1), - RunnerGroupName: String("rgn"), - RunnerID: Int64(1), - RunnerLabels: []string{"s"}, - RunnerName: String("rn"), - SecretsPassed: []string{"s"}, - SourceVersion: String("sv"), - StartedAt: &Timestamp{referenceTime}, - TargetLogin: String("tl"), - TargetVersion: String("tv"), - Team: String("t"), - Timestamp: &Timestamp{referenceTime}, - TokenID: Int64(1), - TokenScopes: String("ts"), - Topic: String("tp"), - TransportProtocolName: String("tpn"), - TransportProtocol: Int(1), - TriggerID: Int64(1), - User: String("u"), - UserAgent: String("ua"), - Visibility: String("v"), - WorkflowID: Int64(1), - WorkflowRunID: Int64(1), - Data: &AuditEntryData{ - OldName: String("on"), - OldLogin: String("ol"), + Timestamp: &Timestamp{referenceTime}, + TokenID: Int64(1), + TokenScopes: String("ts"), + User: String("u"), + Data: map[string]interface{}{ + "old_name": "on", + "old_login": "ol", + }, + AdditionalFields: map[string]interface{}{ + "active": false, + "active_was": false, + "actor_ip": "aip", + "blocked_user": "bu", + "cancelled_at": "2021-03-07T00:35:08.000Z", + "completed_at": "2021-03-07T00:35:08.000Z", + "conclusion": "c", + "config": map[string]interface{}{ + "url": "s", + }, + "config_was": map[string]interface{}{ + "url": "s", + }, + "content_type": "ct", + "deploy_key_fingerprint": "dkf", + "emoji": "e", + "environment_name": "en", + "event": "e", + "events": []interface{}{"s"}, + "events_were": []interface{}{"s"}, + "explanation": "e", + "fingerprint": "f", + "head_branch": "hb", + "head_sha": "hsha", + "hook_id": float64(1), + "is_hosted_runner": false, + "job_name": "jn", + "limited_availability": false, + "message": "m", + "name": "n", + "old_permission": "op", + "old_user": "ou", + "openssh_public_key": "osshpk", + "permission": "p", + "previous_visibility": "pv", + "programmatic_access_type": "pat", + "pull_request_id": float64(1), + "pull_request_title": "prt", + "pull_request_url": "pru", + "read_only": "ro", + "reasons": []interface{}{ + map[string]interface{}{ + "code": "c", + "message": "m", + }, + }, + "referrer": "a referrer", + "repo": "r", + "repository": "repo", + "repository_public": false, + "run_attempt": 1, + "runner_group_id": 1, + "runner_group_name": "rgn", + "runner_id": 1, + "runner_labels": []interface{}{"s"}, + "runner_name": "rn", + "secrets_passed": []interface{}{"s"}, + "source_version": "sv", + "started_at": "2006-01-02T15:04:05Z", + "target_login": "tl", + "target_version": "tv", + "team": "t", + "topic": "cp1-iad.ingest.github.actions.v0.WorkflowUpdate", + "transport_protocol": 1, + "transport_protocol_name": "tpn", + "trigger_id": 1, + "user_agent": "ua", + "visibility": "v", + "workflow_id": 1, + "workflow_run_id": 1, }, } @@ -318,8 +327,8 @@ func TestAuditEntry_Marshal(t *testing.T) { }, "blocked_user": "bu", "business": "b", - "cancelled_at": ` + referenceTimeStr + `, - "completed_at": ` + referenceTimeStr + `, + "cancelled_at": "2021-03-07T00:35:08.000Z", + "completed_at": "2021-03-07T00:35:08.000Z", "conclusion": "c", "config": { "url": "s" @@ -368,6 +377,7 @@ func TestAuditEntry_Marshal(t *testing.T) { "code": "c", "message": "m" }], + "referrer": "a referrer", "read_only": "ro", "repo": "r", "repository": "repo", @@ -391,7 +401,7 @@ func TestAuditEntry_Marshal(t *testing.T) { "@timestamp": ` + referenceTimeStr + `, "token_id": 1, "token_scopes": "ts", - "topic": "tp", + "topic": "cp1-iad.ingest.github.actions.v0.WorkflowUpdate", "transport_protocol_name": "tpn", "transport_protocol": 1, "trigger_id": 1, diff --git a/test/integration/audit_log_test.go b/test/integration/audit_log_test.go index 7819f9292ff..639ea7a6780 100644 --- a/test/integration/audit_log_test.go +++ b/test/integration/audit_log_test.go @@ -28,6 +28,6 @@ func TestOrganizationAuditLog(t *testing.T) { } for _, e := range entries { - t.Log(e.GetAction(), e.GetActor(), e.GetTimestamp(), e.GetUser(), e.GetActive()) + t.Log(e.GetAction(), e.GetActor(), e.GetTimestamp(), e.GetUser()) } }