diff --git a/github.go b/github.go deleted file mode 100644 index 75cbefc..0000000 --- a/github.go +++ /dev/null @@ -1,61 +0,0 @@ -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/github/github.go b/github/github.go new file mode 100644 index 0000000..a0595d8 --- /dev/null +++ b/github/github.go @@ -0,0 +1,71 @@ +package github + +import "github.com/joeybloggs/webhooks" + +// Webhook instance contains all methods needed to process events +type Webhook struct { + provider webhooks.Provider +} + +// Config defines the configuration to create a new GitHubWebhook instance +type Config struct { + Provider webhooks.Provider +} + +// Event defines a GitHub hook event type +type Event string + +// GitHub hook types +const ( + // AnyEvent Event = "*" + CommitCommentEvent Event = "commit_comment" + CreateEvent Event = "create" + DeleteEvent Event = "delete" + DeploymentEvent Event = "deployment" + DeploymentStatusEvent Event = "deployment_status" + ForkEvent Event = "fork" + GollumEvent Event = "gollum" + IssueCommentEvent Event = "issue_comment" + IssuesEvent Event = "issues" + MemberEvent Event = "member" + MembershipEvent Event = "membership" + PageBuildEvent Event = "page_build" + PublicEvent Event = "public" + PullRequestReviewCommentEvent Event = "pull_request_review_comment" + PullRequestEvent Event = "pull_request" + PushEvent Event = "push" + RepositoryEvent Event = "repository" + ReleaseEvent Event = "release" + StatusEvent Event = "status" + TeamAddEvent Event = "team_add" + WatchEvent Event = "watch" +) + +// EventSubtype defines a GitHub Hook Event subtype +type EventSubtype string + +// GitHub hook event subtypes +const ( + NoSubtype EventSubtype = "" + BranchSubtype EventSubtype = "branch" + TagSubtype EventSubtype = "tag" + PullSubtype EventSubtype = "pull" + IssueSubtype EventSubtype = "issues" +) + +// Provider returns the Webhook's provider +func (w Webhook) Provider() webhooks.Provider { + return w.provider +} + +// UnderlyingProvider returns the Config's Provider +func (c Config) UnderlyingProvider() webhooks.Provider { + return c.Provider +} + +// New creates and returns a WebHook instance denoted by the Provider type +func New(config *Config) *Webhook { + return &Webhook{ + provider: config.Provider, + } +} diff --git a/github/github_test.go b/github/github_test.go new file mode 100644 index 0000000..0ae31ee --- /dev/null +++ b/github/github_test.go @@ -0,0 +1,306 @@ +package github + +import ( + "encoding/json" + "os" + "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 TestCommitCommentHook(t *testing.T) { + + Equal(t, true, true) + + body := `{ + "action": "created", + "comment": { + "url": "https://api.github.com/repos/baxterthehacker/public-repo/comments/11056394", + "html_url": "https://github.com/baxterthehacker/public-repo/commit/9049f1265b7d61be4a8904a9a27120d2064dab3b#commitcomment-11056394", + "id": 11056394, + "user": { + "login": "baxterthehacker", + "id": 6752317, + "avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3", + "gravatar_id": "", + "url": "https://api.github.com/users/baxterthehacker", + "html_url": "https://github.com/baxterthehacker", + "followers_url": "https://api.github.com/users/baxterthehacker/followers", + "following_url": "https://api.github.com/users/baxterthehacker/following{/other_user}", + "gists_url": "https://api.github.com/users/baxterthehacker/gists{/gist_id}", + "starred_url": "https://api.github.com/users/baxterthehacker/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/baxterthehacker/subscriptions", + "organizations_url": "https://api.github.com/users/baxterthehacker/orgs", + "repos_url": "https://api.github.com/users/baxterthehacker/repos", + "events_url": "https://api.github.com/users/baxterthehacker/events{/privacy}", + "received_events_url": "https://api.github.com/users/baxterthehacker/received_events", + "type": "User", + "site_admin": false + }, + "position": null, + "line": null, + "path": null, + "commit_id": "9049f1265b7d61be4a8904a9a27120d2064dab3b", + "created_at": "2015-05-05T23:40:29Z", + "updated_at": "2015-05-05T23:40:29Z", + "body": "This is a really good change! :+1:" + }, + "repository": { + "id": 35129377, + "name": "public-repo", + "full_name": "baxterthehacker/public-repo", + "owner": { + "login": "baxterthehacker", + "id": 6752317, + "avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3", + "gravatar_id": "", + "url": "https://api.github.com/users/baxterthehacker", + "html_url": "https://github.com/baxterthehacker", + "followers_url": "https://api.github.com/users/baxterthehacker/followers", + "following_url": "https://api.github.com/users/baxterthehacker/following{/other_user}", + "gists_url": "https://api.github.com/users/baxterthehacker/gists{/gist_id}", + "starred_url": "https://api.github.com/users/baxterthehacker/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/baxterthehacker/subscriptions", + "organizations_url": "https://api.github.com/users/baxterthehacker/orgs", + "repos_url": "https://api.github.com/users/baxterthehacker/repos", + "events_url": "https://api.github.com/users/baxterthehacker/events{/privacy}", + "received_events_url": "https://api.github.com/users/baxterthehacker/received_events", + "type": "User", + "site_admin": false + }, + "private": false, + "html_url": "https://github.com/baxterthehacker/public-repo", + "description": "", + "fork": false, + "url": "https://api.github.com/repos/baxterthehacker/public-repo", + "forks_url": "https://api.github.com/repos/baxterthehacker/public-repo/forks", + "keys_url": "https://api.github.com/repos/baxterthehacker/public-repo/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/baxterthehacker/public-repo/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/baxterthehacker/public-repo/teams", + "hooks_url": "https://api.github.com/repos/baxterthehacker/public-repo/hooks", + "issue_events_url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/events{/number}", + "events_url": "https://api.github.com/repos/baxterthehacker/public-repo/events", + "assignees_url": "https://api.github.com/repos/baxterthehacker/public-repo/assignees{/user}", + "branches_url": "https://api.github.com/repos/baxterthehacker/public-repo/branches{/branch}", + "tags_url": "https://api.github.com/repos/baxterthehacker/public-repo/tags", + "blobs_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/baxterthehacker/public-repo/statuses/{sha}", + "languages_url": "https://api.github.com/repos/baxterthehacker/public-repo/languages", + "stargazers_url": "https://api.github.com/repos/baxterthehacker/public-repo/stargazers", + "contributors_url": "https://api.github.com/repos/baxterthehacker/public-repo/contributors", + "subscribers_url": "https://api.github.com/repos/baxterthehacker/public-repo/subscribers", + "subscription_url": "https://api.github.com/repos/baxterthehacker/public-repo/subscription", + "commits_url": "https://api.github.com/repos/baxterthehacker/public-repo/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/baxterthehacker/public-repo/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/baxterthehacker/public-repo/contents/{+path}", + "compare_url": "https://api.github.com/repos/baxterthehacker/public-repo/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/baxterthehacker/public-repo/merges", + "archive_url": "https://api.github.com/repos/baxterthehacker/public-repo/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/baxterthehacker/public-repo/downloads", + "issues_url": "https://api.github.com/repos/baxterthehacker/public-repo/issues{/number}", + "pulls_url": "https://api.github.com/repos/baxterthehacker/public-repo/pulls{/number}", + "milestones_url": "https://api.github.com/repos/baxterthehacker/public-repo/milestones{/number}", + "notifications_url": "https://api.github.com/repos/baxterthehacker/public-repo/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/baxterthehacker/public-repo/labels{/name}", + "releases_url": "https://api.github.com/repos/baxterthehacker/public-repo/releases{/id}", + "created_at": "2015-05-05T23:40:12Z", + "updated_at": "2015-05-05T23:40:12Z", + "pushed_at": "2015-05-05T23:40:27Z", + "git_url": "git://github.com/baxterthehacker/public-repo.git", + "ssh_url": "git@github.com:baxterthehacker/public-repo.git", + "clone_url": "https://github.com/baxterthehacker/public-repo.git", + "svn_url": "https://github.com/baxterthehacker/public-repo", + "homepage": null, + "size": 0, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": true, + "forks_count": 0, + "mirror_url": null, + "open_issues_count": 2, + "forks": 0, + "open_issues": 2, + "watchers": 0, + "default_branch": "master" + }, + "sender": { + "login": "baxterthehacker", + "id": 6752317, + "avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3", + "gravatar_id": "", + "url": "https://api.github.com/users/baxterthehacker", + "html_url": "https://github.com/baxterthehacker", + "followers_url": "https://api.github.com/users/baxterthehacker/followers", + "following_url": "https://api.github.com/users/baxterthehacker/following{/other_user}", + "gists_url": "https://api.github.com/users/baxterthehacker/gists{/gist_id}", + "starred_url": "https://api.github.com/users/baxterthehacker/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/baxterthehacker/subscriptions", + "organizations_url": "https://api.github.com/users/baxterthehacker/orgs", + "repos_url": "https://api.github.com/users/baxterthehacker/repos", + "events_url": "https://api.github.com/users/baxterthehacker/events{/privacy}", + "received_events_url": "https://api.github.com/users/baxterthehacker/received_events", + "type": "User", + "site_admin": false + } +}` + + var cc CommitCommentPayload + + json.Unmarshal([]byte(body), &cc) + + Equal(t, cc.Comment.Line, nil) +} + +func TestCreateHook(t *testing.T) { + + Equal(t, true, true) + + body := `{ + "ref": "0.0.1", + "ref_type": "tag", + "master_branch": "master", + "description": "", + "pusher_type": "user", + "repository": { + "id": 35129377, + "name": "public-repo", + "full_name": "baxterthehacker/public-repo", + "owner": { + "login": "baxterthehacker", + "id": 6752317, + "avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3", + "gravatar_id": "", + "url": "https://api.github.com/users/baxterthehacker", + "html_url": "https://github.com/baxterthehacker", + "followers_url": "https://api.github.com/users/baxterthehacker/followers", + "following_url": "https://api.github.com/users/baxterthehacker/following{/other_user}", + "gists_url": "https://api.github.com/users/baxterthehacker/gists{/gist_id}", + "starred_url": "https://api.github.com/users/baxterthehacker/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/baxterthehacker/subscriptions", + "organizations_url": "https://api.github.com/users/baxterthehacker/orgs", + "repos_url": "https://api.github.com/users/baxterthehacker/repos", + "events_url": "https://api.github.com/users/baxterthehacker/events{/privacy}", + "received_events_url": "https://api.github.com/users/baxterthehacker/received_events", + "type": "User", + "site_admin": false + }, + "private": false, + "html_url": "https://github.com/baxterthehacker/public-repo", + "description": "", + "fork": false, + "url": "https://api.github.com/repos/baxterthehacker/public-repo", + "forks_url": "https://api.github.com/repos/baxterthehacker/public-repo/forks", + "keys_url": "https://api.github.com/repos/baxterthehacker/public-repo/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/baxterthehacker/public-repo/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/baxterthehacker/public-repo/teams", + "hooks_url": "https://api.github.com/repos/baxterthehacker/public-repo/hooks", + "issue_events_url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/events{/number}", + "events_url": "https://api.github.com/repos/baxterthehacker/public-repo/events", + "assignees_url": "https://api.github.com/repos/baxterthehacker/public-repo/assignees{/user}", + "branches_url": "https://api.github.com/repos/baxterthehacker/public-repo/branches{/branch}", + "tags_url": "https://api.github.com/repos/baxterthehacker/public-repo/tags", + "blobs_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/baxterthehacker/public-repo/statuses/{sha}", + "languages_url": "https://api.github.com/repos/baxterthehacker/public-repo/languages", + "stargazers_url": "https://api.github.com/repos/baxterthehacker/public-repo/stargazers", + "contributors_url": "https://api.github.com/repos/baxterthehacker/public-repo/contributors", + "subscribers_url": "https://api.github.com/repos/baxterthehacker/public-repo/subscribers", + "subscription_url": "https://api.github.com/repos/baxterthehacker/public-repo/subscription", + "commits_url": "https://api.github.com/repos/baxterthehacker/public-repo/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/baxterthehacker/public-repo/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/baxterthehacker/public-repo/contents/{+path}", + "compare_url": "https://api.github.com/repos/baxterthehacker/public-repo/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/baxterthehacker/public-repo/merges", + "archive_url": "https://api.github.com/repos/baxterthehacker/public-repo/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/baxterthehacker/public-repo/downloads", + "issues_url": "https://api.github.com/repos/baxterthehacker/public-repo/issues{/number}", + "pulls_url": "https://api.github.com/repos/baxterthehacker/public-repo/pulls{/number}", + "milestones_url": "https://api.github.com/repos/baxterthehacker/public-repo/milestones{/number}", + "notifications_url": "https://api.github.com/repos/baxterthehacker/public-repo/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/baxterthehacker/public-repo/labels{/name}", + "releases_url": "https://api.github.com/repos/baxterthehacker/public-repo/releases{/id}", + "created_at": "2015-05-05T23:40:12Z", + "updated_at": "2015-05-05T23:40:30Z", + "pushed_at": "2015-05-05T23:40:38Z", + "git_url": "git://github.com/baxterthehacker/public-repo.git", + "ssh_url": "git@github.com:baxterthehacker/public-repo.git", + "clone_url": "https://github.com/baxterthehacker/public-repo.git", + "svn_url": "https://github.com/baxterthehacker/public-repo", + "homepage": null, + "size": 0, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": true, + "forks_count": 0, + "mirror_url": null, + "open_issues_count": 2, + "forks": 0, + "open_issues": 2, + "watchers": 0, + "default_branch": "master" + }, + "sender": { + "login": "baxterthehacker", + "id": 6752317, + "avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3", + "gravatar_id": "", + "url": "https://api.github.com/users/baxterthehacker", + "html_url": "https://github.com/baxterthehacker", + "followers_url": "https://api.github.com/users/baxterthehacker/followers", + "following_url": "https://api.github.com/users/baxterthehacker/following{/other_user}", + "gists_url": "https://api.github.com/users/baxterthehacker/gists{/gist_id}", + "starred_url": "https://api.github.com/users/baxterthehacker/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/baxterthehacker/subscriptions", + "organizations_url": "https://api.github.com/users/baxterthehacker/orgs", + "repos_url": "https://api.github.com/users/baxterthehacker/repos", + "events_url": "https://api.github.com/users/baxterthehacker/events{/privacy}", + "received_events_url": "https://api.github.com/users/baxterthehacker/received_events", + "type": "User", + "site_admin": false + } +}` + + var create CreatePayload + + json.Unmarshal([]byte(body), &create) + + Equal(t, create.Repository.Owner.URL, "https://api.github.com/users/baxterthehacker") +} diff --git a/github/payload.go b/github/payload.go new file mode 100644 index 0000000..580e212 --- /dev/null +++ b/github/payload.go @@ -0,0 +1,702 @@ +package github + +import "time" + +// WatchPayload contains the information for GitHub's watch hook event +type WatchPayload struct { + Action string `json:"action"` + Repository Repository `json:"repository"` + Sender Sender `json:"sender"` +} + +// TeamAddPayload contains the information for GitHub's team_add hook event +type TeamAddPayload struct { + Team Team `json:"team"` + Repository Repository `json:"repository"` + Organization Organization `json:"organization"` + Sender Sender `json:"sender"` +} + +// StatusPayload contains the information for GitHub's status hook event +type StatusPayload struct { + ID int `json:"id"` + SHA string `json:"sha"` + Name string `json:"name"` + TragetURL *string `json:"target_url"` + Context string `json:"context"` + Desctiption *string `json:"description"` + State string `json:"state"` + Commit StatusCommit `json:"commit"` + Branches []Branch `json:"branches"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + Repository Repository `json:"repository"` + Sender Sender `json:"sender"` +} + +// ReleasePayload contains the information for GitHub's release hook event +type ReleasePayload struct { + Action string `json:"action"` + Release Release `json:"release"` + Repository Repository `json:"repository"` + Sender Sender `json:"sender"` +} + +// RepositoryPayload contains the information for GitHub's repository hook event +type RepositoryPayload struct { + Action string `json:"action"` + Repository Repository `json:"repository"` + Organization Organization `json:"organization"` + Sender Sender `json:"sender"` +} + +// PushPayload contains the information for GitHub's push hook event +type PushPayload struct { + Ref string `json:"ref"` + Before string `json:"before"` + After string `json:"after"` + Created bool `json:"created"` + Deleted bool `json:"deleted"` + Forced bool `json:"forced"` + BaseRef *string `json:"base_ref"` + Compare string `json:"compare"` + Commits []Commit `json:"commits"` + HeadCommit HeadCommit `json:"head_commit"` + Repository Repository `json:"repository"` + Pusher PusherPush `json:"pusher"` + Sender Sender `json:"sender"` +} + +// PullRequestPayload contains the information for GitHub's pull_request hook event +type PullRequestPayload struct { + Action string `json:"action"` + Number int `json:"number"` + PullRequest PullRequest `json:"pull_request"` + Repository Repository `json:"repository"` + Sender Sender `json:"sender"` +} + +// PullRequestReviewCommentPayload contains the information for GitHub's pull_request_review_comment hook event +type PullRequestReviewCommentPayload struct { + Action string `json:"action"` + Comment PullRequestComment `json:"comment"` + Repository Repository `json:"repository"` + Sender Sender `json:"sender"` +} + +// PublicPayload contains the information for GitHub's public hook event +type PublicPayload struct { + Repository Repository `json:"repository"` + Sender Sender `json:"sender"` +} + +// PageBuildPayload contains the information for GitHub's page_build hook event +type PageBuildPayload struct { + ID int `json:"id"` + Build Build `json:"build"` + Repository Repository `json:"repository"` + Sender Sender `json:"sender"` +} + +// MembershipPayload contains the information for GitHub's membership hook event +type MembershipPayload struct { + Action string `json:"action"` + Scope string `json:"scope"` + Member Member `json:"member"` + Sender Sender `json:"sender"` + Team Team `json:"team"` + Organization Organization `json:"organization"` +} + +// MemberPayload contains the information for GitHub's member hook event +type MemberPayload struct { + Action string `json:"action"` + Member Member `json:"member"` + Repository Repository `json:"repository"` + Sender Sender `json:"sender"` +} + +// IssuesPayload contains the information for GitHub's issues hook event +type IssuesPayload struct { + Action string `json:"action"` + Issue Issue `json:"issue"` + Repository Repository `json:"repository"` + Sender Sender `json:"sender"` +} + +// IssueCommentPayload contains the information for GitHub's issue_comment hook event +type IssueCommentPayload struct { + IssuesPayload + Comment Comment `json:"comment"` +} + +// GollumPayload contains the information for GitHub's gollum hook event +type GollumPayload struct { + Pages []Page `json:"pages"` + Repository Repository `json:"repository"` + Sender Sender `json:"sender"` +} + +// ForkPayload contains the information for GitHub's fork hook event +type ForkPayload struct { + Forkee Forkee `json:"forkee"` + Repository Repository `json:"repository"` + Sender Sender `json:"sender"` +} + +// DeploymentStatusPayload contains the information for GitHub's deployment_status hook event +type DeploymentStatusPayload struct { + Deployment Deployment `json:"deployment"` + DeploymentStatus DeploymentStatus `json:"deployment_status"` + Repository Repository `json:"repository"` + Sender Sender `json:"sender"` +} + +// DeploymentPayload contains the information for GitHub's deployment hook +type DeploymentPayload struct { + Deployment Deployment `json:"deployment"` + Repository Repository `json:"repository"` + Sender Sender `json:"sender"` +} + +// CommitComment contains the information for GitHub's commit_comment hook event +type CommitCommentPayload struct { + Action string `json:"action"` + RefType string `json:"ref_type"` + Comment Comment `json:"comment"` + Repository Repository `json:"repository"` + Sender Sender `json:"sender"` +} + +// DeletePayload contains the information for GitHub's delete hook event +type DeletePayload struct { + Ref string `json:"ref"` + RefType string `json:"ref_type"` + PusherType string `json:"pusher_type"` + Repository Repository `json:"repository"` + Sender Sender `json:"sender"` +} + +// CreatePayload contains the information for GitHub's create hook event +type CreatePayload struct { + Ref string `json:"ref"` + RefType string `json:"ref_type"` + MasterBranch string `json:"master_branch"` + Description string `json:"description"` + PusherType string `json:"pusher_type"` + Repository Repository `json:"repository"` + Sender Sender `json:"sender"` +} + +// Repository contais all of the GitHub repository information +type Repository struct { + ID int `json:"id"` + Name string `json:"name"` + FullName string `json:"full_name"` + Owner Owner `json:"owner"` + Private bool `json:"private"` + HTMLURL string `json:"html_url"` + Description string `json:"description"` + Fork bool `json:"fork"` + URL string `json:"url"` + ForksURL string `json:"forks_url"` + KeysURL string `json:"keys_url"` + CollaboratorsURL string `json:"collaborators_url"` + TeamsURL string `json:"teams_url"` + HooksURL string `json:"hooks_url"` + IssueEventsURL string `json:"issue_events_url"` + EventsURL string `json:"events_url"` + AssigneesURL string `json:"assignees_url"` + BranchesURL string `json:"branches_url"` + TagsURL string `json:"tags_url"` + BlobsURL string `json:"blobs_url"` + GitTagsURL string `json:"git_tags_url"` + GitRefsURL string `json:"git_refs_url"` + TreesURL string `json:"trees_url"` + StatusesURL string `json:"statuses_url"` + LanguagesURL string `json:"languages_url"` + StargazersURL string `json:"stargazers_url"` + ContributorsURL string `json:"contributors_url"` + SubscribersURL string `json:"subscribers_url"` + SubscriptionURL string `json:"subscription_url"` + CommitsURL string `json:"commits_url"` + GitCommitsURL string `json:"git_commits_url"` + CommentsURL string `json:"comments_url"` + IssueCommentURL string `json:"issue_comment_url"` + ContentsURL string `json:"contents_url"` + CompareURL string `json:"compare_url"` + MergesURL string `json:"merges_url"` + ArchiveURL string `json:"archive_url"` + DownloadsURL string `json:"downloads_url"` + IssuesURL string `json:"issues_url"` + PullsURL string `json:"pulls_url"` + MilestonesURL string `json:"milestones_url"` + NotificationsURL string `json:"notifications_url"` + LabelsURL string `json:"labels_url"` + ReleasesURL string `json:"releases_url"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + PushedAt time.Time `json:"pushed_at"` + GitURL string `json:"git_url"` + SSHURL string `json:"ssh_url"` + CloneURL string `json:"clone_url"` + SVNURL string `json:"svn_url"` + Homepage string `json:"homepage"` + Size int `json:"size"` + StargazersCount int `json:"stargazers_count"` + WatchersCount int `json:"watchers_count"` + Language *string `json:"language"` + HasIssues bool `json:"has_issues"` + HasDownloads bool `json:"has_downloads"` + HasWiki bool `json:"has_wiki"` + HasPages bool `json:"has_pages"` + ForksCount int `json:"forks_count"` + MirrorURL string `json:"mirror_url"` + OpenIssuesCount int `json:"open_issues_count"` + Forks int `json:"forks"` + OpenIssues int `json:"open_issues"` + Watchers int `json:"watchers"` + DefaultBranch string `json:"default_branch"` +} + +// // Repo contains GitHub's repo information +// type Repo struct { +// Repository +// } + +// User contains GitHub's user information +type User struct { + Login string `json:"login"` + ID int `json:"id"` + AvatarURL string `json:"avatar_url"` + GravatarID string `json:"gravatar_id"` + URL string `json:"url"` + HTMLURL string `json:"html_url"` + FollowersURL string `json:"followers_url"` + FollowingURL string `json:"following_url"` + GistsURL string `json:"gists_url"` + StarredURL string `json:"starred_url"` + SubscriptionsURL string `json:"subscriptions_url"` + OrganizationsURL string `json:"organizations_url"` + ReposURL string `json:"repos_url"` + EventsURL string `json:"events_url"` + ReceivedEventsURL string `json:"received_events_url"` + Type string `json:"type"` + SiteAdmin bool `json:"site_admin"` +} + +// Member contains GitHub's member information +type Member struct { + User +} + +// Owner contains GitHub's owner information +type Owner struct { + User +} + +// Sender contains GitHub's sender information +type Sender struct { + User +} + +// Creator contains GitHub's creator information +type Creator struct { + User +} + +// Pusher contains GitHub's pusher information +type Pusher struct { + User +} + +// Author contains GitHub's author information +type Author struct { + User +} + +// Commiter contains GitHub's commiter information +type Commiter struct { + User +} + +// Comment contains GitHub's comment information +type Comment struct { + URL string `json:"url"` + HTMLURL string `json:"html_url"` + ID int `json:"id"` + User User `json:"user"` + Position *int `json:"position"` + Line *int `json:"line"` + Path *string `json:"path"` + CommitID string `json:"commit_id"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + Body string `json:"body"` +} + +// Deployment contains GitHub's deployment information +type Deployment struct { + URL string `json:"url"` + ID int `json:"id"` + SHA string `json:"sha"` + Ref string `json:"ref"` + Task string `json:"task"` + //paylod + Environment string `json:"environment"` + Description *string `json:"description"` + Creator Creator `json:"creator"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + StatusesURL string `json:"statuses_url"` + RepositoryURL string `json:"repository_url"` +} + +// DeploymentStatus contains GitHub's deployment_status information +type DeploymentStatus struct { + URL string `json:"url"` + ID int `json:"id"` + State string `json:"state"` + Creator Creator `json:"creator"` + Description *string `json:"description"` + TargetURL string `json:"target_url"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + DeploymentURL string `json:"deployment_url"` + RepositoryURL string `json:"repository_url"` +} + +// Forkee contains GitHub's forkee information +type Forkee struct { + Repository + Public bool `json:"public"` +} + +// Page contains GitHub's page information +type Page struct { + PageName string `json:"page_name"` + Title string `json:"title"` + Summary *string `json:"summary"` + Action string `json:"action"` + SHA string `json:"sha"` + HTMLURL string `json:"html_url"` +} + +// Page contains GitHub's label information +type Label struct { + URL string `json:"url"` + Name string `json:"name"` + Color string `json:"color"` +} + +// Page contains GitHub's issue information +type Issue struct { + URL string `json:"url"` + LabelsURL string `json:"labels_url"` + CommentsURL string `json:"comments_url"` + EventsURL string `json:"events_url"` + HTMLURL string `json:"html_url"` + ID int `json:"id"` + Number int `json:"number"` + Title string `json:"title"` + User User `json:"user"` + Labels []Label `json:"labels"` + State string `json:"state"` + Locked bool `json:"locked"` + Assignee *string `json:"assignee"` + Milestone *string `json:"milestone"` + Comments int `json:"comments"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + ClosedAt time.Time `json:"closed_at"` + Body string `json:"body"` +} + +// Team contains GitHub's team information +type Team struct { + Name string `json:"name"` + ID int `json:"id"` + Slug string `json:"slug"` + Permission string `json:"permission"` + URL string `json:"url"` + MembersURL string `json:"members_url"` + RepositoriesURL string `json:"repositories_url"` +} + +// Organization contains GitHub's organization information +type Organization struct { + Login string `json:"login"` + ID int `json:"id"` + URL string `json:"url"` + ReposURL string `json:"repos_url"` + EventsURL string `json:"events_url"` + MembersURL string `json:"members_url"` + PublicMembersURL string `json:"public_members_url"` + AvatarURL string `json:"avatar_url"` +} + +// Error contains GitHub's error information +type Error struct { + Message string `json:"message"` +} + +// Build contains GitHub's build information +type Build struct { + URL string `json:"url"` + Status string `json:"status"` + Error Error `json:"error"` + Pusher Pusher `json:"pusher"` + Commit string `json:"commit"` + Duration int `json:"duration"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` +} + +// PullRequestHREF contains GitHub's pull_request href information +type PullRequestHREF struct { + HREF string `json:"href"` +} + +// HTML contains GitHub's html information +type HTML struct { + HREF string `json:"href"` +} + +// Self contains GitHub's self information +type Self struct { + HREF string `json:"href"` +} + +// Links contains GitHub's link information +type Links struct { + Self Self `json:"self"` + HTML HTML `json:"html"` + PullRequest PullRequestHREF `json:"pull_request"` +} + +// PullRequestComment contains GitHub's pull request comment information +type PullRequestComment struct { + URL string `json:"url"` + ID int `json:"id"` + DiffHunk string `json:"diff_hunk"` + Path string `json:"path"` + Position int `json:"position"` + OriginalPosition int `json:"original_position"` + CommitID string `json:"commit_id"` + OriginalCommitID string `json:"original_commit_id"` + User User `json:"user"` + Body string `json:"body"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + HTMLURL string `json:"html_url"` + PullRequestURL string `json:"pull_request_url"` + Links Links `json:"links"` +} + +// Head contains GitHub's head information +type Head struct { + Label string `json:"label"` + Ref string `json:"ref"` + SHA string `json:"sha"` + User User `json:"user"` + Repo Repository `json:"repo"` +} + +// Base contains GitHub's base information +type Base struct { + Head +} + +// IssueHREF contains GitHub's issue href information +type IssueHREF struct { + HREF string `json:"href"` +} + +// CommentsHREF contains GitHub's comments href information +type CommentsHREF struct { + HREF string `json:"href"` +} + +// ReviewCommentsHREF contains GitHub's review comments href information +type ReviewCommentsHREF struct { + HREF string `json:"href"` +} + +// ReviewCommentHREF contains GitHub's review comment href information +type ReviewCommentHREF struct { + HREF string `json:"href"` +} + +// CommitsHREF contains GitHub's commits href information +type CommitsHREF struct { + HREF string `json:"href"` +} + +// StatusesHREF contains GitHub's statuses href information +type StatusesHREF struct { + HREF string `json:"href"` +} + +// LinksPullRequest contains GitHub's pull request link information +type LinksPullRequest struct { + Self Self `json:"self"` + HTML HTML `json:"html"` + Issue IssueHREF `json:"issue"` + Comments CommentsHREF `json:"comments"` + ReviewComments ReviewCommentsHREF `json:"review_comments"` + ReviewComment ReviewCommentHREF `json:"review_comment"` + Commits CommitsHREF `json:"commits"` + Statuses StatusesHREF `json:"statuses"` +} + +// PullRequest contains GitHub's pull_request information +type PullRequest struct { + URL string `json:"url"` + ID int `json:"id"` + HTMLURL string `json:"html_url"` + DiffURL string `json:"diff_url"` + PatchURL string `json:"patch_url"` + IssueURL string `json:"issue_url"` + Number int `json:"number"` + State string `json:"state"` + Locked bool `json:"locked"` + Title string `json:"title"` + User User `json:"user"` + Body string `json:"body"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + ClosedAt time.Time `json:"closed_at"` + MergedAt time.Time `json:"merged_at"` + MergeCommitSHA *string `json:"merge_commit_sha"` + Assignee *string `json:"assignee"` + Milestone *string `json:"milestone"` + CommitsURL string `json:"commits_url"` + ReviewCommentsURL string `json:"review_comments_url"` + ReviewCommentURL string `json:"review_comment_url"` + CommentsURL string `json:"comments_url"` + StatusesURL string `json:"statuses_url"` + Head Head `json:"head"` + Base Base `json:"base"` + Links LinksPullRequest `json:"_links"` + Merged bool `json:"merged"` + Mergable *bool `json:"mergeable"` + MergableState string `json:"mergeable_state"` + MergedBy *string `json:"merged_by"` + Comments int `json:"comments"` + ReviewComments int `json:"review_comments"` + Commits int `json:"commits"` + Additions int `json:"additions"` + Deletions int `json:"deletions"` + ChangedFiles int `json:"changed_files"` +} + +// PusherPush contains GitHub's push pusher information +type PusherPush struct { + Name string `json:"name"` + Email string `json:"email"` +} + +// CommitAuthor contains GitHub's commit author information +type CommitAuthor struct { + Name string `json:"name"` + Email string `json:"email"` + Username string `json:"username"` +} + +// CommitCommitter contains GitHub's commit commiter information +type CommitCommitter struct { + CommitAuthor +} + +// Commit contains GitHub's commit information +type Commit struct { + ID string `json:"id"` + Distinct bool `json:"distinct"` + Message string `json:"message"` + Timestamp time.Time `json:"timestamp"` + URL string `json:"url"` + Author CommitAuthor `json:"author"` + Committer CommitCommitter `json:"committer"` + Added []string `json:"added"` + Removed []string `json:"removed"` + Modified []string `json:"modified"` +} + +// HeadCommit contains GitHub's head_commit information +type HeadCommit struct { + Commit +} + +// Release contains GitHub's release information +type Release struct { + URL string `json:"url"` + AssetsURL string `json:"assets_url"` + UploadURL string `json:"upload_url"` + HTMLURL string `json:"html_url"` + ID string `json:"id"` + TagName string `json:"tag_name"` + TargetCommitish string `json:"target_commitish"` + Name *string `json:"name"` + Draft bool `json:"draft"` + Author Author `json:"author"` + Prelelease bool `json:"prerelease"` + CreatedAt time.Time `json:"created_at"` + PublishedAt time.Time `json:"published_at"` + Assets []string `json:"assets"` + TarballURL string `json:"tarball_url"` + ZipballURL string `json:"zipball_url"` + Body *string `json:"body"` +} + +// BranchCommit contains GitHub's branch commit information +type BranchCommit struct { + SHA string `json:"sha"` + URL string `json:"url"` +} + +// Branch contains GitHub's branch information +type Branch struct { + Name string `json:"name"` + Commit BranchCommit `json:"commit"` +} + +// StatusCommitAuthor contains GitHub's status commit author information +type StatusCommitAuthor struct { + Name string `json:"name"` + Email string `json:"email"` + Date time.Time `json:"date"` +} + +// StatusCommitCommiter contains GitHub's status commit committer information +type StatusCommitCommiter struct { + Name string `json:"name"` + Email string `json:"email"` + Date time.Time `json:"date"` +} + +// Tree contains GitHub's tree information +type Tree struct { + BranchCommit +} + +// StatusCommitInner contains GitHub's inner status commit information +type StatusCommitInner struct { + Author StatusCommitAuthor `json:"author"` + Commiter StatusCommitCommiter `jsons:"committer"` + Message string `json:"message"` + Tree Tree `json:"tree"` + URL string `json:"url"` + CommentCount int `json:"comment_count"` +} + +// StatusCommit contains GitHub's status commit information +type StatusCommit struct { + SHA string `json:"sha"` + Commit StatusCommitInner `json:"commit"` + URL string `json:"url"` + HTMLURL string `json:"html_url"` + CommentsURL string `json:"comments_url` + Author Author `json:"author"` + Committer Commiter `json:"committer"` + Parents []string `json:"parents"` +} diff --git a/webhooks.go b/webhooks.go index 9ecfc92..651a190 100644 --- a/webhooks.go +++ b/webhooks.go @@ -19,15 +19,15 @@ type Config interface { } // New creates and returns a WebHook instance denoted by the Provider type -func New(config Config) Webhook { +// func New(config Config) Webhook { - switch config.UnderlyingProvider() { - case GitHub: - c := config.(*GitHubConfig) - return &GitHubWebhook{ - provider: c.Provider, - } - default: - panic("Invalid config type") - } -} +// 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 index aecf7f4..f74aee8 100644 --- a/webhooks_test.go +++ b/webhooks_test.go @@ -2,7 +2,6 @@ package webhooks import ( "os" - "reflect" "testing" . "gopkg.in/go-playground/assert.v1" @@ -31,7 +30,4 @@ func TestMain(m *testing.M) { func TestHooks(t *testing.T) { Equal(t, true, true) - - results := New(&GitHubConfig{Provider: GitHub}) - Equal(t, reflect.TypeOf(results).String(), "*webhooks.GitHubWebhook") }