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