This repository has been archived by the owner on Dec 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 959
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1282 from 6543-forks/add-support-for-EventTypeSer…
…viceHook Add support for event type service hook
- Loading branch information
Showing
7 changed files
with
202 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ package gitlab | |
|
||
import ( | ||
"net/http" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
@@ -286,8 +287,8 @@ func TestParsePushHook(t *testing.T) { | |
t.Errorf("Expected PushEvent, but parsing produced %T", parsedEvent) | ||
} | ||
|
||
if event.ObjectKind != "push" { | ||
t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "push") | ||
if event.ObjectKind != eventObjectKindPush { | ||
t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, eventObjectKindPush) | ||
} | ||
|
||
if event.ProjectID != 15 { | ||
|
@@ -372,8 +373,8 @@ func TestParseTagHook(t *testing.T) { | |
t.Errorf("Expected TagEvent, but parsing produced %T", parsedEvent) | ||
} | ||
|
||
if event.ObjectKind != "tag_push" { | ||
t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "tag_push") | ||
if event.ObjectKind != eventObjectKindTagPush { | ||
t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, eventObjectKindTagPush) | ||
} | ||
|
||
if event.ProjectID != 1 { | ||
|
@@ -422,3 +423,26 @@ func TestParseWikiPageHook(t *testing.T) { | |
t.Errorf("Message is %v, want %v", event.ObjectAttributes.Message, "adding an awesome page to the wiki") | ||
} | ||
} | ||
|
||
func TestParseServiceWebHook(t *testing.T) { | ||
parsedEvent, err := ParseWebhook("Service Hook", loadFixture("testdata/webhooks/service_merge_request.json")) | ||
if err != nil { | ||
t.Errorf("Error parsing service hook merge request: %s", err) | ||
} | ||
|
||
switch event := parsedEvent.(type) { | ||
case *MergeEvent: | ||
assert.EqualValues(t, &EventUser{ | ||
ID: 2, | ||
Name: "the test", | ||
Username: "test", | ||
Email: "[email protected]", | ||
AvatarURL: "https://www.gravatar.com/avatar/dd46a756faad4727fb679320751f6dea?s=80&d=identicon", | ||
}, event.User) | ||
assert.EqualValues(t, "unchecked", event.ObjectAttributes.MergeStatus) | ||
assert.EqualValues(t, "next-feature", event.ObjectAttributes.SourceBranch) | ||
assert.EqualValues(t, "master", event.ObjectAttributes.TargetBranch) | ||
default: | ||
t.Errorf("unexpected event type: %s", reflect.TypeOf(parsedEvent)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
{ | ||
"object_kind": "merge_request", | ||
"event_type": "merge_request", | ||
"user": { | ||
"id": 2, | ||
"name": "the test", | ||
"username": "test", | ||
"avatar_url": "https://www.gravatar.com/avatar/dd46a756faad4727fb679320751f6dea?s=80&d=identicon", | ||
"email": "[email protected]" | ||
}, | ||
"project": { | ||
"id": 2, | ||
"name": "Woodpecker", | ||
"description": "", | ||
"web_url": "http://10.40.8.5:3200/test/woodpecker", | ||
"avatar_url": null, | ||
"git_ssh_url": "[email protected]:test/woodpecker.git", | ||
"git_http_url": "http://10.40.8.5:3200/test/woodpecker.git", | ||
"namespace": "the test", | ||
"visibility_level": 20, | ||
"path_with_namespace": "test/woodpecker", | ||
"default_branch": "master", | ||
"ci_config_path": null, | ||
"homepage": "http://10.40.8.5:3200/test/woodpecker", | ||
"url": "[email protected]:test/woodpecker.git", | ||
"ssh_url": "[email protected]:test/woodpecker.git", | ||
"http_url": "http://10.40.8.5:3200/test/woodpecker.git" | ||
}, | ||
"object_attributes": { | ||
"assignee_id": null, | ||
"author_id": 2, | ||
"created_at": "2021-09-27 05:00:01 UTC", | ||
"description": "", | ||
"head_pipeline_id": 5, | ||
"id": 2, | ||
"iid": 2, | ||
"last_edited_at": null, | ||
"last_edited_by_id": null, | ||
"merge_commit_sha": null, | ||
"merge_error": null, | ||
"merge_params": { | ||
"force_remove_source_branch": "1" | ||
}, | ||
"merge_status": "unchecked", | ||
"merge_user_id": null, | ||
"merge_when_pipeline_succeeds": false, | ||
"milestone_id": null, | ||
"source_branch": "next-feature", | ||
"source_project_id": 2, | ||
"state_id": 1, | ||
"target_branch": "master", | ||
"target_project_id": 2, | ||
"time_estimate": 0, | ||
"title": "Update client.go 🎉", | ||
"updated_at": "2021-09-27 05:01:21 UTC", | ||
"updated_by_id": null, | ||
"url": "http://10.40.8.5:3200/test/woodpecker/-/merge_requests/2", | ||
"source": { | ||
"id": 2, | ||
"name": "Woodpecker", | ||
"description": "", | ||
"web_url": "http://10.40.8.5:3200/test/woodpecker", | ||
"avatar_url": "http://example.com/uploads/project/avatar/555/Outh-20-Logo.jpg", | ||
"git_ssh_url": "[email protected]:test/woodpecker.git", | ||
"git_http_url": "http://10.40.8.5:3200/test/woodpecker.git", | ||
"namespace": "the test", | ||
"visibility_level": 20, | ||
"path_with_namespace": "test/woodpecker", | ||
"default_branch": "develop", | ||
"ci_config_path": null, | ||
"homepage": "http://10.40.8.5:3200/test/woodpecker", | ||
"url": "[email protected]:test/woodpecker.git", | ||
"ssh_url": "[email protected]:test/woodpecker.git", | ||
"http_url": "http://10.40.8.5:3200/test/woodpecker.git" | ||
}, | ||
"target": { | ||
"id": 2, | ||
"name": "Woodpecker", | ||
"description": "", | ||
"web_url": "http://10.40.8.5:3200/test/woodpecker", | ||
"avatar_url": "http://example.com/uploads/project/avatar/555/Outh-20-Logo.jpg", | ||
"git_ssh_url": "[email protected]:test/woodpecker.git", | ||
"git_http_url": "http://10.40.8.5:3200/test/woodpecker.git", | ||
"namespace": "the test", | ||
"visibility_level": 20, | ||
"path_with_namespace": "test/woodpecker", | ||
"default_branch": "develop", | ||
"ci_config_path": null, | ||
"homepage": "http://10.40.8.5:3200/test/woodpecker", | ||
"url": "[email protected]:test/woodpecker.git", | ||
"ssh_url": "[email protected]:test/woodpecker.git", | ||
"http_url": "http://10.40.8.5:3200/test/woodpecker.git" | ||
}, | ||
"last_commit": { | ||
"id": "0ab96a10266b95b4b533dcfd98738015fbe70889", | ||
"message": "Update state.go", | ||
"title": "Update state.go", | ||
"timestamp": "2021-09-27T05:01:20+00:00", | ||
"url": "http://10.40.8.5:3200/test/woodpecker/-/commit/0ab96a10266b95b4b533dcfd98738015fbe70889", | ||
"author": { | ||
"name": "the test", | ||
"email": "[email protected]" | ||
} | ||
}, | ||
"work_in_progress": false, | ||
"total_time_spent": 0, | ||
"time_change": 0, | ||
"human_total_time_spent": null, | ||
"human_time_change": null, | ||
"human_time_estimate": null, | ||
"assignee_ids": [], | ||
"state": "opened", | ||
"action": "update", | ||
"oldrev": "6ef047571374c96a2bf13c361efd1fb008b0063e" | ||
}, | ||
"labels": [], | ||
"changes": { | ||
"updated_at": { | ||
"previous": "2021-09-27 05:00:01 UTC", | ||
"current": "2021-09-27 05:01:21 UTC" | ||
} | ||
}, | ||
"repository": { | ||
"name": "Woodpecker", | ||
"url": "[email protected]:test/woodpecker.git", | ||
"description": "", | ||
"homepage": "http://10.40.8.5:3200/test/woodpecker" | ||
} | ||
} |