Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2b63b487a9 | |||
| c168baf1a5 | |||
| 08c3e54514 | |||
| 21587e152e | |||
| bf1a77d573 | |||
| d228b48c40 | |||
| 869ac76ba8 | |||
| ebe6b8d143 | |||
| c271d4f1c6 | |||
| 067e3f1d7a |
@@ -1,6 +1,6 @@
|
|||||||
Library webhooks
|
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://travis-ci.org/go-playground/webhooks)
|
||||||
[](https://coveralls.io/github/go-playground/webhooks?branch=v5)
|
[](https://coveralls.io/github/go-playground/webhooks?branch=v5)
|
||||||
[](https://goreportcard.com/report/go-playground/webhooks)
|
[](https://goreportcard.com/report/go-playground/webhooks)
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ const (
|
|||||||
PushEvent Event = "push"
|
PushEvent Event = "push"
|
||||||
ReleaseEvent Event = "release"
|
ReleaseEvent Event = "release"
|
||||||
RepositoryEvent Event = "repository"
|
RepositoryEvent Event = "repository"
|
||||||
|
SecurityAdvisoryEvent Event = "security_advisory"
|
||||||
StatusEvent Event = "status"
|
StatusEvent Event = "status"
|
||||||
TeamEvent Event = "team"
|
TeamEvent Event = "team"
|
||||||
TeamAddEvent Event = "team_add"
|
TeamAddEvent Event = "team_add"
|
||||||
@@ -288,6 +289,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 SecurityAdvisoryEvent:
|
||||||
|
var pl SecurityAdvisoryPayload
|
||||||
|
err = json.Unmarshal([]byte(payload), &pl)
|
||||||
|
return pl, err
|
||||||
case StatusEvent:
|
case StatusEvent:
|
||||||
var pl StatusPayload
|
var pl StatusPayload
|
||||||
err = json.Unmarshal([]byte(payload), &pl)
|
err = json.Unmarshal([]byte(payload), &pl)
|
||||||
|
|||||||
@@ -453,6 +453,16 @@ func TestWebhooks(t *testing.T) {
|
|||||||
"X-Hub-Signature": []string{"sha1=df442a8af41edd2d42ccdd997938d1d111b0f94e"},
|
"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",
|
name: "StatusEvent",
|
||||||
event: StatusEvent,
|
event: StatusEvent,
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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"`
|
||||||
|
|||||||
+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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user