First commit for ghwebhooks service plugin
This commit is contained in:
parent
d3a5cca1bc
commit
8bdcd6d576
|
@ -0,0 +1,369 @@
|
|||
package ghwebhooks
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/gorilla/mux"
|
||||
mod "github.com/influxdata/support-tools/ghWebhooks/models"
|
||||
"github.com/influxdata/telegraf/plugins/inputs"
|
||||
)
|
||||
|
||||
func init() {
|
||||
log.Info("Starting ghWebhook server...")
|
||||
logFile, err := os.Create("server.log")
|
||||
if err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"time": time.Now(),
|
||||
"error": err,
|
||||
}).Warn("Error in creating log file")
|
||||
}
|
||||
log.SetLevel(log.InfoLevel)
|
||||
log.SetOutput(logFile)
|
||||
|
||||
inputs.Add("ghwebhooks", func() inputs.Input { return &GHWebhooks{} })
|
||||
}
|
||||
|
||||
type GHWebhooks struct {
|
||||
ServiceAddress string
|
||||
MeasurementName string
|
||||
|
||||
sync.Mutex
|
||||
|
||||
// Channel for all incoming events from github
|
||||
in chan mod.Event
|
||||
done chan struct{}
|
||||
}
|
||||
|
||||
func (gh *GHWebhooks) SampleConfig() string {
|
||||
return `
|
||||
# Address and port to host Webhook listener on
|
||||
service_address = ":1618"
|
||||
# Measurement name
|
||||
measurement_name = "ghWebhooks"
|
||||
`
|
||||
}
|
||||
|
||||
func (gh *GHWebhooks) Description() string {
|
||||
return "Github Webhook Event collector"
|
||||
}
|
||||
|
||||
// Writes the points from <-gh.in to the Accumulator
|
||||
func (gh *GHWebhooks) Gather(acc inputs.Accumulator) error {
|
||||
gh.Lock()
|
||||
defer gh.Unlock()
|
||||
for {
|
||||
select {
|
||||
case <-gh.done:
|
||||
return nil
|
||||
case e := <-gh.in:
|
||||
p := e.NewPoint()
|
||||
acc.Add(gh.MeasurementName, p.Fields(), p.Tags(), p.Time())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gh *GHWebhooks) Start() error {
|
||||
gh.Lock()
|
||||
defer gh.Unlock()
|
||||
for {
|
||||
select {
|
||||
case <-gh.done:
|
||||
return nil
|
||||
default:
|
||||
r := mux.NewRouter()
|
||||
r.HandleFunc("/webhooks", gh.webhookHandler).Methods("POST")
|
||||
http.ListenAndServe(fmt.Sprintf(":%s", gh.ServiceAddress), r)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (gh *GHWebhooks) Stop() {
|
||||
gh.Lock()
|
||||
defer gh.Unlock()
|
||||
log.Println("Stopping the ghWebhooks service")
|
||||
close(gh.done)
|
||||
close(gh.in)
|
||||
}
|
||||
|
||||
// Handles the /webhooks route
|
||||
func (gh *GHWebhooks) webhookHandler(w http.ResponseWriter, r *http.Request) {
|
||||
eventType := r.Header["X-Github-Event"][0]
|
||||
data, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
fields := log.Fields{"time": time.Now(), "event": eventType, "error": err}
|
||||
log.WithFields(fields).Fatal("Error reading Github payload")
|
||||
}
|
||||
|
||||
// Send event down chan to GHWebhooks
|
||||
e := NewEvent(data, eventType)
|
||||
gh.in <- e
|
||||
fmt.Printf("%v\n", e.NewPoint())
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func newCommitComment(data []byte) mod.Event {
|
||||
commitCommentStruct := mod.CommitCommentEvent{}
|
||||
err := json.Unmarshal(data, &commitCommentStruct)
|
||||
if err != nil {
|
||||
fields := log.Fields{"time": time.Now(), "event": "CommitCommentEvent", "error": err}
|
||||
log.WithFields(fields).Fatalf("Error in unmarshaling JSON")
|
||||
}
|
||||
return commitCommentStruct
|
||||
}
|
||||
|
||||
func newCreate(data []byte) mod.Event {
|
||||
createStruct := mod.CreateEvent{}
|
||||
err := json.Unmarshal(data, &createStruct)
|
||||
if err != nil {
|
||||
fields := log.Fields{"time": time.Now(), "event": "CreateEvent", "error": err}
|
||||
log.WithFields(fields).Fatalf("Error in unmarshaling JSON")
|
||||
}
|
||||
return createStruct
|
||||
}
|
||||
|
||||
func newDelete(data []byte) mod.Event {
|
||||
deleteStruct := mod.DeleteEvent{}
|
||||
err := json.Unmarshal(data, &deleteStruct)
|
||||
if err != nil {
|
||||
fields := log.Fields{"time": time.Now(), "event": "DeleteEvent", "error": err}
|
||||
log.WithFields(fields).Fatalf("Error in unmarshaling JSON")
|
||||
}
|
||||
return deleteStruct
|
||||
}
|
||||
|
||||
func newDeployment(data []byte) mod.Event {
|
||||
deploymentStruct := mod.DeploymentEvent{}
|
||||
err := json.Unmarshal(data, &deploymentStruct)
|
||||
if err != nil {
|
||||
fields := log.Fields{"time": time.Now(), "event": "DeploymentEvent", "error": err}
|
||||
log.WithFields(fields).Fatalf("Error in unmarshaling JSON")
|
||||
}
|
||||
return deploymentStruct
|
||||
}
|
||||
|
||||
func newDeploymentStatus(data []byte) mod.Event {
|
||||
deploymentStatusStruct := mod.DeploymentStatusEvent{}
|
||||
err := json.Unmarshal(data, &deploymentStatusStruct)
|
||||
if err != nil {
|
||||
fields := log.Fields{"time": time.Now(), "event": "DeploymentStatusEvent", "error": err}
|
||||
log.WithFields(fields).Fatalf("Error in unmarshaling JSON")
|
||||
}
|
||||
return deploymentStatusStruct
|
||||
}
|
||||
|
||||
func newFork(data []byte) mod.Event {
|
||||
forkStruct := mod.ForkEvent{}
|
||||
err := json.Unmarshal(data, &forkStruct)
|
||||
if err != nil {
|
||||
fields := log.Fields{"time": time.Now(), "event": "ForkEvent", "error": err}
|
||||
log.WithFields(fields).Fatalf("Error in unmarshaling JSON")
|
||||
}
|
||||
return forkStruct
|
||||
}
|
||||
|
||||
func newGollum(data []byte) mod.Event {
|
||||
gollumStruct := mod.GollumEvent{}
|
||||
err := json.Unmarshal(data, &gollumStruct)
|
||||
if err != nil {
|
||||
fields := log.Fields{"time": time.Now(), "event": "GollumEvent", "error": err}
|
||||
log.WithFields(fields).Fatalf("Error in unmarshaling JSON")
|
||||
}
|
||||
return gollumStruct
|
||||
}
|
||||
|
||||
func newIssueComment(data []byte) mod.Event {
|
||||
issueCommentStruct := mod.IssueCommentEvent{}
|
||||
err := json.Unmarshal(data, &issueCommentStruct)
|
||||
if err != nil {
|
||||
fields := log.Fields{"time": time.Now(), "event": "IssueCommentEvent", "error": err}
|
||||
log.WithFields(fields).Fatalf("Error in unmarshaling JSON")
|
||||
}
|
||||
return issueCommentStruct
|
||||
}
|
||||
|
||||
func newIssues(data []byte) mod.Event {
|
||||
issuesStruct := mod.IssuesEvent{}
|
||||
err := json.Unmarshal(data, &issuesStruct)
|
||||
if err != nil {
|
||||
fields := log.Fields{"time": time.Now(), "event": "IssuesEvent", "error": err}
|
||||
log.WithFields(fields).Fatalf("Error in unmarshaling JSON")
|
||||
}
|
||||
return issuesStruct
|
||||
}
|
||||
|
||||
func newMember(data []byte) mod.Event {
|
||||
memberStruct := mod.MemberEvent{}
|
||||
err := json.Unmarshal(data, &memberStruct)
|
||||
if err != nil {
|
||||
fields := log.Fields{"time": time.Now(), "event": "MemberEvent", "error": err}
|
||||
log.WithFields(fields).Fatalf("Error in unmarshaling JSON")
|
||||
}
|
||||
return memberStruct
|
||||
}
|
||||
|
||||
func newMembership(data []byte) mod.Event {
|
||||
membershipStruct := mod.MembershipEvent{}
|
||||
err := json.Unmarshal(data, &membershipStruct)
|
||||
if err != nil {
|
||||
fields := log.Fields{"time": time.Now(), "event": "MembershipEvent", "error": err}
|
||||
log.WithFields(fields).Fatalf("Error in unmarshaling JSON")
|
||||
}
|
||||
return membershipStruct
|
||||
}
|
||||
|
||||
func newPageBuild(data []byte) mod.Event {
|
||||
pageBuildEvent := mod.PageBuildEvent{}
|
||||
err := json.Unmarshal(data, &pageBuildEvent)
|
||||
if err != nil {
|
||||
fields := log.Fields{"time": time.Now(), "event": "PageBuildEvent", "error": err}
|
||||
log.WithFields(fields).Fatalf("Error in unmarshaling JSON")
|
||||
}
|
||||
return pageBuildEvent
|
||||
}
|
||||
|
||||
func newPublic(data []byte) mod.Event {
|
||||
publicEvent := mod.PublicEvent{}
|
||||
err := json.Unmarshal(data, &publicEvent)
|
||||
if err != nil {
|
||||
fields := log.Fields{"time": time.Now(), "event": "PublicEvent", "error": err}
|
||||
log.WithFields(fields).Fatalf("Error in unmarshaling JSON")
|
||||
}
|
||||
return publicEvent
|
||||
}
|
||||
|
||||
func newPullRequest(data []byte) mod.Event {
|
||||
pullRequestStruct := mod.PullRequestEvent{}
|
||||
err := json.Unmarshal(data, &pullRequestStruct)
|
||||
if err != nil {
|
||||
fields := log.Fields{"time": time.Now(), "event": "PullRequestEvent", "error": err}
|
||||
log.WithFields(fields).Fatalf("Error in unmarshaling JSON")
|
||||
}
|
||||
return pullRequestStruct
|
||||
}
|
||||
|
||||
func newPullRequestReviewComment(data []byte) mod.Event {
|
||||
pullRequestReviewCommentStruct := mod.PullRequestReviewCommentEvent{}
|
||||
err := json.Unmarshal(data, &pullRequestReviewCommentStruct)
|
||||
if err != nil {
|
||||
fields := log.Fields{"time": time.Now(), "event": "PullRequestReviewCommentEvent", "error": err}
|
||||
log.WithFields(fields).Fatalf("Error in unmarshaling JSON")
|
||||
}
|
||||
return pullRequestReviewCommentStruct
|
||||
}
|
||||
|
||||
func newPush(data []byte) mod.Event {
|
||||
pushStruct := mod.PushEvent{}
|
||||
err := json.Unmarshal(data, &pushStruct)
|
||||
if err != nil {
|
||||
fields := log.Fields{"time": time.Now(), "event": "PushEvent", "error": err}
|
||||
log.WithFields(fields).Fatalf("Error in unmarshaling JSON")
|
||||
}
|
||||
return pushStruct
|
||||
}
|
||||
|
||||
func newRelease(data []byte) mod.Event {
|
||||
releaseStruct := mod.ReleaseEvent{}
|
||||
err := json.Unmarshal(data, &releaseStruct)
|
||||
if err != nil {
|
||||
fields := log.Fields{"time": time.Now(), "event": "ReleaseEvent", "error": err}
|
||||
log.WithFields(fields).Fatalf("Error in unmarshaling JSON")
|
||||
}
|
||||
return releaseStruct
|
||||
}
|
||||
|
||||
func newRepository(data []byte) mod.Event {
|
||||
repositoryStruct := mod.RepositoryEvent{}
|
||||
err := json.Unmarshal(data, &repositoryStruct)
|
||||
if err != nil {
|
||||
fields := log.Fields{"time": time.Now(), "event": "RepositoryEvent", "error": err}
|
||||
log.WithFields(fields).Fatalf("Error in unmarshaling JSON")
|
||||
}
|
||||
return repositoryStruct
|
||||
}
|
||||
|
||||
func newStatus(data []byte) mod.Event {
|
||||
statusStruct := mod.StatusEvent{}
|
||||
err := json.Unmarshal(data, &statusStruct)
|
||||
if err != nil {
|
||||
fields := log.Fields{"time": time.Now(), "event": "StatusEvent", "error": err}
|
||||
log.WithFields(fields).Fatalf("Error in unmarshaling JSON")
|
||||
}
|
||||
return statusStruct
|
||||
}
|
||||
|
||||
func newTeamAdd(data []byte) mod.Event {
|
||||
teamAddStruct := mod.TeamAddEvent{}
|
||||
err := json.Unmarshal(data, &teamAddStruct)
|
||||
if err != nil {
|
||||
fields := log.Fields{"time": time.Now(), "event": "TeamAddEvent", "error": err}
|
||||
log.WithFields(fields).Fatalf("Error in unmarshaling JSON")
|
||||
}
|
||||
return teamAddStruct
|
||||
}
|
||||
|
||||
func newWatch(data []byte) mod.Event {
|
||||
watchStruct := mod.WatchEvent{}
|
||||
err := json.Unmarshal(data, &watchStruct)
|
||||
if err != nil {
|
||||
fields := log.Fields{"time": time.Now(), "event": "WatchEvent", "error": err}
|
||||
log.WithFields(fields).Fatalf("Error in unmarshaling JSON")
|
||||
}
|
||||
return watchStruct
|
||||
}
|
||||
|
||||
func NewEvent(r []byte, t string) mod.Event {
|
||||
log.WithFields(log.Fields{"event": t, "time": time.Now()}).Info("Event Recieved")
|
||||
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
|
||||
}
|
|
@ -0,0 +1,753 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/influxdata/influxdb/client/v2"
|
||||
)
|
||||
|
||||
const Measurement = "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,
|
||||
}
|
||||
time := time.Now()
|
||||
p, err := client.NewPoint(Measurement, t, f, time)
|
||||
if err != nil {
|
||||
i := log.Fields{"event": event, "error": err}
|
||||
log.WithFields(i).Fatal("Error creating new point...")
|
||||
}
|
||||
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,
|
||||
}
|
||||
time := time.Now()
|
||||
p, err := client.NewPoint(Measurement, t, f, time)
|
||||
if err != nil {
|
||||
i := log.Fields{"event": event, "error": err}
|
||||
log.WithFields(i).Fatal("Error creating new point...")
|
||||
}
|
||||
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,
|
||||
}
|
||||
time := time.Now()
|
||||
p, err := client.NewPoint(Measurement, t, f, time)
|
||||
if err != nil {
|
||||
i := log.Fields{"event": event, "error": err}
|
||||
log.WithFields(i).Fatal("Error creating new point...")
|
||||
}
|
||||
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,
|
||||
}
|
||||
time := time.Now()
|
||||
p, err := client.NewPoint(Measurement, t, f, time)
|
||||
if err != nil {
|
||||
i := log.Fields{"event": event, "error": err}
|
||||
log.WithFields(i).Fatal("Error creating new point...")
|
||||
}
|
||||
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,
|
||||
}
|
||||
time := time.Now()
|
||||
p, err := client.NewPoint(Measurement, t, f, time)
|
||||
if err != nil {
|
||||
i := log.Fields{"event": event, "error": err}
|
||||
log.WithFields(i).Fatal("Error creating new point...")
|
||||
}
|
||||
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,
|
||||
}
|
||||
time := time.Now()
|
||||
p, err := client.NewPoint(Measurement, t, f, time)
|
||||
if err != nil {
|
||||
i := log.Fields{"event": event, "error": err}
|
||||
log.WithFields(i).Fatal("Error creating new point...")
|
||||
}
|
||||
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,
|
||||
}
|
||||
time := time.Now()
|
||||
p, err := client.NewPoint(Measurement, t, f, time)
|
||||
if err != nil {
|
||||
i := log.Fields{"event": event, "error": err}
|
||||
log.WithFields(i).Fatal("Error creating new point...")
|
||||
}
|
||||
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,
|
||||
}
|
||||
time := time.Now()
|
||||
p, err := client.NewPoint(Measurement, t, f, time)
|
||||
if err != nil {
|
||||
i := log.Fields{"event": event, "error": err}
|
||||
log.WithFields(i).Fatal("Error creating new point...")
|
||||
}
|
||||
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,
|
||||
}
|
||||
time := time.Now()
|
||||
p, err := client.NewPoint(Measurement, t, f, time)
|
||||
if err != nil {
|
||||
i := log.Fields{"event": event, "error": err}
|
||||
log.WithFields(i).Fatal("Error creating new point...")
|
||||
}
|
||||
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,
|
||||
}
|
||||
time := time.Now()
|
||||
p, err := client.NewPoint(Measurement, t, f, time)
|
||||
if err != nil {
|
||||
i := log.Fields{"event": event, "error": err}
|
||||
log.WithFields(i).Fatal("Error creating new point...")
|
||||
}
|
||||
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,
|
||||
}
|
||||
time := time.Now()
|
||||
p, err := client.NewPoint(Measurement, t, f, time)
|
||||
if err != nil {
|
||||
i := log.Fields{"event": event, "error": err}
|
||||
log.WithFields(i).Fatal("Error creating new point...")
|
||||
}
|
||||
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,
|
||||
}
|
||||
time := time.Now()
|
||||
p, err := client.NewPoint(Measurement, t, f, time)
|
||||
if err != nil {
|
||||
i := log.Fields{"event": event, "error": err}
|
||||
log.WithFields(i).Fatal("Error creating new point...")
|
||||
}
|
||||
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,
|
||||
}
|
||||
time := time.Now()
|
||||
p, err := client.NewPoint(Measurement, t, f, time)
|
||||
if err != nil {
|
||||
i := log.Fields{"event": event, "error": err}
|
||||
log.WithFields(i).Fatal("Error creating new point...")
|
||||
}
|
||||
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,
|
||||
}
|
||||
time := time.Now()
|
||||
p, err := client.NewPoint(Measurement, t, f, time)
|
||||
if err != nil {
|
||||
i := log.Fields{"event": event, "error": err}
|
||||
log.WithFields(i).Fatal("Error creating new point...")
|
||||
}
|
||||
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,
|
||||
}
|
||||
time := time.Now()
|
||||
p, err := client.NewPoint(Measurement, t, f, time)
|
||||
if err != nil {
|
||||
i := log.Fields{"event": event, "error": err}
|
||||
log.WithFields(i).Fatal("Error creating new point...")
|
||||
}
|
||||
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,
|
||||
}
|
||||
time := time.Now()
|
||||
p, err := client.NewPoint(Measurement, t, f, time)
|
||||
if err != nil {
|
||||
i := log.Fields{"event": event, "error": err}
|
||||
log.WithFields(i).Fatal("Error creating new point...")
|
||||
}
|
||||
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,
|
||||
}
|
||||
time := time.Now()
|
||||
p, err := client.NewPoint(Measurement, t, f, time)
|
||||
if err != nil {
|
||||
i := log.Fields{"event": event, "error": err}
|
||||
log.WithFields(i).Fatal("Error creating new point...")
|
||||
}
|
||||
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,
|
||||
}
|
||||
time := time.Now()
|
||||
p, err := client.NewPoint(Measurement, t, f, time)
|
||||
if err != nil {
|
||||
i := log.Fields{"event": event, "error": err}
|
||||
log.WithFields(i).Fatal("Error creating new point...")
|
||||
}
|
||||
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,
|
||||
}
|
||||
time := time.Now()
|
||||
p, err := client.NewPoint(Measurement, t, f, time)
|
||||
if err != nil {
|
||||
i := log.Fields{"event": event, "error": err}
|
||||
log.WithFields(i).Fatal("Error creating new point...")
|
||||
}
|
||||
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,
|
||||
}
|
||||
time := time.Now()
|
||||
p, err := client.NewPoint(Measurement, t, f, time)
|
||||
if err != nil {
|
||||
i := log.Fields{"event": event, "error": err}
|
||||
log.WithFields(i).Fatal("Error creating new point...")
|
||||
}
|
||||
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,
|
||||
}
|
||||
time := time.Now()
|
||||
p, err := client.NewPoint(Measurement, t, f, time)
|
||||
if err != nil {
|
||||
i := log.Fields{"event": event, "error": err}
|
||||
log.WithFields(i).Fatal("Error creating new point...")
|
||||
}
|
||||
return p
|
||||
}
|
Loading…
Reference in New Issue