Skip to content
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

Adds CodeScanningAlertEvent #189

Merged
merged 3 commits into from
Jul 30, 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
5 changes: 5 additions & 0 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const (
WorkflowJobEvent Event = "workflow_job"
WorkflowRunEvent Event = "workflow_run"
GitHubAppAuthorizationEvent Event = "github_app_authorization"
CodeScanningAlertEvent Event = "code_scanning_alert"
)

// EventSubtype defines a GitHub Hook Event subtype
Expand Down Expand Up @@ -353,6 +354,10 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error)
var pl GitHubAppAuthorizationPayload
err = json.Unmarshal([]byte(payload), &pl)
return pl, err
case CodeScanningAlertEvent:
var pl CodeScanningAlertPayload
err = json.Unmarshal([]byte(payload), &pl)
return pl, err
default:
return nil, fmt.Errorf("unknown event %s", gitHubEvent)
}
Expand Down
9 changes: 9 additions & 0 deletions github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,15 @@ func TestWebhooks(t *testing.T) {
"X-Github-Event": []string{"github_app_authorization"},
},
},
{
name: "CodeScanningAlertEvent",
event: CodeScanningAlertEvent,
typ: CodeScanningAlertPayload{},
filename: "../testdata/github/code_scanning_alert.json",
headers: http.Header{
"X-Github-Event": []string{"code_scanning_alert"},
},
},
}

for _, tt := range tests {
Expand Down
202 changes: 202 additions & 0 deletions github/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -7179,3 +7179,205 @@ type GitHubAppAuthorizationPayload struct {
SiteAdmin bool `json:"site_admin"`
} `json:"sender"`
}

