Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gh webhooks #573

Merged
merged 11 commits into from
Jan 26, 2016
Prev Previous commit
Next Next commit
Remove internal dependancy
  • Loading branch information
jackzampolin committed Jan 26, 2016
commit a70452219bcf92dbcf91cf7838dd414019f80dd6
1 change: 0 additions & 1 deletion Godeps
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ github.com/hashicorp/raft b95f335efee1992886864389183ebda0c0a5d0f6
github.com/hashicorp/raft-boltdb d1e82c1ec3f15ee991f7cc7ffd5b67ff6f5bbaee
github.com/influxdata/influxdb 0e0f85a0c1fd1788ae4f9145531b02c539cfa5b5
github.com/influxdb/influxdb c1d6c14c47dfb4d60878a979fbdd8b526281d3d6
github.com/influxdb/telegraf d3a5cca1bc18f315dacbd9941f1e4556fde86538
github.com/jmespath/go-jmespath c01cf91b011868172fdcd9f41838e80c9d716264
github.com/klauspost/crc32 999f3125931f6557b991b2f8472172bdfa578d38
github.com/lib/pq 8ad2b298cadd691a77015666a5372eae5dbfac8f
Expand Down
91 changes: 45 additions & 46 deletions plugins/inputs/github_webhooks/github_webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/gorilla/mux"
"github.com/influxdata/telegraf/plugins/inputs"
mod "github.com/influxdata/telegraf/plugins/inputs/github_webhooks/models"
)

func init() {
Expand All @@ -23,7 +22,7 @@ type GithubWebhooks struct {
// Lock for the struct
sync.Mutex
// Events buffer to store events between Gather calls
events []mod.Event
events []Event
}

func NewGithubWebhooks() *GithubWebhooks {
Expand Down Expand Up @@ -51,7 +50,7 @@ func (gh *GithubWebhooks) Gather(acc inputs.Accumulator) error {
p := event.NewPoint()
acc.AddFields(gh.MeasurementName, p.Fields(), p.Tags(), p.Time())
}
gh.events = make([]mod.Event, 0)
gh.events = make([]Event, 0)
return nil
}

Expand Down Expand Up @@ -91,188 +90,188 @@ func (gh *GithubWebhooks) eventHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}

