initial commit of initial base framework
This commit is contained in:
@@ -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
|
||||||
|
}
|
||||||
+33
@@ -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")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user