Address PR comments and merge conflicts
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package ghwebhooks
|
||||
package github_webhooks
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -9,15 +9,15 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
mod "github.com/influxdb/support-tools/ghWebhooks/models"
|
||||
"github.com/influxdb/telegraf/plugins/inputs"
|
||||
"github.com/influxdata/telegraf/plugins/inputs"
|
||||
mod "github.com/influxdata/telegraf/plugins/inputs/ghWebhooks/models"
|
||||
)
|
||||
|
||||
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
|
||||
MeasurementName string
|
||||
// Lock for the struct
|
||||
@@ -26,25 +26,25 @@ type GHWebhooks struct {
|
||||
events []mod.Event
|
||||
}
|
||||
|
||||
func NewGHWebhooks() *GHWebhooks {
|
||||
return &GHWebhooks{}
|
||||
func NewGithubWebhooks() *GithubWebhooks {
|
||||
return &GithubWebhooks{}
|
||||
}
|
||||
|
||||
func (gh *GHWebhooks) SampleConfig() string {
|
||||
func (gh *GithubWebhooks) SampleConfig() string {
|
||||
return `
|
||||
# Address and port to host Webhook listener on
|
||||
service_address = ":1618"
|
||||
# Measurement name
|
||||
measurement_name = "ghwebhooks"
|
||||
# Measurement name
|
||||
measurement_name = "github_webhooks"
|
||||
`
|
||||
}
|
||||
|
||||
func (gh *GHWebhooks) Description() string {
|
||||
func (gh *GithubWebhooks) Description() string {
|
||||
return "A Github Webhook Event collector"
|
||||
}
|
||||
|
||||
// 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()
|
||||
defer gh.Unlock()
|
||||
for _, event := range gh.events {
|
||||
@@ -55,7 +55,7 @@ func (gh *GHWebhooks) Gather(acc inputs.Accumulator) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gh *GHWebhooks) Listen() {
|
||||
func (gh *GithubWebhooks) Listen() {
|
||||
r := mux.NewRouter()
|
||||
r.HandleFunc("/", gh.eventHandler).Methods("POST")
|
||||
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()
|
||||
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
|
||||
}
|
||||
|
||||
func (gh *GHWebhooks) Stop() {
|
||||
func (gh *GithubWebhooks) Stop() {
|
||||
log.Println("Stopping the ghWebhooks service")
|
||||
}
|
||||
|
||||
// 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]
|
||||
data, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
@@ -1,4 +1,4 @@
|
||||
package ghwebhooks
|
||||
package github_webhooks
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -6,12 +6,12 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
mod "github.com/influxdb/telegraf/plugins/inputs/ghwebhooks/models"
|
||||
mod "github.com/influxdata/telegraf/plugins/inputs/ghwebhooks/models"
|
||||
)
|
||||
|
||||
func TestCommitCommentEvent(t *testing.T) {
|
||||
gh := NewGHWebhooks()
|
||||
jsonString := mod.Mock{}.CommitCommentEventJSON()
|
||||
gh := NewGithubWebhooks()
|
||||
jsonString := mod.CommitCommentEventJSON()
|
||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||
req.Header.Add("X-Github-Event", "commit_comment")
|
||||
w := httptest.NewRecorder()
|
||||
@@ -22,8 +22,8 @@ func TestCommitCommentEvent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteEvent(t *testing.T) {
|
||||
gh := NewGHWebhooks()
|
||||
jsonString := mod.Mock{}.DeleteEventJSON()
|
||||
gh := NewGithubWebhooks()
|
||||
jsonString := mod.DeleteEventJSON()
|
||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||
req.Header.Add("X-Github-Event", "delete")
|
||||
w := httptest.NewRecorder()
|
||||
@@ -34,8 +34,8 @@ func TestDeleteEvent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeploymentEvent(t *testing.T) {
|
||||
gh := NewGHWebhooks()
|
||||
jsonString := mod.Mock{}.DeploymentEventJSON()
|
||||
gh := NewGithubWebhooks()
|
||||
jsonString := mod.DeploymentEventJSON()
|
||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||
req.Header.Add("X-Github-Event", "deployment")
|
||||
w := httptest.NewRecorder()
|
||||
@@ -46,8 +46,8 @@ func TestDeploymentEvent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeploymentStatusEvent(t *testing.T) {
|
||||
gh := NewGHWebhooks()
|
||||
jsonString := mod.Mock{}.DeploymentStatusEventJSON()
|
||||
gh := NewGithubWebhooks()
|
||||
jsonString := mod.DeploymentStatusEventJSON()
|
||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||
req.Header.Add("X-Github-Event", "deployment_status")
|
||||
w := httptest.NewRecorder()
|
||||
@@ -58,8 +58,8 @@ func TestDeploymentStatusEvent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestForkEvent(t *testing.T) {
|
||||
gh := NewGHWebhooks()
|
||||
jsonString := mod.Mock{}.ForkEventJSON()
|
||||
gh := NewGithubWebhooks()
|
||||
jsonString := mod.ForkEventJSON()
|
||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||
req.Header.Add("X-Github-Event", "fork")
|
||||
w := httptest.NewRecorder()
|
||||
@@ -70,8 +70,8 @@ func TestForkEvent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGollumEvent(t *testing.T) {
|
||||
gh := NewGHWebhooks()
|
||||
jsonString := mod.Mock{}.GollumEventJSON()
|
||||
gh := NewGithubWebhooks()
|
||||
jsonString := mod.GollumEventJSON()
|
||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||
req.Header.Add("X-Github-Event", "gollum")
|
||||
w := httptest.NewRecorder()
|
||||
@@ -82,8 +82,8 @@ func TestGollumEvent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIssueCommentEvent(t *testing.T) {
|
||||
gh := NewGHWebhooks()
|
||||
jsonString := mod.Mock{}.IssueCommentEventJSON()
|
||||
gh := NewGithubWebhooks()
|
||||
jsonString := mod.IssueCommentEventJSON()
|
||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||
req.Header.Add("X-Github-Event", "issue_comment")
|
||||
w := httptest.NewRecorder()
|
||||
@@ -94,8 +94,8 @@ func TestIssueCommentEvent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIssuesEvent(t *testing.T) {
|
||||
gh := NewGHWebhooks()
|
||||
jsonString := mod.Mock{}.IssuesEventJSON()
|
||||
gh := NewGithubWebhooks()
|
||||
jsonString := mod.IssuesEventJSON()
|
||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||
req.Header.Add("X-Github-Event", "issues")
|
||||
w := httptest.NewRecorder()
|
||||
@@ -106,8 +106,8 @@ func TestIssuesEvent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMemberEvent(t *testing.T) {
|
||||
gh := NewGHWebhooks()
|
||||
jsonString := mod.Mock{}.MemberEventJSON()
|
||||
gh := NewGithubWebhooks()
|
||||
jsonString := mod.MemberEventJSON()
|
||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||
req.Header.Add("X-Github-Event", "member")
|
||||
w := httptest.NewRecorder()
|
||||
@@ -118,8 +118,8 @@ func TestMemberEvent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMembershipEvent(t *testing.T) {
|
||||
gh := NewGHWebhooks()
|
||||
jsonString := mod.Mock{}.MembershipEventJSON()
|
||||
gh := NewGithubWebhooks()
|
||||
jsonString := mod.MembershipEventJSON()
|
||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||
req.Header.Add("X-Github-Event", "membership")
|
||||
w := httptest.NewRecorder()
|
||||
@@ -130,8 +130,8 @@ func TestMembershipEvent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPageBuildEvent(t *testing.T) {
|
||||
gh := NewGHWebhooks()
|
||||
jsonString := mod.Mock{}.PageBuildEventJSON()
|
||||
gh := NewGithubWebhooks()
|
||||
jsonString := mod.PageBuildEventJSON()
|
||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||
req.Header.Add("X-Github-Event", "page_build")
|
||||
w := httptest.NewRecorder()
|
||||
@@ -142,8 +142,8 @@ func TestPageBuildEvent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPublicEvent(t *testing.T) {
|
||||
gh := NewGHWebhooks()
|
||||
jsonString := mod.Mock{}.PublicEventJSON()
|
||||
gh := NewGithubWebhooks()
|
||||
jsonString := mod.PublicEventJSON()
|
||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||
req.Header.Add("X-Github-Event", "public")
|
||||
w := httptest.NewRecorder()
|
||||
@@ -154,8 +154,8 @@ func TestPublicEvent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPullRequestReviewCommentEvent(t *testing.T) {
|
||||
gh := NewGHWebhooks()
|
||||
jsonString := mod.Mock{}.PullRequestReviewCommentEventJSON()
|
||||
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()
|
||||
@@ -166,8 +166,8 @@ func TestPullRequestReviewCommentEvent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPushEvent(t *testing.T) {
|
||||
gh := NewGHWebhooks()
|
||||
jsonString := mod.Mock{}.PushEventJSON()
|
||||
gh := NewGithubWebhooks()
|
||||
jsonString := mod.PushEventJSON()
|
||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||
req.Header.Add("X-Github-Event", "push")
|
||||
w := httptest.NewRecorder()
|
||||
@@ -178,8 +178,8 @@ func TestPushEvent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestReleaseEvent(t *testing.T) {
|
||||
gh := NewGHWebhooks()
|
||||
jsonString := mod.Mock{}.ReleaseEventJSON()
|
||||
gh := NewGithubWebhooks()
|
||||
jsonString := mod.ReleaseEventJSON()
|
||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||
req.Header.Add("X-Github-Event", "release")
|
||||
w := httptest.NewRecorder()
|
||||
@@ -190,8 +190,8 @@ func TestReleaseEvent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRepositoryEvent(t *testing.T) {
|
||||
gh := NewGHWebhooks()
|
||||
jsonString := mod.Mock{}.RepositoryEventJSON()
|
||||
gh := NewGithubWebhooks()
|
||||
jsonString := mod.RepositoryEventJSON()
|
||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||
req.Header.Add("X-Github-Event", "repository")
|
||||
w := httptest.NewRecorder()
|
||||
@@ -202,8 +202,9 @@ func TestRepositoryEvent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStatusEvent(t *testing.T) {
|
||||
gh := NewGHWebhooks()
|
||||
jsonString := mod.Mock{}.StatusEventJSON()
|
||||
gh := NewGithubWebhooks()
|
||||
|
||||
jsonString := mod.StatusEventJSON()
|
||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||
req.Header.Add("X-Github-Event", "status")
|
||||
w := httptest.NewRecorder()
|
||||
@@ -214,8 +215,8 @@ func TestStatusEvent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTeamAddEvent(t *testing.T) {
|
||||
gh := NewGHWebhooks()
|
||||
jsonString := mod.Mock{}.TeamAddEventJSON()
|
||||
gh := NewGithubWebhooks()
|
||||
jsonString := mod.TeamAddEventJSON()
|
||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||
req.Header.Add("X-Github-Event", "team_add")
|
||||
w := httptest.NewRecorder()
|
||||
@@ -226,8 +227,8 @@ func TestTeamAddEvent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWatchEvent(t *testing.T) {
|
||||
gh := NewGHWebhooks()
|
||||
jsonString := mod.Mock{}.WatchEventJSON()
|
||||
gh := NewGithubWebhooks()
|
||||
jsonString := mod.WatchEventJSON()
|
||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
||||
req.Header.Add("X-Github-Event", "watch")
|
||||
w := httptest.NewRecorder()
|
||||
@@ -1,8 +1,6 @@
|
||||
package models
|
||||
|
||||
type Mock struct{}
|
||||
|
||||
func (_ Mock) CommitCommentEventJSON() string {
|
||||
func CommitCommentEventJSON() string {
|
||||
return `{
|
||||
"action": "created",
|
||||
"comment": {
|
||||
@@ -145,7 +143,7 @@ func (_ Mock) CommitCommentEventJSON() string {
|
||||
}`
|
||||
}
|
||||
|
||||
func (_ Mock) CreateEventJSON() string {
|
||||
func CreateEventJSON() string {
|
||||
return `{
|
||||
"ref": "0.0.1",
|
||||
"ref_type": "tag",
|
||||
@@ -261,7 +259,7 @@ func (_ Mock) CreateEventJSON() string {
|
||||
}`
|
||||
}
|
||||
|
||||
func (_ Mock) DeleteEventJSON() string {
|
||||
func DeleteEventJSON() string {
|
||||
return `{
|
||||
"ref": "simple-tag",
|
||||
"ref_type": "tag",
|
||||
@@ -375,7 +373,7 @@ func (_ Mock) DeleteEventJSON() string {
|
||||
}`
|
||||
}
|
||||
|
||||
func (_ Mock) DeploymentEventJSON() string {
|
||||
func DeploymentEventJSON() string {
|
||||
return `{
|
||||
"deployment": {
|
||||
"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 `{
|
||||
"deployment": {
|
||||
"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 `{
|
||||
"forkee": {
|
||||
"id": 35129393,
|
||||
@@ -895,7 +893,7 @@ func (_ Mock) ForkEventJSON() string {
|
||||
}`
|
||||
}
|
||||
|
||||
func (_ Mock) GollumEventJSON() string {
|
||||
func GollumEventJSON() string {
|
||||
return `{
|
||||
"pages": [
|
||||
{
|
||||
@@ -1016,7 +1014,7 @@ func (_ Mock) GollumEventJSON() string {
|
||||
}`
|
||||
}
|
||||
|
||||
func (_ Mock) IssueCommentEventJSON() string {
|
||||
func IssueCommentEventJSON() string {
|
||||
return `{
|
||||
"action": "created",
|
||||
"issue": {
|
||||
@@ -1201,7 +1199,7 @@ func (_ Mock) IssueCommentEventJSON() string {
|
||||
}`
|
||||
}
|
||||
|
||||
func (_ Mock) IssuesEventJSON() string {
|
||||
func IssuesEventJSON() string {
|
||||
return `{
|
||||
"action": "opened",
|
||||
"issue": {
|
||||
@@ -1358,7 +1356,7 @@ func (_ Mock) IssuesEventJSON() string {
|
||||
}`
|
||||
}
|
||||
|
||||
func (_ Mock) MemberEventJSON() string {
|
||||
func MemberEventJSON() string {
|
||||
return `{
|
||||
"action": "added",
|
||||
"member": {
|
||||
@@ -1489,7 +1487,7 @@ func (_ Mock) MemberEventJSON() string {
|
||||
}`
|
||||
}
|
||||
|
||||
func (_ Mock) MembershipEventJSON() string {
|
||||
func MembershipEventJSON() string {
|
||||
return `{
|
||||
"action": "added",
|
||||
"scope": "team",
|
||||
@@ -1553,7 +1551,7 @@ func (_ Mock) MembershipEventJSON() string {
|
||||
}`
|
||||
}
|
||||
|
||||
func (_ Mock) PageBuildEventJSON() string {
|
||||
func PageBuildEventJSON() string {
|
||||
return `{
|
||||
"id": 15995382,
|
||||
"build": {
|
||||
@@ -1695,7 +1693,7 @@ func (_ Mock) PageBuildEventJSON() string {
|
||||
}`
|
||||
}
|
||||
|
||||
func (_ Mock) PublicEventJSON() string {
|
||||
func PublicEventJSON() string {
|
||||
return `{
|
||||
"repository": {
|
||||
"id": 35129377,
|
||||
@@ -1806,7 +1804,7 @@ func (_ Mock) PublicEventJSON() string {
|
||||
}`
|
||||
}
|
||||
|
||||
func (_ Mock) PullRequestReviewCommentEventJSON() string {
|
||||
func PullRequestReviewCommentEventJSON() string {
|
||||
return `{
|
||||
"action": "created",
|
||||
"comment": {
|
||||
@@ -2255,7 +2253,7 @@ func (_ Mock) PullRequestReviewCommentEventJSON() string {
|
||||
}`
|
||||
}
|
||||
|
||||
func (_ Mock) PullRequestEventJSON() string {
|
||||
func PullRequestEventJSON() string {
|
||||
return `{
|
||||
"action": "opened",
|
||||
"number": 1,
|
||||
@@ -2670,7 +2668,7 @@ func (_ Mock) PullRequestEventJSON() string {
|
||||
}`
|
||||
}
|
||||
|
||||
func (_ Mock) PushEventJSON() string {
|
||||
func PushEventJSON() string {
|
||||
return `{
|
||||
"ref": "refs/heads/changes",
|
||||
"before": "9049f1265b7d61be4a8904a9a27120d2064dab3b",
|
||||
@@ -2834,7 +2832,7 @@ func (_ Mock) PushEventJSON() string {
|
||||
}`
|
||||
}
|
||||
|
||||
func (_ Mock) RepositoryEventJSON() string {
|
||||
func RepositoryEventJSON() string {
|
||||
return `{
|
||||
"action": "created",
|
||||
"repository": {
|
||||
@@ -2956,7 +2954,7 @@ func (_ Mock) RepositoryEventJSON() string {
|
||||
}`
|
||||
}
|
||||
|
||||
func (_ Mock) ReleaseEventJSON() string {
|
||||
func ReleaseEventJSON() string {
|
||||
return `{
|
||||
"action": "published",
|
||||
"release": {
|
||||
@@ -3107,7 +3105,7 @@ func (_ Mock) ReleaseEventJSON() string {
|
||||
}`
|
||||
}
|
||||
|
||||
func (_ Mock) StatusEventJSON() string {
|
||||
func StatusEventJSON() string {
|
||||
return `{
|
||||
"id": 214015194,
|
||||
"sha": "9049f1265b7d61be4a8904a9a27120d2064dab3b",
|
||||
@@ -3316,7 +3314,7 @@ func (_ Mock) StatusEventJSON() string {
|
||||
}`
|
||||
}
|
||||
|
||||
func (_ Mock) TeamAddEventJSON() string {
|
||||
func TeamAddEventJSON() string {
|
||||
return `{
|
||||
"team": {
|
||||
"name": "github",
|
||||
@@ -3448,7 +3446,7 @@ func (_ Mock) TeamAddEventJSON() string {
|
||||
}`
|
||||
}
|
||||
|
||||
func (_ Mock) WatchEventJSON() string {
|
||||
func WatchEventJSON() string {
|
||||
return `{
|
||||
"action": "started",
|
||||
"repository": {
|
||||
|
||||
@@ -5,14 +5,13 @@ import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/influxdb/influxdb/client/v2"
|
||||
"github.com/influxdata/influxdb/client/v2"
|
||||
)
|
||||
|
||||
const meas = "ghWebhooks"
|
||||
|
||||
type Event interface {
|
||||
NewPoint() *client.Point
|
||||
JSON() string
|
||||
}
|
||||
|
||||
type Repository struct {
|
||||
|
||||
Reference in New Issue
Block a user