Skip to content

Commit 2d25661

Browse files
author
Dean Karn
committed
Update BitBucket + GitLab Payloads
1 parent 05a2f7c commit 2d25661

File tree

6 files changed

+691
-410
lines changed

6 files changed

+691
-410
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
Library webhooks
22
================
3-
<img align="right" src="https://raw.githubusercontent.com/go-playground/webhooks/v2/logo.png">![Project status](https://img.shields.io/badge/version-2.1.0-green.svg)
3+
<img align="right" src="https://raw.githubusercontent.com/go-playground/webhooks/v3/logo.png">![Project status](https://img.shields.io/badge/version-3.0.0-green.svg)
44
[![Build Status](https://semaphoreci.com/api/v1/projects/5b9e2eda-8f8d-40aa-8cb4-e3f6120171fe/587820/badge.svg)](https://semaphoreci.com/joeybloggs/webhooks)
5-
[![Coverage Status](https://coveralls.io/repos/go-playground/webhooks/badge.svg?branch=v2&service=github)](https://coveralls.io/github/go-playground/webhooks?branch=v2)
5+
[![Coverage Status](https://coveralls.io/repos/go-playground/webhooks/badge.svg?branch=v3&service=github)](https://coveralls.io/github/go-playground/webhooks?branch=v3)
66
[![Go Report Card](https://goreportcard.com/badge/go-playground/webhooks)](https://goreportcard.com/report/go-playground/webhooks)
7-
[![GoDoc](https://godoc.org/gopkg.in/go-playground/webhooks.v2?status.svg)](https://godoc.org/gopkg.in/go-playground/webhooks.v2)
7+
[![GoDoc](https://godoc.org/gopkg.in/go-playground/webhooks.v3?status.svg)](https://godoc.org/gopkg.in/go-playground/webhooks.v3)
88
![License](https://img.shields.io/dub/l/vibe-d.svg)
99

1010
Library webhooks allows for easy recieving and parsing of GitHub, Bitbucket and GitLab Webhook Events
@@ -24,17 +24,17 @@ Installation
2424
Use go get.
2525

2626
```shell
27-
go get -u gopkg.in/go-playground/webhooks.v2
27+
go get -u gopkg.in/go-playground/webhooks.v3
2828
```
2929

3030
Then import the package into your own code.
3131

32-
import "gopkg.in/go-playground/webhooks.v2"
32+
import "gopkg.in/go-playground/webhooks.v3"
3333

3434
Usage and Documentation
3535
------
3636

37-
Please see http://godoc.org/gopkg.in/go-playground/webhooks.v2 for detailed usage docs.
37+
Please see http://godoc.org/gopkg.in/go-playground/webhooks.v3 for detailed usage docs.
3838

3939
##### Examples:
4040

@@ -46,8 +46,8 @@ import (
4646
"fmt"
4747
"strconv"
4848

49-
"gopkg.in/go-playground/webhooks.v2"
50-
"gopkg.in/go-playground/webhooks.v2/github"
49+
"gopkg.in/go-playground/webhooks.v3"
50+
"gopkg.in/go-playground/webhooks.v3/github"
5151
)
5252

5353
const (
@@ -104,8 +104,8 @@ import (
104104
"fmt"
105105
"strconv"
106106

107-
"gopkg.in/go-playground/webhooks.v2"
108-
"gopkg.in/go-playground/webhooks.v2/github"
107+
"gopkg.in/go-playground/webhooks.v3"
108+
"gopkg.in/go-playground/webhooks.v3/github"
109109
)
110110

111111
const (

bitbucket/bitbucket.go

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,24 @@ type Event string
2525

2626
// Bitbucket hook types
2727
const (
28-
RepoPushEvent Event = "repo:push"
29-
RepoForkEvent Event = "repo:fork"
30-
RepoCommitCommentCreatedEvent Event = "repo:commit_comment_created"
31-
RepoCommitStatusCreatedEvent Event = "repo:commit_status_created"
32-
RepoCommitStatusUpdatedEvent Event = "repo:commit_status_updated"
33-
IssueCreatedEvent Event = "issue:created"
34-
IssueUpdatedEvent Event = "issue:updated"
35-
IssueCommentCreatedEvent Event = "issue:comment_created"
36-
PullRequestCreatedEvent Event = "pullrequest:created"
37-
PullRequestUpdatedEvent Event = "pullrequest:updated"
38-
PullRequestApprovedEvent Event = "pullrequest:approved"
39-
PullRequestApprovalRemovedEvent Event = "pullrequest:unapproved"
40-
PullRequestMergedEvent Event = "pullrequest:fulfilled"
41-
PullRequestDeclinedEvent Event = "pullrequest:rejected"
42-
PullRequestCommentCreatedEvent Event = "pullrequest:comment_created"
43-
PullRequestCommentUpdatedEvent Event = "pullrequest:comment_updated"
44-
PullRequestCommentDeletedEvent Event = "pull_request:comment_deleted"
28+
RepoPushEvent Event = "repo:push"
29+
RepoForkEvent Event = "repo:fork"
30+
RepoUpdatedEvent Event = "repo:updated"
31+
RepoCommitCommentCreatedEvent Event = "repo:commit_comment_created"
32+
RepoCommitStatusCreatedEvent Event = "repo:commit_status_created"
33+
RepoCommitStatusUpdatedEvent Event = "repo:commit_status_updated"
34+
IssueCreatedEvent Event = "issue:created"
35+
IssueUpdatedEvent Event = "issue:updated"
36+
IssueCommentCreatedEvent Event = "issue:comment_created"
37+
PullRequestCreatedEvent Event = "pullrequest:created"
38+
PullRequestUpdatedEvent Event = "pullrequest:updated"
39+
PullRequestApprovedEvent Event = "pullrequest:approved"
40+
PullRequestUnapprovedEvent Event = "pullrequest:unapproved"
41+
PullRequestMergedEvent Event = "pullrequest:fulfilled"
42+
PullRequestDeclinedEvent Event = "pullrequest:rejected"
43+
PullRequestCommentCreatedEvent Event = "pullrequest:comment_created"
44+
PullRequestCommentUpdatedEvent Event = "pullrequest:comment_updated"
45+
PullRequestCommentDeletedEvent Event = "pull_request:comment_deleted"
4546
)
4647

4748
// New creates and returns a WebHook instance denoted by the Provider type
@@ -111,6 +112,10 @@ func (hook Webhook) ParsePayload(w http.ResponseWriter, r *http.Request) {
111112
var pl RepoForkPayload
112113
json.Unmarshal([]byte(payload), &pl)
113114
hook.runProcessPayloadFunc(fn, pl, hd)
115+
case RepoUpdatedEvent:
116+
var pl RepoUpdatedPayload
117+
json.Unmarshal([]byte(payload), &pl)
118+
hook.runProcessPayloadFunc(fn, pl, hd)
114119
case RepoCommitCommentCreatedEvent:
115120
var pl RepoCommitCommentCreatedPayload
116121
json.Unmarshal([]byte(payload), &pl)
@@ -147,8 +152,8 @@ func (hook Webhook) ParsePayload(w http.ResponseWriter, r *http.Request) {
147152
var pl PullRequestApprovedPayload
148153
json.Unmarshal([]byte(payload), &pl)
149154
hook.runProcessPayloadFunc(fn, pl, hd)
150-
case PullRequestApprovalRemovedEvent:
151-
var pl PullRequestApprovalRemovedPayload
155+
case PullRequestUnapprovedEvent:
156+
var pl PullRequestUnapprovedPayload
152157
json.Unmarshal([]byte(payload), &pl)
153158
hook.runProcessPayloadFunc(fn, pl, hd)
154159
case PullRequestMergedEvent:

bitbucket/bitbucket_test.go

Lines changed: 157 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,27 @@ func TestMain(m *testing.M) {
3939

4040
// setup
4141
hook = New(&Config{UUID: "MY_UUID"})
42-
hook.RegisterEvents(HandlePayload, RepoPushEvent, RepoForkEvent, RepoCommitCommentCreatedEvent, RepoCommitStatusCreatedEvent, RepoCommitStatusUpdatedEvent, IssueCreatedEvent, IssueUpdatedEvent, IssueCommentCreatedEvent, PullRequestCreatedEvent, PullRequestUpdatedEvent, PullRequestApprovedEvent, PullRequestApprovalRemovedEvent, PullRequestMergedEvent, PullRequestDeclinedEvent, PullRequestCommentCreatedEvent, PullRequestCommentUpdatedEvent, PullRequestCommentDeletedEvent)
42+
hook.RegisterEvents(
43+
HandlePayload,
44+
RepoPushEvent,
45+
RepoForkEvent,
46+
RepoUpdatedEvent,
47+
RepoCommitCommentCreatedEvent,
48+
RepoCommitStatusCreatedEvent,
49+
RepoCommitStatusUpdatedEvent,
50+
IssueCreatedEvent,
51+
IssueUpdatedEvent,
52+
IssueCommentCreatedEvent,
53+
PullRequestCreatedEvent,
54+
PullRequestUpdatedEvent,
55+
PullRequestApprovedEvent,
56+
PullRequestUnapprovedEvent,
57+
PullRequestMergedEvent,
58+
PullRequestDeclinedEvent,
59+
PullRequestCommentCreatedEvent,
60+
PullRequestCommentUpdatedEvent,
61+
PullRequestCommentDeletedEvent,
62+
)
4363

4464
go webhooks.Run(hook, "127.0.0.1:"+strconv.Itoa(port), path)
4565
time.Sleep(time.Millisecond * 500)
@@ -445,6 +465,142 @@ func TestRepoFork(t *testing.T) {
445465
Equal(t, resp.StatusCode, http.StatusOK)
446466
}
447467

468+
func TestRepoUpdated(t *testing.T) {
469+
470+
payload := `{
471+
"actor": {
472+
"type": "user",
473+
"username": "emmap1",
474+
"display_name": "Emma",
475+
"uuid": "{a54f16da-24e9-4d7f-a3a7-b1ba2cd98aa3}",
476+
"links": {
477+
"self": {
478+
"href": "https://api.bitbucket.org/api/2.0/users/emmap1"
479+
},
480+
"html": {
481+
"href": "https://api.bitbucket.org/emmap1"
482+
},
483+
"avatar": {
484+
"href": "https://bitbucket-api-assetroot.s3.amazonaws.com/c/photos/2015/Feb/26/3613917261-0-emmap1-avatar_avatar.png"
485+
}
486+
}
487+
},
488+
"repository": {
489+
"type": "repository",
490+
"links": {
491+
"self": {
492+
"href": "https://api.bitbucket.org/api/2.0/repositories/bitbucket/bitbucket"
493+
},
494+
"html": {
495+
"href": "https://api.bitbucket.org/bitbucket/bitbucket"
496+
},
497+
"avatar": {
498+
"href": "https://api-staging-assetroot.s3.amazonaws.com/c/photos/2014/Aug/01/bitbucket-logo-2629490769-3_avatar.png"
499+
}
500+
},
501+
"uuid": "{673a6070-3421-46c9-9d48-90745f7bfe8e}",
502+
"project": {
503+
"type": "project",
504+
"project": "Untitled project",
505+
"uuid": "{3b7898dc-6891-4225-ae60-24613bb83080}",
506+
"links": {
507+
"html": {
508+
"href": "https://bitbucket.org/account/user/teamawesome/projects/proj"
509+
},
510+
"avatar": {
511+
"href": "https://bitbucket.org/account/user/teamawesome/projects/proj/avatar/32"
512+
}
513+
},
514+
"key": "proj"
515+
},
516+
"full_name": "team_name/repo_name",
517+
"name": "repo_name",
518+
"website": "https://mywebsite.com/",
519+
"owner": {
520+
"type": "user",
521+
"username": "emmap1",
522+
"display_name": "Emma",
523+
"uuid": "{a54f16da-24e9-4d7f-a3a7-b1ba2cd98aa3}",
524+
"links": {
525+
"self": {
526+
"href": "https://api.bitbucket.org/api/2.0/users/emmap1"
527+
},
528+
"html": {
529+
"href": "https://api.bitbucket.org/emmap1"
530+
},
531+
"avatar": {
532+
"href": "https://bitbucket-api-assetroot.s3.amazonaws.com/c/photos/2015/Feb/26/3613917261-0-emmap1-avatar_avatar.png"
533+
}
534+
}
535+
},
536+
"scm": "git",
537+
"is_private": true
538+
},
539+
"changes": {
540+
"name": {
541+
"new": "repository",
542+
"old": "repository_name"
543+
},
544+
"website": {
545+
"new": "http://www.example.com/",
546+
"old": ""
547+
},
548+
"language": {
549+
"new": "java",
550+
"old": ""
551+
},
552+
"links": {
553+
"new": {
554+
"avatar": {
555+
"href": "https://bitbucket.org/teamawesome/repository/avatar/32/"
556+
},
557+
"self": {
558+
"href": "https://api.bitbucket.org/2.0/repositories/teamawesome/repository"
559+
},
560+
"html": {
561+
"href": "https://bitbucket.org/teamawesome/repository"
562+
}
563+
},
564+
"old": {
565+
"avatar": {
566+
"href": "https://bitbucket.org/teamawesome/repository_name/avatar/32/"
567+
},
568+
"self": {
569+
"href": "https://api.bitbucket.org/2.0/repositories/teamawesome/repository_name"
570+
},
571+
"html": {
572+
"href": "https://bitbucket.org/teamawesome/repository_name"
573+
}
574+
}
575+
},
576+
"description": {
577+
"new": "This is a better description.",
578+
"old": "This is a description."
579+
},
580+
"full_name": {
581+
"new": "teamawesome/repository",
582+
"old": "teamawesome/repository_name"
583+
}
584+
}
585+
}
586+
`
587+
588+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
589+
req.Header.Set("Content-Type", "application/json")
590+
req.Header.Set("X-Hook-UUID", "MY_UUID")
591+
req.Header.Set("X-Event-Key", "repo:updated")
592+
593+
Equal(t, err, nil)
594+
595+
client := &http.Client{}
596+
resp, err := client.Do(req)
597+
Equal(t, err, nil)
598+
599+
defer resp.Body.Close()
600+
601+
Equal(t, resp.StatusCode, http.StatusOK)
602+
}
603+
448604
func TestRepoCommitCommentCreated(t *testing.T) {
449605

450606
payload := `{

0 commit comments

Comments
 (0)