Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Golangci linting cleanup #150

Merged
merged 1 commit into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ vendor/
# vim
*~

#goland
.idea

# macOS
.DS_Store

Expand Down
4 changes: 2 additions & 2 deletions pkg/hubbub/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ func (h *Engine) conversation(i GitHubItem, cs []*Comment, age time.Time) *Conve

// Loose, but good enough
months := time.Since(co.Created).Hours() / 24 / 30
co.CommentersPerMonth = float64(co.CommentersTotal) / float64(months)
co.ReactionsPerMonth = float64(co.ReactionsTotal) / float64(months)
co.CommentersPerMonth = float64(co.CommentersTotal) / months
co.ReactionsPerMonth = float64(co.ReactionsTotal) / months
return co
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/hubbub/pull_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func reviewState(pr GitHubItem, timeline []*github.Timeline, reviews []*github.P
return Closed
}

klog.V(1).Infof("PR #%d has %d reviews, hoping one is for %s ...", pr.GetNumber(), (reviews), lastCommitID)
klog.V(1).Infof("PR #%d has %d reviews, hoping one is for %s ...", pr.GetNumber(), len(reviews), lastCommitID)
lastReview := time.Time{}
for _, r := range reviews {
if r.GetCommitID() == lastCommitID || lastCommitID == "" {
Expand Down
7 changes: 5 additions & 2 deletions pkg/hubbub/similar.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var removeWords = map[string]bool{

// normalize titles for a higher hit-rate
func normalizeTitle(t string) string {
keep := []string{}
var keep []string
for _, word := range strings.Split(t, " ") {
word = nonLetter.ReplaceAllString(word, "")
if len(word) == 0 {
Expand Down Expand Up @@ -97,7 +97,10 @@ func (h *Engine) updateSimilarityTables(rawTitle, url string) {
similarTo := []string{}

h.titleToURLs.Range(func(k, v interface{}) bool {
otherTitle := k.(string)
otherTitle, ok := k.(string)
if !ok {
klog.V(1).Infof("key %q is not of type string", k)
}
if otherTitle == title {
return true
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/persist/gocache.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ func newerThanMem(c *cache.Cache, key string, t time.Time) *Thing {
return nil
}

th := x.(*Thing)
th, ok := x.(*Thing)
if !ok {
klog.V(1).Infof("%s is not of type Thing", key)
}

if th.Created.Before(t) {
klog.V(2).Infof("%s in cache, but %s is older than %s", key, logu.STime(th.Created), logu.STime(t))
Expand Down
1 change: 0 additions & 1 deletion pkg/persist/mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

// Package persist provides a bootstrap for the in-memory cache

package persist

import (
Expand Down
2 changes: 1 addition & 1 deletion pkg/triage/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func MustReadToken(path string, env string) string {
klog.Infof("loaded %d byte github token from %s", len(token), env)
}

token = strings.TrimSpace(string(token))
token = strings.TrimSpace(token)
if len(token) < 8 {
klog.Exitf("github token impossibly small: %q", token)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/triage/triage.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func closedAge(fs []hubbub.Filter) time.Duration {

if oldest == 0 {
klog.Warningf("I need closed data, but I'm not sure how old: picking 4 days")
return time.Duration(24 * 4 * time.Hour)
return 24 * 4 * time.Hour
}

return oldest
Expand Down
15 changes: 7 additions & 8 deletions pkg/updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package updater

import (
"context"
"errors"
"fmt"
"math/rand"
"sync"
Expand Down Expand Up @@ -205,32 +206,30 @@ func (u *Updater) update(ctx context.Context, s triage.Collection, newerThan tim

// Run a single collection, optionally forcing an update
func (u *Updater) RefreshCollection(ctx context.Context, id string, newerThan time.Time, force bool) (bool, error) {
updated := false
klog.V(3).Infof("RefreshCollection: %s newer than %s, force=%v (locking mutex)", id, newerThan, force)
u.mutex.Lock()
defer u.mutex.Unlock()

s, err := u.party.LookupCollection(id)
if err != nil {
return updated, err
return false, err
}

if err := u.shouldUpdate(s.ID, force); err != nil {
klog.Infof("reason for updating %q: %v", s.ID, err)

err := u.update(ctx, s, newerThan)
if err != nil {
return updated, err
return false, err
}
updated = true
}
return updated, nil
return true, nil
}

// Persist saves results to the persistence layer
func (u *Updater) Persist() error {
if !u.persistStart.IsZero() {
return fmt.Errorf("already persisting!")
return errors.New("already persisting")
}

// advisory lock
Expand Down Expand Up @@ -291,7 +290,7 @@ func (u *Updater) RunOnce(ctx context.Context, force bool) (bool, error) {
}()

if force {
klog.Warningf(">>> RunOnce has force enabled")
klog.Warning(">>> RunOnce has force enabled")
} else {
klog.V(3).Infof("RunOnce: force=%v", force)
}
Expand All @@ -308,7 +307,7 @@ func (u *Updater) RunOnce(ctx context.Context, force bool) (bool, error) {

newerThan := start.Add(-2 * minFlushAge)
if u.updateCycles == 0 {
klog.Infof("have not yet completed a cycle - will accept stale results")
klog.Info("have not yet completed a cycle - will accept stale results")
newerThan = time.Time{}
}

Expand Down