Documentation
¶
Overview ¶
Package rulesets reads and writes repository rulesets with the provider's own types over go-github's transport. Each rule keeps its type and raw parameters, so the provider sees every rule type GitHub returns.
Index ¶
- func IsModelled(ruleType string) bool
- func UnmanagedParameters(rule *Rule) []string
- type Actor
- type BypassActor
- type CodeCoverageRuleParameters
- type CodeQualityRuleParameters
- type CodeScanningRuleParameters
- type CodeScanningTool
- type Conditions
- type CopilotCodeReviewRuleParameters
- type DismissalRestriction
- type EmptyRuleParameters
- type FileExtensionRestrictionRuleParameters
- type FilePathRestrictionRuleParameters
- type MaxFilePathLengthRuleParameters
- type MaxFileSizeRuleParameters
- type MergeQueueRuleParameters
- type ModelledRules
- type PatternRuleParameters
- type PullRequestRuleParameters
- type RefName
- type RequireSecretScanningAlertResolutionRuleParameters
- type RequiredDeploymentsRuleParameters
- type RequiredReviewer
- type RequiredStatusChecksRuleParameters
- type Rule
- type Ruleset
- type Service
- func (s *Service) CreateRuleset(ctx context.Context, owner, repo string, ruleset Ruleset) (*Ruleset, *github.Response, error)
- func (s *Service) DeleteRuleset(ctx context.Context, owner, repo string, rulesetID int64) (*github.Response, error)
- func (s *Service) GetAllRulesets(ctx context.Context, owner, repo string, ...) ([]*Ruleset, *github.Response, error)
- func (s *Service) GetRuleset(ctx context.Context, owner, repo string, rulesetID int64, includesParents bool) (*Ruleset, *github.Response, error)
- func (s *Service) UpdateRuleset(ctx context.Context, owner, repo string, rulesetID int64, ruleset Ruleset) (*Ruleset, *github.Response, error)
- type StatusCheck
- type UpdateRuleParameters
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsModelled ¶
IsModelled reports whether the provider models rules of ruleType.
func UnmanagedParameters ¶
UnmanagedParameters returns, sorted, the key paths of rule's parameters, at any depth, that the rule type's parameter structs have no JSON field for. A path joins keys with dots and marks an array element with [], as in required_reviewers[].key. It returns nil for a rule type the provider does not model and for parameters that are not a JSON object.
Types ¶
type Actor ¶
Actor is an actor named by ID and type inside a rule's parameters. GitHub may return the ID as a JSON string or a number; it is sent as a number.
type BypassActor ¶
type BypassActor struct {
ActorID *int64 `json:"actor_id,omitempty"`
ActorType *string `json:"actor_type,omitempty"`
BypassMode *string `json:"bypass_mode,omitempty"`
}
BypassActor is an actor that may bypass a ruleset. GitHub returns a null actor_id for OrganizationAdmin and DeployKey.
type CodeCoverageRuleParameters ¶
type CodeCoverageRuleParameters struct {
MaxCoverageDrop *float64 `json:"max_coverage_drop,omitempty"`
MinimumCoverage *float64 `json:"minimum_coverage,omitempty"`
}
CodeCoverageRuleParameters are the parameters of the code_coverage rule, in percent. A nil parameter is omitted from the request.
type CodeQualityRuleParameters ¶
type CodeQualityRuleParameters struct {
Severity string `json:"severity"`
}
CodeQualityRuleParameters are the parameters of the code_quality rule.
type CodeScanningRuleParameters ¶
type CodeScanningRuleParameters struct {
CodeScanningTools []*CodeScanningTool `json:"code_scanning_tools"`
}
CodeScanningRuleParameters are the parameters of the code_scanning rule.
type CodeScanningTool ¶
type CodeScanningTool struct {
AlertsThreshold string `json:"alerts_threshold"`
SecurityAlertsThreshold string `json:"security_alerts_threshold"`
Tool string `json:"tool"`
}
CodeScanningTool is one tool of the code_scanning rule.
type Conditions ¶
type Conditions struct {
RefName *RefName `json:"ref_name,omitempty"`
}
Conditions holds the ref conditions of a ruleset. An empty Conditions is sent as {} and clears them on update. A nil Conditions keeps them.
type CopilotCodeReviewRuleParameters ¶
type CopilotCodeReviewRuleParameters struct {
ReviewOnPush bool `json:"review_on_push"`
ReviewDraftPullRequests bool `json:"review_draft_pull_requests"`
}
CopilotCodeReviewRuleParameters are the parameters of the copilot_code_review rule.
type DismissalRestriction ¶
type DismissalRestriction struct {
AllowedActors []*Actor `json:"allowed_actors"`
Enabled bool `json:"enabled"`
}
DismissalRestriction limits who may dismiss reviews under the pull_request rule.
type EmptyRuleParameters ¶
type EmptyRuleParameters struct{}
EmptyRuleParameters marks a rule that is sent without parameters.
type FileExtensionRestrictionRuleParameters ¶
type FileExtensionRestrictionRuleParameters struct {
RestrictedFileExtensions []string `json:"restricted_file_extensions"`
}
FileExtensionRestrictionRuleParameters are the parameters of the file_extension_restriction rule.
type FilePathRestrictionRuleParameters ¶
type FilePathRestrictionRuleParameters struct {
IgnoredFilePaths []string `json:"ignored_file_paths"`
RestrictedFilePaths []string `json:"restricted_file_paths"`
}
FilePathRestrictionRuleParameters are the parameters of the file_path_restriction rule.
type MaxFilePathLengthRuleParameters ¶
type MaxFilePathLengthRuleParameters struct {
MaxFilePathLength int `json:"max_file_path_length"`
}
MaxFilePathLengthRuleParameters are the parameters of the max_file_path_length rule.
type MaxFileSizeRuleParameters ¶
type MaxFileSizeRuleParameters struct {
IgnoredFilePaths []string `json:"ignored_file_paths"`
MaxFileSize int64 `json:"max_file_size"`
}
MaxFileSizeRuleParameters are the parameters of the max_file_size rule.
type MergeQueueRuleParameters ¶
type MergeQueueRuleParameters struct {
CheckResponseTimeoutMinutes int `json:"check_response_timeout_minutes"`
GroupingStrategy string `json:"grouping_strategy"`
MaxEntriesToBuild int `json:"max_entries_to_build"`
MaxEntriesToMerge int `json:"max_entries_to_merge"`
MergeMethod string `json:"merge_method"`
MinEntriesToMerge int `json:"min_entries_to_merge"`
MinEntriesToMergeWaitMinutes int `json:"min_entries_to_merge_wait_minutes"`
}
MergeQueueRuleParameters are the modelled parameters of the merge_queue rule.
type ModelledRules ¶
type ModelledRules struct {
Creation *EmptyRuleParameters `rule:"creation"`
Update *UpdateRuleParameters `rule:"update"`
Deletion *EmptyRuleParameters `rule:"deletion"`
RequiredLinearHistory *EmptyRuleParameters `rule:"required_linear_history"`
MergeQueue *MergeQueueRuleParameters `rule:"merge_queue"`
RequiredDeployments *RequiredDeploymentsRuleParameters `rule:"required_deployments"`
RequiredSignatures *EmptyRuleParameters `rule:"required_signatures"`
PullRequest *PullRequestRuleParameters `rule:"pull_request"`
RequiredStatusChecks *RequiredStatusChecksRuleParameters `rule:"required_status_checks"`
NonFastForward *EmptyRuleParameters `rule:"non_fast_forward"`
CommitMessagePattern *PatternRuleParameters `rule:"commit_message_pattern"`
CommitAuthorEmailPattern *PatternRuleParameters `rule:"commit_author_email_pattern"`
CommitterEmailPattern *PatternRuleParameters `rule:"committer_email_pattern"`
BranchNamePattern *PatternRuleParameters `rule:"branch_name_pattern"`
TagNamePattern *PatternRuleParameters `rule:"tag_name_pattern"`
FilePathRestriction *FilePathRestrictionRuleParameters `rule:"file_path_restriction"`
MaxFilePathLength *MaxFilePathLengthRuleParameters `rule:"max_file_path_length"`
FileExtensionRestriction *FileExtensionRestrictionRuleParameters `rule:"file_extension_restriction"`
MaxFileSize *MaxFileSizeRuleParameters `rule:"max_file_size"`
CodeScanning *CodeScanningRuleParameters `rule:"code_scanning"`
CodeQuality *CodeQualityRuleParameters `rule:"code_quality"`
CodeCoverage *CodeCoverageRuleParameters `rule:"code_coverage"`
CopilotCodeReview *CopilotCodeReviewRuleParameters `rule:"copilot_code_review"`
LicenseComplianceScanning *EmptyRuleParameters `rule:"license_compliance_scanning"`
RequireSecretScanningAlertResolution *RequireSecretScanningAlertResolutionRuleParameters `rule:"require_secret_scanning_alert_resolution"`
}
ModelledRules holds the rules the provider models: one field per rule type, tagged with the type and in the order the rules are sent. A set field means the ruleset holds that rule.
func Decode ¶
func Decode(rules []*Rule) (*ModelledRules, error)
Decode returns the rules the provider models, with their modelled parameters.
func (*ModelledRules) Encode ¶
func (m *ModelledRules) Encode() ([]*Rule, error)
Encode returns the rules array for m. With no rules it returns an empty array, which is sent as [] and clears the rules on GitHub.
type PatternRuleParameters ¶
type PatternRuleParameters struct {
Name *string `json:"name,omitempty"`
Negate *bool `json:"negate,omitempty"`
Operator string `json:"operator"`
Pattern string `json:"pattern"`
}
PatternRuleParameters are the parameters of the five pattern rules.
type PullRequestRuleParameters ¶
type PullRequestRuleParameters struct {
AllowedMergeMethods []string `json:"allowed_merge_methods"`
DismissStaleReviewsOnPush bool `json:"dismiss_stale_reviews_on_push"`
DismissalRestriction *DismissalRestriction `json:"dismissal_restriction,omitempty"`
RequireCodeOwnerReview bool `json:"require_code_owner_review"`
RequireExtraApprovalForUnattributedChanges *bool `json:"require_extra_approval_for_unattributed_changes,omitempty"`
RequireLastPushApproval bool `json:"require_last_push_approval"`
RequiredApprovingReviewCount int `json:"required_approving_review_count"`
RequiredReviewThreadResolution bool `json:"required_review_thread_resolution"`
RequiredReviewers []*RequiredReviewer `json:"required_reviewers"`
}
PullRequestRuleParameters are the modelled parameters of the pull_request rule. RequireExtraApprovalForUnattributedChanges is undocumented; it is sent only when set.
type RequireSecretScanningAlertResolutionRuleParameters ¶
type RequireSecretScanningAlertResolutionRuleParameters struct {
SecretTypes []string `json:"secret_types"`
}
RequireSecretScanningAlertResolutionRuleParameters are the parameters of the require_secret_scanning_alert_resolution rule.
type RequiredDeploymentsRuleParameters ¶
type RequiredDeploymentsRuleParameters struct {
RequiredDeploymentEnvironments []string `json:"required_deployment_environments"`
}
RequiredDeploymentsRuleParameters are the modelled parameters of the required_deployments rule.
type RequiredReviewer ¶
type RequiredReviewer struct {
FilePatterns []string `json:"file_patterns"`
MinimumApprovals int `json:"minimum_approvals"`
Reviewer Actor `json:"reviewer"`
}
RequiredReviewer is one team whose approval the pull_request rule requires for changes to matching files.
type RequiredStatusChecksRuleParameters ¶
type RequiredStatusChecksRuleParameters struct {
DoNotEnforceOnCreate bool `json:"do_not_enforce_on_create"`
RequiredStatusChecks []*StatusCheck `json:"required_status_checks"`
StrictRequiredStatusChecksPolicy bool `json:"strict_required_status_checks_policy"`
}
RequiredStatusChecksRuleParameters are the modelled parameters of the required_status_checks rule.
type Rule ¶
type Rule struct {
Type string `json:"type"`
Parameters json.RawMessage `json:"parameters,omitempty"`
}
Rule is one entry of a ruleset's rules array, of any type.
type Ruleset ¶
type Ruleset struct {
ID *int64 `json:"id,omitempty"`
Name string `json:"name"`
Target *string `json:"target,omitempty"`
SourceType *string `json:"source_type,omitempty"`
Source string `json:"source,omitempty"`
Enforcement string `json:"enforcement"`
BypassActors []*BypassActor `json:"bypass_actors,omitzero"`
Conditions *Conditions `json:"conditions,omitempty"`
Rules []*Rule `json:"rules,omitzero"`
}
Ruleset is a repository ruleset as the REST API returns and accepts it. Source is set by GitHub, so requests leave it out.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service calls the repository ruleset endpoints on go-github's transport, so the calls keep its authentication and rate-limit handling.
func NewService ¶
NewService returns a Service that sends its requests with client.
func (*Service) CreateRuleset ¶
func (s *Service) CreateRuleset(ctx context.Context, owner, repo string, ruleset Ruleset) (*Ruleset, *github.Response, error)
CreateRuleset creates a ruleset on a repository.
func (*Service) DeleteRuleset ¶
func (s *Service) DeleteRuleset(ctx context.Context, owner, repo string, rulesetID int64) (*github.Response, error)
DeleteRuleset deletes a ruleset of a repository.
func (*Service) GetAllRulesets ¶
func (s *Service) GetAllRulesets(ctx context.Context, owner, repo string, opts *github.RepositoryListRulesetsOptions) ([]*Ruleset, *github.Response, error)
GetAllRulesets lists the rulesets of a repository, one page per call.
type StatusCheck ¶
type StatusCheck struct {
Context string `json:"context"`
IntegrationID *int64 `json:"integration_id,omitempty"`
}
StatusCheck is one status check of the required_status_checks rule.
type UpdateRuleParameters ¶
type UpdateRuleParameters struct {
UpdateAllowsFetchAndMerge *bool `json:"update_allows_fetch_and_merge,omitempty"`
}
UpdateRuleParameters are the parameters of the update rule. GitHub returns update_allows_fetch_and_merge on forks only, so it may be nil.