Skip to content

feat: add Azure DevOps git push event #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions azuredevops/azuredevops.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions azuredevops/azuredevops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
47 changes: 47 additions & 0 deletions azuredevops/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
76 changes: 76 additions & 0 deletions testdata/azuredevops/git.push.json
Original file line number Diff line number Diff line change
@@ -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 <a href=\"https://dev.azure.com/fabrikam-fiber-inc/DefaultCollection/_git/Fabrikam-Fiber-Git/#version=GBmaster\">master</a> of repository <a href=\"https://dev.azure.com/fabrikam-fiber-inc/DefaultCollection/_git/Fabrikam-Fiber-Git/\">Fabrikam-Fiber-Git</a>.\n<ul>\n<li>Fixed bug in web.config file <a href=\"https://dev.azure.com/fabrikam-fiber-inc/DefaultCollection/_git/Fabrikam-Fiber-Git/commit/33b55f7cb7e7e245323987634f960cf4a6e6bc74\">33b55f7c</a>\n</ul>",
"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"
}