Skip to content

Add BranchProtectionConfigurationEvent and SecretScanningAlertLocationEvent #3332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions github/event_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ type BranchProtectionRuleEvent struct {
Installation *Installation `json:"installation,omitempty"`
}

// BranchProtectionConfigurationEvent is triggered when there is a change to branch protection configurations for a repository.
// The Webhook event name is "branch_protection_configuration".
//
// GitHub API docs: https://docs.github.com/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#branch_protection_configuration
type BranchProtectionConfigurationEvent struct {
Action *string `json:"action,omitempty"`
Repo *Repository `json:"repository,omitempty"`
Org *Organization `json:"organization,omitempty"`
Enterprise *Enterprise `json:"enterprise,omitempty"`
Sender *User `json:"sender,omitempty"`
Installation *Installation `json:"installation,omitempty"`
}

// CheckRunEvent is triggered when a check run is "created", "completed", or "rerequested".
// The Webhook event name is "check_run".
//
Expand Down Expand Up @@ -1580,6 +1593,20 @@ type SecretScanningAlertEvent struct {
Installation *Installation `json:"installation,omitempty"`
}

// SecretScanningAlertLocationEvent is triggered when there is activity relating to the locations of a secret in a secret scanning alert.
// The Webhook event name is "secret_scanning_alert_location".
//
// GitHub API docs: https://docs.github.com/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#secret_scanning_alert_location
type SecretScanningAlertLocationEvent struct {
Action *string `json:"action,omitempty"`
Alert *SecretScanningAlert `json:"alert,omitempty"`
Installation *Installation `json:"installation,omitempty"`
Location *SecretScanningAlertLocation `json:"location,omitempty"`
Organization *Organization `json:"organization,omitempty"`
Repo *Repository `json:"repository,omitempty"`
Sender *User `json:"sender,omitempty"`
}

// SecurityAndAnalysisEvent is triggered when code security and analysis features
// are enabled or disabled for a repository.
//
Expand Down
147 changes: 147 additions & 0 deletions github/event_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,61 @@ func TestProjectColumnChange_Marshal_NameChange(t *testing.T) {
testJSONMarshal(t, u, want)
}

func TestBranchProtectionConfigurationEvent_Marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &BranchProtectionConfigurationEvent{}, "{}")
u := &BranchProtectionConfigurationEvent{
Action: String("enabled"),
Repo: &Repository{
ID: Int64(12345),
NodeID: String("MDEwOlJlcG9zaXRvcnkxMjM0NQ=="),
Name: String("example-repo"),
},
Org: &Organization{
Login: String("example-org"),
ID: Int64(67890),
},
Sender: &User{
Login: String("example-user"),
ID: Int64(1111),
},
Installation: &Installation{
ID: Int64(2222),
},
Enterprise: &Enterprise{
ID: Int(3333),
Slug: String("example-enterprise"),
Name: String("Example Enterprise"),
},
}

want := `{
"action": "enabled",
"repository": {
"id": 12345,
"node_id": "MDEwOlJlcG9zaXRvcnkxMjM0NQ==",
"name": "example-repo"
},
"organization": {
"login": "example-org",
"id": 67890
},
"sender": {
"login": "example-user",
"id": 1111
},
"installation": {
"id": 2222
},
"enterprise": {
"id": 3333,
"slug": "example-enterprise",
"name": "Example Enterprise"
}
}`
testJSONMarshal(t, u, want)
}

func TestTeamAddEvent_Marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &TeamAddEvent{}, "{}")
Expand Down Expand Up @@ -19295,6 +19350,98 @@ func TestSecretScanningAlertEvent_Marshal(t *testing.T) {
testJSONMarshal(t, u, want)
}

func TestSecretScanningAlertLocationEvent_Marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &SecretScanningAlertLocationEvent{}, "{}")
u := &SecretScanningAlertLocationEvent{
Action: String("created"),
Alert: &SecretScanningAlert{
Number: Int(10),
CreatedAt: &Timestamp{referenceTime},
UpdatedAt: &Timestamp{referenceTime},
URL: String("a"),
HTMLURL: String("a"),
SecretType: String("mailchimp_api_key"),
},
Location: &SecretScanningAlertLocation{
Type: String("blob"),
Details: &SecretScanningAlertLocationDetails{
Path: String("path/to/file"),
Startline: Int(10),
EndLine: Int(20),
StartColumn: Int(1),
EndColumn: Int(2),
BlobSHA: String("d6e4c75c141dbacecc279b721b8bsomeSHA"),
BlobURL: String("a"),
CommitSHA: String("d6e4c75c141dbacecc279b721b8bsomeSHA"),
CommitURL: String("a"),
},
},
Repo: &Repository{
ID: Int64(12345),
NodeID: String("MDEwOlJlcG9zaXRvcnkxMjM0NQ=="),
Name: String("example-repo"),
},
Organization: &Organization{
Login: String("example-org"),
ID: Int64(67890),
},
Sender: &User{
Login: String("example-user"),
ID: Int64(1111),
},
Installation: &Installation{
ID: Int64(2222),
},
}

want := `{
"action": "created",
"alert": {
"number": 10,
"created_at": ` + referenceTimeStr + `,
"updated_at": ` + referenceTimeStr + `,
"url": "a",
"html_url": "a",
"secret_type": "mailchimp_api_key"
},
"location": {

"type": "blob",
"details": {
"path": "path/to/file",
"start_line": 10,
"end_line": 20,
"start_column": 1,
"end_column": 2,
"blob_sha": "d6e4c75c141dbacecc279b721b8bsomeSHA",
"blob_url": "a",
"commit_sha": "d6e4c75c141dbacecc279b721b8bsomeSHA",
"commit_url": "a"
}
},
"repository": {

"id": 12345,
"node_id": "MDEwOlJlcG9zaXRvcnkxMjM0NQ==",
"name": "example-repo"
},
"organization": {
"login": "example-org",
"id": 67890
},
"sender": {
"login": "example-user",
"id": 1111
},
"installation": {
"id": 2222
}
}`

testJSONMarshal(t, u, want)
}

func TestSecurityAdvisoryEvent_Marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &SecurityAdvisoryEvent{}, "{}")
Expand Down
104 changes: 104 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading