diff --git a/github/event_types.go b/github/event_types.go index fbe56b20d0..64726d7739 100644 --- a/github/event_types.go +++ b/github/event_types.go @@ -1505,6 +1505,22 @@ type RepositoryImportEvent struct { Sender *User `json:"sender,omitempty"` } +// RepositoryRulesetEvent triggers whenever there is a change to the repository's ruleset configuration. +// +// This can include updates to protection rules, required status checks, code owners, or other related configurations. +// +// GitHub API docs: https://docs.github.com/en/webhooks/webhook-events-and-payloads#repository_ruleset +type RepositoryRulesetEvent struct { + Action *string `json:"action,omitempty"` + Enterprise *Enterprise `json:"enterprise,omitempty"` + Installation *Installation `json:"installation,omitempty"` + Organization *Organization `json:"organization,omitempty"` + Repository *Repository `json:"repository,omitempty"` + RepositoryRuleset *RepositoryRuleset `json:"repository_ruleset"` + Changes *RepositoryRulesetEditedChanges `json:"changes,omitempty"` + Sender *User `json:"sender"` +} + // RepositoryVulnerabilityAlertEvent is triggered when a security alert is created, dismissed, or resolved. // // GitHub API docs: https://docs.github.com/developers/webhooks-and-events/webhook-events-and-payloads#repository_vulnerability_alert diff --git a/github/event_types_test.go b/github/event_types_test.go index 474c9ceb3d..71c8ac3df2 100644 --- a/github/event_types_test.go +++ b/github/event_types_test.go @@ -9506,6 +9506,1783 @@ func TestReleaseEvent_Marshal(t *testing.T) { testJSONMarshal(t, u, want) } +func TestRepositoryRulesetEvent_Marshal(t *testing.T) { + t.Parallel() + testJSONMarshal(t, &RepositoryRulesetEvent{}, "{}") + + l := make(map[string]interface{}) + l["key"] = "value" + + jsonMsg, _ := json.Marshal(&l) + + u := &RepositoryRulesetEvent{ + Action: String("a"), + Enterprise: &Enterprise{ + ID: Int(1), + Slug: String("s"), + Name: String("n"), + NodeID: String("nid"), + AvatarURL: String("au"), + Description: String("d"), + WebsiteURL: String("wu"), + HTMLURL: String("hu"), + CreatedAt: &Timestamp{referenceTime}, + UpdatedAt: &Timestamp{referenceTime}, + }, + Installation: &Installation{ + ID: Int64(1), + NodeID: String("nid"), + AppID: Int64(1), + AppSlug: String("as"), + TargetID: Int64(1), + Account: &User{ + Login: String("l"), + ID: Int64(1), + URL: String("u"), + AvatarURL: String("a"), + GravatarID: String("g"), + Name: String("n"), + Company: String("c"), + Blog: String("b"), + Location: String("l"), + Email: String("e"), + Hireable: Bool(true), + Bio: String("b"), + TwitterUsername: String("t"), + PublicRepos: Int(1), + Followers: Int(1), + Following: Int(1), + CreatedAt: &Timestamp{referenceTime}, + SuspendedAt: &Timestamp{referenceTime}, + }, + AccessTokensURL: String("atu"), + RepositoriesURL: String("ru"), + HTMLURL: String("hu"), + TargetType: String("tt"), + SingleFileName: String("sfn"), + RepositorySelection: String("rs"), + Events: []string{"e"}, + SingleFilePaths: []string{"s"}, + Permissions: &InstallationPermissions{ + Actions: String("a"), + Administration: String("ad"), + Checks: String("c"), + Contents: String("co"), + ContentReferences: String("cr"), + Deployments: String("d"), + Environments: String("e"), + Issues: String("i"), + Metadata: String("md"), + Members: String("m"), + OrganizationAdministration: String("oa"), + OrganizationHooks: String("oh"), + OrganizationPlan: String("op"), + OrganizationPreReceiveHooks: String("opr"), + OrganizationProjects: String("op"), + OrganizationSecrets: String("os"), + OrganizationSelfHostedRunners: String("osh"), + OrganizationUserBlocking: String("oub"), + Packages: String("pkg"), + Pages: String("pg"), + PullRequests: String("pr"), + RepositoryHooks: String("rh"), + RepositoryProjects: String("rp"), + RepositoryPreReceiveHooks: String("rprh"), + Secrets: String("s"), + SecretScanningAlerts: String("ssa"), + SecurityEvents: String("se"), + SingleFile: String("sf"), + Statuses: String("s"), + TeamDiscussions: String("td"), + VulnerabilityAlerts: String("va"), + Workflows: String("w"), + }, + CreatedAt: &Timestamp{referenceTime}, + UpdatedAt: &Timestamp{referenceTime}, + HasMultipleSingleFiles: Bool(false), + SuspendedBy: &User{ + Login: String("l"), + ID: Int64(1), + URL: String("u"), + AvatarURL: String("a"), + GravatarID: String("g"), + Name: String("n"), + Company: String("c"), + Blog: String("b"), + Location: String("l"), + Email: String("e"), + Hireable: Bool(true), + Bio: String("b"), + TwitterUsername: String("t"), + PublicRepos: Int(1), + Followers: Int(1), + Following: Int(1), + CreatedAt: &Timestamp{referenceTime}, + SuspendedAt: &Timestamp{referenceTime}, + }, + SuspendedAt: &Timestamp{referenceTime}, + }, + Organization: &Organization{ + BillingEmail: String("be"), + Blog: String("b"), + Company: String("c"), + Email: String("e"), + TwitterUsername: String("tu"), + Location: String("loc"), + Name: String("n"), + Description: String("d"), + IsVerified: Bool(true), + HasOrganizationProjects: Bool(true), + HasRepositoryProjects: Bool(true), + DefaultRepoPermission: String("drp"), + MembersCanCreateRepos: Bool(true), + MembersCanCreateInternalRepos: Bool(true), + MembersCanCreatePrivateRepos: Bool(true), + MembersCanCreatePublicRepos: Bool(false), + MembersAllowedRepositoryCreationType: String("marct"), + MembersCanCreatePages: Bool(true), + MembersCanCreatePublicPages: Bool(false), + MembersCanCreatePrivatePages: Bool(true), + }, + Repository: &Repository{ + ID: Int64(1), + URL: String("u"), + Name: String("n"), + }, + RepositoryRuleset: &RepositoryRuleset{ + ID: 1, + Name: "n", + Target: String("branch"), + SourceType: String("Repository"), + Source: "s", + Enforcement: "disabled", + BypassActors: []*BypassActor{ + { + ActorID: Int64(234), + ActorType: String("Team"), + BypassMode: String("Always"), + }, + }, + CurrentUserCanBypass: String("always"), + NodeID: String("n"), + Links: &RepositoryRulesetLink{ + Self: &RulesetLink{ + HRef: String("href"), + }, + HTML: &RulesetLink{ + HRef: String("href"), + }, + }, + Conditions: json.RawMessage(jsonMsg), + Rules: []*RepositoryRulesetRule{ + { + Creation: &RepositoryRulesetRuleType{ + Type: "creation", + }, + Update: &RepositoryRulesetUpdateRule{ + Type: "update", + Parameters: &UpdateAllowsFetchAndMergeRuleParameters{ + UpdateAllowsFetchAndMerge: true, + }, + }, + Deletion: &RepositoryRulesetRuleType{ + Type: "deletion", + }, + RequiredLinearHistory: &RepositoryRulesetRuleType{ + Type: "required_linear_history", + }, + MergeQueue: &RepositoryRulesetMergeQueueRule{ + Type: "merge_queue", + Parameters: &MergeQueueRuleParameters{ + CheckResponseTimeoutMinutes: 35, + GroupingStrategy: "HEADGREEN", + MaxEntriesToBuild: 8, + MaxEntriesToMerge: 4, + MergeMethod: "SQUASH", + MinEntriesToMerge: 2, + MinEntriesToMergeWaitMinutes: 13, + }, + }, + RequiredDeployments: &RepositoryRulesetRequiredDeploymentsRule{ + Type: "required_deployments", + Parameters: &RequiredDeploymentEnvironmentsRuleParameters{ + RequiredDeploymentEnvironments: []string{"test"}, + }, + }, + RequiredSignatures: &RepositoryRulesetRuleType{ + Type: "required_signatures", + }, + PullRequest: &RepositoryRulesetPullRequestRule{ + Type: "pull_request", + Parameters: &PullRequestRuleParameters{ + RequireCodeOwnerReview: true, + RequireLastPushApproval: true, + RequiredApprovingReviewCount: 1, + RequiredReviewThreadResolution: true, + DismissStaleReviewsOnPush: true, + }, + }, + RequiredStatusChecks: &RepositoryRulesetRequiredStatusChecksRule{ + Type: "required_status_checks", + Parameters: &RequiredStatusChecksRuleParameters{ + RequiredStatusChecks: []RuleRequiredStatusChecks{ + { + Context: "test", + IntegrationID: Int64(1), + }, + }, + StrictRequiredStatusChecksPolicy: true, + }, + }, + NonFastForward: &RepositoryRulesetRuleType{ + Type: "non_fast_forward", + }, + CommitMessagePattern: &RepositoryRulesetPatternRule{ + Type: "commit_message_pattern", + Parameters: &RulePatternParameters{ + Name: String("avoid test commits"), + Negate: Bool(true), + Operator: "starts_with", + Pattern: "[test]", + }, + }, + CommitAuthorEmailPattern: &RepositoryRulesetPatternRule{ + Type: "commit_author_email_pattern", + Parameters: &RulePatternParameters{ + Operator: "contains", + Pattern: "github", + }, + }, + CommitterEmailPattern: &RepositoryRulesetPatternRule{ + Type: "committer_email_pattern", + Parameters: &RulePatternParameters{ + Name: String("avoid commit emails"), + Negate: Bool(true), + Operator: "ends_with", + Pattern: "abc", + }, + }, + BranchNamePattern: &RepositoryRulesetPatternRule{ + Type: "branch_name_pattern", + Parameters: &RulePatternParameters{ + Name: String("avoid branch names"), + Negate: Bool(true), + Operator: "regex", + Pattern: "github$", + }, + }, + TagNamePattern: &RepositoryRulesetPatternRule{ + Type: "tag_name_pattern", + Parameters: &RulePatternParameters{ + Name: String("avoid tag names"), + Negate: Bool(true), + Operator: "contains", + Pattern: "github", + }, + }, + FilePathRestriction: &RepositoryRulesetFilePathRestrictionRule{ + Type: "file_path_restriction", + Parameters: &RuleFileParameters{ + RestrictedFilePaths: &[]string{"/a/file"}, + }, + }, + MaxFilePathLength: &RepositoryRulesetMaxFilePathLengthRule{ + Type: "max_file_path_length", + Parameters: &RuleMaxFilePathLengthParameters{ + MaxFilePathLength: 255, + }, + }, + FileExtensionRestriction: &RepositoryRulesetFileExtensionRestrictionRule{ + Type: "file_extension_restriction", + Parameters: &RuleFileExtensionRestrictionParameters{ + RestrictedFileExtensions: []string{".exe"}, + }, + }, + MaxFileSize: &RepositoryRulesetMaxFileSizeRule{ + Type: "max_file_size", + Parameters: &RuleMaxFileSizeParameters{ + MaxFileSize: 1024, + }, + }, + Workflows: &RepositoryRulesetWorkflowsRule{ + Type: "workflows", + Parameters: &RequiredWorkflowsRuleParameters{ + RequiredWorkflows: []*RuleRequiredWorkflow{ + { + Path: ".github/workflows/test.yml", + RepositoryID: Int64(1), + }, + }, + }, + }, + CodeScanning: &RepositoryRulesetCodeScanningRule{ + Type: "code_scanning", + Parameters: &RuleCodeScanningParameters{ + CodeScanningTools: []*CodeScanningTool{{ + AlertsThreshold: "alert", + SecurityAlertsThreshold: "security", + Tool: "tool", + }}, + }, + }, + }, + }, + CreatedAt: &Timestamp{referenceTime}, + UpdatedAt: &Timestamp{referenceTime}, + }, + Changes: &RepositoryRulesetEditedChanges{ + Name: &RepositoryRulesetEditedSource{ + From: String("f"), + }, + Enforcement: &RepositoryRulesetEditedSource{ + From: String("e"), + }, + Conditions: &RepositoryRulesetEditedConditions{ + Added: []*RepositoryRulesetRefCondition{ + { + RefName: &RulesetRefConditionParameters{ + Include: []string{"refs/heads/main", "refs/heads/master"}, + Exclude: []string{"refs/heads/dev*"}, + }, + }, + }, + Deleted: []*RepositoryRulesetRefCondition{ + { + RefName: &RulesetRefConditionParameters{ + Include: []string{"refs/heads/main", "refs/heads/master"}, + Exclude: []string{"refs/heads/dev*"}, + }, + }, + }, + Updated: []*RepositoryRulesetEditedUpdatedConditions{ + { + Condition: &RepositoryRulesetRefCondition{ + RefName: &RulesetRefConditionParameters{ + Include: []string{"refs/heads/main", "refs/heads/master"}, + Exclude: []string{"refs/heads/dev*"}, + }, + }, + Changes: &RepositoryRulesetUpdatedConditionsEdited{ + ConditionType: &RepositoryRulesetEditedSource{ + From: String("c"), + }, + Target: &RepositoryRulesetEditedSource{ + From: String("t"), + }, + Include: &RepositoryRulesetEditedSources{ + From: []string{"from"}, + }, + Exclude: &RepositoryRulesetEditedSources{ + From: []string{"to"}, + }, + }, + }, + }, + }, + Rules: &RepositoryRulesetEditedRules{ + Added: []*RepositoryRulesetRule{ + //Creating just one object with all the possible rules for testing + { + Creation: &RepositoryRulesetRuleType{ + Type: "creation", + }, + Update: &RepositoryRulesetUpdateRule{ + Type: "update", + Parameters: &UpdateAllowsFetchAndMergeRuleParameters{ + UpdateAllowsFetchAndMerge: true, + }, + }, + Deletion: &RepositoryRulesetRuleType{ + Type: "deletion", + }, + RequiredLinearHistory: &RepositoryRulesetRuleType{ + Type: "required_linear_history", + }, + MergeQueue: &RepositoryRulesetMergeQueueRule{ + Type: "merge_queue", + Parameters: &MergeQueueRuleParameters{ + CheckResponseTimeoutMinutes: 35, + GroupingStrategy: "HEADGREEN", + MaxEntriesToBuild: 8, + MaxEntriesToMerge: 4, + MergeMethod: "SQUASH", + MinEntriesToMerge: 2, + MinEntriesToMergeWaitMinutes: 13, + }, + }, + RequiredDeployments: &RepositoryRulesetRequiredDeploymentsRule{ + Type: "required_deployments", + Parameters: &RequiredDeploymentEnvironmentsRuleParameters{ + RequiredDeploymentEnvironments: []string{"test"}, + }, + }, + RequiredSignatures: &RepositoryRulesetRuleType{ + Type: "required_signatures", + }, + PullRequest: &RepositoryRulesetPullRequestRule{ + Type: "pull_request", + Parameters: &PullRequestRuleParameters{ + RequireCodeOwnerReview: true, + RequireLastPushApproval: true, + RequiredApprovingReviewCount: 1, + RequiredReviewThreadResolution: true, + DismissStaleReviewsOnPush: true, + }, + }, + RequiredStatusChecks: &RepositoryRulesetRequiredStatusChecksRule{ + Type: "required_status_checks", + Parameters: &RequiredStatusChecksRuleParameters{ + RequiredStatusChecks: []RuleRequiredStatusChecks{ + { + Context: "test", + IntegrationID: Int64(1), + }, + }, + StrictRequiredStatusChecksPolicy: true, + }, + }, + NonFastForward: &RepositoryRulesetRuleType{ + Type: "non_fast_forward", + }, + CommitMessagePattern: &RepositoryRulesetPatternRule{ + Type: "commit_message_pattern", + Parameters: &RulePatternParameters{ + Name: String("avoid test commits"), + Negate: Bool(true), + Operator: "starts_with", + Pattern: "[test]", + }, + }, + CommitAuthorEmailPattern: &RepositoryRulesetPatternRule{ + Type: "commit_author_email_pattern", + Parameters: &RulePatternParameters{ + Operator: "contains", + Pattern: "github", + }, + }, + CommitterEmailPattern: &RepositoryRulesetPatternRule{ + Type: "committer_email_pattern", + Parameters: &RulePatternParameters{ + Name: String("avoid commit emails"), + Negate: Bool(true), + Operator: "ends_with", + Pattern: "abc", + }, + }, + BranchNamePattern: &RepositoryRulesetPatternRule{ + Type: "branch_name_pattern", + Parameters: &RulePatternParameters{ + Name: String("avoid branch names"), + Negate: Bool(true), + Operator: "regex", + Pattern: "github$", + }, + }, + TagNamePattern: &RepositoryRulesetPatternRule{ + Type: "tag_name_pattern", + Parameters: &RulePatternParameters{ + Name: String("avoid tag names"), + Negate: Bool(true), + Operator: "contains", + Pattern: "github", + }, + }, + FilePathRestriction: &RepositoryRulesetFilePathRestrictionRule{ + Type: "file_path_restriction", + Parameters: &RuleFileParameters{ + RestrictedFilePaths: &[]string{"/a/file"}, + }, + }, + MaxFilePathLength: &RepositoryRulesetMaxFilePathLengthRule{ + Type: "max_file_path_length", + Parameters: &RuleMaxFilePathLengthParameters{ + MaxFilePathLength: 255, + }, + }, + FileExtensionRestriction: &RepositoryRulesetFileExtensionRestrictionRule{ + Type: "file_extension_restriction", + Parameters: &RuleFileExtensionRestrictionParameters{ + RestrictedFileExtensions: []string{".exe"}, + }, + }, + MaxFileSize: &RepositoryRulesetMaxFileSizeRule{ + Type: "max_file_size", + Parameters: &RuleMaxFileSizeParameters{ + MaxFileSize: 1024, + }, + }, + Workflows: &RepositoryRulesetWorkflowsRule{ + Type: "workflows", + Parameters: &RequiredWorkflowsRuleParameters{ + RequiredWorkflows: []*RuleRequiredWorkflow{ + { + Path: ".github/workflows/test.yml", + RepositoryID: Int64(1), + }, + }, + }, + }, + CodeScanning: &RepositoryRulesetCodeScanningRule{ + Type: "code_scanning", + Parameters: &RuleCodeScanningParameters{ + CodeScanningTools: []*CodeScanningTool{{ + AlertsThreshold: "alert", + SecurityAlertsThreshold: "security", + Tool: "tool", + }}, + }, + }, + }, + }, + Deleted: []*RepositoryRulesetRule{ + //Creating just one object with all the possible rules for testing + { + Creation: &RepositoryRulesetRuleType{ + Type: "creation", + }, + Update: &RepositoryRulesetUpdateRule{ + Type: "update", + Parameters: &UpdateAllowsFetchAndMergeRuleParameters{ + UpdateAllowsFetchAndMerge: true, + }, + }, + Deletion: &RepositoryRulesetRuleType{ + Type: "deletion", + }, + RequiredLinearHistory: &RepositoryRulesetRuleType{ + Type: "required_linear_history", + }, + MergeQueue: &RepositoryRulesetMergeQueueRule{ + Type: "merge_queue", + Parameters: &MergeQueueRuleParameters{ + CheckResponseTimeoutMinutes: 35, + GroupingStrategy: "HEADGREEN", + MaxEntriesToBuild: 8, + MaxEntriesToMerge: 4, + MergeMethod: "SQUASH", + MinEntriesToMerge: 2, + MinEntriesToMergeWaitMinutes: 13, + }, + }, + RequiredDeployments: &RepositoryRulesetRequiredDeploymentsRule{ + Type: "required_deployments", + Parameters: &RequiredDeploymentEnvironmentsRuleParameters{ + RequiredDeploymentEnvironments: []string{"test"}, + }, + }, + RequiredSignatures: &RepositoryRulesetRuleType{ + Type: "required_signatures", + }, + PullRequest: &RepositoryRulesetPullRequestRule{ + Type: "pull_request", + Parameters: &PullRequestRuleParameters{ + RequireCodeOwnerReview: true, + RequireLastPushApproval: true, + RequiredApprovingReviewCount: 1, + RequiredReviewThreadResolution: true, + DismissStaleReviewsOnPush: true, + }, + }, + RequiredStatusChecks: &RepositoryRulesetRequiredStatusChecksRule{ + Type: "required_status_checks", + Parameters: &RequiredStatusChecksRuleParameters{ + RequiredStatusChecks: []RuleRequiredStatusChecks{ + { + Context: "test", + IntegrationID: Int64(1), + }, + }, + StrictRequiredStatusChecksPolicy: true, + }, + }, + NonFastForward: &RepositoryRulesetRuleType{ + Type: "non_fast_forward", + }, + CommitMessagePattern: &RepositoryRulesetPatternRule{ + Type: "commit_message_pattern", + Parameters: &RulePatternParameters{ + Name: String("avoid test commits"), + Negate: Bool(true), + Operator: "starts_with", + Pattern: "[test]", + }, + }, + CommitAuthorEmailPattern: &RepositoryRulesetPatternRule{ + Type: "commit_author_email_pattern", + Parameters: &RulePatternParameters{ + Operator: "contains", + Pattern: "github", + }, + }, + CommitterEmailPattern: &RepositoryRulesetPatternRule{ + Type: "committer_email_pattern", + Parameters: &RulePatternParameters{ + Name: String("avoid commit emails"), + Negate: Bool(true), + Operator: "ends_with", + Pattern: "abc", + }, + }, + BranchNamePattern: &RepositoryRulesetPatternRule{ + Type: "branch_name_pattern", + Parameters: &RulePatternParameters{ + Name: String("avoid branch names"), + Negate: Bool(true), + Operator: "regex", + Pattern: "github$", + }, + }, + TagNamePattern: &RepositoryRulesetPatternRule{ + Type: "tag_name_pattern", + Parameters: &RulePatternParameters{ + Name: String("avoid tag names"), + Negate: Bool(true), + Operator: "contains", + Pattern: "github", + }, + }, + FilePathRestriction: &RepositoryRulesetFilePathRestrictionRule{ + Type: "file_path_restriction", + Parameters: &RuleFileParameters{ + RestrictedFilePaths: &[]string{"/a/file"}, + }, + }, + MaxFilePathLength: &RepositoryRulesetMaxFilePathLengthRule{ + Type: "max_file_path_length", + Parameters: &RuleMaxFilePathLengthParameters{ + MaxFilePathLength: 255, + }, + }, + FileExtensionRestriction: &RepositoryRulesetFileExtensionRestrictionRule{ + Type: "file_extension_restriction", + Parameters: &RuleFileExtensionRestrictionParameters{ + RestrictedFileExtensions: []string{".exe"}, + }, + }, + MaxFileSize: &RepositoryRulesetMaxFileSizeRule{ + Type: "max_file_size", + Parameters: &RuleMaxFileSizeParameters{ + MaxFileSize: 1024, + }, + }, + Workflows: &RepositoryRulesetWorkflowsRule{ + Type: "workflows", + Parameters: &RequiredWorkflowsRuleParameters{ + RequiredWorkflows: []*RuleRequiredWorkflow{ + { + Path: ".github/workflows/test.yml", + RepositoryID: Int64(1), + }, + }, + }, + }, + CodeScanning: &RepositoryRulesetCodeScanningRule{ + Type: "code_scanning", + Parameters: &RuleCodeScanningParameters{ + CodeScanningTools: []*CodeScanningTool{{ + AlertsThreshold: "alert", + SecurityAlertsThreshold: "security", + Tool: "tool", + }}, + }, + }, + }, + }, + Updated: []*RepositoryRulesetUpdatedRules{ + { + Rule: &RepositoryRulesetRule{ + Creation: &RepositoryRulesetRuleType{ + Type: "creation", + }, + Update: &RepositoryRulesetUpdateRule{ + Type: "update", + Parameters: &UpdateAllowsFetchAndMergeRuleParameters{ + UpdateAllowsFetchAndMerge: true, + }, + }, + Deletion: &RepositoryRulesetRuleType{ + Type: "deletion", + }, + RequiredLinearHistory: &RepositoryRulesetRuleType{ + Type: "required_linear_history", + }, + MergeQueue: &RepositoryRulesetMergeQueueRule{ + Type: "merge_queue", + Parameters: &MergeQueueRuleParameters{ + CheckResponseTimeoutMinutes: 35, + GroupingStrategy: "HEADGREEN", + MaxEntriesToBuild: 8, + MaxEntriesToMerge: 4, + MergeMethod: "SQUASH", + MinEntriesToMerge: 2, + MinEntriesToMergeWaitMinutes: 13, + }, + }, + RequiredDeployments: &RepositoryRulesetRequiredDeploymentsRule{ + Type: "required_deployments", + Parameters: &RequiredDeploymentEnvironmentsRuleParameters{ + RequiredDeploymentEnvironments: []string{"test"}, + }, + }, + RequiredSignatures: &RepositoryRulesetRuleType{ + Type: "required_signatures", + }, + PullRequest: &RepositoryRulesetPullRequestRule{ + Type: "pull_request", + Parameters: &PullRequestRuleParameters{ + RequireCodeOwnerReview: true, + RequireLastPushApproval: true, + RequiredApprovingReviewCount: 1, + RequiredReviewThreadResolution: true, + DismissStaleReviewsOnPush: true, + }, + }, + RequiredStatusChecks: &RepositoryRulesetRequiredStatusChecksRule{ + Type: "required_status_checks", + Parameters: &RequiredStatusChecksRuleParameters{ + RequiredStatusChecks: []RuleRequiredStatusChecks{ + { + Context: "test", + IntegrationID: Int64(1), + }, + }, + StrictRequiredStatusChecksPolicy: true, + }, + }, + NonFastForward: &RepositoryRulesetRuleType{ + Type: "non_fast_forward", + }, + CommitMessagePattern: &RepositoryRulesetPatternRule{ + Type: "commit_message_pattern", + Parameters: &RulePatternParameters{ + Name: String("avoid test commits"), + Negate: Bool(true), + Operator: "starts_with", + Pattern: "[test]", + }, + }, + CommitAuthorEmailPattern: &RepositoryRulesetPatternRule{ + Type: "commit_author_email_pattern", + Parameters: &RulePatternParameters{ + Operator: "contains", + Pattern: "github", + }, + }, + CommitterEmailPattern: &RepositoryRulesetPatternRule{ + Type: "committer_email_pattern", + Parameters: &RulePatternParameters{ + Name: String("avoid commit emails"), + Negate: Bool(true), + Operator: "ends_with", + Pattern: "abc", + }, + }, + BranchNamePattern: &RepositoryRulesetPatternRule{ + Type: "branch_name_pattern", + Parameters: &RulePatternParameters{ + Name: String("avoid branch names"), + Negate: Bool(true), + Operator: "regex", + Pattern: "github$", + }, + }, + TagNamePattern: &RepositoryRulesetPatternRule{ + Type: "tag_name_pattern", + Parameters: &RulePatternParameters{ + Name: String("avoid tag names"), + Negate: Bool(true), + Operator: "contains", + Pattern: "github", + }, + }, + FilePathRestriction: &RepositoryRulesetFilePathRestrictionRule{ + Type: "file_path_restriction", + Parameters: &RuleFileParameters{ + RestrictedFilePaths: &[]string{"/a/file"}, + }, + }, + MaxFilePathLength: &RepositoryRulesetMaxFilePathLengthRule{ + Type: "max_file_path_length", + Parameters: &RuleMaxFilePathLengthParameters{ + MaxFilePathLength: 255, + }, + }, + FileExtensionRestriction: &RepositoryRulesetFileExtensionRestrictionRule{ + Type: "file_extension_restriction", + Parameters: &RuleFileExtensionRestrictionParameters{ + RestrictedFileExtensions: []string{".exe"}, + }, + }, + MaxFileSize: &RepositoryRulesetMaxFileSizeRule{ + Type: "max_file_size", + Parameters: &RuleMaxFileSizeParameters{ + MaxFileSize: 1024, + }, + }, + Workflows: &RepositoryRulesetWorkflowsRule{ + Type: "workflows", + Parameters: &RequiredWorkflowsRuleParameters{ + RequiredWorkflows: []*RuleRequiredWorkflow{ + { + Path: ".github/workflows/test.yml", + RepositoryID: Int64(1), + }, + }, + }, + }, + CodeScanning: &RepositoryRulesetCodeScanningRule{ + Type: "code_scanning", + Parameters: &RuleCodeScanningParameters{ + CodeScanningTools: []*CodeScanningTool{{ + AlertsThreshold: "alert", + SecurityAlertsThreshold: "security", + Tool: "tool", + }}, + }, + }, + }, + Changes: &RepositoryRulesetEditedRuleChanges{ + Configuration: &RepositoryRulesetEditedSources{ + From: []string{"from"}, + }, + RuleType: &RepositoryRulesetEditedSources{ + From: []string{"from"}, + }, + Pattern: &RepositoryRulesetEditedSources{ + From: []string{"from"}, + }, + }, + }, + }, + }, + }, + Sender: &User{ + Login: String("l"), + ID: Int64(1), + NodeID: String("n"), + URL: String("u"), + ReposURL: String("r"), + EventsURL: String("e"), + AvatarURL: String("a"), + }, + } + + want := `{ + "action": "a", + "enterprise": { + "id": 1, + "slug": "s", + "name": "n", + "node_id": "nid", + "avatar_url": "au", + "description": "d", + "website_url": "wu", + "html_url": "hu", + "created_at": ` + referenceTimeStr + `, + "updated_at": ` + referenceTimeStr + ` + }, + "installation": { + "id": 1, + "node_id": "nid", + "app_id": 1, + "app_slug": "as", + "target_id": 1, + "account": { + "login": "l", + "id": 1, + "avatar_url": "a", + "gravatar_id": "g", + "name": "n", + "company": "c", + "blog": "b", + "location": "l", + "email": "e", + "hireable": true, + "bio": "b", + "twitter_username": "t", + "public_repos": 1, + "followers": 1, + "following": 1, + "created_at": ` + referenceTimeStr + `, + "suspended_at": ` + referenceTimeStr + `, + "url": "u" + }, + "access_tokens_url": "atu", + "repositories_url": "ru", + "html_url": "hu", + "target_type": "tt", + "single_file_name": "sfn", + "repository_selection": "rs", + "events": [ + "e" + ], + "single_file_paths": [ + "s" + ], + "permissions": { + "actions": "a", + "administration": "ad", + "checks": "c", + "contents": "co", + "content_references": "cr", + "deployments": "d", + "environments": "e", + "issues": "i", + "metadata": "md", + "members": "m", + "organization_administration": "oa", + "organization_hooks": "oh", + "organization_plan": "op", + "organization_pre_receive_hooks": "opr", + "organization_projects": "op", + "organization_secrets": "os", + "organization_self_hosted_runners": "osh", + "organization_user_blocking": "oub", + "packages": "pkg", + "pages": "pg", + "pull_requests": "pr", + "repository_hooks": "rh", + "repository_projects": "rp", + "repository_pre_receive_hooks": "rprh", + "secrets": "s", + "secret_scanning_alerts": "ssa", + "security_events": "se", + "single_file": "sf", + "statuses": "s", + "team_discussions": "td", + "vulnerability_alerts": "va", + "workflows": "w" + }, + "created_at": ` + referenceTimeStr + `, + "updated_at": ` + referenceTimeStr + `, + "has_multiple_single_files": false, + "suspended_by": { + "login": "l", + "id": 1, + "avatar_url": "a", + "gravatar_id": "g", + "name": "n", + "company": "c", + "blog": "b", + "location": "l", + "email": "e", + "hireable": true, + "bio": "b", + "twitter_username": "t", + "public_repos": 1, + "followers": 1, + "following": 1, + "created_at": ` + referenceTimeStr + `, + "suspended_at": ` + referenceTimeStr + `, + "url": "u" + }, + "suspended_at": ` + referenceTimeStr + ` + }, + "organization": { + "name": "n", + "company": "c", + "blog": "b", + "location": "loc", + "email": "e", + "twitter_username": "tu", + "description": "d", + "billing_email": "be", + "is_verified": true, + "has_organization_projects": true, + "has_repository_projects": true, + "default_repository_permission": "drp", + "members_can_create_repositories": true, + "members_can_create_public_repositories": false, + "members_can_create_private_repositories": true, + "members_can_create_internal_repositories": true, + "members_allowed_repository_creation_type": "marct", + "members_can_create_pages": true, + "members_can_create_public_pages": false, + "members_can_create_private_pages": true + }, + "repository": { + "id": 1, + "name": "n", + "url": "u" + }, + "repository_ruleset": { + "id": 1, + "name": "n", + "target": "branch", + "source_type": "Repository", + "source": "s", + "enforcement": "disabled", + "bypass_actors": [ + { + "actor_id": 234, + "actor_type": "Team", + "bypass_mode": "Always" + } + ], + "current_user_can_bypass": "always", + "node_id": "n", + "_links": { + "self": { + "href": "href" + }, + "html": { + "href": "href" + } + }, + "conditions": { + "key": "value" + }, + "rules": [ + { + "creation": { + "type": "creation" + }, + "update": { + "type": "update", + "parameters": { + "update_allows_fetch_and_merge": true + } + }, + "deletion": { + "type": "deletion" + }, + "required_linear_history": { + "type": "required_linear_history" + }, + "merge_queue": { + "type": "merge_queue", + "parameters": { + "check_response_timeout_minutes": 35, + "grouping_strategy": "HEADGREEN", + "max_entries_to_build": 8, + "max_entries_to_merge": 4, + "merge_method": "SQUASH", + "min_entries_to_merge": 2, + "min_entries_to_merge_wait_minutes": 13 + } + }, + "required_deployments": { + "type": "required_deployments", + "parameters": { + "required_deployment_environments": [ + "test" + ] + } + }, + "required_signatures": { + "type": "required_signatures" + }, + "pull_request": { + "type": "pull_request", + "parameters": { + "dismiss_stale_reviews_on_push": true, + "require_code_owner_review": true, + "require_last_push_approval": true, + "required_approving_review_count": 1, + "required_review_thread_resolution": true + } + }, + "required_status_checks": { + "type": "required_status_checks", + "parameters": { + "required_status_checks": [ + { + "context": "test", + "integration_id": 1 + } + ], + "strict_required_status_checks_policy": true + } + }, + "non_fast_forward": { + "type": "non_fast_forward" + }, + "commit_message_pattern": { + "type": "commit_message_pattern", + "parameters": { + "name": "avoid test commits", + "negate": true, + "operator": "starts_with", + "pattern": "[test]" + } + }, + "commit_author_email_pattern": { + "type": "commit_author_email_pattern", + "parameters": { + "operator": "contains", + "pattern": "github" + } + }, + "committer_email_pattern": { + "type": "committer_email_pattern", + "parameters": { + "name": "avoid commit emails", + "negate": true, + "operator": "ends_with", + "pattern": "abc" + } + }, + "branch_name_pattern": { + "type": "branch_name_pattern", + "parameters": { + "name": "avoid branch names", + "negate": true, + "operator": "regex", + "pattern": "github$" + } + }, + "tag_name_pattern": { + "type": "tag_name_pattern", + "parameters": { + "name": "avoid tag names", + "negate": true, + "operator": "contains", + "pattern": "github" + } + }, + "file_path_restriction": { + "type": "file_path_restriction", + "parameters": { + "restricted_file_paths": [ + "/a/file" + ] + } + }, + "max_file_path_length": { + "type": "max_file_path_length", + "parameters": { + "max_file_path_length": 255 + } + }, + "file_extension_restriction": { + "type": "file_extension_restriction", + "parameters": { + "restricted_file_extensions": [ + ".exe" + ] + } + }, + "max_file_size": { + "type": "max_file_size", + "parameters": { + "max_file_size": 1024 + } + }, + "workflows": { + "type": "workflows", + "parameters": { + "workflows": [ + { + "path": ".github/workflows/test.yml", + "repository_id": 1 + } + ] + } + }, + "code_scanning": { + "type": "code_scanning", + "parameters": { + "code_scanning_tools": [ + { + "alerts_threshold": "alert", + "security_alerts_threshold": "security", + "tool": "tool" + } + ] + } + } + } + ], + "created_at": ` + referenceTimeStr + `, + "updated_at": ` + referenceTimeStr + ` + }, + "changes": { + "name": { + "from": "f" + }, + "enforcement": { + "from": "e" + }, + "conditions": { + "added": [ + { + "ref_name": { + "include": [ + "refs/heads/main", + "refs/heads/master" + ], + "exclude": [ + "refs/heads/dev*" + ] + } + } + ], + "deleted": [ + { + "ref_name": { + "include": [ + "refs/heads/main", + "refs/heads/master" + ], + "exclude": [ + "refs/heads/dev*" + ] + } + } + ], + "updated": [ + { + "condition": { + "ref_name": { + "include": [ + "refs/heads/main", + "refs/heads/master" + ], + "exclude": [ + "refs/heads/dev*" + ] + } + }, + "changes": { + "condition_type": { + "from": "c" + }, + "target": { + "from": "t" + }, + "include": { + "from": [ + "from" + ] + }, + "exclude": { + "from": [ + "to" + ] + } + } + } + ] + }, + "rules": { + "added": [ + { + "creation": { + "type": "creation" + }, + "update": { + "type": "update", + "parameters": { + "update_allows_fetch_and_merge": true + } + }, + "deletion": { + "type": "deletion" + }, + "required_linear_history": { + "type": "required_linear_history" + }, + "merge_queue": { + "type": "merge_queue", + "parameters": { + "check_response_timeout_minutes": 35, + "grouping_strategy": "HEADGREEN", + "max_entries_to_build": 8, + "max_entries_to_merge": 4, + "merge_method": "SQUASH", + "min_entries_to_merge": 2, + "min_entries_to_merge_wait_minutes": 13 + } + }, + "required_deployments": { + "type": "required_deployments", + "parameters": { + "required_deployment_environments": [ + "test" + ] + } + }, + "required_signatures": { + "type": "required_signatures" + }, + "pull_request": { + "type": "pull_request", + "parameters": { + "dismiss_stale_reviews_on_push": true, + "require_code_owner_review": true, + "require_last_push_approval": true, + "required_approving_review_count": 1, + "required_review_thread_resolution": true + } + }, + "required_status_checks": { + "type": "required_status_checks", + "parameters": { + "required_status_checks": [ + { + "context": "test", + "integration_id": 1 + } + ], + "strict_required_status_checks_policy": true + } + }, + "non_fast_forward": { + "type": "non_fast_forward" + }, + "commit_message_pattern": { + "type": "commit_message_pattern", + "parameters": { + "name": "avoid test commits", + "negate": true, + "operator": "starts_with", + "pattern": "[test]" + } + }, + "commit_author_email_pattern": { + "type": "commit_author_email_pattern", + "parameters": { + "operator": "contains", + "pattern": "github" + } + }, + "committer_email_pattern": { + "type": "committer_email_pattern", + "parameters": { + "name": "avoid commit emails", + "negate": true, + "operator": "ends_with", + "pattern": "abc" + } + }, + "branch_name_pattern": { + "type": "branch_name_pattern", + "parameters": { + "name": "avoid branch names", + "negate": true, + "operator": "regex", + "pattern": "github$" + } + }, + "tag_name_pattern": { + "type": "tag_name_pattern", + "parameters": { + "name": "avoid tag names", + "negate": true, + "operator": "contains", + "pattern": "github" + } + }, + "file_path_restriction": { + "type": "file_path_restriction", + "parameters": { + "restricted_file_paths": [ + "/a/file" + ] + } + }, + "max_file_path_length": { + "type": "max_file_path_length", + "parameters": { + "max_file_path_length": 255 + } + }, + "file_extension_restriction": { + "type": "file_extension_restriction", + "parameters": { + "restricted_file_extensions": [ + ".exe" + ] + } + }, + "max_file_size": { + "type": "max_file_size", + "parameters": { + "max_file_size": 1024 + } + }, + "workflows": { + "type": "workflows", + "parameters": { + "workflows": [ + { + "path": ".github/workflows/test.yml", + "repository_id": 1 + } + ] + } + }, + "code_scanning": { + "type": "code_scanning", + "parameters": { + "code_scanning_tools": [ + { + "alerts_threshold": "alert", + "security_alerts_threshold": "security", + "tool": "tool" + } + ] + } + } + } + ], + "deleted": [ + { + "creation": { + "type": "creation" + }, + "update": { + "type": "update", + "parameters": { + "update_allows_fetch_and_merge": true + } + }, + "deletion": { + "type": "deletion" + }, + "required_linear_history": { + "type": "required_linear_history" + }, + "merge_queue": { + "type": "merge_queue", + "parameters": { + "check_response_timeout_minutes": 35, + "grouping_strategy": "HEADGREEN", + "max_entries_to_build": 8, + "max_entries_to_merge": 4, + "merge_method": "SQUASH", + "min_entries_to_merge": 2, + "min_entries_to_merge_wait_minutes": 13 + } + }, + "required_deployments": { + "type": "required_deployments", + "parameters": { + "required_deployment_environments": [ + "test" + ] + } + }, + "required_signatures": { + "type": "required_signatures" + }, + "pull_request": { + "type": "pull_request", + "parameters": { + "dismiss_stale_reviews_on_push": true, + "require_code_owner_review": true, + "require_last_push_approval": true, + "required_approving_review_count": 1, + "required_review_thread_resolution": true + } + }, + "required_status_checks": { + "type": "required_status_checks", + "parameters": { + "required_status_checks": [ + { + "context": "test", + "integration_id": 1 + } + ], + "strict_required_status_checks_policy": true + } + }, + "non_fast_forward": { + "type": "non_fast_forward" + }, + "commit_message_pattern": { + "type": "commit_message_pattern", + "parameters": { + "name": "avoid test commits", + "negate": true, + "operator": "starts_with", + "pattern": "[test]" + } + }, + "commit_author_email_pattern": { + "type": "commit_author_email_pattern", + "parameters": { + "operator": "contains", + "pattern": "github" + } + }, + "committer_email_pattern": { + "type": "committer_email_pattern", + "parameters": { + "name": "avoid commit emails", + "negate": true, + "operator": "ends_with", + "pattern": "abc" + } + }, + "branch_name_pattern": { + "type": "branch_name_pattern", + "parameters": { + "name": "avoid branch names", + "negate": true, + "operator": "regex", + "pattern": "github$" + } + }, + "tag_name_pattern": { + "type": "tag_name_pattern", + "parameters": { + "name": "avoid tag names", + "negate": true, + "operator": "contains", + "pattern": "github" + } + }, + "file_path_restriction": { + "type": "file_path_restriction", + "parameters": { + "restricted_file_paths": [ + "/a/file" + ] + } + }, + "max_file_path_length": { + "type": "max_file_path_length", + "parameters": { + "max_file_path_length": 255 + } + }, + "file_extension_restriction": { + "type": "file_extension_restriction", + "parameters": { + "restricted_file_extensions": [ + ".exe" + ] + } + }, + "max_file_size": { + "type": "max_file_size", + "parameters": { + "max_file_size": 1024 + } + }, + "workflows": { + "type": "workflows", + "parameters": { + "workflows": [ + { + "path": ".github/workflows/test.yml", + "repository_id": 1 + } + ] + } + }, + "code_scanning": { + "type": "code_scanning", + "parameters": { + "code_scanning_tools": [ + { + "alerts_threshold": "alert", + "security_alerts_threshold": "security", + "tool": "tool" + } + ] + } + } + } + ], + "updated": [ + { + "rule": { + "creation": { + "type": "creation" + }, + "update": { + "type": "update", + "parameters": { + "update_allows_fetch_and_merge": true + } + }, + "deletion": { + "type": "deletion" + }, + "required_linear_history": { + "type": "required_linear_history" + }, + "merge_queue": { + "type": "merge_queue", + "parameters": { + "check_response_timeout_minutes": 35, + "grouping_strategy": "HEADGREEN", + "max_entries_to_build": 8, + "max_entries_to_merge": 4, + "merge_method": "SQUASH", + "min_entries_to_merge": 2, + "min_entries_to_merge_wait_minutes": 13 + } + }, + "required_deployments": { + "type": "required_deployments", + "parameters": { + "required_deployment_environments": [ + "test" + ] + } + }, + "required_signatures": { + "type": "required_signatures" + }, + "pull_request": { + "type": "pull_request", + "parameters": { + "dismiss_stale_reviews_on_push": true, + "require_code_owner_review": true, + "require_last_push_approval": true, + "required_approving_review_count": 1, + "required_review_thread_resolution": true + } + }, + "required_status_checks": { + "type": "required_status_checks", + "parameters": { + "required_status_checks": [ + { + "context": "test", + "integration_id": 1 + } + ], + "strict_required_status_checks_policy": true + } + }, + "non_fast_forward": { + "type": "non_fast_forward" + }, + "commit_message_pattern": { + "type": "commit_message_pattern", + "parameters": { + "name": "avoid test commits", + "negate": true, + "operator": "starts_with", + "pattern": "[test]" + } + }, + "commit_author_email_pattern": { + "type": "commit_author_email_pattern", + "parameters": { + "operator": "contains", + "pattern": "github" + } + }, + "committer_email_pattern": { + "type": "committer_email_pattern", + "parameters": { + "name": "avoid commit emails", + "negate": true, + "operator": "ends_with", + "pattern": "abc" + } + }, + "branch_name_pattern": { + "type": "branch_name_pattern", + "parameters": { + "name": "avoid branch names", + "negate": true, + "operator": "regex", + "pattern": "github$" + } + }, + "tag_name_pattern": { + "type": "tag_name_pattern", + "parameters": { + "name": "avoid tag names", + "negate": true, + "operator": "contains", + "pattern": "github" + } + }, + "file_path_restriction": { + "type": "file_path_restriction", + "parameters": { + "restricted_file_paths": [ + "/a/file" + ] + } + }, + "max_file_path_length": { + "type": "max_file_path_length", + "parameters": { + "max_file_path_length": 255 + } + }, + "file_extension_restriction": { + "type": "file_extension_restriction", + "parameters": { + "restricted_file_extensions": [ + ".exe" + ] + } + }, + "max_file_size": { + "type": "max_file_size", + "parameters": { + "max_file_size": 1024 + } + }, + "workflows": { + "type": "workflows", + "parameters": { + "workflows": [ + { + "path": ".github/workflows/test.yml", + "repository_id": 1 + } + ] + } + }, + "code_scanning": { + "type": "code_scanning", + "parameters": { + "code_scanning_tools": [ + { + "alerts_threshold": "alert", + "security_alerts_threshold": "security", + "tool": "tool" + } + ] + } + } + }, + "changes": { + "configuration": { + "from": [ + "from" + ] + }, + "rule_type": { + "from": [ + "from" + ] + }, + "pattern": { + "from": [ + "from" + ] + } + } + } + ] + } + }, + "sender": { + "login": "l", + "id": 1, + "node_id": "n", + "avatar_url": "a", + "url": "u", + "events_url": "e", + "repos_url": "r" + } + }` + + testJSONMarshal(t, u, want) +} + func TestContentReferenceEvent_Marshal(t *testing.T) { t.Parallel() testJSONMarshal(t, &ContentReferenceEvent{}, "{}") diff --git a/github/github-accessors.go b/github/github-accessors.go index a43ce8b9bd..019ba35440 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -20846,6 +20846,542 @@ func (r *RepositoryRule) GetParameters() json.RawMessage { return *r.Parameters } +// GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. +func (r *RepositoryRuleset) GetCreatedAt() Timestamp { + if r == nil || r.CreatedAt == nil { + return Timestamp{} + } + return *r.CreatedAt +} + +// GetCurrentUserCanBypass returns the CurrentUserCanBypass field if it's non-nil, zero value otherwise. +func (r *RepositoryRuleset) GetCurrentUserCanBypass() string { + if r == nil || r.CurrentUserCanBypass == nil { + return "" + } + return *r.CurrentUserCanBypass +} + +// GetLinks returns the Links field. +func (r *RepositoryRuleset) GetLinks() *RepositoryRulesetLink { + if r == nil { + return nil + } + return r.Links +} + +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (r *RepositoryRuleset) GetNodeID() string { + if r == nil || r.NodeID == nil { + return "" + } + return *r.NodeID +} + +// GetSourceType returns the SourceType field if it's non-nil, zero value otherwise. +func (r *RepositoryRuleset) GetSourceType() string { + if r == nil || r.SourceType == nil { + return "" + } + return *r.SourceType +} + +// GetTarget returns the Target field if it's non-nil, zero value otherwise. +func (r *RepositoryRuleset) GetTarget() string { + if r == nil || r.Target == nil { + return "" + } + return *r.Target +} + +// GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise. +func (r *RepositoryRuleset) GetUpdatedAt() Timestamp { + if r == nil || r.UpdatedAt == nil { + return Timestamp{} + } + return *r.UpdatedAt +} + +// GetParameters returns the Parameters field. +func (r *RepositoryRulesetCodeScanningRule) GetParameters() *RuleCodeScanningParameters { + if r == nil { + return nil + } + return r.Parameters +} + +// GetConditions returns the Conditions field. +func (r *RepositoryRulesetEditedChanges) GetConditions() *RepositoryRulesetEditedConditions { + if r == nil { + return nil + } + return r.Conditions +} + +// GetEnforcement returns the Enforcement field. +func (r *RepositoryRulesetEditedChanges) GetEnforcement() *RepositoryRulesetEditedSource { + if r == nil { + return nil + } + return r.Enforcement +} + +// GetName returns the Name field. +func (r *RepositoryRulesetEditedChanges) GetName() *RepositoryRulesetEditedSource { + if r == nil { + return nil + } + return r.Name +} + +// GetRules returns the Rules field. +func (r *RepositoryRulesetEditedChanges) GetRules() *RepositoryRulesetEditedRules { + if r == nil { + return nil + } + return r.Rules +} + +// GetConfiguration returns the Configuration field. +func (r *RepositoryRulesetEditedRuleChanges) GetConfiguration() *RepositoryRulesetEditedSources { + if r == nil { + return nil + } + return r.Configuration +} + +// GetPattern returns the Pattern field. +func (r *RepositoryRulesetEditedRuleChanges) GetPattern() *RepositoryRulesetEditedSources { + if r == nil { + return nil + } + return r.Pattern +} + +// GetRuleType returns the RuleType field. +func (r *RepositoryRulesetEditedRuleChanges) GetRuleType() *RepositoryRulesetEditedSources { + if r == nil { + return nil + } + return r.RuleType +} + +// GetFrom returns the From field if it's non-nil, zero value otherwise. +func (r *RepositoryRulesetEditedSource) GetFrom() string { + if r == nil || r.From == nil { + return "" + } + return *r.From +} + +// GetChanges returns the Changes field. +func (r *RepositoryRulesetEditedUpdatedConditions) GetChanges() *RepositoryRulesetUpdatedConditionsEdited { + if r == nil { + return nil + } + return r.Changes +} + +// GetCondition returns the Condition field. +func (r *RepositoryRulesetEditedUpdatedConditions) GetCondition() *RepositoryRulesetRefCondition { + if r == nil { + return nil + } + return r.Condition +} + +// GetAction returns the Action field if it's non-nil, zero value otherwise. +func (r *RepositoryRulesetEvent) GetAction() string { + if r == nil || r.Action == nil { + return "" + } + return *r.Action +} + +// GetChanges returns the Changes field. +func (r *RepositoryRulesetEvent) GetChanges() *RepositoryRulesetEditedChanges { + if r == nil { + return nil + } + return r.Changes +} + +// GetEnterprise returns the Enterprise field. +func (r *RepositoryRulesetEvent) GetEnterprise() *Enterprise { + if r == nil { + return nil + } + return r.Enterprise +} + +// GetInstallation returns the Installation field. +func (r *RepositoryRulesetEvent) GetInstallation() *Installation { + if r == nil { + return nil + } + return r.Installation +} + +// GetOrganization returns the Organization field. +func (r *RepositoryRulesetEvent) GetOrganization() *Organization { + if r == nil { + return nil + } + return r.Organization +} + +// GetRepository returns the Repository field. +func (r *RepositoryRulesetEvent) GetRepository() *Repository { + if r == nil { + return nil + } + return r.Repository +} + +// GetRepositoryRuleset returns the RepositoryRuleset field. +func (r *RepositoryRulesetEvent) GetRepositoryRuleset() *RepositoryRuleset { + if r == nil { + return nil + } + return r.RepositoryRuleset +} + +// GetSender returns the Sender field. +func (r *RepositoryRulesetEvent) GetSender() *User { + if r == nil { + return nil + } + return r.Sender +} + +// GetParameters returns the Parameters field. +func (r *RepositoryRulesetFileExtensionRestrictionRule) GetParameters() *RuleFileExtensionRestrictionParameters { + if r == nil { + return nil + } + return r.Parameters +} + +// GetParameters returns the Parameters field. +func (r *RepositoryRulesetFilePathRestrictionRule) GetParameters() *RuleFileParameters { + if r == nil { + return nil + } + return r.Parameters +} + +// GetHTML returns the HTML field. +func (r *RepositoryRulesetLink) GetHTML() *RulesetLink { + if r == nil { + return nil + } + return r.HTML +} + +// GetSelf returns the Self field. +func (r *RepositoryRulesetLink) GetSelf() *RulesetLink { + if r == nil { + return nil + } + return r.Self +} + +// GetParameters returns the Parameters field. +func (r *RepositoryRulesetMaxFilePathLengthRule) GetParameters() *RuleMaxFilePathLengthParameters { + if r == nil { + return nil + } + return r.Parameters +} + +// GetParameters returns the Parameters field. +func (r *RepositoryRulesetMaxFileSizeRule) GetParameters() *RuleMaxFileSizeParameters { + if r == nil { + return nil + } + return r.Parameters +} + +// GetParameters returns the Parameters field. +func (r *RepositoryRulesetMergeQueueRule) GetParameters() *MergeQueueRuleParameters { + if r == nil { + return nil + } + return r.Parameters +} + +// GetParameters returns the Parameters field. +func (r *RepositoryRulesetPatternRule) GetParameters() *RulePatternParameters { + if r == nil { + return nil + } + return r.Parameters +} + +// GetParameters returns the Parameters field. +func (r *RepositoryRulesetPullRequestRule) GetParameters() *PullRequestRuleParameters { + if r == nil { + return nil + } + return r.Parameters +} + +// GetRefName returns the RefName field. +func (r *RepositoryRulesetRefCondition) GetRefName() *RulesetRefConditionParameters { + if r == nil { + return nil + } + return r.RefName +} + +// GetParameters returns the Parameters field. +func (r *RepositoryRulesetRequiredDeploymentsRule) GetParameters() *RequiredDeploymentEnvironmentsRuleParameters { + if r == nil { + return nil + } + return r.Parameters +} + +// GetParameters returns the Parameters field. +func (r *RepositoryRulesetRequiredStatusChecksRule) GetParameters() *RequiredStatusChecksRuleParameters { + if r == nil { + return nil + } + return r.Parameters +} + +// GetBranchNamePattern returns the BranchNamePattern field. +func (r *RepositoryRulesetRule) GetBranchNamePattern() *RepositoryRulesetPatternRule { + if r == nil { + return nil + } + return r.BranchNamePattern +} + +// GetCodeScanning returns the CodeScanning field. +func (r *RepositoryRulesetRule) GetCodeScanning() *RepositoryRulesetCodeScanningRule { + if r == nil { + return nil + } + return r.CodeScanning +} + +// GetCommitAuthorEmailPattern returns the CommitAuthorEmailPattern field. +func (r *RepositoryRulesetRule) GetCommitAuthorEmailPattern() *RepositoryRulesetPatternRule { + if r == nil { + return nil + } + return r.CommitAuthorEmailPattern +} + +// GetCommitMessagePattern returns the CommitMessagePattern field. +func (r *RepositoryRulesetRule) GetCommitMessagePattern() *RepositoryRulesetPatternRule { + if r == nil { + return nil + } + return r.CommitMessagePattern +} + +// GetCommitterEmailPattern returns the CommitterEmailPattern field. +func (r *RepositoryRulesetRule) GetCommitterEmailPattern() *RepositoryRulesetPatternRule { + if r == nil { + return nil + } + return r.CommitterEmailPattern +} + +// GetCreation returns the Creation field. +func (r *RepositoryRulesetRule) GetCreation() *RepositoryRulesetRuleType { + if r == nil { + return nil + } + return r.Creation +} + +// GetDeletion returns the Deletion field. +func (r *RepositoryRulesetRule) GetDeletion() *RepositoryRulesetRuleType { + if r == nil { + return nil + } + return r.Deletion +} + +// GetFileExtensionRestriction returns the FileExtensionRestriction field. +func (r *RepositoryRulesetRule) GetFileExtensionRestriction() *RepositoryRulesetFileExtensionRestrictionRule { + if r == nil { + return nil + } + return r.FileExtensionRestriction +} + +// GetFilePathRestriction returns the FilePathRestriction field. +func (r *RepositoryRulesetRule) GetFilePathRestriction() *RepositoryRulesetFilePathRestrictionRule { + if r == nil { + return nil + } + return r.FilePathRestriction +} + +// GetMaxFilePathLength returns the MaxFilePathLength field. +func (r *RepositoryRulesetRule) GetMaxFilePathLength() *RepositoryRulesetMaxFilePathLengthRule { + if r == nil { + return nil + } + return r.MaxFilePathLength +} + +// GetMaxFileSize returns the MaxFileSize field. +func (r *RepositoryRulesetRule) GetMaxFileSize() *RepositoryRulesetMaxFileSizeRule { + if r == nil { + return nil + } + return r.MaxFileSize +} + +// GetMergeQueue returns the MergeQueue field. +func (r *RepositoryRulesetRule) GetMergeQueue() *RepositoryRulesetMergeQueueRule { + if r == nil { + return nil + } + return r.MergeQueue +} + +// GetNonFastForward returns the NonFastForward field. +func (r *RepositoryRulesetRule) GetNonFastForward() *RepositoryRulesetRuleType { + if r == nil { + return nil + } + return r.NonFastForward +} + +// GetPullRequest returns the PullRequest field. +func (r *RepositoryRulesetRule) GetPullRequest() *RepositoryRulesetPullRequestRule { + if r == nil { + return nil + } + return r.PullRequest +} + +// GetRequiredDeployments returns the RequiredDeployments field. +func (r *RepositoryRulesetRule) GetRequiredDeployments() *RepositoryRulesetRequiredDeploymentsRule { + if r == nil { + return nil + } + return r.RequiredDeployments +} + +// GetRequiredLinearHistory returns the RequiredLinearHistory field. +func (r *RepositoryRulesetRule) GetRequiredLinearHistory() *RepositoryRulesetRuleType { + if r == nil { + return nil + } + return r.RequiredLinearHistory +} + +// GetRequiredSignatures returns the RequiredSignatures field. +func (r *RepositoryRulesetRule) GetRequiredSignatures() *RepositoryRulesetRuleType { + if r == nil { + return nil + } + return r.RequiredSignatures +} + +// GetRequiredStatusChecks returns the RequiredStatusChecks field. +func (r *RepositoryRulesetRule) GetRequiredStatusChecks() *RepositoryRulesetRequiredStatusChecksRule { + if r == nil { + return nil + } + return r.RequiredStatusChecks +} + +// GetTagNamePattern returns the TagNamePattern field. +func (r *RepositoryRulesetRule) GetTagNamePattern() *RepositoryRulesetPatternRule { + if r == nil { + return nil + } + return r.TagNamePattern +} + +// GetUpdate returns the Update field. +func (r *RepositoryRulesetRule) GetUpdate() *RepositoryRulesetUpdateRule { + if r == nil { + return nil + } + return r.Update +} + +// GetWorkflows returns the Workflows field. +func (r *RepositoryRulesetRule) GetWorkflows() *RepositoryRulesetWorkflowsRule { + if r == nil { + return nil + } + return r.Workflows +} + +// GetConditionType returns the ConditionType field. +func (r *RepositoryRulesetUpdatedConditionsEdited) GetConditionType() *RepositoryRulesetEditedSource { + if r == nil { + return nil + } + return r.ConditionType +} + +// GetExclude returns the Exclude field. +func (r *RepositoryRulesetUpdatedConditionsEdited) GetExclude() *RepositoryRulesetEditedSources { + if r == nil { + return nil + } + return r.Exclude +} + +// GetInclude returns the Include field. +func (r *RepositoryRulesetUpdatedConditionsEdited) GetInclude() *RepositoryRulesetEditedSources { + if r == nil { + return nil + } + return r.Include +} + +// GetTarget returns the Target field. +func (r *RepositoryRulesetUpdatedConditionsEdited) GetTarget() *RepositoryRulesetEditedSource { + if r == nil { + return nil + } + return r.Target +} + +// GetChanges returns the Changes field. +func (r *RepositoryRulesetUpdatedRules) GetChanges() *RepositoryRulesetEditedRuleChanges { + if r == nil { + return nil + } + return r.Changes +} + +// GetRule returns the Rule field. +func (r *RepositoryRulesetUpdatedRules) GetRule() *RepositoryRulesetRule { + if r == nil { + return nil + } + return r.Rule +} + +// GetParameters returns the Parameters field. +func (r *RepositoryRulesetUpdateRule) GetParameters() *UpdateAllowsFetchAndMergeRuleParameters { + if r == nil { + return nil + } + return r.Parameters +} + +// GetParameters returns the Parameters field. +func (r *RepositoryRulesetWorkflowsRule) GetParameters() *RequiredWorkflowsRuleParameters { + if r == nil { + return nil + } + return r.Parameters +} + // GetCommit returns the Commit field. func (r *RepositoryTag) GetCommit() *Commit { if r == nil { @@ -21246,6 +21782,14 @@ func (r *RequiredStatusChecksRequest) GetStrict() bool { return *r.Strict } +// GetDoNotEnforceOnCreate returns the DoNotEnforceOnCreate field if it's non-nil, zero value otherwise. +func (r *RequiredStatusChecksRuleParameters) GetDoNotEnforceOnCreate() bool { + if r == nil || r.DoNotEnforceOnCreate == nil { + return false + } + return *r.DoNotEnforceOnCreate +} + // GetTotalCount returns the TotalCount field if it's non-nil, zero value otherwise. func (r *RequiredWorkflowSelectedRepos) GetTotalCount() int { if r == nil || r.TotalCount == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index a4d5315ba4..8f1407eeea 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -26808,6 +26808,566 @@ func TestRepositoryRule_GetParameters(tt *testing.T) { r.GetParameters() } +func TestRepositoryRuleset_GetCreatedAt(tt *testing.T) { + tt.Parallel() + var zeroValue Timestamp + r := &RepositoryRuleset{CreatedAt: &zeroValue} + r.GetCreatedAt() + r = &RepositoryRuleset{} + r.GetCreatedAt() + r = nil + r.GetCreatedAt() +} + +func TestRepositoryRuleset_GetCurrentUserCanBypass(tt *testing.T) { + tt.Parallel() + var zeroValue string + r := &RepositoryRuleset{CurrentUserCanBypass: &zeroValue} + r.GetCurrentUserCanBypass() + r = &RepositoryRuleset{} + r.GetCurrentUserCanBypass() + r = nil + r.GetCurrentUserCanBypass() +} + +func TestRepositoryRuleset_GetLinks(tt *testing.T) { + tt.Parallel() + r := &RepositoryRuleset{} + r.GetLinks() + r = nil + r.GetLinks() +} + +func TestRepositoryRuleset_GetNodeID(tt *testing.T) { + tt.Parallel() + var zeroValue string + r := &RepositoryRuleset{NodeID: &zeroValue} + r.GetNodeID() + r = &RepositoryRuleset{} + r.GetNodeID() + r = nil + r.GetNodeID() +} + +func TestRepositoryRuleset_GetSourceType(tt *testing.T) { + tt.Parallel() + var zeroValue string + r := &RepositoryRuleset{SourceType: &zeroValue} + r.GetSourceType() + r = &RepositoryRuleset{} + r.GetSourceType() + r = nil + r.GetSourceType() +} + +func TestRepositoryRuleset_GetTarget(tt *testing.T) { + tt.Parallel() + var zeroValue string + r := &RepositoryRuleset{Target: &zeroValue} + r.GetTarget() + r = &RepositoryRuleset{} + r.GetTarget() + r = nil + r.GetTarget() +} + +func TestRepositoryRuleset_GetUpdatedAt(tt *testing.T) { + tt.Parallel() + var zeroValue Timestamp + r := &RepositoryRuleset{UpdatedAt: &zeroValue} + r.GetUpdatedAt() + r = &RepositoryRuleset{} + r.GetUpdatedAt() + r = nil + r.GetUpdatedAt() +} + +func TestRepositoryRulesetCodeScanningRule_GetParameters(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetCodeScanningRule{} + r.GetParameters() + r = nil + r.GetParameters() +} + +func TestRepositoryRulesetEditedChanges_GetConditions(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetEditedChanges{} + r.GetConditions() + r = nil + r.GetConditions() +} + +func TestRepositoryRulesetEditedChanges_GetEnforcement(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetEditedChanges{} + r.GetEnforcement() + r = nil + r.GetEnforcement() +} + +func TestRepositoryRulesetEditedChanges_GetName(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetEditedChanges{} + r.GetName() + r = nil + r.GetName() +} + +func TestRepositoryRulesetEditedChanges_GetRules(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetEditedChanges{} + r.GetRules() + r = nil + r.GetRules() +} + +func TestRepositoryRulesetEditedRuleChanges_GetConfiguration(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetEditedRuleChanges{} + r.GetConfiguration() + r = nil + r.GetConfiguration() +} + +func TestRepositoryRulesetEditedRuleChanges_GetPattern(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetEditedRuleChanges{} + r.GetPattern() + r = nil + r.GetPattern() +} + +func TestRepositoryRulesetEditedRuleChanges_GetRuleType(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetEditedRuleChanges{} + r.GetRuleType() + r = nil + r.GetRuleType() +} + +func TestRepositoryRulesetEditedSource_GetFrom(tt *testing.T) { + tt.Parallel() + var zeroValue string + r := &RepositoryRulesetEditedSource{From: &zeroValue} + r.GetFrom() + r = &RepositoryRulesetEditedSource{} + r.GetFrom() + r = nil + r.GetFrom() +} + +func TestRepositoryRulesetEditedUpdatedConditions_GetChanges(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetEditedUpdatedConditions{} + r.GetChanges() + r = nil + r.GetChanges() +} + +func TestRepositoryRulesetEditedUpdatedConditions_GetCondition(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetEditedUpdatedConditions{} + r.GetCondition() + r = nil + r.GetCondition() +} + +func TestRepositoryRulesetEvent_GetAction(tt *testing.T) { + tt.Parallel() + var zeroValue string + r := &RepositoryRulesetEvent{Action: &zeroValue} + r.GetAction() + r = &RepositoryRulesetEvent{} + r.GetAction() + r = nil + r.GetAction() +} + +func TestRepositoryRulesetEvent_GetChanges(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetEvent{} + r.GetChanges() + r = nil + r.GetChanges() +} + +func TestRepositoryRulesetEvent_GetEnterprise(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetEvent{} + r.GetEnterprise() + r = nil + r.GetEnterprise() +} + +func TestRepositoryRulesetEvent_GetInstallation(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetEvent{} + r.GetInstallation() + r = nil + r.GetInstallation() +} + +func TestRepositoryRulesetEvent_GetOrganization(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetEvent{} + r.GetOrganization() + r = nil + r.GetOrganization() +} + +func TestRepositoryRulesetEvent_GetRepository(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetEvent{} + r.GetRepository() + r = nil + r.GetRepository() +} + +func TestRepositoryRulesetEvent_GetRepositoryRuleset(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetEvent{} + r.GetRepositoryRuleset() + r = nil + r.GetRepositoryRuleset() +} + +func TestRepositoryRulesetEvent_GetSender(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetEvent{} + r.GetSender() + r = nil + r.GetSender() +} + +func TestRepositoryRulesetFileExtensionRestrictionRule_GetParameters(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetFileExtensionRestrictionRule{} + r.GetParameters() + r = nil + r.GetParameters() +} + +func TestRepositoryRulesetFilePathRestrictionRule_GetParameters(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetFilePathRestrictionRule{} + r.GetParameters() + r = nil + r.GetParameters() +} + +func TestRepositoryRulesetLink_GetHTML(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetLink{} + r.GetHTML() + r = nil + r.GetHTML() +} + +func TestRepositoryRulesetLink_GetSelf(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetLink{} + r.GetSelf() + r = nil + r.GetSelf() +} + +func TestRepositoryRulesetMaxFilePathLengthRule_GetParameters(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetMaxFilePathLengthRule{} + r.GetParameters() + r = nil + r.GetParameters() +} + +func TestRepositoryRulesetMaxFileSizeRule_GetParameters(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetMaxFileSizeRule{} + r.GetParameters() + r = nil + r.GetParameters() +} + +func TestRepositoryRulesetMergeQueueRule_GetParameters(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetMergeQueueRule{} + r.GetParameters() + r = nil + r.GetParameters() +} + +func TestRepositoryRulesetPatternRule_GetParameters(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetPatternRule{} + r.GetParameters() + r = nil + r.GetParameters() +} + +func TestRepositoryRulesetPullRequestRule_GetParameters(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetPullRequestRule{} + r.GetParameters() + r = nil + r.GetParameters() +} + +func TestRepositoryRulesetRefCondition_GetRefName(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRefCondition{} + r.GetRefName() + r = nil + r.GetRefName() +} + +func TestRepositoryRulesetRequiredDeploymentsRule_GetParameters(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRequiredDeploymentsRule{} + r.GetParameters() + r = nil + r.GetParameters() +} + +func TestRepositoryRulesetRequiredStatusChecksRule_GetParameters(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRequiredStatusChecksRule{} + r.GetParameters() + r = nil + r.GetParameters() +} + +func TestRepositoryRulesetRule_GetBranchNamePattern(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRule{} + r.GetBranchNamePattern() + r = nil + r.GetBranchNamePattern() +} + +func TestRepositoryRulesetRule_GetCodeScanning(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRule{} + r.GetCodeScanning() + r = nil + r.GetCodeScanning() +} + +func TestRepositoryRulesetRule_GetCommitAuthorEmailPattern(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRule{} + r.GetCommitAuthorEmailPattern() + r = nil + r.GetCommitAuthorEmailPattern() +} + +func TestRepositoryRulesetRule_GetCommitMessagePattern(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRule{} + r.GetCommitMessagePattern() + r = nil + r.GetCommitMessagePattern() +} + +func TestRepositoryRulesetRule_GetCommitterEmailPattern(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRule{} + r.GetCommitterEmailPattern() + r = nil + r.GetCommitterEmailPattern() +} + +func TestRepositoryRulesetRule_GetCreation(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRule{} + r.GetCreation() + r = nil + r.GetCreation() +} + +func TestRepositoryRulesetRule_GetDeletion(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRule{} + r.GetDeletion() + r = nil + r.GetDeletion() +} + +func TestRepositoryRulesetRule_GetFileExtensionRestriction(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRule{} + r.GetFileExtensionRestriction() + r = nil + r.GetFileExtensionRestriction() +} + +func TestRepositoryRulesetRule_GetFilePathRestriction(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRule{} + r.GetFilePathRestriction() + r = nil + r.GetFilePathRestriction() +} + +func TestRepositoryRulesetRule_GetMaxFilePathLength(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRule{} + r.GetMaxFilePathLength() + r = nil + r.GetMaxFilePathLength() +} + +func TestRepositoryRulesetRule_GetMaxFileSize(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRule{} + r.GetMaxFileSize() + r = nil + r.GetMaxFileSize() +} + +func TestRepositoryRulesetRule_GetMergeQueue(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRule{} + r.GetMergeQueue() + r = nil + r.GetMergeQueue() +} + +func TestRepositoryRulesetRule_GetNonFastForward(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRule{} + r.GetNonFastForward() + r = nil + r.GetNonFastForward() +} + +func TestRepositoryRulesetRule_GetPullRequest(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRule{} + r.GetPullRequest() + r = nil + r.GetPullRequest() +} + +func TestRepositoryRulesetRule_GetRequiredDeployments(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRule{} + r.GetRequiredDeployments() + r = nil + r.GetRequiredDeployments() +} + +func TestRepositoryRulesetRule_GetRequiredLinearHistory(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRule{} + r.GetRequiredLinearHistory() + r = nil + r.GetRequiredLinearHistory() +} + +func TestRepositoryRulesetRule_GetRequiredSignatures(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRule{} + r.GetRequiredSignatures() + r = nil + r.GetRequiredSignatures() +} + +func TestRepositoryRulesetRule_GetRequiredStatusChecks(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRule{} + r.GetRequiredStatusChecks() + r = nil + r.GetRequiredStatusChecks() +} + +func TestRepositoryRulesetRule_GetTagNamePattern(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRule{} + r.GetTagNamePattern() + r = nil + r.GetTagNamePattern() +} + +func TestRepositoryRulesetRule_GetUpdate(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRule{} + r.GetUpdate() + r = nil + r.GetUpdate() +} + +func TestRepositoryRulesetRule_GetWorkflows(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetRule{} + r.GetWorkflows() + r = nil + r.GetWorkflows() +} + +func TestRepositoryRulesetUpdatedConditionsEdited_GetConditionType(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetUpdatedConditionsEdited{} + r.GetConditionType() + r = nil + r.GetConditionType() +} + +func TestRepositoryRulesetUpdatedConditionsEdited_GetExclude(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetUpdatedConditionsEdited{} + r.GetExclude() + r = nil + r.GetExclude() +} + +func TestRepositoryRulesetUpdatedConditionsEdited_GetInclude(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetUpdatedConditionsEdited{} + r.GetInclude() + r = nil + r.GetInclude() +} + +func TestRepositoryRulesetUpdatedConditionsEdited_GetTarget(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetUpdatedConditionsEdited{} + r.GetTarget() + r = nil + r.GetTarget() +} + +func TestRepositoryRulesetUpdatedRules_GetChanges(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetUpdatedRules{} + r.GetChanges() + r = nil + r.GetChanges() +} + +func TestRepositoryRulesetUpdatedRules_GetRule(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetUpdatedRules{} + r.GetRule() + r = nil + r.GetRule() +} + +func TestRepositoryRulesetUpdateRule_GetParameters(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetUpdateRule{} + r.GetParameters() + r = nil + r.GetParameters() +} + +func TestRepositoryRulesetWorkflowsRule_GetParameters(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetWorkflowsRule{} + r.GetParameters() + r = nil + r.GetParameters() +} + func TestRepositoryTag_GetCommit(tt *testing.T) { tt.Parallel() r := &RepositoryTag{} @@ -27334,6 +27894,17 @@ func TestRequiredStatusChecksRequest_GetStrict(tt *testing.T) { r.GetStrict() } +func TestRequiredStatusChecksRuleParameters_GetDoNotEnforceOnCreate(tt *testing.T) { + tt.Parallel() + var zeroValue bool + r := &RequiredStatusChecksRuleParameters{DoNotEnforceOnCreate: &zeroValue} + r.GetDoNotEnforceOnCreate() + r = &RequiredStatusChecksRuleParameters{} + r.GetDoNotEnforceOnCreate() + r = nil + r.GetDoNotEnforceOnCreate() +} + func TestRequiredWorkflowSelectedRepos_GetTotalCount(tt *testing.T) { tt.Parallel() var zeroValue int diff --git a/github/messages.go b/github/messages.go index 0997479335..f365190ae3 100644 --- a/github/messages.go +++ b/github/messages.go @@ -98,6 +98,7 @@ var ( "repository": &RepositoryEvent{}, "repository_dispatch": &RepositoryDispatchEvent{}, "repository_import": &RepositoryImportEvent{}, + "repository_ruleset": &RepositoryRulesetEvent{}, "repository_vulnerability_alert": &RepositoryVulnerabilityAlertEvent{}, "release": &ReleaseEvent{}, "secret_scanning_alert": &SecretScanningAlertEvent{}, diff --git a/github/messages_test.go b/github/messages_test.go index a9de425690..e04c0b18a7 100644 --- a/github/messages_test.go +++ b/github/messages_test.go @@ -468,6 +468,10 @@ func TestParseWebHook(t *testing.T) { payload: &RepositoryEvent{}, messageType: "repository", }, + { + payload: &RepositoryRulesetEvent{}, + messageType: "repository_ruleset", + }, { payload: &RepositoryVulnerabilityAlertEvent{}, messageType: "repository_vulnerability_alert", diff --git a/github/repos_rules.go b/github/repos_rules.go index ca9e9ea85b..b812bd0b98 100644 --- a/github/repos_rules.go +++ b/github/repos_rules.go @@ -140,7 +140,7 @@ type MergeQueueRuleParameters struct { // RequiredStatusChecksRuleParameters represents the required_status_checks rule parameters. type RequiredStatusChecksRuleParameters struct { - DoNotEnforceOnCreate bool `json:"do_not_enforce_on_create"` + DoNotEnforceOnCreate *bool `json:"do_not_enforce_on_create,omitempty"` RequiredStatusChecks []RuleRequiredStatusChecks `json:"required_status_checks"` StrictRequiredStatusChecksPolicy bool `json:"strict_required_status_checks_policy"` } @@ -155,7 +155,8 @@ type RuleRequiredWorkflow struct { // RequiredWorkflowsRuleParameters represents the workflows rule parameters. type RequiredWorkflowsRuleParameters struct { - RequiredWorkflows []*RuleRequiredWorkflow `json:"workflows"` + DoNotEnforceOnCreate bool `json:"do_not_enforce_on_create,omitempty"` + RequiredWorkflows []*RuleRequiredWorkflow `json:"workflows"` } // RepositoryRule represents a GitHub Rule. @@ -167,6 +168,226 @@ type RepositoryRule struct { RulesetID int64 `json:"ruleset_id"` } +// RepositoryRulesetEditedChanges represents the changes made to a repository ruleset. +type RepositoryRulesetEditedChanges struct { + Name *RepositoryRulesetEditedSource `json:"name,omitempty"` + Enforcement *RepositoryRulesetEditedSource `json:"enforcement,omitempty"` + Conditions *RepositoryRulesetEditedConditions `json:"conditions,omitempty"` + Rules *RepositoryRulesetEditedRules `json:"rules,omitempty"` +} + +// RepositoryRulesetEditedSource represents a source change for the ruleset. +type RepositoryRulesetEditedSource struct { + From *string `json:"from,omitempty"` +} + +// RepositoryRulesetEditedSources represents multiple source changes for the ruleset. +type RepositoryRulesetEditedSources struct { + From []string `json:"from,omitempty"` +} + +// RepositoryRulesetEditedConditions holds changes to conditions in a ruleset. +type RepositoryRulesetEditedConditions struct { + Added []*RepositoryRulesetRefCondition `json:"added,omitempty"` + Deleted []*RepositoryRulesetRefCondition `json:"deleted,omitempty"` + Updated []*RepositoryRulesetEditedUpdatedConditions `json:"updated,omitempty"` +} + +// RepositoryRulesetEditedRules holds changes to rules in a ruleset. +type RepositoryRulesetEditedRules struct { + Added []*RepositoryRulesetRule `json:"added,omitempty"` + Deleted []*RepositoryRulesetRule `json:"deleted,omitempty"` + Updated []*RepositoryRulesetUpdatedRules `json:"updated,omitempty"` +} + +// RepositoryRulesetRefCondition represents a reference condition for the ruleset. +type RepositoryRulesetRefCondition struct { + RefName *RulesetRefConditionParameters `json:"ref_name,omitempty"` +} + +// RepositoryRulesetEditedUpdatedConditions holds updates to conditions in a ruleset. +type RepositoryRulesetEditedUpdatedConditions struct { + Condition *RepositoryRulesetRefCondition `json:"condition,omitempty"` + Changes *RepositoryRulesetUpdatedConditionsEdited `json:"changes,omitempty"` +} + +// RepositoryRulesetUpdatedConditionsEdited holds the edited updates to conditions in a ruleset. +type RepositoryRulesetUpdatedConditionsEdited struct { + ConditionType *RepositoryRulesetEditedSource `json:"condition_type,omitempty"` + Target *RepositoryRulesetEditedSource `json:"target,omitempty"` + Include *RepositoryRulesetEditedSources `json:"include,omitempty"` + Exclude *RepositoryRulesetEditedSources `json:"exclude,omitempty"` +} + +// RepositoryRulesetUpdatedRules holds updates to rules in a ruleset. +type RepositoryRulesetUpdatedRules struct { + Rule *RepositoryRulesetRule `json:"rule,omitempty"` + Changes *RepositoryRulesetEditedRuleChanges `json:"changes,omitempty"` +} + +// RepositoryRulesetEditedRuleChanges holds changes made to a rule in a ruleset. +type RepositoryRulesetEditedRuleChanges struct { + Configuration *RepositoryRulesetEditedSources `json:"configuration,omitempty"` + RuleType *RepositoryRulesetEditedSources `json:"rule_type,omitempty"` + Pattern *RepositoryRulesetEditedSources `json:"pattern,omitempty"` +} + +// RepositoryRuleset represents the structure of a ruleset associated with a GitHub repository. +type RepositoryRuleset struct { + ID int64 `json:"id"` + Name string `json:"name"` + // Possible values for target: "branch", "tag", "push" + Target *string `json:"target,omitempty"` + // Possible values for source type: "Repository", "Organization" + SourceType *string `json:"source_type,omitempty"` + Source string `json:"source"` + // Possible values for enforcement: "disabled", "active", "evaluate" + Enforcement string `json:"enforcement"` + BypassActors []*BypassActor `json:"bypass_actors,omitempty"` + // Possible values for current user can bypass: "always", "pull_requests_only", "never" + CurrentUserCanBypass *string `json:"current_user_can_bypass,omitempty"` + NodeID *string `json:"node_id,omitempty"` + Links *RepositoryRulesetLink `json:"_links,omitempty"` + Conditions json.RawMessage `json:"conditions,omitempty"` + Rules []*RepositoryRulesetRule `json:"rules,omitempty"` + CreatedAt *Timestamp `json:"created_at,omitempty"` + UpdatedAt *Timestamp `json:"updated_at,omitempty"` +} + +// RepositoryRulesetRule represents individual rules which are present in a repository's ruleset. +type RepositoryRulesetRule struct { + Creation *RepositoryRulesetRuleType `json:"creation,omitempty"` + Update *RepositoryRulesetUpdateRule `json:"update,omitempty"` + Deletion *RepositoryRulesetRuleType `json:"deletion,omitempty"` + RequiredLinearHistory *RepositoryRulesetRuleType `json:"required_linear_history,omitempty"` + MergeQueue *RepositoryRulesetMergeQueueRule `json:"merge_queue,omitempty"` + RequiredDeployments *RepositoryRulesetRequiredDeploymentsRule `json:"required_deployments,omitempty"` + RequiredSignatures *RepositoryRulesetRuleType `json:"required_signatures,omitempty"` + PullRequest *RepositoryRulesetPullRequestRule `json:"pull_request,omitempty"` + RequiredStatusChecks *RepositoryRulesetRequiredStatusChecksRule `json:"required_status_checks,omitempty"` + NonFastForward *RepositoryRulesetRuleType `json:"non_fast_forward,omitempty"` + CommitMessagePattern *RepositoryRulesetPatternRule `json:"commit_message_pattern,omitempty"` + CommitAuthorEmailPattern *RepositoryRulesetPatternRule `json:"commit_author_email_pattern,omitempty"` + CommitterEmailPattern *RepositoryRulesetPatternRule `json:"committer_email_pattern,omitempty"` + BranchNamePattern *RepositoryRulesetPatternRule `json:"branch_name_pattern,omitempty"` + TagNamePattern *RepositoryRulesetPatternRule `json:"tag_name_pattern,omitempty"` + FilePathRestriction *RepositoryRulesetFilePathRestrictionRule `json:"file_path_restriction,omitempty"` + MaxFilePathLength *RepositoryRulesetMaxFilePathLengthRule `json:"max_file_path_length,omitempty"` + FileExtensionRestriction *RepositoryRulesetFileExtensionRestrictionRule `json:"file_extension_restriction,omitempty"` + MaxFileSize *RepositoryRulesetMaxFileSizeRule `json:"max_file_size,omitempty"` + Workflows *RepositoryRulesetWorkflowsRule `json:"workflows,omitempty"` + CodeScanning *RepositoryRulesetCodeScanningRule `json:"code_scanning,omitempty"` +} + +// RepositoryRulesetLink represents Links associated with a repository's rulesets. These links are used to provide more information about the ruleset. +type RepositoryRulesetLink struct { + Self *RulesetLink `json:"self,omitempty"` + HTML *RulesetLink `json:"html,omitempty"` +} + +// RepositoryRulesetRuleType represents the type of a ruleset rule. +type RepositoryRulesetRuleType struct { + Type string `json:"type"` +} + +// RepositoryRulesetUpdateRule defines an update rule for the repository. +type RepositoryRulesetUpdateRule struct { + // Type can be one of: "update". + Type string `json:"type"` + Parameters *UpdateAllowsFetchAndMergeRuleParameters `json:"parameters,omitempty"` +} + +// RepositoryRulesetMergeQueueRule defines a merge queue rule for the repository. +type RepositoryRulesetMergeQueueRule struct { + // Type can be one of: "merge_queue". + Type string `json:"type"` + Parameters *MergeQueueRuleParameters `json:"parameters,omitempty"` +} + +// RepositoryRulesetRequiredDeploymentsRule defines a rule for required deployments. +type RepositoryRulesetRequiredDeploymentsRule struct { + // Type can be one of: "required_deployments". + Type string `json:"type"` + Parameters *RequiredDeploymentEnvironmentsRuleParameters `json:"parameters,omitempty"` +} + +// RepositoryRulesetPullRequestRule defines a rule for pull requests. +type RepositoryRulesetPullRequestRule struct { + // Type can be one of: "pull_request". + + Type string `json:"type"` + Parameters *PullRequestRuleParameters `json:"parameters,omitempty"` +} + +// RepositoryRulesetRequiredStatusChecksRule defines a rule for required status checks. +type RepositoryRulesetRequiredStatusChecksRule struct { + // Type can be one of: "required_status_checks". + + Type string `json:"type"` + Parameters *RequiredStatusChecksRuleParameters `json:"parameters,omitempty"` +} + +// RepositoryRulesetPatternRule defines a pattern rule for the repository. +type RepositoryRulesetPatternRule struct { + Type string `json:"type"` + Parameters *RulePatternParameters `json:"parameters,omitempty"` +} + +// RepositoryRulesetFilePathRestrictionRule defines a file path restriction rule for the repository. +type RepositoryRulesetFilePathRestrictionRule struct { + // Type can be one of: "file_path_restriction". + Type string `json:"type"` + Parameters *RuleFileParameters `json:"parameters,omitempty"` +} + +// RepositoryRulesetMaxFilePathLengthRule defines a maximum file path length rule for the repository. +type RepositoryRulesetMaxFilePathLengthRule struct { + // Type can be one of: "max_file_path_length". + + Type string `json:"type"` + Parameters *RuleMaxFilePathLengthParameters `json:"parameters,omitempty"` +} + +// RepositoryRulesetFileExtensionRestrictionRule defines a file extension restriction rule for the repository. +type RepositoryRulesetFileExtensionRestrictionRule struct { + // Type can be one of: "file_extension_restriction". + Type string `json:"type"` + Parameters *RuleFileExtensionRestrictionParameters `json:"parameters,omitempty"` +} + +// RepositoryRulesetMaxFileSizeRule defines a maximum file size rule for the repository. +type RepositoryRulesetMaxFileSizeRule struct { + // Type can be one of: "max_file_size". + Type string `json:"type"` + Parameters *RuleMaxFileSizeParameters `json:"parameters,omitempty"` +} + +// RepositoryRulesetWorkflowsRule defines a workflow rule for the repository. +type RepositoryRulesetWorkflowsRule struct { + // Type can be one of: "workflows". + Type string `json:"type"` + Parameters *RequiredWorkflowsRuleParameters `json:"parameters,omitempty"` +} + +// RepositoryRulesetCodeScanningRule defines a code scanning rule for the repository. +type RepositoryRulesetCodeScanningRule struct { + // Type can be one of: "code_scanning". + Type string `json:"type"` + Parameters *RuleCodeScanningParameters `json:"parameters,omitempty"` +} + +// RuleCodeScanningParameters defines parameters for code scanning rules. +type RuleCodeScanningParameters struct { + CodeScanningTools []*CodeScanningTool `json:"code_scanning_tools,omitempty"` +} + +// CodeScanningTool defines a specific tool used for code scanning. +type CodeScanningTool struct { + AlertsThreshold string `json:"alerts_threshold"` + SecurityAlertsThreshold string `json:"security_alerts_threshold"` + Tool string `json:"tool"` +} + // UnmarshalJSON implements the json.Unmarshaler interface. // This helps us handle the fact that RepositoryRule parameter field can be of numerous types. func (r *RepositoryRule) UnmarshalJSON(data []byte) error { diff --git a/github/repos_rules_test.go b/github/repos_rules_test.go index a34b84cd89..e7faf7e7b2 100644 --- a/github/repos_rules_test.go +++ b/github/repos_rules_test.go @@ -269,7 +269,7 @@ func TestRepositoryRule_UnmarshalJSON(t *testing.T) { "Valid required_status_checks params": { data: `{"type":"required_status_checks","parameters":{"required_status_checks":[{"context":"test","integration_id":1}],"strict_required_status_checks_policy":true,"do_not_enforce_on_create":true}}`, want: NewRequiredStatusChecksRule(&RequiredStatusChecksRuleParameters{ - DoNotEnforceOnCreate: true, + DoNotEnforceOnCreate: Bool(true), RequiredStatusChecks: []RuleRequiredStatusChecks{ { Context: "test",