From 44214c9ba7bfe2fa087969eab9026372342cae33 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Fri, 10 May 2019 20:04:54 -0700 Subject: [PATCH] mostly fix ci --- src/github.com/matrix-org/go-neb/goneb.go | 14 +++++++------- .../matrix-org/go-neb/realms/jira/jira.go | 2 +- .../go-neb/services/alertmanager/alertmanager.go | 14 +++++++------- .../matrix-org/go-neb/services/github/github.go | 9 +++++---- .../go-neb/services/github/github_webhook.go | 4 ++-- .../matrix-org/go-neb/services/jira/jira.go | 6 +++--- .../go-neb/services/jira/webhook/webhook.go | 2 +- .../matrix-org/go-neb/services/rssbot/rssbot.go | 12 ++++++------ .../go-neb/services/travisci/travisci.go | 4 ++-- 9 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/github.com/matrix-org/go-neb/goneb.go b/src/github.com/matrix-org/go-neb/goneb.go index 6afcb56..c8ed9ca 100644 --- a/src/github.com/matrix-org/go-neb/goneb.go +++ b/src/github.com/matrix-org/go-neb/goneb.go @@ -172,15 +172,15 @@ func setup(e envVars, mux *http.ServeMux, matrixClient *http.Client) { log.Info("Inserted ", len(cfg.Sessions), " sessions") } - clients := clients.New(db, matrixClient) - if err := clients.Start(); err != nil { + newClients := clients.New(db, matrixClient) + if err := newClients.Start(); err != nil { log.WithError(err).Panic("Failed to start up clients") } // Handle non-admin paths for normal NEB functioning mux.Handle("/metrics", prometheus.Handler()) mux.Handle("/test", prometheus.InstrumentHandler("test", util.MakeJSONAPI(&handlers.Heartbeat{}))) - wh := handlers.NewWebhook(db, clients) + wh := handlers.NewWebhook(db, newClients) mux.HandleFunc("/services/hooks/", prometheus.InstrumentHandlerFunc("webhookHandler", util.Protect(wh.Handle))) rh := &handlers.RealmRedirect{db} mux.HandleFunc("/realms/redirects/", prometheus.InstrumentHandlerFunc("realmRedirectHandler", util.Protect(rh.Handle))) @@ -188,7 +188,7 @@ func setup(e envVars, mux *http.ServeMux, matrixClient *http.Client) { // Read exclusively from the config file if one was supplied. // Otherwise, add HTTP listeners for new Services/Sessions/Clients/etc. if e.ConfigFile != "" { - if err := insertServicesFromConfig(clients, cfg.Services); err != nil { + if err := insertServicesFromConfig(newClients, cfg.Services); err != nil { log.WithError(err).Panic("Failed to insert services") } @@ -196,13 +196,13 @@ func setup(e envVars, mux *http.ServeMux, matrixClient *http.Client) { } else { mux.Handle("/admin/getService", prometheus.InstrumentHandler("getService", util.MakeJSONAPI(&handlers.GetService{db}))) mux.Handle("/admin/getSession", prometheus.InstrumentHandler("getSession", util.MakeJSONAPI(&handlers.GetSession{db}))) - mux.Handle("/admin/configureClient", prometheus.InstrumentHandler("configureClient", util.MakeJSONAPI(&handlers.ConfigureClient{clients}))) - mux.Handle("/admin/configureService", prometheus.InstrumentHandler("configureService", util.MakeJSONAPI(handlers.NewConfigureService(db, clients)))) + mux.Handle("/admin/configureClient", prometheus.InstrumentHandler("configureClient", util.MakeJSONAPI(&handlers.ConfigureClient{newClients}))) + mux.Handle("/admin/configureService", prometheus.InstrumentHandler("configureService", util.MakeJSONAPI(handlers.NewConfigureService(db, newClients)))) mux.Handle("/admin/configureAuthRealm", prometheus.InstrumentHandler("configureAuthRealm", util.MakeJSONAPI(&handlers.ConfigureAuthRealm{db}))) mux.Handle("/admin/requestAuthSession", prometheus.InstrumentHandler("requestAuthSession", util.MakeJSONAPI(&handlers.RequestAuthSession{db}))) mux.Handle("/admin/removeAuthSession", prometheus.InstrumentHandler("removeAuthSession", util.MakeJSONAPI(&handlers.RemoveAuthSession{db}))) } - polling.SetClients(clients) + polling.SetClients(newClients) if err := polling.Start(); err != nil { log.WithError(err).Panic("Failed to start polling") } diff --git a/src/github.com/matrix-org/go-neb/realms/jira/jira.go b/src/github.com/matrix-org/go-neb/realms/jira/jira.go index 41f5889..93c9328 100644 --- a/src/github.com/matrix-org/go-neb/realms/jira/jira.go +++ b/src/github.com/matrix-org/go-neb/realms/jira/jira.go @@ -165,7 +165,7 @@ func (r *Realm) Init() error { // Register is called when this realm is being created from an external entity func (r *Realm) Register() error { if r.ConsumerName == "" || r.ConsumerKey == "" || r.ConsumerSecret == "" || r.PrivateKeyPEM == "" { - return errors.New("ConsumerName, ConsumerKey, ConsumerSecret, PrivateKeyPEM must be specified.") + return errors.New("ConsumerName, ConsumerKey, ConsumerSecret, PrivateKeyPEM must be specified") } if r.JIRAEndpoint == "" { return errors.New("JIRAEndpoint must be specified") diff --git a/src/github.com/matrix-org/go-neb/services/alertmanager/alertmanager.go b/src/github.com/matrix-org/go-neb/services/alertmanager/alertmanager.go index dde808f..b3fbd3d 100644 --- a/src/github.com/matrix-org/go-neb/services/alertmanager/alertmanager.go +++ b/src/github.com/matrix-org/go-neb/services/alertmanager/alertmanager.go @@ -52,7 +52,7 @@ type Service struct { } `json:"rooms"` } -// The payload from Alertmanager +// WebhookNotification is the payload from Alertmanager type WebhookNotification struct { Version string `json:"version"` GroupKey string `json:"groupKey"` @@ -125,13 +125,13 @@ func (s *Service) Register(oldService types.Service, client *gomatrix.Client) er // validate that we have at least a plain text template if templates.TextTemplate == "" { return fmt.Errorf("plain text template missing") - } else { - // validate the plain text template is valid - _, err := text.New("textTemplate").Parse(templates.TextTemplate) - if err != nil { - return fmt.Errorf("plain text template is invalid") - } + + // validate the plain text template is valid + _, err := text.New("textTemplate").Parse(templates.TextTemplate) + if err != nil { + return fmt.Errorf("plain text template is invalid") } + if templates.HTMLTemplate != "" { // validate that the html template is valid _, err := html.New("htmlTemplate").Parse(templates.HTMLTemplate) diff --git a/src/github.com/matrix-org/go-neb/services/github/github.go b/src/github.com/matrix-org/go-neb/services/github/github.go index ca3fc2f..9b1b379 100644 --- a/src/github.com/matrix-org/go-neb/services/github/github.go +++ b/src/github.com/matrix-org/go-neb/services/github/github.go @@ -12,6 +12,8 @@ import ( "strings" "bytes" + "html" + log "github.com/Sirupsen/logrus" gogithub "github.com/google/go-github/github" "github.com/matrix-org/go-neb/database" @@ -20,7 +22,6 @@ import ( "github.com/matrix-org/go-neb/services/github/client" "github.com/matrix-org/go-neb/types" "github.com/matrix-org/gomatrix" - "html" ) // ServiceType of the Github service @@ -450,8 +451,8 @@ func (s *Service) expandCommit(roomID, userID, owner, repo, sha string) interfac if err != nil { log.WithError(err).WithFields(log.Fields{ "owner": owner, - "repo": repo, - "sha": sha, + "repo": repo, + "sha": sha, }).Print("Failed to fetch commit") return nil } @@ -744,7 +745,7 @@ func getTokenForUser(realmID, userID string) (string, error) { return "", fmt.Errorf("Session is not a github session: %s", session.ID()) } if ghSession.AccessToken == "" { - return "", fmt.Errorf("Github auth session for %s has not been completed.", userID) + return "", fmt.Errorf("Github auth session for %s has not been completed", userID) } return ghSession.AccessToken, nil } diff --git a/src/github.com/matrix-org/go-neb/services/github/github_webhook.go b/src/github.com/matrix-org/go-neb/services/github/github_webhook.go index fdf36e6..ddbf1d3 100644 --- a/src/github.com/matrix-org/go-neb/services/github/github_webhook.go +++ b/src/github.com/matrix-org/go-neb/services/github/github_webhook.go @@ -156,7 +156,7 @@ func (s *WebhookService) Register(oldService types.Service, client *gomatrix.Cli cli := s.githubClientFor(s.ClientUserID, false) if cli == nil { return fmt.Errorf( - "User %s does not have a Github auth session with realm %s.", s.ClientUserID, realm.ID()) + "User %s does not have a Github auth session with realm %s", s.ClientUserID, realm.ID()) } // Fetch the old service list and work out the difference between the two services. @@ -182,7 +182,7 @@ func (s *WebhookService) Register(oldService types.Service, client *gomatrix.Cli // The user didn't specify any webhooks. This may be a bug or it may be // a conscious decision to remove all webhooks for this service. Figure out // which it is by checking if we'd be removing any webhooks. - return fmt.Errorf("No webhooks specified.") + return fmt.Errorf("No webhooks specified") } for _, r := range newRepos { logger := log.WithField("repo", r) diff --git a/src/github.com/matrix-org/go-neb/services/jira/jira.go b/src/github.com/matrix-org/go-neb/services/jira/jira.go index 647c9d9..8e15b05 100644 --- a/src/github.com/matrix-org/go-neb/services/jira/jira.go +++ b/src/github.com/matrix-org/go-neb/services/jira/jira.go @@ -101,7 +101,7 @@ func (s *Service) cmdJiraCreate(roomID, userID string, args []string) (interface } if !projectKeyRegex.MatchString(args[0]) { - return nil, errors.New("Project key must only contain A-Z.") + return nil, errors.New("Project key must only contain A-Z") } pkey := strings.ToUpper(args[0]) // REST API complains if they are not ALL CAPS @@ -118,10 +118,10 @@ func (s *Service) cmdJiraCreate(roomID, userID string, args []string) (interface r, err := s.projectToRealm(userID, pkey) if err != nil { log.WithError(err).Print("Failed to map project key to realm") - return nil, errors.New("Failed to map project key to a JIRA endpoint.") + return nil, errors.New("Failed to map project key to a JIRA endpoint") } if r == nil { - return nil, errors.New("No known project exists with that project key.") + return nil, errors.New("No known project exists with that project key") } iss := gojira.Issue{ diff --git a/src/github.com/matrix-org/go-neb/services/jira/webhook/webhook.go b/src/github.com/matrix-org/go-neb/services/jira/webhook/webhook.go index edc9417..c9738f7 100644 --- a/src/github.com/matrix-org/go-neb/services/jira/webhook/webhook.go +++ b/src/github.com/matrix-org/go-neb/services/jira/webhook/webhook.go @@ -85,7 +85,7 @@ func RegisterHook(jrealm *jira.Realm, projects []string, userID, webhookEndpoint // JIRA endpoint. if !jrealm.HasWebhook { logger.Print("No webhook exists for this realm.") - return fmt.Errorf("Not authorised to create webhook: not an admin.") + return fmt.Errorf("Not authorised to create webhook: not an admin") } return nil } diff --git a/src/github.com/matrix-org/go-neb/services/rssbot/rssbot.go b/src/github.com/matrix-org/go-neb/services/rssbot/rssbot.go index 32495c5..0a13c32 100644 --- a/src/github.com/matrix-org/go-neb/services/rssbot/rssbot.go +++ b/src/github.com/matrix-org/go-neb/services/rssbot/rssbot.go @@ -81,7 +81,7 @@ func (s *Service) Register(oldService types.Service, client *gomatrix.Client) er numOldFeeds = len(oldFeedService.Feeds) } if numOldFeeds == 0 { - return errors.New("An RSS feed must be specified.") + return errors.New("An RSS feed must be specified") } return nil } @@ -353,13 +353,13 @@ func itemToHTML(feed *gofeed.Feed, item gofeed.Item) gomatrix.HTMLMessage { Body: fmt.Sprintf("%s: %s (%s)", html.EscapeString(feed.Title), html.EscapeString(item.Title), html.EscapeString(item.Link)), MsgType: "m.notice", - Format: "org.matrix.custom.html", + Format: "org.matrix.custom.html", FormattedBody: fmt.Sprintf("%s:
%s", html.EscapeString(feed.Title), html.EscapeString(item.Link), html.EscapeString(item.Title)), - // FeedTitle: - //
- // Title of the Entry - } + // FeedTitle: + //
+ // Title of the Entry + } } func ensureItemsHaveGUIDs(feed *gofeed.Feed) { diff --git a/src/github.com/matrix-org/go-neb/services/travisci/travisci.go b/src/github.com/matrix-org/go-neb/services/travisci/travisci.go index 936bd1b..dc1421b 100644 --- a/src/github.com/matrix-org/go-neb/services/travisci/travisci.go +++ b/src/github.com/matrix-org/go-neb/services/travisci/travisci.go @@ -247,7 +247,7 @@ func (s *Service) Register(oldService types.Service, client *gomatrix.Client) er for repo := range roomData.Repos { match := ownerRepoRegex.FindStringSubmatch(repo) if len(match) == 0 { - return fmt.Errorf("Repository '%s' is not a valid repository name.", repo) + return fmt.Errorf("Repository '%s' is not a valid repository name", repo) } } } @@ -258,7 +258,7 @@ func (s *Service) Register(oldService types.Service, client *gomatrix.Client) er // PostRegister deletes this service if there are no registered repos. func (s *Service) PostRegister(oldService types.Service) { for _, roomData := range s.Rooms { - for _ = range roomData.Repos { + for range roomData.Repos { return // at least 1 repo exists } }