func newCommitComment(data []byte) (mod.Event, error) {
commitCommentStruct := mod.CommitCommentEvent{}
func newCommitComment(data []byte) (Event, error) {
commitCommentStruct := CommitCommentEvent{}
err := json.Unmarshal(data, &commitCommentStruct)
if err != nil {
return nil, err
}
return commitCommentStruct, nil
}

func newCreate(data []byte) (mod.Event, error) {
createStruct := mod.CreateEvent{}
func newCreate(data []byte) (Event, error) {
createStruct := CreateEvent{}
err := json.Unmarshal(data, &createStruct)
if err != nil {
return nil, err
}
return createStruct, nil
}

func newDelete(data []byte) (mod.Event, error) {
deleteStruct := mod.DeleteEvent{}
func newDelete(data []byte) (Event, error) {
deleteStruct := DeleteEvent{}
err := json.Unmarshal(data, &deleteStruct)
if err != nil {
return nil, err
}
return deleteStruct, nil
}

func newDeployment(data []byte) (mod.Event, error) {
deploymentStruct := mod.DeploymentEvent{}
func newDeployment(data []byte) (Event, error) {
deploymentStruct := DeploymentEvent{}
err := json.Unmarshal(data, &deploymentStruct)
if err != nil {
return nil, err
}
return deploymentStruct, nil
}

func newDeploymentStatus(data []byte) (mod.Event, error) {
deploymentStatusStruct := mod.DeploymentStatusEvent{}
func newDeploymentStatus(data []byte) (Event, error) {
deploymentStatusStruct := DeploymentStatusEvent{}
err := json.Unmarshal(data, &deploymentStatusStruct)
if err != nil {
return nil, err
}
return deploymentStatusStruct, nil
}

func newFork(data []byte) (mod.Event, error) {
forkStruct := mod.ForkEvent{}
func newFork(data []byte) (Event, error) {
forkStruct := ForkEvent{}
err := json.Unmarshal(data, &forkStruct)
if err != nil {
return nil, err
}
return forkStruct, nil
}

func newGollum(data []byte) (mod.Event, error) {
gollumStruct := mod.GollumEvent{}
func newGollum(data []byte) (Event, error) {
gollumStruct := GollumEvent{}
err := json.Unmarshal(data, &gollumStruct)
if err != nil {
return nil, err
}
return gollumStruct, nil
}

func newIssueComment(data []byte) (mod.Event, error) {
issueCommentStruct := mod.IssueCommentEvent{}
func newIssueComment(data []byte) (Event, error) {
issueCommentStruct := IssueCommentEvent{}
err := json.Unmarshal(data, &issueCommentStruct)
if err != nil {
return nil, err
}
return issueCommentStruct, nil
}

func newIssues(data []byte) (mod.Event, error) {
issuesStruct := mod.IssuesEvent{}
func newIssues(data []byte) (Event, error) {
issuesStruct := IssuesEvent{}
err := json.Unmarshal(data, &issuesStruct)
if err != nil {
return nil, err
}
return issuesStruct, nil
}

func newMember(data []byte) (mod.Event, error) {
memberStruct := mod.MemberEvent{}
func newMember(data []byte) (Event, error) {
memberStruct := MemberEvent{}
err := json.Unmarshal(data, &memberStruct)
if err != nil {
return nil, err
}
return memberStruct, nil
}

func newMembership(data []byte) (mod.Event, error) {
membershipStruct := mod.MembershipEvent{}
func newMembership(data []byte) (Event, error) {
membershipStruct := MembershipEvent{}
err := json.Unmarshal(data, &membershipStruct)
if err != nil {
return nil, err
}
return membershipStruct, nil
}

func newPageBuild(data []byte) (mod.Event, error) {
pageBuildEvent := mod.PageBuildEvent{}
func newPageBuild(data []byte) (Event, error) {
pageBuildEvent := PageBuildEvent{}
err := json.Unmarshal(data, &pageBuildEvent)
if err != nil {
return nil, err
}
return pageBuildEvent, nil
}

func newPublic(data []byte) (mod.Event, error) {
publicEvent := mod.PublicEvent{}
func newPublic(data []byte) (Event, error) {
publicEvent := PublicEvent{}
err := json.Unmarshal(data, &publicEvent)
if err != nil {
return nil, err
}
return publicEvent, nil
}

func newPullRequest(data []byte) (mod.Event, error) {
pullRequestStruct := mod.PullRequestEvent{}
func newPullRequest(data []byte) (Event, error) {
pullRequestStruct := PullRequestEvent{}
err := json.Unmarshal(data, &pullRequestStruct)
if err != nil {
return nil, err
}
return pullRequestStruct, nil
}

func newPullRequestReviewComment(data []byte) (mod.Event, error) {
pullRequestReviewCommentStruct := mod.PullRequestReviewCommentEvent{}
func newPullRequestReviewComment(data []byte) (Event, error) {
pullRequestReviewCommentStruct := PullRequestReviewCommentEvent{}
err := json.Unmarshal(data, &pullRequestReviewCommentStruct)
if err != nil {
return nil, err
}
return pullRequestReviewCommentStruct, nil
}

func newPush(data []byte) (mod.Event, error) {
pushStruct := mod.PushEvent{}
func newPush(data []byte) (Event, error) {
pushStruct := PushEvent{}
err := json.Unmarshal(data, &pushStruct)
if err != nil {
return nil, err
}
return pushStruct, nil
}

func newRelease(data []byte) (mod.Event, error) {
releaseStruct := mod.ReleaseEvent{}
func newRelease(data []byte) (Event, error) {
releaseStruct := ReleaseEvent{}
err := json.Unmarshal(data, &releaseStruct)
if err != nil {
return nil, err
}
return releaseStruct, nil
}

func newRepository(data []byte) (mod.Event, error) {
repositoryStruct := mod.RepositoryEvent{}
func newRepository(data []byte) (Event, error) {
repositoryStruct := RepositoryEvent{}
err := json.Unmarshal(data, &repositoryStruct)
if err != nil {
return nil, err
}
return repositoryStruct, nil
}

func newStatus(data []byte) (mod.Event, error) {
statusStruct := mod.StatusEvent{}
func newStatus(data []byte) (Event, error) {
statusStruct := StatusEvent{}
err := json.Unmarshal(data, &statusStruct)
if err != nil {
return nil, err
}
return statusStruct, nil
}

func newTeamAdd(data []byte) (mod.Event, error) {
teamAddStruct := mod.TeamAddEvent{}
func newTeamAdd(data []byte) (Event, error) {
teamAddStruct := TeamAddEvent{}
err := json.Unmarshal(data, &teamAddStruct)
if err != nil {
return nil, err
}
return teamAddStruct, nil
}

func newWatch(data []byte) (mod.Event, error) {
watchStruct := mod.WatchEvent{}
func newWatch(data []byte) (Event, error) {
watchStruct := WatchEvent{}
err := json.Unmarshal(data, &watchStruct)
if err != nil {
return nil, err
Expand All @@ -288,7 +287,7 @@ func (e *newEventError) Error() string {
return e.s
}

func NewEvent(r []byte, t string) (mod.Event, error) {
func NewEvent(r []byte, t string) (Event, error) {
log.Printf("New %v event recieved", t)
switch t {
case "commit_comment":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models
package github_webhooks

func CommitCommentEventJSON() string {
return `{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models
package github_webhooks

import (
"fmt"
Expand All @@ -8,7 +8,7 @@ import (
"github.com/influxdata/influxdb/client/v2"
)

const meas = "ghWebhooks"
const meas = "github_webhooks"

type Event interface {
NewPoint() *client.Point
Expand Down
Loading