From 8c02b7a6d777cdbbe62a83e802094c7b71c1fd54 Mon Sep 17 00:00:00 2001 From: joeybloggs Date: Sun, 25 Oct 2015 15:18:54 -0400 Subject: [PATCH] initial commit of initial base framework --- github.go | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ webhooks.go | 33 ++++++++++++++++++++++++++ webhooks_test.go | 37 +++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 github.go create mode 100644 webhooks.go create mode 100644 webhooks_test.go diff --git a/github.go b/github.go new file mode 100644 index 0000000..75cbefc --- /dev/null +++ b/github.go @@ -0,0 +1,61 @@ +package webhooks + +// GitHubWebhook instance contains all methods needed to process events +type GitHubWebhook struct { + provider Provider +} + +// GitHubConfig defines the configuration to create a new GitHubWebhook instance +type GitHubConfig struct { + Provider Provider +} + +// GitHubHook defines a GitHub hook type +type GitHubHook string + +// GitHub hook types +const ( + Any GitHubHook = "*" + CommitComment GitHubHook = "commit_comment" + Create GitHubHook = "create" + Delete GitHubHook = "delete" + Deployment GitHubHook = "deployment" + DeploymentStatus GitHubHook = "deployment_status" + Fork GitHubHook = "fork" + Gollum GitHubHook = "gollum" + IssueComment GitHubHook = "issue_comment" + Issues GitHubHook = "issues" + Member GitHubHook = "member" + Membership GitHubHook = "membership" + PageBuild GitHubHook = "page_build" + Public GitHubHook = "public" + PullRequestReviewComment GitHubHook = "pull_request_review_comment" + PullRequest GitHubHook = "pull_request" + Push GitHubHook = "push" + Repository GitHubHook = "repository" + Release GitHubHook = "release" + Status GitHubHook = "status" + TeamAdd GitHubHook = "team_add" + Watch GitHubHook = "watch" +) + +// GitHubHookSubtype defines a GitHub Hook subtype +type GitHubHookSubtype string + +// GitHub hook subtypes +const ( + Branch GitHubHookSubtype = "branch" + Tag GitHubHookSubtype = "tag" + Pull GitHubHookSubtype = "pull" + Issue GitHubHookSubtype = "issues" +) + +// Provider returns the GitHubWebhook's provider +func (w GitHubWebhook) Provider() Provider { + return w.provider +} + +// UnderlyingProvider returns the GitHubConfig's Provider +func (c GitHubConfig) UnderlyingProvider() Provider { + return c.Provider +} diff --git a/webhooks.go b/webhooks.go new file mode 100644 index 0000000..9ecfc92 --- /dev/null +++ b/webhooks.go @@ -0,0 +1,33 @@ +package webhooks + +// Provider defines the type of webhook +type Provider int + +// webhooks available providers +const ( + GitHub Provider = iota +) + +// Webhook interface defines a webhook to recieve events +type Webhook interface { + Provider() Provider +} + +// Config interface defines the config to setup a webhook instance +type Config interface { + UnderlyingProvider() Provider +} + +// New creates and returns a WebHook instance denoted by the Provider type +func New(config Config) Webhook { + + switch config.UnderlyingProvider() { + case GitHub: + c := config.(*GitHubConfig) + return &GitHubWebhook{ + provider: c.Provider, + } + default: + panic("Invalid config type") + } +} diff --git a/webhooks_test.go b/webhooks_test.go new file mode 100644 index 0000000..aecf7f4 --- /dev/null +++ b/webhooks_test.go @@ -0,0 +1,37 @@ +package webhooks + +import ( + "os" + "reflect" + "testing" + + . "gopkg.in/go-playground/assert.v1" +) + +// NOTES: +// - Run "go test" to run tests +// - Run "gocov test | gocov report" to report on test converage by file +// - Run "gocov test | gocov annotate -" to report on all code and functions, those ,marked with "MISS" were never called +// +// or +// +// -- may be a good idea to change to output path to somewherelike /tmp +// go test -coverprofile cover.out && go tool cover -html=cover.out -o cover.html +// + +func TestMain(m *testing.M) { + + // setup + + os.Exit(m.Run()) + + // teardown +} + +func TestHooks(t *testing.T) { + + Equal(t, true, true) + + results := New(&GitHubConfig{Provider: GitHub}) + Equal(t, reflect.TypeOf(results).String(), "*webhooks.GitHubWebhook") +}