Compare commits

...

11 Commits

Author SHA1 Message Date
Dean Karn 1751865845 Update README.md 2019-05-23 07:51:41 -07:00
Dean Karn 0a9a3aab3e Merge pull request #76 from v4lproik/add-repository-vulnerability-alert
Add repository vulnerability alert event
2019-05-23 07:51:04 -07:00
jrousseau 43ffb318d2 Add repository vulnerability alert event 2019-05-22 14:09:39 +02:00
Dean Karn 6edb377cee Update README.md 2019-05-20 13:34:26 -07:00
Dean Karn c205145bc6 Merge pull request #75 from maguro/v5
Update PipelineEventPayload with Job
2019-05-20 13:33:52 -07:00
Alan D. Cabrera a8ef7768a6 Update Pipeline even with jobs 2019-05-20 06:53:40 -07:00
Dean Karn 2b63b487a9 Update README.md 2019-05-18 22:50:58 -07:00
Dean Karn c168baf1a5 Merge pull request #73 from iladin/master
Add support for Job Events
2019-05-18 22:48:52 -07:00
Dean Karn 08c3e54514 Merge pull request #72 from geeknoid/v5
Add support for some additional fields.
2019-05-18 22:46:34 -07:00
Daniel Silverman 21587e152e Add support for Job Events
Closes go-playground/webhooks#70, closes go-playground/webhooks#71
2019-05-18 21:46:08 -07:00
mtail bf1a77d573 Add support for some additional fields. 2019-05-18 07:51:32 -07:00
10 changed files with 475 additions and 85 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
Library webhooks Library webhooks
================ ================
<img align="right" src="https://raw.githubusercontent.com/go-playground/webhooks/v5/logo.png">![Project status](https://img.shields.io/badge/version-5.9.0-green.svg) <img align="right" src="https://raw.githubusercontent.com/go-playground/webhooks/v5/logo.png">![Project status](https://img.shields.io/badge/version-5.11.0-green.svg)
[![Build Status](https://travis-ci.org/go-playground/webhooks.svg?branch=v5)](https://travis-ci.org/go-playground/webhooks) [![Build Status](https://travis-ci.org/go-playground/webhooks.svg?branch=v5)](https://travis-ci.org/go-playground/webhooks)
[![Coverage Status](https://coveralls.io/repos/go-playground/webhooks/badge.svg?branch=v5&service=github)](https://coveralls.io/github/go-playground/webhooks?branch=v5) [![Coverage Status](https://coveralls.io/repos/go-playground/webhooks/badge.svg?branch=v5&service=github)](https://coveralls.io/github/go-playground/webhooks?branch=v5)
[![Go Report Card](https://goreportcard.com/badge/go-playground/webhooks)](https://goreportcard.com/report/go-playground/webhooks) [![Go Report Card](https://goreportcard.com/badge/go-playground/webhooks)](https://goreportcard.com/report/go-playground/webhooks)
+42 -37
View File
@@ -28,43 +28,44 @@ type Event string
// GitHub hook types // GitHub hook types
const ( const (
CheckRunEvent Event = "check_run" CheckRunEvent Event = "check_run"
CheckSuiteEvent Event = "check_suite" CheckSuiteEvent Event = "check_suite"
CommitCommentEvent Event = "commit_comment" CommitCommentEvent Event = "commit_comment"
CreateEvent Event = "create" CreateEvent Event = "create"
DeleteEvent Event = "delete" DeleteEvent Event = "delete"
DeploymentEvent Event = "deployment" DeploymentEvent Event = "deployment"
DeploymentStatusEvent Event = "deployment_status" DeploymentStatusEvent Event = "deployment_status"
ForkEvent Event = "fork" ForkEvent Event = "fork"
GollumEvent Event = "gollum" GollumEvent Event = "gollum"
InstallationEvent Event = "installation" InstallationEvent Event = "installation"
InstallationRepositoriesEvent Event = "installation_repositories" InstallationRepositoriesEvent Event = "installation_repositories"
IntegrationInstallationEvent Event = "integration_installation" IntegrationInstallationEvent Event = "integration_installation"
IssueCommentEvent Event = "issue_comment" IssueCommentEvent Event = "issue_comment"
IssuesEvent Event = "issues" IssuesEvent Event = "issues"
LabelEvent Event = "label" LabelEvent Event = "label"
MemberEvent Event = "member" MemberEvent Event = "member"
MembershipEvent Event = "membership" MembershipEvent Event = "membership"
MilestoneEvent Event = "milestone" MilestoneEvent Event = "milestone"
OrganizationEvent Event = "organization" OrganizationEvent Event = "organization"
OrgBlockEvent Event = "org_block" OrgBlockEvent Event = "org_block"
PageBuildEvent Event = "page_build" PageBuildEvent Event = "page_build"
PingEvent Event = "ping" PingEvent Event = "ping"
ProjectCardEvent Event = "project_card" ProjectCardEvent Event = "project_card"
ProjectColumnEvent Event = "project_column" ProjectColumnEvent Event = "project_column"
ProjectEvent Event = "project" ProjectEvent Event = "project"
PublicEvent Event = "public" PublicEvent Event = "public"
PullRequestEvent Event = "pull_request" PullRequestEvent Event = "pull_request"
PullRequestReviewEvent Event = "pull_request_review" PullRequestReviewEvent Event = "pull_request_review"
PullRequestReviewCommentEvent Event = "pull_request_review_comment" PullRequestReviewCommentEvent Event = "pull_request_review_comment"
PushEvent Event = "push" PushEvent Event = "push"
ReleaseEvent Event = "release" ReleaseEvent Event = "release"
RepositoryEvent Event = "repository" RepositoryEvent Event = "repository"
SecurityAdvisoryEvent Event = "security_advisory" RepositoryVulnerabilityAlertEvent Event = "repository_vulnerability_alert"
StatusEvent Event = "status" SecurityAdvisoryEvent Event = "security_advisory"
TeamEvent Event = "team" StatusEvent Event = "status"
TeamAddEvent Event = "team_add" TeamEvent Event = "team"
WatchEvent Event = "watch" TeamAddEvent Event = "team_add"
WatchEvent Event = "watch"
) )
// EventSubtype defines a GitHub Hook Event subtype // EventSubtype defines a GitHub Hook Event subtype
@@ -289,6 +290,10 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error)
var pl RepositoryPayload var pl RepositoryPayload
err = json.Unmarshal([]byte(payload), &pl) err = json.Unmarshal([]byte(payload), &pl)
return pl, err return pl, err
case RepositoryVulnerabilityAlertEvent:
var pl RepositoryVulnerabilityAlertPayload
err = json.Unmarshal([]byte(payload), &pl)
return pl, err
case SecurityAdvisoryEvent: case SecurityAdvisoryEvent:
var pl SecurityAdvisoryPayload var pl SecurityAdvisoryPayload
err = json.Unmarshal([]byte(payload), &pl) err = json.Unmarshal([]byte(payload), &pl)
+11 -1
View File
@@ -453,13 +453,23 @@ func TestWebhooks(t *testing.T) {
"X-Hub-Signature": []string{"sha1=df442a8af41edd2d42ccdd997938d1d111b0f94e"}, "X-Hub-Signature": []string{"sha1=df442a8af41edd2d42ccdd997938d1d111b0f94e"},
}, },
}, },
{
name: "RepositoryVulnerabilityAlertEvent",
event: RepositoryVulnerabilityAlertEvent,
typ: RepositoryVulnerabilityAlertPayload{},
filename: "../testdata/github/repository-vulnerability-alert.json",
headers: http.Header{
"X-Github-Event": []string{"repository_vulnerability_alert"},
"X-Hub-Signature": []string{"sha1=c42c0649e7e06413bcd756763edbab48dff400db"},
},
},
{ {
name: "SecurityAdvisoryEvent", name: "SecurityAdvisoryEvent",
event: SecurityAdvisoryEvent, event: SecurityAdvisoryEvent,
typ: SecurityAdvisoryPayload{}, typ: SecurityAdvisoryPayload{},
filename: "../testdata/github/security-advisory.json", filename: "../testdata/github/security-advisory.json",
headers: http.Header{ headers: http.Header{
"X-Github-Event": []string{"security_advisory"}, "X-Github-Event": []string{"security_advisory"},
"X-Hub-Signature": []string{"sha1=6a71f24fa69f55469843a91dc3a5c3e29714a565"}, "X-Hub-Signature": []string{"sha1=6a71f24fa69f55469843a91dc3a5c3e29714a565"},
}, },
}, },
+278 -37
View File
File diff suppressed because it is too large Load Diff
+5
View File
@@ -32,6 +32,7 @@ const (
WikiPageEvents Event = "Wiki Page Hook" WikiPageEvents Event = "Wiki Page Hook"
PipelineEvents Event = "Pipeline Hook" PipelineEvents Event = "Pipeline Hook"
BuildEvents Event = "Build Hook" BuildEvents Event = "Build Hook"
JobEvents Event = "Job Hook"
SystemHookEvents Event = "System Hook" SystemHookEvents Event = "System Hook"
objectPush string = "push" objectPush string = "push"
@@ -171,6 +172,10 @@ func eventParsing(gitLabEvent Event, events []Event, payload []byte) (interface{
var pl BuildEventPayload var pl BuildEventPayload
err := json.Unmarshal([]byte(payload), &pl) err := json.Unmarshal([]byte(payload), &pl)
return pl, err return pl, err
case JobEvents:
var p1 JobEventPayload
err := json.Unmarshal([]byte(payload), &p1)
return p1, err
case SystemHookEvents: case SystemHookEvents:
var pl SystemHookPayload var pl SystemHookPayload
+9
View File
@@ -231,6 +231,15 @@ func TestWebhooks(t *testing.T) {
"X-Gitlab-Event": []string{"Build Hook"}, "X-Gitlab-Event": []string{"Build Hook"},
}, },
}, },
{
name: "JobEvent",
event: JobEvents,
typ: JobEventPayload{},
filename: "../testdata/gitlab/job-event.json",
headers: http.Header{
"X-Gitlab-Event": []string{"Job Hook"},
},
},
} }
for _, tt := range tests { for _, tt := range tests {
+26 -3
View File
@@ -109,7 +109,7 @@ type PipelineEventPayload struct {
Project Project `json:"project"` Project Project `json:"project"`
Commit Commit `json:"commit"` Commit Commit `json:"commit"`
ObjectAttributes ObjectAttributes `json:"object_attributes"` ObjectAttributes ObjectAttributes `json:"object_attributes"`
Builds []Build `json:"builds"` Jobs []Job `json:"jobs"`
} }
// CommentEventPayload contains the information for GitLab's comment event // CommentEventPayload contains the information for GitLab's comment event
@@ -148,6 +148,29 @@ type BuildEventPayload struct {
Repository Repository `json:"repository"` Repository Repository `json:"repository"`
} }
// JobEventPayload contains the information for GitLab's Job status change
type JobEventPayload struct {
ObjectKind string `json:"object_kind"`
Ref string `json:"ref"`
Tag bool `json:"tag"`
BeforeSHA string `json:"before_sha"`
SHA string `json:"sha"`
JobID int64 `json:"Job_id"`
JobName string `json:"Job_name"`
JobStage string `json:"Job_stage"`
JobStatus string `json:"Job_status"`
JobStartedAt customTime `json:"Job_started_at"`
JobFinishedAt customTime `json:"Job_finished_at"`
JobDuration int64 `json:"Job_duration"`
Job bool `json:"Job"`
JobFailureReason string `json:"job_failure_reason"`
ProjectID int64 `json:"project_id"`
ProjectName string `json:"project_name"`
User User `json:"user"`
Commit BuildCommit `json:"commit"`
Repository Repository `json:"repository"`
}
// SystemHookPayload contains the ObjectKind to match with real hook events // SystemHookPayload contains the ObjectKind to match with real hook events
type SystemHookPayload struct { type SystemHookPayload struct {
ObjectKind string `json:"object_kind"` ObjectKind string `json:"object_kind"`
@@ -170,8 +193,8 @@ type Issue struct {
IID int64 `json:"iid"` IID int64 `json:"iid"`
} }
// Build contains all of the GitLab build information // Job contains all of the GitLab job information
type Build struct { type Job struct {
ID int64 `json:"id"` ID int64 `json:"id"`
Stage string `json:"stage"` Stage string `json:"stage"`
Name string `json:"name"` Name string `json:"name"`
+33
View File
@@ -0,0 +1,33 @@
{
"action": "dismiss",
"alert": {
"id": 7649605,
"affected_range": "0.2.0",
"affected_package_name": "many_versioned_gem",
"external_reference": "https://nvd.nist.gov/vuln/detail/CVE-2018-3728",
"external_identifier": "CVE-2018-3728",
"fixed_in": "0.2.5",
"dismisser": {
"login":"octocat",
"id":1,
"node_id": "MDQ6VXNlcjIxMDMxMDY3",
"avatar_url":"https://github.com/images/error/octocat_happy.gif",
"gravatar_id":"",
"url":"https://api.github.com/users/octocat",
"html_url":"https://github.com/octocat",
"followers_url":"https://api.github.com/users/octocat/followers",
"following_url":"https://api.github.com/users/octocat/following{/other_user}",
"gists_url":"https://api.github.com/users/octocat/gists{/gist_id}",
"starred_url":"https://api.github.com/users/octocat/starred{/owner}{/repo}",
"subscriptions_url":"https://api.github.com/users/octocat/subscriptions",
"organizations_url":"https://api.github.com/users/octocat/orgs",
"repos_url":"https://api.github.com/users/octocat/repos",
"events_url":"https://api.github.com/users/octocat/events{/privacy}",
"received_events_url":"https://api.github.com/users/octocat/received_events",
"type":"User",
"site_admin":true
},
"dismiss_reason": "No bandwidth to fix this",
"dismissed_at": "2017-10-25T00:00:00+00:00"
}
}
+42
View File
@@ -0,0 +1,42 @@
{
"object_kind": "job",
"ref": "gitlab-script-trigger",
"tag": false,
"before_sha": "2293ada6b400935a1378653304eaf6221e0fdb8f",
"sha": "2293ada6b400935a1378653304eaf6221e0fdb8f",
"job_id": 1977,
"job_name": "test",
"job_stage": "test",
"job_status": "created",
"job_started_at": null,
"job_finished_at": null,
"job_duration": null,
"job_allow_failure": false,
"job_failure_reason": "script_failure",
"project_id": 380,
"project_name": "gitlab-org/gitlab-test",
"user": {
"id": 3,
"name": "User",
"email": "user@gitlab.com"
},
"commit": {
"id": 2366,
"sha": "2293ada6b400935a1378653304eaf6221e0fdb8f",
"message": "test\n",
"author_name": "User",
"author_email": "user@gitlab.com",
"status": "created",
"duration": null,
"started_at": null,
"finished_at": null
},
"repository": {
"name": "gitlab_test",
"description": "Atque in sunt eos similique dolores voluptatem.",
"homepage": "http://192.168.64.1:3005/gitlab-org/gitlab-test",
"git_ssh_url": "git@192.168.64.1:gitlab-org/gitlab-test.git",
"git_http_url": "http://192.168.64.1:3005/gitlab-org/gitlab-test.git",
"visibility_level": 20
}
}
+27 -5
View File
@@ -14,7 +14,13 @@
], ],
"created_at": "2016-08-12 15:23:28 UTC", "created_at": "2016-08-12 15:23:28 UTC",
"finished_at": "2016-08-12 15:26:29 UTC", "finished_at": "2016-08-12 15:26:29 UTC",
"duration": 63 "duration": 63,
"variables": [
{
"key": "NESTOR_PROD_ENVIRONMENT",
"value": "us-west-1"
}
]
}, },
"user":{ "user":{
"name": "Administrator", "name": "Administrator",
@@ -22,6 +28,7 @@
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon"
}, },
"project":{ "project":{
"id": 1,
"name": "Gitlab Test", "name": "Gitlab Test",
"description": "Atque in sunt eos similique dolores voluptatem.", "description": "Atque in sunt eos similique dolores voluptatem.",
"web_url": "http://192.168.64.1:3005/gitlab-org/gitlab-test", "web_url": "http://192.168.64.1:3005/gitlab-org/gitlab-test",
@@ -43,7 +50,7 @@
"email": "user@gitlab.com" "email": "user@gitlab.com"
} }
}, },
"builds":[ "jobs":[
{ {
"id": 380, "id": 380,
"stage": "deploy", "stage": "deploy",
@@ -80,7 +87,12 @@
"username": "root", "username": "root",
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon"
}, },
"runner": null, "runner": {
"id":380987,
"description":"shared-runners-manager-6.gitlab.com",
"active":true,
"is_shared":true
},
"artifacts_file":{ "artifacts_file":{
"filename": null, "filename": null,
"size": null "size": null
@@ -101,7 +113,12 @@
"username": "root", "username": "root",
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon"
}, },
"runner": null, "runner": {
"id":380987,
"description":"shared-runners-manager-6.gitlab.com",
"active":true,
"is_shared":true
},
"artifacts_file":{ "artifacts_file":{
"filename": null, "filename": null,
"size": null "size": null
@@ -122,7 +139,12 @@
"username": "root", "username": "root",
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon"
}, },
"runner": null, "runner": {
"id":380987,
"description":"shared-runners-manager-6.gitlab.com",
"active":true,
"is_shared":true
},
"artifacts_file":{ "artifacts_file":{
"filename": null, "filename": null,
"size": null "size": null