// CodeScanningAlertPayload contains code scanning alert payload
type CodeScanningAlertPayload struct {
Action string `json:"action"`
Alert struct {
Number int `json:"number"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Url string `json:"url"`
HtmlUrl string `json:"html_url"`
State string `json:"state"`
FixedAt interface{} `json:"fixed_at"`
DismissedBy interface{} `json:"dismissed_by"`
DismissedAt interface{} `json:"dismissed_at"`
DismissedReason interface{} `json:"dismissed_reason"`
DismissedComment interface{} `json:"dismissed_comment"`
Rule struct {
Id string `json:"id"`
Severity string `json:"severity"`
Description string `json:"description"`
Name string `json:"name"`
Tags []string `json:"tags"`
FullDescription string `json:"full_description"`
Help string `json:"help"`
HelpUri string `json:"help_uri"`
SecuritySeverityLevel string `json:"security_severity_level"`
} `json:"rule"`
Tool struct {
Name string `json:"name"`
Guid interface{} `json:"guid"`
Version string `json:"version"`
} `json:"tool"`
MostRecentInstance struct {
Ref string `json:"ref"`
AnalysisKey string `json:"analysis_key"`
Environment string `json:"environment"`
Category string `json:"category"`
State string `json:"state"`
CommitSha string `json:"commit_sha"`
Message struct {
Text string `json:"text"`
} `json:"message"`
Location struct {
Path string `json:"path"`
StartLine int `json:"start_line"`
EndLine int `json:"end_line"`
StartColumn int `json:"start_column"`
EndColumn int `json:"end_column"`
} `json:"location"`
Classifications []interface{} `json:"classifications"`
} `json:"most_recent_instance"`
InstancesUrl string `json:"instances_url"`
} `json:"alert"`
Ref string `json:"ref"`
CommitOid string `json:"commit_oid"`
Repository struct {
Id int `json:"id"`
NodeId string `json:"node_id"`
Name string `json:"name"`
FullName string `json:"full_name"`
Private bool `json:"private"`
Owner struct {
Login string `json:"login"`
Id int `json:"id"`
NodeId string `json:"node_id"`
AvatarUrl string `json:"avatar_url"`
GravatarId string `json:"gravatar_id"`
Url string `json:"url"`
HtmlUrl string `json:"html_url"`
FollowersUrl string `json:"followers_url"`
FollowingUrl string `json:"following_url"`
GistsUrl string `json:"gists_url"`
StarredUrl string `json:"starred_url"`
SubscriptionsUrl string `json:"subscriptions_url"`
OrganizationsUrl string `json:"organizations_url"`
ReposUrl string `json:"repos_url"`
EventsUrl string `json:"events_url"`
ReceivedEventsUrl string `json:"received_events_url"`
Type string `json:"type"`
SiteAdmin bool `json:"site_admin"`
} `json:"owner"`
HtmlUrl string `json:"html_url"`
Description string `json:"description"`
Fork bool `json:"fork"`
Url string `json:"url"`
ForksUrl string `json:"forks_url"`
KeysUrl string `json:"keys_url"`
CollaboratorsUrl string `json:"collaborators_url"`
TeamsUrl string `json:"teams_url"`
HooksUrl string `json:"hooks_url"`
IssueEventsUrl string `json:"issue_events_url"`
EventsUrl string `json:"events_url"`
AssigneesUrl string `json:"assignees_url"`
BranchesUrl string `json:"branches_url"`
TagsUrl string `json:"tags_url"`
BlobsUrl string `json:"blobs_url"`
GitTagsUrl string `json:"git_tags_url"`
GitRefsUrl string `json:"git_refs_url"`
TreesUrl string `json:"trees_url"`
StatusesUrl string `json:"statuses_url"`
LanguagesUrl string `json:"languages_url"`
StargazersUrl string `json:"stargazers_url"`
ContributorsUrl string `json:"contributors_url"`
SubscribersUrl string `json:"subscribers_url"`
SubscriptionUrl string `json:"subscription_url"`
CommitsUrl string `json:"commits_url"`
GitCommitsUrl string `json:"git_commits_url"`
CommentsUrl string `json:"comments_url"`
IssueCommentUrl string `json:"issue_comment_url"`
ContentsUrl string `json:"contents_url"`
CompareUrl string `json:"compare_url"`
MergesUrl string `json:"merges_url"`
ArchiveUrl string `json:"archive_url"`
DownloadsUrl string `json:"downloads_url"`
IssuesUrl string `json:"issues_url"`
PullsUrl string `json:"pulls_url"`
MilestonesUrl string `json:"milestones_url"`
NotificationsUrl string `json:"notifications_url"`
LabelsUrl string `json:"labels_url"`
ReleasesUrl string `json:"releases_url"`
DeploymentsUrl string `json:"deployments_url"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
PushedAt time.Time `json:"pushed_at"`
GitUrl string `json:"git_url"`
SshUrl string `json:"ssh_url"`
CloneUrl string `json:"clone_url"`
SvnUrl string `json:"svn_url"`
Homepage string `json:"homepage"`
Size int `json:"size"`
StargazersCount int `json:"stargazers_count"`
WatchersCount int `json:"watchers_count"`
Language string `json:"language"`
HasIssues bool `json:"has_issues"`
HasProjects bool `json:"has_projects"`
HasDownloads bool `json:"has_downloads"`
HasWiki bool `json:"has_wiki"`
HasPages bool `json:"has_pages"`
HasDiscussions bool `json:"has_discussions"`
ForksCount int `json:"forks_count"`
MirrorUrl interface{} `json:"mirror_url"`
Archived bool `json:"archived"`
Disabled bool `json:"disabled"`
OpenIssuesCount int `json:"open_issues_count"`
License interface{} `json:"license"`
AllowForking bool `json:"allow_forking"`
IsTemplate bool `json:"is_template"`
WebCommitSignoffRequired bool `json:"web_commit_signoff_required"`
Topics []string `json:"topics"`
Visibility string `json:"visibility"`
Forks int `json:"forks"`
OpenIssues int `json:"open_issues"`
Watchers int `json:"watchers"`
DefaultBranch string `json:"default_branch"`
} `json:"repository"`
Organization struct {
Login string `json:"login"`
Id int `json:"id"`
NodeId string `json:"node_id"`
Url string `json:"url"`
ReposUrl string `json:"repos_url"`
EventsUrl string `json:"events_url"`
HooksUrl string `json:"hooks_url"`
IssuesUrl string `json:"issues_url"`
MembersUrl string `json:"members_url"`
PublicMembersUrl string `json:"public_members_url"`
AvatarUrl string `json:"avatar_url"`
Description string `json:"description"`
} `json:"organization"`
Enterprise struct {
Id int `json:"id"`
Slug string `json:"slug"`
Name string `json:"name"`
NodeId string `json:"node_id"`
AvatarUrl string `json:"avatar_url"`
Description string `json:"description"`
WebsiteUrl string `json:"website_url"`
HtmlUrl string `json:"html_url"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
} `json:"enterprise"`
Sender struct {
Login string `json:"login"`
Id int `json:"id"`
NodeId string `json:"node_id"`
AvatarUrl string `json:"avatar_url"`
GravatarId string `json:"gravatar_id"`
Url string `json:"url"`
HtmlUrl string `json:"html_url"`
FollowersUrl string `json:"followers_url"`
FollowingUrl string `json:"following_url"`
GistsUrl string `json:"gists_url"`
StarredUrl string `json:"starred_url"`
SubscriptionsUrl string `json:"subscriptions_url"`
OrganizationsUrl string `json:"organizations_url"`
ReposUrl string `json:"repos_url"`
EventsUrl string `json:"events_url"`
ReceivedEventsUrl string `json:"received_events_url"`
Type string `json:"type"`
SiteAdmin bool `json:"site_admin"`
} `json:"sender"`
}
Loading