Address PR comments and merge conflicts
This commit is contained in:
parent
89f5b77550
commit
4e5dfa5d33
5
Godeps
5
Godeps
|
@ -18,12 +18,15 @@ github.com/gogo/protobuf c57e439bad574c2e0877ff18d514badcfced004d
|
||||||
github.com/golang/protobuf 2402d76f3d41f928c7902a765dfc872356dd3aad
|
github.com/golang/protobuf 2402d76f3d41f928c7902a765dfc872356dd3aad
|
||||||
github.com/golang/snappy 723cc1e459b8eea2dea4583200fd60757d40097a
|
github.com/golang/snappy 723cc1e459b8eea2dea4583200fd60757d40097a
|
||||||
github.com/gonuts/go-shellquote e842a11b24c6abfb3dd27af69a17f482e4b483c2
|
github.com/gonuts/go-shellquote e842a11b24c6abfb3dd27af69a17f482e4b483c2
|
||||||
|
github.com/gorilla/context 1c83b3eabd45b6d76072b66b746c20815fb2872d
|
||||||
|
github.com/gorilla/mux 26a6070f849969ba72b72256e9f14cf519751690
|
||||||
github.com/hailocab/go-hostpool 50839ee41f32bfca8d03a183031aa634b2dc1c64
|
github.com/hailocab/go-hostpool 50839ee41f32bfca8d03a183031aa634b2dc1c64
|
||||||
github.com/hashicorp/go-msgpack fa3f63826f7c23912c15263591e65d54d080b458
|
github.com/hashicorp/go-msgpack fa3f63826f7c23912c15263591e65d54d080b458
|
||||||
github.com/hashicorp/raft b95f335efee1992886864389183ebda0c0a5d0f6
|
github.com/hashicorp/raft b95f335efee1992886864389183ebda0c0a5d0f6
|
||||||
github.com/hashicorp/raft-boltdb d1e82c1ec3f15ee991f7cc7ffd5b67ff6f5bbaee
|
github.com/hashicorp/raft-boltdb d1e82c1ec3f15ee991f7cc7ffd5b67ff6f5bbaee
|
||||||
github.com/influxdata/influxdb 0e0f85a0c1fd1788ae4f9145531b02c539cfa5b5
|
github.com/influxdata/influxdb 0e0f85a0c1fd1788ae4f9145531b02c539cfa5b5
|
||||||
github.com/influxdb/influxdb 0e0f85a0c1fd1788ae4f9145531b02c539cfa5b5
|
github.com/influxdb/influxdb c1d6c14c47dfb4d60878a979fbdd8b526281d3d6
|
||||||
|
github.com/influxdb/telegraf d3a5cca1bc18f315dacbd9941f1e4556fde86538
|
||||||
github.com/jmespath/go-jmespath c01cf91b011868172fdcd9f41838e80c9d716264
|
github.com/jmespath/go-jmespath c01cf91b011868172fdcd9f41838e80c9d716264
|
||||||
github.com/klauspost/crc32 999f3125931f6557b991b2f8472172bdfa578d38
|
github.com/klauspost/crc32 999f3125931f6557b991b2f8472172bdfa578d38
|
||||||
github.com/lib/pq 8ad2b298cadd691a77015666a5372eae5dbfac8f
|
github.com/lib/pq 8ad2b298cadd691a77015666a5372eae5dbfac8f
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/docker"
|
_ "github.com/influxdata/telegraf/plugins/inputs/docker"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/elasticsearch"
|
_ "github.com/influxdata/telegraf/plugins/inputs/elasticsearch"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/exec"
|
_ "github.com/influxdata/telegraf/plugins/inputs/exec"
|
||||||
|
_ "github.com/influxdata/telegraf/plugins/inputs/github_webhooks"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/haproxy"
|
_ "github.com/influxdata/telegraf/plugins/inputs/haproxy"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/httpjson"
|
_ "github.com/influxdata/telegraf/plugins/inputs/httpjson"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/influxdb"
|
_ "github.com/influxdata/telegraf/plugins/inputs/influxdb"
|
||||||
|
@ -38,5 +39,4 @@ import (
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/twemproxy"
|
_ "github.com/influxdata/telegraf/plugins/inputs/twemproxy"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/zfs"
|
_ "github.com/influxdata/telegraf/plugins/inputs/zfs"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/zookeeper"
|
_ "github.com/influxdata/telegraf/plugins/inputs/zookeeper"
|
||||||
_ "github.com/influxdb/telegraf/plugins/inputs/ghwebhooks"
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package ghwebhooks
|
package github_webhooks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
@ -9,15 +9,15 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
mod "github.com/influxdb/support-tools/ghWebhooks/models"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
"github.com/influxdb/telegraf/plugins/inputs"
|
mod "github.com/influxdata/telegraf/plugins/inputs/ghWebhooks/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
inputs.Add("ghwebhooks", func() inputs.Input { return &GHWebhooks{} })
|
inputs.Add("github_webhooks", func() inputs.Input { return &GithubWebhooks{} })
|
||||||
}
|
}
|
||||||
|
|
||||||
type GHWebhooks struct {
|
type GithubWebhooks struct {
|
||||||
ServiceAddress string
|
ServiceAddress string
|
||||||
MeasurementName string
|
MeasurementName string
|
||||||
// Lock for the struct
|
// Lock for the struct
|
||||||
|
@ -26,25 +26,25 @@ type GHWebhooks struct {
|
||||||
events []mod.Event
|
events []mod.Event
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGHWebhooks() *GHWebhooks {
|
func NewGithubWebhooks() *GithubWebhooks {
|
||||||
return &GHWebhooks{}
|
return &GithubWebhooks{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gh *GHWebhooks) SampleConfig() string {
|
func (gh *GithubWebhooks) SampleConfig() string {
|
||||||
return `
|
return `
|
||||||
# Address and port to host Webhook listener on
|
# Address and port to host Webhook listener on
|
||||||
service_address = ":1618"
|
service_address = ":1618"
|
||||||
# Measurement name
|
# Measurement name
|
||||||
measurement_name = "ghwebhooks"
|
measurement_name = "github_webhooks"
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gh *GHWebhooks) Description() string {
|
func (gh *GithubWebhooks) Description() string {
|
||||||
return "A Github Webhook Event collector"
|
return "A Github Webhook Event collector"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Writes the points from <-gh.in to the Accumulator
|
// Writes the points from <-gh.in to the Accumulator
|
||||||
func (gh *GHWebhooks) Gather(acc inputs.Accumulator) error {
|
func (gh *GithubWebhooks) Gather(acc inputs.Accumulator) error {
|
||||||
gh.Lock()
|
gh.Lock()
|
||||||
defer gh.Unlock()
|
defer gh.Unlock()
|
||||||
for _, event := range gh.events {
|
for _, event := range gh.events {
|
||||||
|
@ -55,7 +55,7 @@ func (gh *GHWebhooks) Gather(acc inputs.Accumulator) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gh *GHWebhooks) Listen() {
|
func (gh *GithubWebhooks) Listen() {
|
||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
r.HandleFunc("/", gh.eventHandler).Methods("POST")
|
r.HandleFunc("/", gh.eventHandler).Methods("POST")
|
||||||
err := http.ListenAndServe(fmt.Sprintf("%s", gh.ServiceAddress), r)
|
err := http.ListenAndServe(fmt.Sprintf("%s", gh.ServiceAddress), r)
|
||||||
|
@ -64,18 +64,18 @@ func (gh *GHWebhooks) Listen() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gh *GHWebhooks) Start() error {
|
func (gh *GithubWebhooks) Start() error {
|
||||||
go gh.Listen()
|
go gh.Listen()
|
||||||
log.Printf("Started the ghwebhooks service on %s\n", gh.ServiceAddress)
|
log.Printf("Started the github_webhooks service on %s\n", gh.ServiceAddress)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gh *GHWebhooks) Stop() {
|
func (gh *GithubWebhooks) Stop() {
|
||||||
log.Println("Stopping the ghWebhooks service")
|
log.Println("Stopping the ghWebhooks service")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handles the / route
|
// Handles the / route
|
||||||
func (gh *GHWebhooks) eventHandler(w http.ResponseWriter, r *http.Request) {
|
func (gh *GithubWebhooks) eventHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
eventType := r.Header["X-Github-Event"][0]
|
eventType := r.Header["X-Github-Event"][0]
|
||||||
data, err := ioutil.ReadAll(r.Body)
|
data, err := ioutil.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
|
@ -1,4 +1,4 @@
|
||||||
package ghwebhooks
|
package github_webhooks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -6,12 +6,12 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
mod "github.com/influxdb/telegraf/plugins/inputs/ghwebhooks/models"
|
mod "github.com/influxdata/telegraf/plugins/inputs/ghwebhooks/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCommitCommentEvent(t *testing.T) {
|
func TestCommitCommentEvent(t *testing.T) {
|
||||||
gh := NewGHWebhooks()
|
gh := NewGithubWebhooks()
|
||||||
jsonString := mod.Mock{}.CommitCommentEventJSON()
|
jsonString := mod.CommitCommentEventJSON()
|
||||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
req.Header.Add("X-Github-Event", "commit_comment")
|
req.Header.Add("X-Github-Event", "commit_comment")
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
@ -22,8 +22,8 @@ func TestCommitCommentEvent(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeleteEvent(t *testing.T) {
|
func TestDeleteEvent(t *testing.T) {
|
||||||
gh := NewGHWebhooks()
|
gh := NewGithubWebhooks()
|
||||||
jsonString := mod.Mock{}.DeleteEventJSON()
|
jsonString := mod.DeleteEventJSON()
|
||||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
req.Header.Add("X-Github-Event", "delete")
|
req.Header.Add("X-Github-Event", "delete")
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
@ -34,8 +34,8 @@ func TestDeleteEvent(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeploymentEvent(t *testing.T) {
|
func TestDeploymentEvent(t *testing.T) {
|
||||||
gh := NewGHWebhooks()
|
gh := NewGithubWebhooks()
|
||||||
jsonString := mod.Mock{}.DeploymentEventJSON()
|
jsonString := mod.DeploymentEventJSON()
|
||||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
req.Header.Add("X-Github-Event", "deployment")
|
req.Header.Add("X-Github-Event", "deployment")
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
@ -46,8 +46,8 @@ func TestDeploymentEvent(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeploymentStatusEvent(t *testing.T) {
|
func TestDeploymentStatusEvent(t *testing.T) {
|
||||||
gh := NewGHWebhooks()
|
gh := NewGithubWebhooks()
|
||||||
jsonString := mod.Mock{}.DeploymentStatusEventJSON()
|
jsonString := mod.DeploymentStatusEventJSON()
|
||||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
req.Header.Add("X-Github-Event", "deployment_status")
|
req.Header.Add("X-Github-Event", "deployment_status")
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
@ -58,8 +58,8 @@ func TestDeploymentStatusEvent(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestForkEvent(t *testing.T) {
|
func TestForkEvent(t *testing.T) {
|
||||||
gh := NewGHWebhooks()
|
gh := NewGithubWebhooks()
|
||||||
jsonString := mod.Mock{}.ForkEventJSON()
|
jsonString := mod.ForkEventJSON()
|
||||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
req.Header.Add("X-Github-Event", "fork")
|
req.Header.Add("X-Github-Event", "fork")
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
@ -70,8 +70,8 @@ func TestForkEvent(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGollumEvent(t *testing.T) {
|
func TestGollumEvent(t *testing.T) {
|
||||||
gh := NewGHWebhooks()
|
gh := NewGithubWebhooks()
|
||||||
jsonString := mod.Mock{}.GollumEventJSON()
|
jsonString := mod.GollumEventJSON()
|
||||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
req.Header.Add("X-Github-Event", "gollum")
|
req.Header.Add("X-Github-Event", "gollum")
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
@ -82,8 +82,8 @@ func TestGollumEvent(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIssueCommentEvent(t *testing.T) {
|
func TestIssueCommentEvent(t *testing.T) {
|
||||||
gh := NewGHWebhooks()
|
gh := NewGithubWebhooks()
|
||||||
jsonString := mod.Mock{}.IssueCommentEventJSON()
|
jsonString := mod.IssueCommentEventJSON()
|
||||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
req.Header.Add("X-Github-Event", "issue_comment")
|
req.Header.Add("X-Github-Event", "issue_comment")
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
@ -94,8 +94,8 @@ func TestIssueCommentEvent(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIssuesEvent(t *testing.T) {
|
func TestIssuesEvent(t *testing.T) {
|
||||||
gh := NewGHWebhooks()
|
gh := NewGithubWebhooks()
|
||||||
jsonString := mod.Mock{}.IssuesEventJSON()
|
jsonString := mod.IssuesEventJSON()
|
||||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
req.Header.Add("X-Github-Event", "issues")
|
req.Header.Add("X-Github-Event", "issues")
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
@ -106,8 +106,8 @@ func TestIssuesEvent(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMemberEvent(t *testing.T) {
|
func TestMemberEvent(t *testing.T) {
|
||||||
gh := NewGHWebhooks()
|
gh := NewGithubWebhooks()
|
||||||
jsonString := mod.Mock{}.MemberEventJSON()
|
jsonString := mod.MemberEventJSON()
|
||||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
req.Header.Add("X-Github-Event", "member")
|
req.Header.Add("X-Github-Event", "member")
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
@ -118,8 +118,8 @@ func TestMemberEvent(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMembershipEvent(t *testing.T) {
|
func TestMembershipEvent(t *testing.T) {
|
||||||
gh := NewGHWebhooks()
|
gh := NewGithubWebhooks()
|
||||||
jsonString := mod.Mock{}.MembershipEventJSON()
|
jsonString := mod.MembershipEventJSON()
|
||||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
req.Header.Add("X-Github-Event", "membership")
|
req.Header.Add("X-Github-Event", "membership")
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
@ -130,8 +130,8 @@ func TestMembershipEvent(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPageBuildEvent(t *testing.T) {
|
func TestPageBuildEvent(t *testing.T) {
|
||||||
gh := NewGHWebhooks()
|
gh := NewGithubWebhooks()
|
||||||
jsonString := mod.Mock{}.PageBuildEventJSON()
|
jsonString := mod.PageBuildEventJSON()
|
||||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
req.Header.Add("X-Github-Event", "page_build")
|
req.Header.Add("X-Github-Event", "page_build")
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
@ -142,8 +142,8 @@ func TestPageBuildEvent(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPublicEvent(t *testing.T) {
|
func TestPublicEvent(t *testing.T) {
|
||||||
gh := NewGHWebhooks()
|
gh := NewGithubWebhooks()
|
||||||
jsonString := mod.Mock{}.PublicEventJSON()
|
jsonString := mod.PublicEventJSON()
|
||||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
req.Header.Add("X-Github-Event", "public")
|
req.Header.Add("X-Github-Event", "public")
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
@ -154,8 +154,8 @@ func TestPublicEvent(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPullRequestReviewCommentEvent(t *testing.T) {
|
func TestPullRequestReviewCommentEvent(t *testing.T) {
|
||||||
gh := NewGHWebhooks()
|
gh := NewGithubWebhooks()
|
||||||
jsonString := mod.Mock{}.PullRequestReviewCommentEventJSON()
|
jsonString := mod.PullRequestReviewCommentEventJSON()
|
||||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
req.Header.Add("X-Github-Event", "pull_request_review_comment")
|
req.Header.Add("X-Github-Event", "pull_request_review_comment")
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
@ -166,8 +166,8 @@ func TestPullRequestReviewCommentEvent(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPushEvent(t *testing.T) {
|
func TestPushEvent(t *testing.T) {
|
||||||
gh := NewGHWebhooks()
|
gh := NewGithubWebhooks()
|
||||||
jsonString := mod.Mock{}.PushEventJSON()
|
jsonString := mod.PushEventJSON()
|
||||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
req.Header.Add("X-Github-Event", "push")
|
req.Header.Add("X-Github-Event", "push")
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
@ -178,8 +178,8 @@ func TestPushEvent(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReleaseEvent(t *testing.T) {
|
func TestReleaseEvent(t *testing.T) {
|
||||||
gh := NewGHWebhooks()
|
gh := NewGithubWebhooks()
|
||||||
jsonString := mod.Mock{}.ReleaseEventJSON()
|
jsonString := mod.ReleaseEventJSON()
|
||||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
req.Header.Add("X-Github-Event", "release")
|
req.Header.Add("X-Github-Event", "release")
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
@ -190,8 +190,8 @@ func TestReleaseEvent(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRepositoryEvent(t *testing.T) {
|
func TestRepositoryEvent(t *testing.T) {
|
||||||
gh := NewGHWebhooks()
|
gh := NewGithubWebhooks()
|
||||||
jsonString := mod.Mock{}.RepositoryEventJSON()
|
jsonString := mod.RepositoryEventJSON()
|
||||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
req.Header.Add("X-Github-Event", "repository")
|
req.Header.Add("X-Github-Event", "repository")
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
@ -202,8 +202,9 @@ func TestRepositoryEvent(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStatusEvent(t *testing.T) {
|
func TestStatusEvent(t *testing.T) {
|
||||||
gh := NewGHWebhooks()
|
gh := NewGithubWebhooks()
|
||||||
jsonString := mod.Mock{}.StatusEventJSON()
|
|
||||||
|
jsonString := mod.StatusEventJSON()
|
||||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
req.Header.Add("X-Github-Event", "status")
|
req.Header.Add("X-Github-Event", "status")
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
@ -214,8 +215,8 @@ func TestStatusEvent(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTeamAddEvent(t *testing.T) {
|
func TestTeamAddEvent(t *testing.T) {
|
||||||
gh := NewGHWebhooks()
|
gh := NewGithubWebhooks()
|
||||||
jsonString := mod.Mock{}.TeamAddEventJSON()
|
jsonString := mod.TeamAddEventJSON()
|
||||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
req.Header.Add("X-Github-Event", "team_add")
|
req.Header.Add("X-Github-Event", "team_add")
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
@ -226,8 +227,8 @@ func TestTeamAddEvent(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWatchEvent(t *testing.T) {
|
func TestWatchEvent(t *testing.T) {
|
||||||
gh := NewGHWebhooks()
|
gh := NewGithubWebhooks()
|
||||||
jsonString := mod.Mock{}.WatchEventJSON()
|
jsonString := mod.WatchEventJSON()
|
||||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
req.Header.Add("X-Github-Event", "watch")
|
req.Header.Add("X-Github-Event", "watch")
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
|
@ -1,8 +1,6 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
type Mock struct{}
|
func CommitCommentEventJSON() string {
|
||||||
|
|
||||||
func (_ Mock) CommitCommentEventJSON() string {
|
|
||||||
return `{
|
return `{
|
||||||
"action": "created",
|
"action": "created",
|
||||||
"comment": {
|
"comment": {
|
||||||
|
@ -145,7 +143,7 @@ func (_ Mock) CommitCommentEventJSON() string {
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ Mock) CreateEventJSON() string {
|
func CreateEventJSON() string {
|
||||||
return `{
|
return `{
|
||||||
"ref": "0.0.1",
|
"ref": "0.0.1",
|
||||||
"ref_type": "tag",
|
"ref_type": "tag",
|
||||||
|
@ -261,7 +259,7 @@ func (_ Mock) CreateEventJSON() string {
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ Mock) DeleteEventJSON() string {
|
func DeleteEventJSON() string {
|
||||||
return `{
|
return `{
|
||||||
"ref": "simple-tag",
|
"ref": "simple-tag",
|
||||||
"ref_type": "tag",
|
"ref_type": "tag",
|
||||||
|
@ -375,7 +373,7 @@ func (_ Mock) DeleteEventJSON() string {
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ Mock) DeploymentEventJSON() string {
|
func DeploymentEventJSON() string {
|
||||||
return `{
|
return `{
|
||||||
"deployment": {
|
"deployment": {
|
||||||
"url": "https://api.github.com/repos/baxterthehacker/public-repo/deployments/710692",
|
"url": "https://api.github.com/repos/baxterthehacker/public-repo/deployments/710692",
|
||||||
|
@ -520,7 +518,7 @@ func (_ Mock) DeploymentEventJSON() string {
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ Mock) DeploymentStatusEventJSON() string {
|
func DeploymentStatusEventJSON() string {
|
||||||
return `{
|
return `{
|
||||||
"deployment": {
|
"deployment": {
|
||||||
"url": "https://api.github.com/repos/baxterthehacker/public-repo/deployments/710692",
|
"url": "https://api.github.com/repos/baxterthehacker/public-repo/deployments/710692",
|
||||||
|
@ -696,7 +694,7 @@ func (_ Mock) DeploymentStatusEventJSON() string {
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ Mock) ForkEventJSON() string {
|
func ForkEventJSON() string {
|
||||||
return `{
|
return `{
|
||||||
"forkee": {
|
"forkee": {
|
||||||
"id": 35129393,
|
"id": 35129393,
|
||||||
|
@ -895,7 +893,7 @@ func (_ Mock) ForkEventJSON() string {
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ Mock) GollumEventJSON() string {
|
func GollumEventJSON() string {
|
||||||
return `{
|
return `{
|
||||||
"pages": [
|
"pages": [
|
||||||
{
|
{
|
||||||
|
@ -1016,7 +1014,7 @@ func (_ Mock) GollumEventJSON() string {
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ Mock) IssueCommentEventJSON() string {
|
func IssueCommentEventJSON() string {
|
||||||
return `{
|
return `{
|
||||||
"action": "created",
|
"action": "created",
|
||||||
"issue": {
|
"issue": {
|
||||||
|
@ -1201,7 +1199,7 @@ func (_ Mock) IssueCommentEventJSON() string {
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ Mock) IssuesEventJSON() string {
|
func IssuesEventJSON() string {
|
||||||
return `{
|
return `{
|
||||||
"action": "opened",
|
"action": "opened",
|
||||||
"issue": {
|
"issue": {
|
||||||
|
@ -1358,7 +1356,7 @@ func (_ Mock) IssuesEventJSON() string {
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ Mock) MemberEventJSON() string {
|
func MemberEventJSON() string {
|
||||||
return `{
|
return `{
|
||||||
"action": "added",
|
"action": "added",
|
||||||
"member": {
|
"member": {
|
||||||
|
@ -1489,7 +1487,7 @@ func (_ Mock) MemberEventJSON() string {
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ Mock) MembershipEventJSON() string {
|
func MembershipEventJSON() string {
|
||||||
return `{
|
return `{
|
||||||
"action": "added",
|
"action": "added",
|
||||||
"scope": "team",
|
"scope": "team",
|
||||||
|
@ -1553,7 +1551,7 @@ func (_ Mock) MembershipEventJSON() string {
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ Mock) PageBuildEventJSON() string {
|
func PageBuildEventJSON() string {
|
||||||
return `{
|
return `{
|
||||||
"id": 15995382,
|
"id": 15995382,
|
||||||
"build": {
|
"build": {
|
||||||
|
@ -1695,7 +1693,7 @@ func (_ Mock) PageBuildEventJSON() string {
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ Mock) PublicEventJSON() string {
|
func PublicEventJSON() string {
|
||||||
return `{
|
return `{
|
||||||
"repository": {
|
"repository": {
|
||||||
"id": 35129377,
|
"id": 35129377,
|
||||||
|
@ -1806,7 +1804,7 @@ func (_ Mock) PublicEventJSON() string {
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ Mock) PullRequestReviewCommentEventJSON() string {
|
func PullRequestReviewCommentEventJSON() string {
|
||||||
return `{
|
return `{
|
||||||
"action": "created",
|
"action": "created",
|
||||||
"comment": {
|
"comment": {
|
||||||
|
@ -2255,7 +2253,7 @@ func (_ Mock) PullRequestReviewCommentEventJSON() string {
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ Mock) PullRequestEventJSON() string {
|
func PullRequestEventJSON() string {
|
||||||
return `{
|
return `{
|
||||||
"action": "opened",
|
"action": "opened",
|
||||||
"number": 1,
|
"number": 1,
|
||||||
|
@ -2670,7 +2668,7 @@ func (_ Mock) PullRequestEventJSON() string {
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ Mock) PushEventJSON() string {
|
func PushEventJSON() string {
|
||||||
return `{
|
return `{
|
||||||
"ref": "refs/heads/changes",
|
"ref": "refs/heads/changes",
|
||||||
"before": "9049f1265b7d61be4a8904a9a27120d2064dab3b",
|
"before": "9049f1265b7d61be4a8904a9a27120d2064dab3b",
|
||||||
|
@ -2834,7 +2832,7 @@ func (_ Mock) PushEventJSON() string {
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ Mock) RepositoryEventJSON() string {
|
func RepositoryEventJSON() string {
|
||||||
return `{
|
return `{
|
||||||
"action": "created",
|
"action": "created",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -2956,7 +2954,7 @@ func (_ Mock) RepositoryEventJSON() string {
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ Mock) ReleaseEventJSON() string {
|
func ReleaseEventJSON() string {
|
||||||
return `{
|
return `{
|
||||||
"action": "published",
|
"action": "published",
|
||||||
"release": {
|
"release": {
|
||||||
|
@ -3107,7 +3105,7 @@ func (_ Mock) ReleaseEventJSON() string {
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ Mock) StatusEventJSON() string {
|
func StatusEventJSON() string {
|
||||||
return `{
|
return `{
|
||||||
"id": 214015194,
|
"id": 214015194,
|
||||||
"sha": "9049f1265b7d61be4a8904a9a27120d2064dab3b",
|
"sha": "9049f1265b7d61be4a8904a9a27120d2064dab3b",
|
||||||
|
@ -3316,7 +3314,7 @@ func (_ Mock) StatusEventJSON() string {
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ Mock) TeamAddEventJSON() string {
|
func TeamAddEventJSON() string {
|
||||||
return `{
|
return `{
|
||||||
"team": {
|
"team": {
|
||||||
"name": "github",
|
"name": "github",
|
||||||
|
@ -3448,7 +3446,7 @@ func (_ Mock) TeamAddEventJSON() string {
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ Mock) WatchEventJSON() string {
|
func WatchEventJSON() string {
|
||||||
return `{
|
return `{
|
||||||
"action": "started",
|
"action": "started",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
@ -5,14 +5,13 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/influxdb/influxdb/client/v2"
|
"github.com/influxdata/influxdb/client/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const meas = "ghWebhooks"
|
const meas = "ghWebhooks"
|
||||||
|
|
||||||
type Event interface {
|
type Event interface {
|
||||||
NewPoint() *client.Point
|
NewPoint() *client.Point
|
||||||
JSON() string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
|
|
|
@ -0,0 +1,338 @@
|
||||||
|
package github_webhooks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
|
mod "github.com/influxdata/telegraf/plugins/inputs/github_webhooks/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
inputs.Add("github_webhooks", func() inputs.Input { return &GithubWebhooks{} })
|
||||||
|
}
|
||||||
|
|
||||||
|
type GithubWebhooks struct {
|
||||||
|
ServiceAddress string
|
||||||
|
MeasurementName string
|
||||||
|
// Lock for the struct
|
||||||
|
sync.Mutex
|
||||||
|
// Events buffer to store events between Gather calls
|
||||||
|
events []mod.Event
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGithubWebhooks() *GithubWebhooks {
|
||||||
|
return &GithubWebhooks{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gh *GithubWebhooks) SampleConfig() string {
|
||||||
|
return `
|
||||||
|
# Address and port to host Webhook listener on
|
||||||
|
service_address = ":1618"
|
||||||
|
# Measurement name
|
||||||
|
measurement_name = "github_webhooks"
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gh *GithubWebhooks) Description() string {
|
||||||
|
return "A Github Webhook Event collector"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Writes the points from <-gh.in to the Accumulator
|
||||||
|
func (gh *GithubWebhooks) Gather(acc inputs.Accumulator) error {
|
||||||
|
gh.Lock()
|
||||||
|
defer gh.Unlock()
|
||||||
|
for _, event := range gh.events {
|
||||||
|
p := event.NewPoint()
|
||||||
|
acc.AddFields(gh.MeasurementName, p.Fields(), p.Tags(), p.Time())
|
||||||
|
}
|
||||||
|
gh.events = make([]mod.Event, 0)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gh *GithubWebhooks) Listen() {
|
||||||
|
r := mux.NewRouter()
|
||||||
|
r.HandleFunc("/", gh.eventHandler).Methods("POST")
|
||||||
|
err := http.ListenAndServe(fmt.Sprintf("%s", gh.ServiceAddress), r)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error starting server: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gh *GithubWebhooks) Start() error {
|
||||||
|
go gh.Listen()
|
||||||
|
log.Printf("Started the github_webhooks service on %s\n", gh.ServiceAddress)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gh *GithubWebhooks) Stop() {
|
||||||
|
log.Println("Stopping the ghWebhooks service")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handles the / route
|
||||||
|
func (gh *GithubWebhooks) eventHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
eventType := r.Header["X-Github-Event"][0]
|
||||||
|
data, err := ioutil.ReadAll(r.Body)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
e, err := NewEvent(data, eventType)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
gh.Lock()
|
||||||
|
gh.events = append(gh.events, e)
|
||||||
|
gh.Unlock()
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newCommitComment(data []byte) (mod.Event, error) {
|
||||||
|
commitCommentStruct := mod.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{}
|
||||||
|
err := json.Unmarshal(data, &createStruct)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return createStruct, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func newDelete(data []byte) (mod.Event, error) {
|
||||||
|
deleteStruct := mod.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{}
|
||||||
|
err := json.Unmarshal(data, &deploymentStruct)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return deploymentStruct, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func newDeploymentStatus(data []byte) (mod.Event, error) {
|
||||||
|
deploymentStatusStruct := mod.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{}
|
||||||
|
err := json.Unmarshal(data, &forkStruct)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return forkStruct, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func newGollum(data []byte) (mod.Event, error) {
|
||||||
|
gollumStruct := mod.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{}
|
||||||
|
err := json.Unmarshal(data, &issueCommentStruct)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return issueCommentStruct, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func newIssues(data []byte) (mod.Event, error) {
|
||||||
|
issuesStruct := mod.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{}
|
||||||
|
err := json.Unmarshal(data, &memberStruct)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return memberStruct, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func newMembership(data []byte) (mod.Event, error) {
|
||||||
|
membershipStruct := mod.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{}
|
||||||
|
err := json.Unmarshal(data, &pageBuildEvent)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return pageBuildEvent, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func newPublic(data []byte) (mod.Event, error) {
|
||||||
|
publicEvent := mod.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{}
|
||||||
|
err := json.Unmarshal(data, &pullRequestStruct)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return pullRequestStruct, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func newPullRequestReviewComment(data []byte) (mod.Event, error) {
|
||||||
|
pullRequestReviewCommentStruct := mod.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{}
|
||||||
|
err := json.Unmarshal(data, &pushStruct)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return pushStruct, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func newRelease(data []byte) (mod.Event, error) {
|
||||||
|
releaseStruct := mod.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{}
|
||||||
|
err := json.Unmarshal(data, &repositoryStruct)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return repositoryStruct, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func newStatus(data []byte) (mod.Event, error) {
|
||||||
|
statusStruct := mod.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{}
|
||||||
|
err := json.Unmarshal(data, &teamAddStruct)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return teamAddStruct, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func newWatch(data []byte) (mod.Event, error) {
|
||||||
|
watchStruct := mod.WatchEvent{}
|
||||||
|
err := json.Unmarshal(data, &watchStruct)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return watchStruct, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type newEventError struct {
|
||||||
|
s string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *newEventError) Error() string {
|
||||||
|
return e.s
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEvent(r []byte, t string) (mod.Event, error) {
|
||||||
|
log.Printf("New %v event recieved", t)
|
||||||
|
switch t {
|
||||||
|
case "commit_comment":
|
||||||
|
return newCommitComment(r)
|
||||||
|
case "create":
|
||||||
|
return newCreate(r)
|
||||||
|
case "delete":
|
||||||
|
return newDelete(r)
|
||||||
|
case "deployment":
|
||||||
|
return newDeployment(r)
|
||||||
|
case "deployment_status":
|
||||||
|
return newDeploymentStatus(r)
|
||||||
|
case "fork":
|
||||||
|
return newFork(r)
|
||||||
|
case "gollum":
|
||||||
|
return newGollum(r)
|
||||||
|
case "issue_comment":
|
||||||
|
return newIssueComment(r)
|
||||||
|
case "issues":
|
||||||
|
return newIssues(r)
|
||||||
|
case "member":
|
||||||
|
return newMember(r)
|
||||||
|
case "membership":
|
||||||
|
return newMembership(r)
|
||||||
|
case "page_build":
|
||||||
|
return newPageBuild(r)
|
||||||
|
case "public":
|
||||||
|
return newPublic(r)
|
||||||
|
case "pull_request":
|
||||||
|
return newPullRequest(r)
|
||||||
|
case "pull_request_review_comment":
|
||||||
|
return newPullRequestReviewComment(r)
|
||||||
|
case "push":
|
||||||
|
return newPush(r)
|
||||||
|
case "release":
|
||||||
|
return newRelease(r)
|
||||||
|
case "repository":
|
||||||
|
return newRepository(r)
|
||||||
|
case "status":
|
||||||
|
return newStatus(r)
|
||||||
|
case "team_add":
|
||||||
|
return newTeamAdd(r)
|
||||||
|
case "watch":
|
||||||
|
return newWatch(r)
|
||||||
|
}
|
||||||
|
return nil, &newEventError{"Not a recgonized event type"}
|
||||||
|
}
|
|
@ -0,0 +1,239 @@
|
||||||
|
package github_webhooks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
mod "github.com/influxdata/telegraf/plugins/inputs/github_webhooks/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCommitCommentEvent(t *testing.T) {
|
||||||
|
gh := NewGithubWebhooks()
|
||||||
|
jsonString := mod.CommitCommentEventJSON()
|
||||||
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
|
req.Header.Add("X-Github-Event", "commit_comment")
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
gh.eventHandler(w, req)
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("POST commit_comment returned HTTP status code %v.\nExpected %v", w.Code, http.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDeleteEvent(t *testing.T) {
|
||||||
|
gh := NewGithubWebhooks()
|
||||||
|
jsonString := mod.DeleteEventJSON()
|
||||||
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
|
req.Header.Add("X-Github-Event", "delete")
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
gh.eventHandler(w, req)
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("POST commit_comment returned HTTP status code %v.\nExpected %v", w.Code, http.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDeploymentEvent(t *testing.T) {
|
||||||
|
gh := NewGithubWebhooks()
|
||||||
|
jsonString := mod.DeploymentEventJSON()
|
||||||
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
|
req.Header.Add("X-Github-Event", "deployment")
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
gh.eventHandler(w, req)
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("POST commit_comment returned HTTP status code %v.\nExpected %v", w.Code, http.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDeploymentStatusEvent(t *testing.T) {
|
||||||
|
gh := NewGithubWebhooks()
|
||||||
|
jsonString := mod.DeploymentStatusEventJSON()
|
||||||
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
|
req.Header.Add("X-Github-Event", "deployment_status")
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
gh.eventHandler(w, req)
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("POST commit_comment returned HTTP status code %v.\nExpected %v", w.Code, http.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestForkEvent(t *testing.T) {
|
||||||
|
gh := NewGithubWebhooks()
|
||||||
|
jsonString := mod.ForkEventJSON()
|
||||||
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
|
req.Header.Add("X-Github-Event", "fork")
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
gh.eventHandler(w, req)
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("POST commit_comment returned HTTP status code %v.\nExpected %v", w.Code, http.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGollumEvent(t *testing.T) {
|
||||||
|
gh := NewGithubWebhooks()
|
||||||
|
jsonString := mod.GollumEventJSON()
|
||||||
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
|
req.Header.Add("X-Github-Event", "gollum")
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
gh.eventHandler(w, req)
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("POST commit_comment returned HTTP status code %v.\nExpected %v", w.Code, http.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIssueCommentEvent(t *testing.T) {
|
||||||
|
gh := NewGithubWebhooks()
|
||||||
|
jsonString := mod.IssueCommentEventJSON()
|
||||||
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
|
req.Header.Add("X-Github-Event", "issue_comment")
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
gh.eventHandler(w, req)
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("POST commit_comment returned HTTP status code %v.\nExpected %v", w.Code, http.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIssuesEvent(t *testing.T) {
|
||||||
|
gh := NewGithubWebhooks()
|
||||||
|
jsonString := mod.IssuesEventJSON()
|
||||||
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
|
req.Header.Add("X-Github-Event", "issues")
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
gh.eventHandler(w, req)
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("POST commit_comment returned HTTP status code %v.\nExpected %v", w.Code, http.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMemberEvent(t *testing.T) {
|
||||||
|
gh := NewGithubWebhooks()
|
||||||
|
jsonString := mod.MemberEventJSON()
|
||||||
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
|
req.Header.Add("X-Github-Event", "member")
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
gh.eventHandler(w, req)
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("POST commit_comment returned HTTP status code %v.\nExpected %v", w.Code, http.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMembershipEvent(t *testing.T) {
|
||||||
|
gh := NewGithubWebhooks()
|
||||||
|
jsonString := mod.MembershipEventJSON()
|
||||||
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
|
req.Header.Add("X-Github-Event", "membership")
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
gh.eventHandler(w, req)
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("POST commit_comment returned HTTP status code %v.\nExpected %v", w.Code, http.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPageBuildEvent(t *testing.T) {
|
||||||
|
gh := NewGithubWebhooks()
|
||||||
|
jsonString := mod.PageBuildEventJSON()
|
||||||
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
|
req.Header.Add("X-Github-Event", "page_build")
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
gh.eventHandler(w, req)
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("POST commit_comment returned HTTP status code %v.\nExpected %v", w.Code, http.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPublicEvent(t *testing.T) {
|
||||||
|
gh := NewGithubWebhooks()
|
||||||
|
jsonString := mod.PublicEventJSON()
|
||||||
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
|
req.Header.Add("X-Github-Event", "public")
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
gh.eventHandler(w, req)
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("POST commit_comment returned HTTP status code %v.\nExpected %v", w.Code, http.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPullRequestReviewCommentEvent(t *testing.T) {
|
||||||
|
gh := NewGithubWebhooks()
|
||||||
|
jsonString := mod.PullRequestReviewCommentEventJSON()
|
||||||
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
|
req.Header.Add("X-Github-Event", "pull_request_review_comment")
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
gh.eventHandler(w, req)
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("POST commit_comment returned HTTP status code %v.\nExpected %v", w.Code, http.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPushEvent(t *testing.T) {
|
||||||
|
gh := NewGithubWebhooks()
|
||||||
|
jsonString := mod.PushEventJSON()
|
||||||
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
|
req.Header.Add("X-Github-Event", "push")
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
gh.eventHandler(w, req)
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("POST commit_comment returned HTTP status code %v.\nExpected %v", w.Code, http.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestReleaseEvent(t *testing.T) {
|
||||||
|
gh := NewGithubWebhooks()
|
||||||
|
jsonString := mod.ReleaseEventJSON()
|
||||||
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
|
req.Header.Add("X-Github-Event", "release")
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
gh.eventHandler(w, req)
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("POST commit_comment returned HTTP status code %v.\nExpected %v", w.Code, http.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRepositoryEvent(t *testing.T) {
|
||||||
|
gh := NewGithubWebhooks()
|
||||||
|
jsonString := mod.RepositoryEventJSON()
|
||||||
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
|
req.Header.Add("X-Github-Event", "repository")
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
gh.eventHandler(w, req)
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("POST commit_comment returned HTTP status code %v.\nExpected %v", w.Code, http.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStatusEvent(t *testing.T) {
|
||||||
|
gh := NewGithubWebhooks()
|
||||||
|
|
||||||
|
jsonString := mod.StatusEventJSON()
|
||||||
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
|
req.Header.Add("X-Github-Event", "status")
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
gh.eventHandler(w, req)
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("POST commit_comment returned HTTP status code %v.\nExpected %v", w.Code, http.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTeamAddEvent(t *testing.T) {
|
||||||
|
gh := NewGithubWebhooks()
|
||||||
|
jsonString := mod.TeamAddEventJSON()
|
||||||
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
|
req.Header.Add("X-Github-Event", "team_add")
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
gh.eventHandler(w, req)
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("POST commit_comment returned HTTP status code %v.\nExpected %v", w.Code, http.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWatchEvent(t *testing.T) {
|
||||||
|
gh := NewGithubWebhooks()
|
||||||
|
jsonString := mod.WatchEventJSON()
|
||||||
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||||
|
req.Header.Add("X-Github-Event", "watch")
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
gh.eventHandler(w, req)
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("POST commit_comment returned HTTP status code %v.\nExpected %v", w.Code, http.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,711 @@
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/influxdata/influxdb/client/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
const meas = "ghWebhooks"
|
||||||
|
|
||||||
|
type Event interface {
|
||||||
|
NewPoint() *client.Point
|
||||||
|
}
|
||||||
|
|
||||||
|
type Repository struct {
|
||||||
|
Repository string `json:"full_name"`
|
||||||
|
Private bool `json:"private"`
|
||||||
|
Stars int `json:"stargazers_count"`
|
||||||
|
Forks int `json:"forks_count"`
|
||||||
|
Issues int `json:"open_issues_count"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Sender struct {
|
||||||
|
User string `json:"login"`
|
||||||
|
Admin bool `json:"site_admin"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CommitComment struct {
|
||||||
|
Commit string `json:"commit_id"`
|
||||||
|
Body string `json:"body"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Deployment struct {
|
||||||
|
Commit string `json:"sha"`
|
||||||
|
Task string `json:"task"`
|
||||||
|
Environment string `json:"environment"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Page struct {
|
||||||
|
Name string `json:"page_name"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Action string `json:"action"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Issue struct {
|
||||||
|
Number int `json:"number"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Comments int `json:"comments"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type IssueComment struct {
|
||||||
|
Body string `json:"body"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Team struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PullRequest struct {
|
||||||
|
Number int `json:"number"`
|
||||||
|
State string `json:"state"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Comments int `json:"comments"`
|
||||||
|
Commits int `json:"commits"`
|
||||||
|
Additions int `json:"additions"`
|
||||||
|
Deletions int `json:"deletions"`
|
||||||
|
ChangedFiles int `json:"changed_files"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PullRequestReviewComment struct {
|
||||||
|
File string `json:"path"`
|
||||||
|
Comment string `json:"body"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Release struct {
|
||||||
|
TagName string `json:"tag_name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeploymentStatus struct {
|
||||||
|
State string `json:"state"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CommitCommentEvent struct {
|
||||||
|
Comment CommitComment `json:"comment"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Sender Sender `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s CommitCommentEvent) NewPoint() *client.Point {
|
||||||
|
event := "commit_comment"
|
||||||
|
t := map[string]string{
|
||||||
|
"event": event,
|
||||||
|
"repository": s.Repository.Repository,
|
||||||
|
"private": fmt.Sprintf("%v", s.Repository.Private),
|
||||||
|
"user": s.Sender.User,
|
||||||
|
"admin": fmt.Sprintf("%v", s.Sender.Admin),
|
||||||
|
}
|
||||||
|
f := map[string]interface{}{
|
||||||
|
"stars": s.Repository.Stars,
|
||||||
|
"forks": s.Repository.Forks,
|
||||||
|
"issues": s.Repository.Issues,
|
||||||
|
"commit": s.Comment.Commit,
|
||||||
|
"comment": s.Comment.Body,
|
||||||
|
}
|
||||||
|
p, err := client.NewPoint(meas, t, f, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create %v event", event)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateEvent struct {
|
||||||
|
Ref string `json:"ref"`
|
||||||
|
RefType string `json:"ref_type"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Sender Sender `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s CreateEvent) NewPoint() *client.Point {
|
||||||
|
event := "create"
|
||||||
|
t := map[string]string{
|
||||||
|
"event": event,
|
||||||
|
"repository": s.Repository.Repository,
|
||||||
|
"private": fmt.Sprintf("%v", s.Repository.Private),
|
||||||
|
"user": s.Sender.User,
|
||||||
|
"admin": fmt.Sprintf("%v", s.Sender.Admin),
|
||||||
|
}
|
||||||
|
f := map[string]interface{}{
|
||||||
|
"stars": s.Repository.Stars,
|
||||||
|
"forks": s.Repository.Forks,
|
||||||
|
"issues": s.Repository.Issues,
|
||||||
|
"ref": s.Ref,
|
||||||
|
"refType": s.RefType,
|
||||||
|
}
|
||||||
|
p, err := client.NewPoint(meas, t, f, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create %v event", event)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteEvent struct {
|
||||||
|
Ref string `json:"ref"`
|
||||||
|
RefType string `json:"ref_type"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Sender Sender `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s DeleteEvent) NewPoint() *client.Point {
|
||||||
|
event := "delete"
|
||||||
|
t := map[string]string{
|
||||||
|
"event": event,
|
||||||
|
"repository": s.Repository.Repository,
|
||||||
|
"private": fmt.Sprintf("%v", s.Repository.Private),
|
||||||
|
"user": s.Sender.User,
|
||||||
|
"admin": fmt.Sprintf("%v", s.Sender.Admin),
|
||||||
|
}
|
||||||
|
f := map[string]interface{}{
|
||||||
|
"stars": s.Repository.Stars,
|
||||||
|
"forks": s.Repository.Forks,
|
||||||
|
"issues": s.Repository.Issues,
|
||||||
|
"ref": s.Ref,
|
||||||
|
"refType": s.RefType,
|
||||||
|
}
|
||||||
|
p, err := client.NewPoint(meas, t, f, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create %v event", event)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeploymentEvent struct {
|
||||||
|
Deployment Deployment `json:"deployment"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Sender Sender `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s DeploymentEvent) NewPoint() *client.Point {
|
||||||
|
event := "deployment"
|
||||||
|
t := map[string]string{
|
||||||
|
"event": event,
|
||||||
|
"repository": s.Repository.Repository,
|
||||||
|
"private": fmt.Sprintf("%v", s.Repository.Private),
|
||||||
|
"user": s.Sender.User,
|
||||||
|
"admin": fmt.Sprintf("%v", s.Sender.Admin),
|
||||||
|
}
|
||||||
|
f := map[string]interface{}{
|
||||||
|
"stars": s.Repository.Stars,
|
||||||
|
"forks": s.Repository.Forks,
|
||||||
|
"issues": s.Repository.Issues,
|
||||||
|
"commit": s.Deployment.Commit,
|
||||||
|
"task": s.Deployment.Task,
|
||||||
|
"environment": s.Deployment.Environment,
|
||||||
|
"description": s.Deployment.Description,
|
||||||
|
}
|
||||||
|
p, err := client.NewPoint(meas, t, f, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create %v event", event)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeploymentStatusEvent struct {
|
||||||
|
Deployment Deployment `json:"deployment"`
|
||||||
|
DeploymentStatus DeploymentStatus `json:"deployment_status"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Sender Sender `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s DeploymentStatusEvent) NewPoint() *client.Point {
|
||||||
|
event := "delete"
|
||||||
|
t := map[string]string{
|
||||||
|
"event": event,
|
||||||
|
"repository": s.Repository.Repository,
|
||||||
|
"private": fmt.Sprintf("%v", s.Repository.Private),
|
||||||
|
"user": s.Sender.User,
|
||||||
|
"admin": fmt.Sprintf("%v", s.Sender.Admin),
|
||||||
|
}
|
||||||
|
f := map[string]interface{}{
|
||||||
|
"stars": s.Repository.Stars,
|
||||||
|
"forks": s.Repository.Forks,
|
||||||
|
"issues": s.Repository.Issues,
|
||||||
|
"commit": s.Deployment.Commit,
|
||||||
|
"task": s.Deployment.Task,
|
||||||
|
"environment": s.Deployment.Environment,
|
||||||
|
"description": s.Deployment.Description,
|
||||||
|
"depState": s.DeploymentStatus.State,
|
||||||
|
"depDescription": s.DeploymentStatus.Description,
|
||||||
|
}
|
||||||
|
p, err := client.NewPoint(meas, t, f, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create %v event", event)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type ForkEvent struct {
|
||||||
|
Forkee Repository `json:"forkee"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Sender Sender `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s ForkEvent) NewPoint() *client.Point {
|
||||||
|
event := "fork"
|
||||||
|
t := map[string]string{
|
||||||
|
"event": event,
|
||||||
|
"repository": s.Repository.Repository,
|
||||||
|
"private": fmt.Sprintf("%v", s.Repository.Private),
|
||||||
|
"user": s.Sender.User,
|
||||||
|
"admin": fmt.Sprintf("%v", s.Sender.Admin),
|
||||||
|
}
|
||||||
|
f := map[string]interface{}{
|
||||||
|
"stars": s.Repository.Stars,
|
||||||
|
"forks": s.Repository.Forks,
|
||||||
|
"issues": s.Repository.Issues,
|
||||||
|
"fork": s.Forkee.Repository,
|
||||||
|
}
|
||||||
|
p, err := client.NewPoint(meas, t, f, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create %v event", event)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type GollumEvent struct {
|
||||||
|
Pages []Page `json:"pages"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Sender Sender `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// REVIEW: Going to be lazy and not deal with the pages.
|
||||||
|
func (s GollumEvent) NewPoint() *client.Point {
|
||||||
|
event := "gollum"
|
||||||
|
t := map[string]string{
|
||||||
|
"event": event,
|
||||||
|
"repository": s.Repository.Repository,
|
||||||
|
"private": fmt.Sprintf("%v", s.Repository.Private),
|
||||||
|
"user": s.Sender.User,
|
||||||
|
"admin": fmt.Sprintf("%v", s.Sender.Admin),
|
||||||
|
}
|
||||||
|
f := map[string]interface{}{
|
||||||
|
"stars": s.Repository.Stars,
|
||||||
|
"forks": s.Repository.Forks,
|
||||||
|
"issues": s.Repository.Issues,
|
||||||
|
}
|
||||||
|
p, err := client.NewPoint(meas, t, f, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create %v event", event)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type IssueCommentEvent struct {
|
||||||
|
Issue Issue `json:"issue"`
|
||||||
|
Comment IssueComment `json:"comment"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Sender Sender `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s IssueCommentEvent) NewPoint() *client.Point {
|
||||||
|
event := "issue_comment"
|
||||||
|
t := map[string]string{
|
||||||
|
"event": event,
|
||||||
|
"repository": s.Repository.Repository,
|
||||||
|
"private": fmt.Sprintf("%v", s.Repository.Private),
|
||||||
|
"user": s.Sender.User,
|
||||||
|
"admin": fmt.Sprintf("%v", s.Sender.Admin),
|
||||||
|
"issue": fmt.Sprintf("%v", s.Issue.Number),
|
||||||
|
}
|
||||||
|
f := map[string]interface{}{
|
||||||
|
"stars": s.Repository.Stars,
|
||||||
|
"forks": s.Repository.Forks,
|
||||||
|
"issues": s.Repository.Issues,
|
||||||
|
"title": s.Issue.Title,
|
||||||
|
"comments": s.Issue.Comments,
|
||||||
|
"body": s.Comment.Body,
|
||||||
|
}
|
||||||
|
p, err := client.NewPoint(meas, t, f, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create %v event", event)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type IssuesEvent struct {
|
||||||
|
Action string `json:"action"`
|
||||||
|
Issue Issue `json:"issue"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Sender Sender `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s IssuesEvent) NewPoint() *client.Point {
|
||||||
|
event := "issue"
|
||||||
|
t := map[string]string{
|
||||||
|
"event": event,
|
||||||
|
"repository": s.Repository.Repository,
|
||||||
|
"private": fmt.Sprintf("%v", s.Repository.Private),
|
||||||
|
"user": s.Sender.User,
|
||||||
|
"admin": fmt.Sprintf("%v", s.Sender.Admin),
|
||||||
|
"issue": fmt.Sprintf("%v", s.Issue.Number),
|
||||||
|
"action": s.Action,
|
||||||
|
}
|
||||||
|
f := map[string]interface{}{
|
||||||
|
"stars": s.Repository.Stars,
|
||||||
|
"forks": s.Repository.Forks,
|
||||||
|
"issues": s.Repository.Issues,
|
||||||
|
"title": s.Issue.Title,
|
||||||
|
"comments": s.Issue.Comments,
|
||||||
|
}
|
||||||
|
p, err := client.NewPoint(meas, t, f, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create %v event", event)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type MemberEvent struct {
|
||||||
|
Member Sender `json:"member"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Sender Sender `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s MemberEvent) NewPoint() *client.Point {
|
||||||
|
event := "member"
|
||||||
|
t := map[string]string{
|
||||||
|
"event": event,
|
||||||
|
"repository": s.Repository.Repository,
|
||||||
|
"private": fmt.Sprintf("%v", s.Repository.Private),
|
||||||
|
"user": s.Sender.User,
|
||||||
|
"admin": fmt.Sprintf("%v", s.Sender.Admin),
|
||||||
|
}
|
||||||
|
f := map[string]interface{}{
|
||||||
|
"stars": s.Repository.Stars,
|
||||||
|
"forks": s.Repository.Forks,
|
||||||
|
"issues": s.Repository.Issues,
|
||||||
|
"newMember": s.Member.User,
|
||||||
|
"newMemberStatus": s.Member.Admin,
|
||||||
|
}
|
||||||
|
p, err := client.NewPoint(meas, t, f, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create %v event", event)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type MembershipEvent struct {
|
||||||
|
Action string `json:"action"`
|
||||||
|
Member Sender `json:"member"`
|
||||||
|
Sender Sender `json:"sender"`
|
||||||
|
Team Team `json:"team"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s MembershipEvent) NewPoint() *client.Point {
|
||||||
|
event := "membership"
|
||||||
|
t := map[string]string{
|
||||||
|
"event": event,
|
||||||
|
"user": s.Sender.User,
|
||||||
|
"admin": fmt.Sprintf("%v", s.Sender.Admin),
|
||||||
|
"action": s.Action,
|
||||||
|
}
|
||||||
|
f := map[string]interface{}{
|
||||||
|
"newMember": s.Member.User,
|
||||||
|
"newMemberStatus": s.Member.Admin,
|
||||||
|
}
|
||||||
|
p, err := client.NewPoint(meas, t, f, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create %v event", event)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type PageBuildEvent struct {
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Sender Sender `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s PageBuildEvent) NewPoint() *client.Point {
|
||||||
|
event := "page_build"
|
||||||
|
t := map[string]string{
|
||||||
|
"event": event,
|
||||||
|
"repository": s.Repository.Repository,
|
||||||
|
"private": fmt.Sprintf("%v", s.Repository.Private),
|
||||||
|
"user": s.Sender.User,
|
||||||
|
"admin": fmt.Sprintf("%v", s.Sender.Admin),
|
||||||
|
}
|
||||||
|
f := map[string]interface{}{
|
||||||
|
"stars": s.Repository.Stars,
|
||||||
|
"forks": s.Repository.Forks,
|
||||||
|
"issues": s.Repository.Issues,
|
||||||
|
}
|
||||||
|
p, err := client.NewPoint(meas, t, f, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create %v event", event)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type PublicEvent struct {
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Sender Sender `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s PublicEvent) NewPoint() *client.Point {
|
||||||
|
event := "public"
|
||||||
|
t := map[string]string{
|
||||||
|
"event": event,
|
||||||
|
"repository": s.Repository.Repository,
|
||||||
|
"private": fmt.Sprintf("%v", s.Repository.Private),
|
||||||
|
"user": s.Sender.User,
|
||||||
|
"admin": fmt.Sprintf("%v", s.Sender.Admin),
|
||||||
|
}
|
||||||
|
f := map[string]interface{}{
|
||||||
|
"stars": s.Repository.Stars,
|
||||||
|
"forks": s.Repository.Forks,
|
||||||
|
"issues": s.Repository.Issues,
|
||||||
|
}
|
||||||
|
p, err := client.NewPoint(meas, t, f, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create %v event", event)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type PullRequestEvent struct {
|
||||||
|
Action string `json:"action"`
|
||||||
|
PullRequest PullRequest `json:"pull_request"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Sender Sender `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s PullRequestEvent) NewPoint() *client.Point {
|
||||||
|
event := "pull_request"
|
||||||
|
t := map[string]string{
|
||||||
|
"event": event,
|
||||||
|
"action": s.Action,
|
||||||
|
"repository": s.Repository.Repository,
|
||||||
|
"private": fmt.Sprintf("%v", s.Repository.Private),
|
||||||
|
"user": s.Sender.User,
|
||||||
|
"admin": fmt.Sprintf("%v", s.Sender.Admin),
|
||||||
|
"prNumber": fmt.Sprintf("%v", s.PullRequest.Number),
|
||||||
|
}
|
||||||
|
f := map[string]interface{}{
|
||||||
|
"stars": s.Repository.Stars,
|
||||||
|
"forks": s.Repository.Forks,
|
||||||
|
"issues": s.Repository.Issues,
|
||||||
|
"state": s.PullRequest.State,
|
||||||
|
"title": s.PullRequest.Title,
|
||||||
|
"comments": s.PullRequest.Comments,
|
||||||
|
"commits": s.PullRequest.Commits,
|
||||||
|
"additions": s.PullRequest.Additions,
|
||||||
|
"deletions": s.PullRequest.Deletions,
|
||||||
|
"changedFiles": s.PullRequest.ChangedFiles,
|
||||||
|
}
|
||||||
|
p, err := client.NewPoint(meas, t, f, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create %v event", event)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type PullRequestReviewCommentEvent struct {
|
||||||
|
Comment PullRequestReviewComment `json:"comment"`
|
||||||
|
PullRequest PullRequest `json:"pull_request"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Sender Sender `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s PullRequestReviewCommentEvent) NewPoint() *client.Point {
|
||||||
|
event := "pull_request_review_comment"
|
||||||
|
t := map[string]string{
|
||||||
|
"event": event,
|
||||||
|
"repository": s.Repository.Repository,
|
||||||
|
"private": fmt.Sprintf("%v", s.Repository.Private),
|
||||||
|
"user": s.Sender.User,
|
||||||
|
"admin": fmt.Sprintf("%v", s.Sender.Admin),
|
||||||
|
"prNumber": fmt.Sprintf("%v", s.PullRequest.Number),
|
||||||
|
}
|
||||||
|
f := map[string]interface{}{
|
||||||
|
"stars": s.Repository.Stars,
|
||||||
|
"forks": s.Repository.Forks,
|
||||||
|
"issues": s.Repository.Issues,
|
||||||
|
"state": s.PullRequest.State,
|
||||||
|
"title": s.PullRequest.Title,
|
||||||
|
"comments": s.PullRequest.Comments,
|
||||||
|
"commits": s.PullRequest.Commits,
|
||||||
|
"additions": s.PullRequest.Additions,
|
||||||
|
"deletions": s.PullRequest.Deletions,
|
||||||
|
"changedFiles": s.PullRequest.ChangedFiles,
|
||||||
|
"commentFile": s.Comment.File,
|
||||||
|
"comment": s.Comment.Comment,
|
||||||
|
}
|
||||||
|
p, err := client.NewPoint(meas, t, f, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create %v event", event)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type PushEvent struct {
|
||||||
|
Ref string `json:"ref"`
|
||||||
|
Before string `json:"before"`
|
||||||
|
After string `json:"after"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Sender Sender `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s PushEvent) NewPoint() *client.Point {
|
||||||
|
event := "push"
|
||||||
|
t := map[string]string{
|
||||||
|
"event": event,
|
||||||
|
"repository": s.Repository.Repository,
|
||||||
|
"private": fmt.Sprintf("%v", s.Repository.Private),
|
||||||
|
"user": s.Sender.User,
|
||||||
|
"admin": fmt.Sprintf("%v", s.Sender.Admin),
|
||||||
|
}
|
||||||
|
f := map[string]interface{}{
|
||||||
|
"stars": s.Repository.Stars,
|
||||||
|
"forks": s.Repository.Forks,
|
||||||
|
"issues": s.Repository.Issues,
|
||||||
|
"Ref": s.Ref,
|
||||||
|
"Before": s.Before,
|
||||||
|
"After": s.After,
|
||||||
|
}
|
||||||
|
p, err := client.NewPoint(meas, t, f, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create %v event", event)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type ReleaseEvent struct {
|
||||||
|
Release Release `json:"release"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Sender Sender `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s ReleaseEvent) NewPoint() *client.Point {
|
||||||
|
event := "release"
|
||||||
|
t := map[string]string{
|
||||||
|
"event": event,
|
||||||
|
"repository": s.Repository.Repository,
|
||||||
|
"private": fmt.Sprintf("%v", s.Repository.Private),
|
||||||
|
"user": s.Sender.User,
|
||||||
|
"admin": fmt.Sprintf("%v", s.Sender.Admin),
|
||||||
|
}
|
||||||
|
f := map[string]interface{}{
|
||||||
|
"stars": s.Repository.Stars,
|
||||||
|
"forks": s.Repository.Forks,
|
||||||
|
"issues": s.Repository.Issues,
|
||||||
|
"tagName": s.Release.TagName,
|
||||||
|
}
|
||||||
|
p, err := client.NewPoint(meas, t, f, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create %v event", event)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type RepositoryEvent struct {
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Sender Sender `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s RepositoryEvent) NewPoint() *client.Point {
|
||||||
|
event := "repository"
|
||||||
|
t := map[string]string{
|
||||||
|
"event": event,
|
||||||
|
"repository": s.Repository.Repository,
|
||||||
|
"private": fmt.Sprintf("%v", s.Repository.Private),
|
||||||
|
"user": s.Sender.User,
|
||||||
|
"admin": fmt.Sprintf("%v", s.Sender.Admin),
|
||||||
|
}
|
||||||
|
f := map[string]interface{}{
|
||||||
|
"stars": s.Repository.Stars,
|
||||||
|
"forks": s.Repository.Forks,
|
||||||
|
"issues": s.Repository.Issues,
|
||||||
|
}
|
||||||
|
p, err := client.NewPoint(meas, t, f, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create %v event", event)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type StatusEvent struct {
|
||||||
|
Commit string `json:"sha"`
|
||||||
|
State string `json:"state"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Sender Sender `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s StatusEvent) NewPoint() *client.Point {
|
||||||
|
event := "status"
|
||||||
|
t := map[string]string{
|
||||||
|
"event": event,
|
||||||
|
"repository": s.Repository.Repository,
|
||||||
|
"private": fmt.Sprintf("%v", s.Repository.Private),
|
||||||
|
"user": s.Sender.User,
|
||||||
|
"admin": fmt.Sprintf("%v", s.Sender.Admin),
|
||||||
|
}
|
||||||
|
f := map[string]interface{}{
|
||||||
|
"stars": s.Repository.Stars,
|
||||||
|
"forks": s.Repository.Forks,
|
||||||
|
"issues": s.Repository.Issues,
|
||||||
|
"commit": s.Commit,
|
||||||
|
"state": s.State,
|
||||||
|
}
|
||||||
|
p, err := client.NewPoint(meas, t, f, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create %v event", event)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type TeamAddEvent struct {
|
||||||
|
Team Team `json:"team"`
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Sender Sender `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s TeamAddEvent) NewPoint() *client.Point {
|
||||||
|
event := "team_add"
|
||||||
|
t := map[string]string{
|
||||||
|
"event": event,
|
||||||
|
"repository": s.Repository.Repository,
|
||||||
|
"private": fmt.Sprintf("%v", s.Repository.Private),
|
||||||
|
"user": s.Sender.User,
|
||||||
|
"admin": fmt.Sprintf("%v", s.Sender.Admin),
|
||||||
|
}
|
||||||
|
f := map[string]interface{}{
|
||||||
|
"stars": s.Repository.Stars,
|
||||||
|
"forks": s.Repository.Forks,
|
||||||
|
"issues": s.Repository.Issues,
|
||||||
|
"teamName": s.Team.Name,
|
||||||
|
}
|
||||||
|
p, err := client.NewPoint(meas, t, f, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create %v event", event)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type WatchEvent struct {
|
||||||
|
Repository Repository `json:"repository"`
|
||||||
|
Sender Sender `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s WatchEvent) NewPoint() *client.Point {
|
||||||
|
event := "delete"
|
||||||
|
t := map[string]string{
|
||||||
|
"event": event,
|
||||||
|
"repository": s.Repository.Repository,
|
||||||
|
"private": fmt.Sprintf("%v", s.Repository.Private),
|
||||||
|
"user": s.Sender.User,
|
||||||
|
"admin": fmt.Sprintf("%v", s.Sender.Admin),
|
||||||
|
}
|
||||||
|
f := map[string]interface{}{
|
||||||
|
"stars": s.Repository.Stars,
|
||||||
|
"forks": s.Repository.Forks,
|
||||||
|
"issues": s.Repository.Issues,
|
||||||
|
}
|
||||||
|
p, err := client.NewPoint(meas, t, f, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create %v event", event)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
Loading…
Reference in New Issue