Browse Source

Fix cosmetic issues from go lint/vet

pull/266/head
Víctor Cuadrado Juan 7 years ago
parent
commit
e766505241
No known key found for this signature in database GPG Key ID: 223F15CA5AAF0E78
  1. 2
      src/github.com/matrix-org/go-neb/realms/jira/jira.go
  2. 13
      src/github.com/matrix-org/go-neb/services/alertmanager/alertmanager.go
  3. 15
      src/github.com/matrix-org/go-neb/services/github/github.go
  4. 4
      src/github.com/matrix-org/go-neb/services/github/github_webhook.go
  5. 6
      src/github.com/matrix-org/go-neb/services/jira/jira.go
  6. 2
      src/github.com/matrix-org/go-neb/services/jira/webhook/webhook.go
  7. 2
      src/github.com/matrix-org/go-neb/services/rssbot/rssbot.go
  8. 2
      src/github.com/matrix-org/go-neb/services/travisci/travisci.go

2
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")

13
src/github.com/matrix-org/go-neb/services/alertmanager/alertmanager.go

@ -5,13 +5,14 @@ import (
"bytes"
"encoding/json"
"fmt"
html "html/template"
"net/http"
text "text/template"
log "github.com/Sirupsen/logrus"
"github.com/matrix-org/go-neb/database"
"github.com/matrix-org/go-neb/types"
"github.com/matrix-org/gomatrix"
html "html/template"
"net/http"
text "text/template"
)
// ServiceType of the Alertmanager service.
@ -52,7 +53,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"`
@ -61,14 +62,14 @@ type WebhookNotification struct {
GroupLabels map[string]string `json:"groupLabels"`
CommonLabels map[string]string `json:"commonLabels"`
CommonAnnotations map[string]string `json:"commonAnnotations"`
ExternalUrl string `json:"externalURL"`
ExternalURL string `json:"externalURL"`
Alerts []struct {
Status string `json:"status"`
Labels map[string]string `json:"labels"`
Annotations map[string]string `json:"annotations"`
StartsAt string `json:"startsAt"`
EndsAt string `json:"endsAt"`
GeneratorUrl string `json:"generatorURL"`
GeneratorURL string `json:"generatorURL"`
} `json:"alerts"`
}

15
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
}
@ -460,9 +461,9 @@ func (s *Service) expandCommit(roomID, userID, owner, repo, sha string) interfac
var htmlBuffer bytes.Buffer
var plainBuffer bytes.Buffer
shortUrl := strings.TrimSuffix(*c.HTMLURL, *c.SHA) + sha
htmlBuffer.WriteString(fmt.Sprintf("<a href=\"%s\">%s</a><br />", *c.HTMLURL, shortUrl))
plainBuffer.WriteString(fmt.Sprintf("%s\n", shortUrl))
shortURL := strings.TrimSuffix(*c.HTMLURL, *c.SHA) + sha
htmlBuffer.WriteString(fmt.Sprintf("<a href=\"%s\">%s</a><br />", *c.HTMLURL, shortURL))
plainBuffer.WriteString(fmt.Sprintf("%s\n", shortURL))
if c.Stats != nil {
htmlBuffer.WriteString(fmt.Sprintf("[<strong><font color='#1cc3ed'>~%d</font>, <font color='#30bf2b'>+%d</font>, <font color='#fc3a25'>-%d</font></strong>] ", len(c.Files), *c.Stats.Additions, *c.Stats.Deletions))
@ -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
}

4
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)

6
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{

2
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
}

2
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
}

2
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)
}
}
}

Loading…
Cancel
Save