From bf8d5d554c1b8e3b4a29a93fa0029afdf0835572 Mon Sep 17 00:00:00 2001 From: Khanh Ngo Date: Fri, 15 Dec 2023 18:55:20 +0100 Subject: [PATCH] Add Referrer field to AuditEntry (#3032) Fixes: #3031. --- github/github-accessors.go | 179 +++++++++++++++++++++++++ github/github-accessors_test.go | 223 ++++++++++++++++++++++++++++++++ github/orgs_audit_log.go | 84 ++++++++++++ 3 files changed, 486 insertions(+) diff --git a/github/github-accessors.go b/github/github-accessors.go index c90ee88d8ce..289fff8ad49 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -1166,6 +1166,185 @@ func (a *AuditEntry) GetOrgID() int64 { return *a.OrgID } +<<<<<<< HEAD +======= +// 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 +} + +>>>>>>> d47936f (Add Referrer field to AuditEntry (#3032)) // GetTimestamp returns the Timestamp field if it's non-nil, zero value otherwise. func (a *AuditEntry) GetTimestamp() Timestamp { if a == nil || a.Timestamp == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 19c7f381c25..e4e56bb761a 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -1380,6 +1380,229 @@ func TestAuditEntry_GetOrgID(tt *testing.T) { a.GetOrgID() } +<<<<<<< HEAD +======= +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() +} + +>>>>>>> d47936f (Add Referrer field to AuditEntry (#3032)) func TestAuditEntry_GetTimestamp(tt *testing.T) { var zeroValue Timestamp a := &AuditEntry{Timestamp: &zeroValue} diff --git a/github/orgs_audit_log.go b/github/orgs_audit_log.go index 28ac079bb3b..78761faf24f 100644 --- a/github/orgs_audit_log.go +++ b/github/orgs_audit_log.go @@ -40,6 +40,7 @@ type ActorLocation struct { // 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 { +<<<<<<< HEAD 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"` @@ -58,6 +59,89 @@ type AuditEntry struct { 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"` +======= + 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"` +>>>>>>> d47936f (Add Referrer field to AuditEntry (#3032)) // Some events types have a data field that contains additional information about the event. Data map[string]interface{} `json:"data,omitempty"`