Skip to content

Commit 5464ad4

Browse files
author
Jon Rumion
committed
Add Branch Protection Events
1 parent 610cb6a commit 5464ad4

File tree

2 files changed

+200
-0
lines changed

2 files changed

+200
-0
lines changed

github/github.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const (
7575
WorkflowRunEvent Event = "workflow_run"
7676
GitHubAppAuthorizationEvent Event = "github_app_authorization"
7777
CodeScanningAlertEvent Event = "code_scanning_alert"
78+
BranchProtectionRuleEvent Event = "branch_protection_rule"
7879
)
7980

8081
// EventSubtype defines a GitHub Hook Event subtype
@@ -358,6 +359,10 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error)
358359
var pl CodeScanningAlertPayload
359360
err = json.Unmarshal([]byte(payload), &pl)
360361
return pl, err
362+
case BranchProtectionRuleEvent:
363+
var pl BranchProtectionRulePayload
364+
err = json.Unmarshal([]byte(payload), &pl)
365+
return pl, err
361366
default:
362367
return nil, fmt.Errorf("unknown event %s", gitHubEvent)
363368
}

github/payload.go

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7514,3 +7514,198 @@ type CodeScanningAlertPayload struct {
75147514
SiteAdmin bool `json:"site_admin"`
75157515
} `json:"sender"`
75167516
}
7517+
7518+
// BranchProtectionRulePayload contains branch protection rule payload
7519+
type BranchProtectionRulePayload struct {
7520+
Action string `json:"action"`
7521+
Rule struct {
7522+
ID int `json:"id"`
7523+
RepositoryID int `json:"repository_id"`
7524+
Name string `json:"name"`
7525+
CreatedAt string `json:"created_at"`
7526+
UpdatedAt string `json:"updated_at"`
7527+
PullRequestReviewsEnforcementLevel string `json:"pull_request_reviews_enforcement_level"`
7528+
RequiredApprovingReviewCount int `json:"required_approving_review_count"`
7529+
DismissStaleReviewsOnPush bool `json:"dismiss_stale_reviews_on_push"`
7530+
RequireCodeOwnerReview bool `json:"require_code_owner_review"`
7531+
AuthorizedDismissalActorsOnly bool `json:"authorized_dismissal_actors_only"`
7532+
IgnoreApprovalsFromContributors bool `json:"ignore_approvals_from_contributors"`
7533+
RequiredStatusChecks []string `json:"required_status_checks"`
7534+
RequiredStatusChecksEnforcementLevel string `json:"required_status_checks_enforcement_level"`
7535+
StrictRequiredStatusChecksPolicy bool `json:"strict_required_status_checks_policy"`
7536+
SignatureRequirementEnforcementLevel string `json:"signature_requirement_enforcement_level"`
7537+
LinearHistoryRequirementEnforcementLevel string `json:"linear_history_requirement_enforcement_level"`
7538+
AdminEnforced bool `json:"admin_enforced"`
7539+
CreateProtected bool `json:"create_protected"`
7540+
AllowForcePushesEnforcementLevel string `json:"allow_force_pushes_enforcement_level"`
7541+
AllowDeletionsEnforcementLevel string `json:"allow_deletions_enforcement_level"`
7542+
MergeQueueEnforcementLevel string `json:"merge_queue_enforcement_level"`
7543+
RequiredDeploymentsEnforcementLevel string `json:"required_deployments_enforcement_level"`
7544+
RequiredConversationResolutionLevel string `json:"required_conversation_resolution_level"`
7545+
AuthorizedActorsOnly bool `json:"authorized_actors_only"`
7546+
AuthorizedActorNames []any `json:"authorized_actor_names"`
7547+
RequireLastPushApproval bool `json:"require_last_push_approval"`
7548+
LockBranchEnforcementLevel string `json:"lock_branch_enforcement_level"`
7549+
} `json:"rule"`
7550+
Changes struct {
7551+
PullRequestReviewsEnforcementLevel struct {
7552+
From string `json:"from"`
7553+
} `json:"pull_request_reviews_enforcement_level"`
7554+
RequireCodeOwnerReview struct {
7555+
From bool `json:"from"`
7556+
} `json:"require_code_owner_review"`
7557+
AuthorizedDismissalActorsOnly struct {
7558+
From bool `json:"from"`
7559+
} `json:"authorized_dismissal_actors_only"`
7560+
} `json:"changes"`
7561+
Repository struct {
7562+
ID int `json:"id"`
7563+
NodeID string `json:"node_id"`
7564+
Name string `json:"name"`
7565+
FullName string `json:"full_name"`
7566+
Private bool `json:"private"`
7567+
Owner struct {
7568+
Login string `json:"login"`
7569+
ID int `json:"id"`
7570+
NodeID string `json:"node_id"`
7571+
AvatarURL string `json:"avatar_url"`
7572+
GravatarID string `json:"gravatar_id"`
7573+
URL string `json:"url"`
7574+
HTMLURL string `json:"html_url"`
7575+
FollowersURL string `json:"followers_url"`
7576+
FollowingURL string `json:"following_url"`
7577+
GistsURL string `json:"gists_url"`
7578+
StarredURL string `json:"starred_url"`
7579+
SubscriptionsURL string `json:"subscriptions_url"`
7580+
OrganizationsURL string `json:"organizations_url"`
7581+
ReposURL string `json:"repos_url"`
7582+
EventsURL string `json:"events_url"`
7583+
ReceivedEventsURL string `json:"received_events_url"`
7584+
Type string `json:"type"`
7585+
UserViewType string `json:"user_view_type"`
7586+
SiteAdmin bool `json:"site_admin"`
7587+
} `json:"owner"`
7588+
HTMLURL string `json:"html_url"`
7589+
Description string `json:"description"`
7590+
Fork bool `json:"fork"`
7591+
URL string `json:"url"`
7592+
ForksURL string `json:"forks_url"`
7593+
KeysURL string `json:"keys_url"`
7594+
CollaboratorsURL string `json:"collaborators_url"`
7595+
TeamsURL string `json:"teams_url"`
7596+
HooksURL string `json:"hooks_url"`
7597+
IssueEventsURL string `json:"issue_events_url"`
7598+
EventsURL string `json:"events_url"`
7599+
AssigneesURL string `json:"assignees_url"`
7600+
BranchesURL string `json:"branches_url"`
7601+
TagsURL string `json:"tags_url"`
7602+
BlobsURL string `json:"blobs_url"`
7603+
GitTagsURL string `json:"git_tags_url"`
7604+
GitRefsURL string `json:"git_refs_url"`
7605+
TreesURL string `json:"trees_url"`
7606+
StatusesURL string `json:"statuses_url"`
7607+
LanguagesURL string `json:"languages_url"`
7608+
StargazersURL string `json:"stargazers_url"`
7609+
ContributorsURL string `json:"contributors_url"`
7610+
SubscribersURL string `json:"subscribers_url"`
7611+
SubscriptionURL string `json:"subscription_url"`
7612+
CommitsURL string `json:"commits_url"`
7613+
GitCommitsURL string `json:"git_commits_url"`
7614+
CommentsURL string `json:"comments_url"`
7615+
IssueCommentURL string `json:"issue_comment_url"`
7616+
ContentsURL string `json:"contents_url"`
7617+
CompareURL string `json:"compare_url"`
7618+
MergesURL string `json:"merges_url"`
7619+
ArchiveURL string `json:"archive_url"`
7620+
DownloadsURL string `json:"downloads_url"`
7621+
IssuesURL string `json:"issues_url"`
7622+
PullsURL string `json:"pulls_url"`
7623+
MilestonesURL string `json:"milestones_url"`
7624+
NotificationsURL string `json:"notifications_url"`
7625+
LabelsURL string `json:"labels_url"`
7626+
ReleasesURL string `json:"releases_url"`
7627+
DeploymentsURL string `json:"deployments_url"`
7628+
CreatedAt time.Time `json:"created_at"`
7629+
UpdatedAt time.Time `json:"updated_at"`
7630+
PushedAt time.Time `json:"pushed_at"`
7631+
GitURL string `json:"git_url"`
7632+
SSHURL string `json:"ssh_url"`
7633+
CloneURL string `json:"clone_url"`
7634+
SvnURL string `json:"svn_url"`
7635+
Homepage string `json:"homepage"`
7636+
Size int `json:"size"`
7637+
StargazersCount int `json:"stargazers_count"`
7638+
WatchersCount int `json:"watchers_count"`
7639+
Language string `json:"language"`
7640+
HasIssues bool `json:"has_issues"`
7641+
HasProjects bool `json:"has_projects"`
7642+
HasDownloads bool `json:"has_downloads"`
7643+
HasWiki bool `json:"has_wiki"`
7644+
HasPages bool `json:"has_pages"`
7645+
HasDiscussions bool `json:"has_discussions"`
7646+
ForksCount int `json:"forks_count"`
7647+
MirrorURL any `json:"mirror_url"`
7648+
Archived bool `json:"archived"`
7649+
Disabled bool `json:"disabled"`
7650+
OpenIssuesCount int `json:"open_issues_count"`
7651+
License any `json:"license"`
7652+
AllowForking bool `json:"allow_forking"`
7653+
IsTemplate bool `json:"is_template"`
7654+
WebCommitSignoffRequired bool `json:"web_commit_signoff_required"`
7655+
Topics []string `json:"topics"`
7656+
Visibility string `json:"visibility"`
7657+
Forks int `json:"forks"`
7658+
OpenIssues int `json:"open_issues"`
7659+
Watchers int `json:"watchers"`
7660+
DefaultBranch string `json:"default_branch"`
7661+
CustomProperties struct {
7662+
} `json:"custom_properties"`
7663+
} `json:"repository"`
7664+
Organization struct {
7665+
Login string `json:"login"`
7666+
ID int `json:"id"`
7667+
NodeID string `json:"node_id"`
7668+
URL string `json:"url"`
7669+
ReposURL string `json:"repos_url"`
7670+
EventsURL string `json:"events_url"`
7671+
HooksURL string `json:"hooks_url"`
7672+
IssuesURL string `json:"issues_url"`
7673+
MembersURL string `json:"members_url"`
7674+
PublicMembersURL string `json:"public_members_url"`
7675+
AvatarURL string `json:"avatar_url"`
7676+
Description string `json:"description"`
7677+
} `json:"organization"`
7678+
Enterprise struct {
7679+
ID int `json:"id"`
7680+
Slug string `json:"slug"`
7681+
Name string `json:"name"`
7682+
NodeID string `json:"node_id"`
7683+
AvatarURL string `json:"avatar_url"`
7684+
Description string `json:"description"`
7685+
WebsiteURL string `json:"website_url"`
7686+
HTMLURL string `json:"html_url"`
7687+
CreatedAt time.Time `json:"created_at"`
7688+
UpdatedAt time.Time `json:"updated_at"`
7689+
} `json:"enterprise"`
7690+
Sender struct {
7691+
Login string `json:"login"`
7692+
ID int `json:"id"`
7693+
NodeID string `json:"node_id"`
7694+
AvatarURL string `json:"avatar_url"`
7695+
GravatarID string `json:"gravatar_id"`
7696+
URL string `json:"url"`
7697+
HTMLURL string `json:"html_url"`
7698+
FollowersURL string `json:"followers_url"`
7699+
FollowingURL string `json:"following_url"`
7700+
GistsURL string `json:"gists_url"`
7701+
StarredURL string `json:"starred_url"`
7702+
SubscriptionsURL string `json:"subscriptions_url"`
7703+
OrganizationsURL string `json:"organizations_url"`
7704+
ReposURL string `json:"repos_url"`
7705+
EventsURL string `json:"events_url"`
7706+
ReceivedEventsURL string `json:"received_events_url"`
7707+
Type string `json:"type"`
7708+
UserViewType string `json:"user_view_type"`
7709+
SiteAdmin bool `json:"site_admin"`
7710+
} `json:"sender"`
7711+
}

0 commit comments

Comments
 (0)