Skip to content

Commit 8c02b7a

Browse files
joeybloggsjoeybloggs
authored andcommitted
initial commit of initial base framework
1 parent 9eea023 commit 8c02b7a

File tree

3 files changed

+131
-0
lines changed

3 files changed

+131
-0
lines changed

github.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package webhooks
2+
3+
// GitHubWebhook instance contains all methods needed to process events
4+
type GitHubWebhook struct {
5+
provider Provider
6+
}
7+
8+
// GitHubConfig defines the configuration to create a new GitHubWebhook instance
9+
type GitHubConfig struct {
10+
Provider Provider
11+
}
12+
13+
// GitHubHook defines a GitHub hook type
14+
type GitHubHook string
15+
16+
// GitHub hook types
17+
const (
18+
Any GitHubHook = "*"
19+
CommitComment GitHubHook = "commit_comment"
20+
Create GitHubHook = "create"
21+
Delete GitHubHook = "delete"
22+
Deployment GitHubHook = "deployment"
23+
DeploymentStatus GitHubHook = "deployment_status"
24+
Fork GitHubHook = "fork"
25+
Gollum GitHubHook = "gollum"
26+
IssueComment GitHubHook = "issue_comment"
27+
Issues GitHubHook = "issues"
28+
Member GitHubHook = "member"
29+
Membership GitHubHook = "membership"
30+
PageBuild GitHubHook = "page_build"
31+
Public GitHubHook = "public"
32+
PullRequestReviewComment GitHubHook = "pull_request_review_comment"
33+
PullRequest GitHubHook = "pull_request"
34+
Push GitHubHook = "push"
35+
Repository GitHubHook = "repository"
36+
Release GitHubHook = "release"
37+
Status GitHubHook = "status"
38+
TeamAdd GitHubHook = "team_add"
39+
Watch GitHubHook = "watch"
40+
)
41+
42+
// GitHubHookSubtype defines a GitHub Hook subtype
43+
type GitHubHookSubtype string
44+
45+
// GitHub hook subtypes
46+
const (
47+
Branch GitHubHookSubtype = "branch"
48+
Tag GitHubHookSubtype = "tag"
49+
Pull GitHubHookSubtype = "pull"
50+
Issue GitHubHookSubtype = "issues"
51+
)
52+
53+
// Provider returns the GitHubWebhook's provider
54+
func (w GitHubWebhook) Provider() Provider {
55+
return w.provider
56+
}
57+
58+
// UnderlyingProvider returns the GitHubConfig's Provider
59+
func (c GitHubConfig) UnderlyingProvider() Provider {
60+
return c.Provider
61+
}

webhooks.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package webhooks
2+
3+
// Provider defines the type of webhook
4+
type Provider int
5+
6+
// webhooks available providers
7+
const (
8+
GitHub Provider = iota
9+
)
10+
11+
// Webhook interface defines a webhook to recieve events
12+
type Webhook interface {
13+
Provider() Provider
14+
}
15+
16+
// Config interface defines the config to setup a webhook instance
17+
type Config interface {
18+
UnderlyingProvider() Provider
19+
}
20+
21+
// New creates and returns a WebHook instance denoted by the Provider type
22+
func New(config Config) Webhook {
23+
24+
switch config.UnderlyingProvider() {
25+
case GitHub:
26+
c := config.(*GitHubConfig)
27+
return &GitHubWebhook{
28+
provider: c.Provider,
29+
}
30+
default:
31+
panic("Invalid config type")
32+
}
33+
}

webhooks_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package webhooks
2+
3+
import (
4+
"os"
5+
"reflect"
6+
"testing"
7+
8+
. "gopkg.in/go-playground/assert.v1"
9+
)
10+
11+
// NOTES:
12+
// - Run "go test" to run tests
13+
// - Run "gocov test | gocov report" to report on test converage by file
14+
// - Run "gocov test | gocov annotate -" to report on all code and functions, those ,marked with "MISS" were never called
15+
//
16+
// or
17+
//
18+
// -- may be a good idea to change to output path to somewherelike /tmp
19+
// go test -coverprofile cover.out && go tool cover -html=cover.out -o cover.html
20+
//
21+
22+
func TestMain(m *testing.M) {
23+
24+
// setup
25+
26+
os.Exit(m.Run())
27+
28+
// teardown
29+
}
30+
31+
func TestHooks(t *testing.T) {
32+
33+
Equal(t, true, true)
34+
35+
results := New(&GitHubConfig{Provider: GitHub})
36+
Equal(t, reflect.TypeOf(results).String(), "*webhooks.GitHubWebhook")
37+
}

0 commit comments

Comments
 (0)