diff --git a/azuredevops/azuredevops.go b/azuredevops/azuredevops.go index 79f665f..408b34a 100644 --- a/azuredevops/azuredevops.go +++ b/azuredevops/azuredevops.go @@ -27,6 +27,7 @@ const ( GitPullRequestCreatedEventType Event = "git.pullrequest.created" GitPullRequestUpdatedEventType Event = "git.pullrequest.updated" GitPullRequestMergedEventType Event = "git.pullrequest.merged" + GitPushEventType Event = "git.push" ) // Webhook instance contains all methods needed to process events @@ -62,6 +63,10 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error) } switch pl.EventType { + case GitPushEventType: + var fpl GitPushEvent + err = json.Unmarshal([]byte(payload), &fpl) + return fpl, err case GitPullRequestCreatedEventType, GitPullRequestMergedEventType, GitPullRequestUpdatedEventType: var fpl GitPullRequestEvent err = json.Unmarshal([]byte(payload), &fpl) diff --git a/azuredevops/azuredevops_test.go b/azuredevops/azuredevops_test.go index 5cfc099..1ca7591 100644 --- a/azuredevops/azuredevops_test.go +++ b/azuredevops/azuredevops_test.go @@ -80,6 +80,12 @@ func TestWebhooks(t *testing.T) { typ: GitPullRequestEvent{}, filename: "../testdata/azuredevops/git.pullrequest.updated.json", }, + { + name: "git.push", + event: GitPushEventType, + typ: GitPushEvent{}, + filename: "../testdata/azuredevops/git.push.json", + }, } for _, tt := range tests { diff --git a/azuredevops/payload.go b/azuredevops/payload.go index cf8e820..8554752 100644 --- a/azuredevops/payload.go +++ b/azuredevops/payload.go @@ -36,6 +36,21 @@ type GitPullRequestEvent struct { CreatedDate Date `json:"createdDate"` } +// git.push + +type GitPushEvent struct { + CreatedDate string `json:"createdDate"` + DetailedMessage Message `json:"detailedMessage"` + EventType string `json:"eventType"` + ID string `json:"id"` + Message Message `json:"message"` + PublisherID string `json:"publisherId"` + Resource Resource `json:"resource"` + ResourceContainers ResourceContainers `json:"resourceContainers"` + ResourceVersion string `json:"resourceVersion"` + Scope string `json:"scope"` +} + // build.complete type BuildCompleteEvent struct { @@ -176,6 +191,38 @@ type Request struct { RequestedFor User `json:"requestedFor"` } +type Resource struct { + Commits []Commit `json:"commits"` + Date string `json:"date"` + PushedBy PushedBy `json:"pushedBy"` + PushID int `json:"pushId"` + RefUpdates []RefUpdate `json:"refUpdates"` + Repository Repository `json:"repository"` + URL string `json:"url"` +} + +type RefUpdate struct { + Name string `json:"name"` + NewObjectID string `json:"newObjectId"` + OldObjectID string `json:"oldObjectId"` +} + +type PushedBy struct { + DisplayName string `json:"displayName"` + ID string `json:"id"` + UniqueName string `json:"uniqueName"` +} + +type ResourceContainers struct { + Account Account `json:"account"` + Collection Account `json:"collection"` + Project Account `json:"project"` +} + +type Account struct { + ID string `json:"id"` +} + type Date time.Time func (b *Date) UnmarshalJSON(p []byte) error { diff --git a/testdata/azuredevops/git.push.json b/testdata/azuredevops/git.push.json new file mode 100644 index 0000000..c1ec181 --- /dev/null +++ b/testdata/azuredevops/git.push.json @@ -0,0 +1,76 @@ +{ + "id": "03c164c2-8912-4d5e-8009-3707d5f83734", + "eventType": "git.push", + "publisherId": "tfs", + "scope": "all", + "message": { + "text": "Jamal Hartnett pushed updates to branch master of repository Fabrikam-Fiber-Git.", + "html": "Jamal Hartnett pushed updates to branch master of repository Fabrikam-Fiber-Git.", + "markdown": "Jamal Hartnett pushed updates to branch `master` of repository `Fabrikam-Fiber-Git`." + }, + "detailedMessage": { + "text": "Jamal Hartnett pushed 1 commit to branch master of repository Fabrikam-Fiber-Git.\n - Fixed bug in web.config file 33b55f7c", + "html": "Jamal Hartnett pushed 1 commit to branch master of repository Fabrikam-Fiber-Git.\n", + "markdown": "Jamal Hartnett pushed 1 commit to branch [master](https://dev.azure.com/fabrikam-fiber-inc/DefaultCollection/_git/Fabrikam-Fiber-Git/#version=GBmaster) of repository [Fabrikam-Fiber-Git](https://dev.azure.com/fabrikam-fiber-inc/DefaultCollection/_git/Fabrikam-Fiber-Git/).\n* Fixed bug in web.config file [33b55f7c](https://dev.azure.com/fabrikam-fiber-inc/DefaultCollection/_git/Fabrikam-Fiber-Git/commit/33b55f7cb7e7e245323987634f960cf4a6e6bc74)" + }, + "resource": { + "commits": [ + { + "commitId": "33b55f7cb7e7e245323987634f960cf4a6e6bc74", + "author": { + "name": "Jamal Hartnett", + "email": "fabrikamfiber4@hotmail.com", + "date": "2015-02-25T19:01:00Z" + }, + "committer": { + "name": "Jamal Hartnett", + "email": "fabrikamfiber4@hotmail.com", + "date": "2015-02-25T19:01:00Z" + }, + "comment": "Fixed bug in web.config file", + "url": "https://dev.azure.com/fabrikam-fiber-inc/DefaultCollection/_git/Fabrikam-Fiber-Git/commit/33b55f7cb7e7e245323987634f960cf4a6e6bc74" + } + ], + "refUpdates": [ + { + "name": "refs/heads/main", + "oldObjectId": "aad331d8d3b131fa9ae03cf5e53965b51942618a", + "newObjectId": "33b55f7cb7e7e245323987634f960cf4a6e6bc74" + } + ], + "repository": { + "id": "278d5cd2-584d-4b63-824a-2ba458937249", + "name": "Fabrikam-Fiber-Git", + "url": "https://dev.azure.com/fabrikam-fiber-inc/DefaultCollection/_apis/repos/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249", + "project": { + "id": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c", + "name": "Fabrikam-Fiber-Git", + "url": "https://dev.azure.com/fabrikam-fiber-inc/DefaultCollection/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c", + "state": "wellFormed" + }, + "defaultBranch": "refs/heads/main", + "remoteUrl": "https://dev.azure.com/fabrikam-fiber-inc/DefaultCollection/_git/Fabrikam-Fiber-Git" + }, + "pushedBy": { + "id": "00067FFED5C7AF52@Live.com", + "displayName": "Jamal Hartnett", + "uniqueName": "Windows Live ID\\fabrikamfiber4@hotmail.com" + }, + "pushId": 14, + "date": "2014-05-02T19:17:13.3309587Z", + "url": "https://dev.azure.com/fabrikam-fiber-inc/DefaultCollection/_apis/repos/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/pushes/14" + }, + "resourceVersion": "1.0", + "resourceContainers": { + "collection": { + "id": "c12d0eb8-e382-443b-9f9c-c52cba5014c2" + }, + "account": { + "id": "f844ec47-a9db-4511-8281-8b63f4eaf94e" + }, + "project": { + "id": "be9b3917-87e6-42a4-a549-2bc06a7a878f" + } + }, + "createdDate": "2016-09-19T13:03:27.0379153Z" + } \ No newline at end of file