Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6edb377cee | |||
| c205145bc6 | |||
| a8ef7768a6 | |||
| 2b63b487a9 | |||
| c168baf1a5 | |||
| 08c3e54514 | |||
| 21587e152e | |||
| bf1a77d573 | |||
| d228b48c40 | |||
| 869ac76ba8 | |||
| ebe6b8d143 | |||
| c271d4f1c6 | |||
| 067e3f1d7a | |||
| 0f4713c1d1 | |||
| f053ac6ee1 | |||
| 65f5d60701 | |||
| 295aa6531f |
@@ -1,6 +1,6 @@
|
||||
Library webhooks
|
||||
================
|
||||
<img align="right" src="https://raw.githubusercontent.com/go-playground/webhooks/v5/logo.png">
|
||||
<img align="right" src="https://raw.githubusercontent.com/go-playground/webhooks/v5/logo.png">
|
||||
[](https://travis-ci.org/go-playground/webhooks)
|
||||
[](https://coveralls.io/github/go-playground/webhooks?branch=v5)
|
||||
[](https://goreportcard.com/report/go-playground/webhooks)
|
||||
|
||||
@@ -60,6 +60,7 @@ const (
|
||||
PushEvent Event = "push"
|
||||
ReleaseEvent Event = "release"
|
||||
RepositoryEvent Event = "repository"
|
||||
SecurityAdvisoryEvent Event = "security_advisory"
|
||||
StatusEvent Event = "status"
|
||||
TeamEvent Event = "team"
|
||||
TeamAddEvent Event = "team_add"
|
||||
@@ -288,6 +289,10 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error)
|
||||
var pl RepositoryPayload
|
||||
err = json.Unmarshal([]byte(payload), &pl)
|
||||
return pl, err
|
||||
case SecurityAdvisoryEvent:
|
||||
var pl SecurityAdvisoryPayload
|
||||
err = json.Unmarshal([]byte(payload), &pl)
|
||||
return pl, err
|
||||
case StatusEvent:
|
||||
var pl StatusPayload
|
||||
err = json.Unmarshal([]byte(payload), &pl)
|
||||
|
||||
@@ -453,6 +453,16 @@ func TestWebhooks(t *testing.T) {
|
||||
"X-Hub-Signature": []string{"sha1=df442a8af41edd2d42ccdd997938d1d111b0f94e"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "SecurityAdvisoryEvent",
|
||||
event: SecurityAdvisoryEvent,
|
||||
typ: SecurityAdvisoryPayload{},
|
||||
filename: "../testdata/github/security-advisory.json",
|
||||
headers: http.Header{
|
||||
"X-Github-Event": []string{"security_advisory"},
|
||||
"X-Hub-Signature": []string{"sha1=6a71f24fa69f55469843a91dc3a5c3e29714a565"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "StatusEvent",
|
||||
event: StatusEvent,
|
||||
|
||||
+325
-74
File diff suppressed because it is too large
Load Diff
@@ -32,6 +32,7 @@ const (
|
||||
WikiPageEvents Event = "Wiki Page Hook"
|
||||
PipelineEvents Event = "Pipeline Hook"
|
||||
BuildEvents Event = "Build Hook"
|
||||
JobEvents Event = "Job Hook"
|
||||
SystemHookEvents Event = "System Hook"
|
||||
|
||||
objectPush string = "push"
|
||||
@@ -171,6 +172,10 @@ func eventParsing(gitLabEvent Event, events []Event, payload []byte) (interface{
|
||||
var pl BuildEventPayload
|
||||
err := json.Unmarshal([]byte(payload), &pl)
|
||||
return pl, err
|
||||
case JobEvents:
|
||||
var p1 JobEventPayload
|
||||
err := json.Unmarshal([]byte(payload), &p1)
|
||||
return p1, err
|
||||
|
||||
case SystemHookEvents:
|
||||
var pl SystemHookPayload
|
||||
|
||||
@@ -231,6 +231,15 @@ func TestWebhooks(t *testing.T) {
|
||||
"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 {
|
||||
|
||||
+26
-3
@@ -109,7 +109,7 @@ type PipelineEventPayload struct {
|
||||
Project Project `json:"project"`
|
||||
Commit Commit `json:"commit"`
|
||||
ObjectAttributes ObjectAttributes `json:"object_attributes"`
|
||||
Builds []Build `json:"builds"`
|
||||
Jobs []Job `json:"jobs"`
|
||||
}
|
||||
|
||||
// CommentEventPayload contains the information for GitLab's comment event
|
||||
@@ -148,6 +148,29 @@ type BuildEventPayload struct {
|
||||
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
|
||||
type SystemHookPayload struct {
|
||||
ObjectKind string `json:"object_kind"`
|
||||
@@ -170,8 +193,8 @@ type Issue struct {
|
||||
IID int64 `json:"iid"`
|
||||
}
|
||||
|
||||
// Build contains all of the GitLab build information
|
||||
type Build struct {
|
||||
// Job contains all of the GitLab job information
|
||||
type Job struct {
|
||||
ID int64 `json:"id"`
|
||||
Stage string `json:"stage"`
|
||||
Name string `json:"name"`
|
||||
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"action": "published",
|
||||
"security_advisory": {
|
||||
"ghsa_id": "GHSA-rf4j-j272-fj86",
|
||||
"summary": "Moderate severity vulnerability that affects django",
|
||||
"description": "django.contrib.auth.forms.AuthenticationForm in Django 2.0 before 2.0.2, and 1.11.8 and 1.11.9, allows remote attackers to obtain potentially sensitive information by leveraging data exposure from the confirm_login_allowed() method, as demonstrated by discovering whether a user account is inactive.",
|
||||
"severity": "moderate",
|
||||
"identifiers": [
|
||||
{
|
||||
"value": "GHSA-rf4j-j272-fj86",
|
||||
"type": "GHSA"
|
||||
},
|
||||
{
|
||||
"value": "CVE-2018-6188",
|
||||
"type": "CVE"
|
||||
}
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"url": "https://nvd.nist.gov/vuln/detail/CVE-2018-6188"
|
||||
}
|
||||
],
|
||||
"published_at": "2018-10-03T21:13:54Z",
|
||||
"updated_at": "2018-10-03T21:13:54Z",
|
||||
"withdrawn_at": null,
|
||||
"vulnerabilities": [
|
||||
{
|
||||
"package": {
|
||||
"ecosystem": "pip",
|
||||
"name": "django"
|
||||
},
|
||||
"severity": "moderate",
|
||||
"vulnerable_version_range": ">= 2.0.0, < 2.0.2",
|
||||
"first_patched_version": {
|
||||
"identifier": "2.0.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": {
|
||||
"ecosystem": "pip",
|
||||
"name": "django"
|
||||
},
|
||||
"severity": "moderate",
|
||||
"vulnerable_version_range": ">= 1.11.8, < 1.11.10",
|
||||
"first_patched_version": {
|
||||
"identifier": "1.11.10"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Vendored
+42
@@ -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
|
||||
}
|
||||
}
|
||||
Vendored
+28
-6
@@ -14,7 +14,13 @@
|
||||
],
|
||||
"created_at": "2016-08-12 15:23:28 UTC",
|
||||
"finished_at": "2016-08-12 15:26:29 UTC",
|
||||
"duration": 63
|
||||
"duration": 63,
|
||||
"variables": [
|
||||
{
|
||||
"key": "NESTOR_PROD_ENVIRONMENT",
|
||||
"value": "us-west-1"
|
||||
}
|
||||
]
|
||||
},
|
||||
"user":{
|
||||
"name": "Administrator",
|
||||
@@ -22,6 +28,7 @@
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon"
|
||||
},
|
||||
"project":{
|
||||
"id": 1,
|
||||
"name": "Gitlab Test",
|
||||
"description": "Atque in sunt eos similique dolores voluptatem.",
|
||||
"web_url": "http://192.168.64.1:3005/gitlab-org/gitlab-test",
|
||||
@@ -43,7 +50,7 @@
|
||||
"email": "user@gitlab.com"
|
||||
}
|
||||
},
|
||||
"builds":[
|
||||
"jobs":[
|
||||
{
|
||||
"id": 380,
|
||||
"stage": "deploy",
|
||||
@@ -80,7 +87,12 @@
|
||||
"username": "root",
|
||||
"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":{
|
||||
"filename": null,
|
||||
"size": null
|
||||
@@ -101,7 +113,12 @@
|
||||
"username": "root",
|
||||
"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":{
|
||||
"filename": null,
|
||||
"size": null
|
||||
@@ -122,7 +139,12 @@
|
||||
"username": "root",
|
||||
"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":{
|
||||
"filename": null,
|
||||
"size": null
|
||||
@@ -150,4 +172,4 @@
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user