Skip to content

Commit

Permalink
Fix velodrome lint errors, fixes #8355
Browse files Browse the repository at this point in the history
  • Loading branch information
matthyx committed Jun 19, 2018
1 parent 48e7ca0 commit c0b1332
Show file tree
Hide file tree
Showing 28 changed files with 210 additions and 122 deletions.
2 changes: 2 additions & 0 deletions velodrome/fetcher/client.go
Expand Up @@ -56,6 +56,7 @@ func (client *Client) AddFlags(cmd *cobra.Command) {
"The github project to scan")
}

// CheckFlags looks for organization and project flags to configure the client
func (client *Client) CheckFlags() error {
if client.Org == "" {
return fmt.Errorf("organization flag must be set")
Expand Down Expand Up @@ -125,6 +126,7 @@ type ClientInterface interface {
FetchPullComments(issueID int, last time.Time, c chan *github.PullRequestComment)
}

// RepositoryName returns github's repository name in the form of org/project
func (client *Client) RepositoryName() string {
return fmt.Sprintf("%s/%s", client.Org, client.Project)
}
Expand Down
18 changes: 9 additions & 9 deletions velodrome/fetcher/conversion.go
Expand Up @@ -103,15 +103,15 @@ func NewIssueEvent(gIssueEvent *github.IssueEvent, issueID int, repository strin
Label: label,
Event: *gIssueEvent.Event,
EventCreatedAt: *gIssueEvent.CreatedAt,
IssueId: strconv.Itoa(issueID),
IssueID: strconv.Itoa(issueID),
Assignee: assignee,
Actor: actor,
Repository: strings.ToLower(repository),
}, nil
}

// newLabels creates a new Label for each label in the issue
func newLabels(issueId int, gLabels []github.Label, repository string) ([]sql.Label, error) {
func newLabels(issueID int, gLabels []github.Label, repository string) ([]sql.Label, error) {
labels := []sql.Label{}
repository = strings.ToLower(repository)

Expand All @@ -120,7 +120,7 @@ func newLabels(issueId int, gLabels []github.Label, repository string) ([]sql.La
return nil, fmt.Errorf("Label is missing name field")
}
labels = append(labels, sql.Label{
IssueID: strconv.Itoa(issueId),
IssueID: strconv.Itoa(issueID),
Name: *label.Name,
Repository: repository,
})
Expand All @@ -130,7 +130,7 @@ func newLabels(issueId int, gLabels []github.Label, repository string) ([]sql.La
}

// newAssignees creates a new Label for each label in the issue
func newAssignees(issueId int, gAssignees []*github.User, repository string) ([]sql.Assignee, error) {
func newAssignees(issueID int, gAssignees []*github.User, repository string) ([]sql.Assignee, error) {
assignees := []sql.Assignee{}
repository = strings.ToLower(repository)

Expand All @@ -139,7 +139,7 @@ func newAssignees(issueId int, gAssignees []*github.User, repository string) ([]
return nil, fmt.Errorf("Assignee is missing Login field")
}
assignees = append(assignees, sql.Assignee{
IssueID: strconv.Itoa(issueId),
IssueID: strconv.Itoa(issueID),
Name: *assignee.Login,
Repository: repository,
})
Expand All @@ -149,7 +149,7 @@ func newAssignees(issueId int, gAssignees []*github.User, repository string) ([]
}

// NewIssueComment creates a Comment from a github.IssueComment
func NewIssueComment(issueId int, gComment *github.IssueComment, repository string) (*sql.Comment, error) {
func NewIssueComment(issueID int, gComment *github.IssueComment, repository string) (*sql.Comment, error) {
if gComment.ID == nil ||
gComment.Body == nil ||
gComment.CreatedAt == nil ||
Expand All @@ -164,7 +164,7 @@ func NewIssueComment(issueId int, gComment *github.IssueComment, repository stri

return &sql.Comment{
ID: strconv.Itoa(*gComment.ID),
IssueID: strconv.Itoa(issueId),
IssueID: strconv.Itoa(issueID),
Body: *gComment.Body,
User: login,
CommentCreatedAt: *gComment.CreatedAt,
Expand All @@ -175,7 +175,7 @@ func NewIssueComment(issueId int, gComment *github.IssueComment, repository stri
}

// NewPullComment creates a Comment from a github.PullRequestComment
func NewPullComment(issueId int, gComment *github.PullRequestComment, repository string) (*sql.Comment, error) {
func NewPullComment(issueID int, gComment *github.PullRequestComment, repository string) (*sql.Comment, error) {
if gComment.ID == nil ||
gComment.Body == nil ||
gComment.CreatedAt == nil ||
Expand All @@ -189,7 +189,7 @@ func NewPullComment(issueId int, gComment *github.PullRequestComment, repository
}
return &sql.Comment{
ID: strconv.Itoa(*gComment.ID),
IssueID: strconv.Itoa(issueId),
IssueID: strconv.Itoa(issueID),
Body: *gComment.Body,
User: login,
CommentCreatedAt: *gComment.CreatedAt,
Expand Down
44 changes: 22 additions & 22 deletions velodrome/fetcher/conversion_test.go
Expand Up @@ -28,7 +28,7 @@ import (
)

func makeIssue(number int,
title, body, state, user, prUrl, repository string,
title, body, state, user, prURL, repository string,
comments int,
isPullRequest bool,
createdAt, updatedAt, closedAt time.Time) *sql.Issue {
Expand All @@ -54,7 +54,7 @@ func makeIssue(number int,
}

func makeGithubIssue(number int,
title, body, state, user, prUrl string,
title, body, state, user, prURL string,
comments int,
isPullRequest bool,
createdAt, updatedAt, closedAt time.Time) *github.Issue {
Expand All @@ -64,8 +64,8 @@ func makeGithubIssue(number int,
pBody = &body
}
var pullRequest *github.PullRequestLinks
if prUrl != "" {
pullRequest = &github.PullRequestLinks{URL: &prUrl}
if prURL != "" {
pullRequest = &github.PullRequestLinks{URL: &prURL}
}
gUser := &github.User{Login: &user}
var pClosedAt *time.Time
Expand Down Expand Up @@ -142,7 +142,7 @@ func TestNewIssue(t *testing.T) {
}

func makeIssueEvent(
eventId, issueId int,
eventID, issueID int,
label, event, assignee, actor, repository string,
createdAt time.Time) *sql.IssueEvent {

Expand All @@ -158,19 +158,19 @@ func makeIssueEvent(
}

return &sql.IssueEvent{
ID: strconv.Itoa(eventId),
ID: strconv.Itoa(eventID),
Label: pLabel,
Event: event,
EventCreatedAt: createdAt,
IssueId: strconv.Itoa(issueId),
IssueID: strconv.Itoa(issueID),
Assignee: pAssignee,
Actor: pActor,
Repository: repository,
}
}

func makeGithubIssueEvent(
eventId int,
eventID int,
label, event, assignee, actor string,
createdAt time.Time) *github.IssueEvent {

Expand All @@ -189,7 +189,7 @@ func makeGithubIssueEvent(
}

return &github.IssueEvent{
ID: &eventId,
ID: &eventID,
Label: gLabel,
Event: &event,
CreatedAt: &createdAt,
Expand Down Expand Up @@ -244,7 +244,7 @@ func createLabel(name string) github.Label {
func TestNewLabels(t *testing.T) {
tests := []struct {
gLabels []github.Label
issueId int
issueID int
expectedLabels []sql.Label
}{
// Empty list gives empty list
Expand All @@ -266,7 +266,7 @@ func TestNewLabels(t *testing.T) {
}

for _, test := range tests {
actualLabels, _ := newLabels(test.issueId, test.gLabels, "FULL/REPO")
actualLabels, _ := newLabels(test.issueID, test.gLabels, "FULL/REPO")
if !reflect.DeepEqual(actualLabels, test.expectedLabels) {
t.Error("Actual: ", actualLabels,
"doesn't match expected: ", test.expectedLabels)
Expand Down Expand Up @@ -302,10 +302,10 @@ func makeGithubPullComment(id int, body, login string, createdAt, updatedAt time
}
}

func makeComment(issueId, Id int, body, login, repository string, createdAt, updatedAt time.Time, pullRequest bool) *sql.Comment {
func makeComment(issueID, iD int, body, login, repository string, createdAt, updatedAt time.Time, pullRequest bool) *sql.Comment {
return &sql.Comment{
ID: strconv.Itoa(Id),
IssueID: strconv.Itoa(issueId),
ID: strconv.Itoa(iD),
IssueID: strconv.Itoa(issueID),
Body: body,
User: login,
CommentCreatedAt: createdAt,
Expand All @@ -318,14 +318,14 @@ func makeComment(issueId, Id int, body, login, repository string, createdAt, upd
func TestNewIssueComment(t *testing.T) {
tests := []struct {
gComment *github.IssueComment
issueId int
issueID int
expectedComment *sql.Comment
}{
{
gComment: makeGithubIssueComment(1, "Body", "Login",
time.Date(2000, time.January, 1, 19, 30, 0, 0, time.UTC),
time.Date(2001, time.January, 1, 19, 30, 0, 0, time.UTC)),
issueId: 12,
issueID: 12,
expectedComment: makeComment(12, 1, "Body", "Login", "full/repo",
time.Date(2000, time.January, 1, 19, 30, 0, 0, time.UTC),
time.Date(2001, time.January, 1, 19, 30, 0, 0, time.UTC), false),
Expand All @@ -334,15 +334,15 @@ func TestNewIssueComment(t *testing.T) {
gComment: makeGithubIssueComment(1, "Body", "",
time.Date(2000, time.January, 1, 19, 30, 0, 0, time.UTC),
time.Date(2001, time.January, 1, 19, 30, 0, 0, time.UTC)),
issueId: 12,
issueID: 12,
expectedComment: makeComment(12, 1, "Body", "", "full/repo",
time.Date(2000, time.January, 1, 19, 30, 0, 0, time.UTC),
time.Date(2001, time.January, 1, 19, 30, 0, 0, time.UTC), false),
},
}

for _, test := range tests {
actualComment, _ := NewIssueComment(test.issueId, test.gComment, "FULL/REPO")
actualComment, _ := NewIssueComment(test.issueID, test.gComment, "FULL/REPO")
if !reflect.DeepEqual(actualComment, test.expectedComment) {
t.Error("Actual: ", actualComment,
"doesn't match expected: ", test.expectedComment)
Expand All @@ -353,15 +353,15 @@ func TestNewIssueComment(t *testing.T) {
func TestNewPullComment(t *testing.T) {
tests := []struct {
gComment *github.PullRequestComment
issueId int
issueID int
repository string
expectedComment *sql.Comment
}{
{
gComment: makeGithubPullComment(1, "Body", "Login",
time.Date(2000, time.January, 1, 19, 30, 0, 0, time.UTC),
time.Date(2001, time.January, 1, 19, 30, 0, 0, time.UTC)),
issueId: 12,
issueID: 12,
repository: "FULL/REPO",
expectedComment: makeComment(12, 1, "Body", "Login", "full/repo",
time.Date(2000, time.January, 1, 19, 30, 0, 0, time.UTC),
Expand All @@ -371,7 +371,7 @@ func TestNewPullComment(t *testing.T) {
gComment: makeGithubPullComment(1, "Body", "",
time.Date(2000, time.January, 1, 19, 30, 0, 0, time.UTC),
time.Date(2001, time.January, 1, 19, 30, 0, 0, time.UTC)),
issueId: 12,
issueID: 12,
repository: "FULL/REPO",
expectedComment: makeComment(12, 1, "Body", "", "full/repo",
time.Date(2000, time.January, 1, 19, 30, 0, 0, time.UTC),
Expand All @@ -380,7 +380,7 @@ func TestNewPullComment(t *testing.T) {
}

for _, test := range tests {
actualComment, _ := NewPullComment(test.issueId, test.gComment, test.repository)
actualComment, _ := NewPullComment(test.issueID, test.gComment, test.repository)
if !reflect.DeepEqual(actualComment, test.expectedComment) {
t.Error("Actual: ", actualComment,
"doesn't match expected: ", test.expectedComment)
Expand Down
2 changes: 1 addition & 1 deletion velodrome/fetcher/issue-events.go
Expand Up @@ -30,7 +30,7 @@ func findLatestEvent(issueID int, db *gorm.DB, repository string) (*int, error)

query := db.
Select("id, event_created_at").
Where(&sql.IssueEvent{IssueId: strconv.Itoa(issueID)}).
Where(&sql.IssueEvent{IssueID: strconv.Itoa(issueID)}).
Where("repository = ?", repository).
Order("event_created_at desc").
First(&latestEvent)
Expand Down
16 changes: 8 additions & 8 deletions velodrome/fetcher/issue-events_test.go
Expand Up @@ -45,28 +45,28 @@ func TestFindLatestUpdate(t *testing.T) {
},
{
[]sql.IssueEvent{
{ID: "2", IssueId: "7", EventCreatedAt: time.Date(1999, 1, 1, 0, 0, 0, 0, time.UTC), Repository: "ONE"},
{ID: "7", IssueId: "7", EventCreatedAt: time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), Repository: "ONE"},
{ID: "2", IssueID: "7", EventCreatedAt: time.Date(1999, 1, 1, 0, 0, 0, 0, time.UTC), Repository: "ONE"},
{ID: "7", IssueID: "7", EventCreatedAt: time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), Repository: "ONE"},
},
0,
"TWO",
7,
},
{
[]sql.IssueEvent{
{ID: "2", IssueId: "7", EventCreatedAt: time.Date(1999, 1, 1, 0, 0, 0, 0, time.UTC), Repository: "ONE"},
{ID: "7", IssueId: "2", EventCreatedAt: time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), Repository: "ONE"},
{ID: "1", IssueId: "7", EventCreatedAt: time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC), Repository: "TWO"},
{ID: "2", IssueID: "7", EventCreatedAt: time.Date(1999, 1, 1, 0, 0, 0, 0, time.UTC), Repository: "ONE"},
{ID: "7", IssueID: "2", EventCreatedAt: time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), Repository: "ONE"},
{ID: "1", IssueID: "7", EventCreatedAt: time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC), Repository: "TWO"},
},
2,
"ONE",
7,
},
{
[]sql.IssueEvent{
{ID: "2", IssueId: "7", EventCreatedAt: time.Date(1999, 1, 1, 0, 0, 0, 0, time.UTC), Repository: "ONE"},
{ID: "7", IssueId: "7", EventCreatedAt: time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), Repository: "ONE"},
{ID: "1", IssueId: "7", EventCreatedAt: time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC), Repository: "TWO"},
{ID: "2", IssueID: "7", EventCreatedAt: time.Date(1999, 1, 1, 0, 0, 0, 0, time.UTC), Repository: "ONE"},
{ID: "7", IssueID: "7", EventCreatedAt: time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), Repository: "ONE"},
{ID: "1", IssueID: "7", EventCreatedAt: time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC), Repository: "TWO"},
},
1,
"TWO",
Expand Down
2 changes: 1 addition & 1 deletion velodrome/sql/model.go
Expand Up @@ -59,7 +59,7 @@ type IssueEvent struct {
Label *string
Event string
EventCreatedAt time.Time `gorm:"index:repo_created"`
IssueId string
IssueID string
Assignee *string
Actor *string
}
Expand Down
2 changes: 1 addition & 1 deletion velodrome/token-counter/token-counter.go
Expand Up @@ -68,7 +68,7 @@ func GetUsername(client *github.Client) (string, error) {
return "", err
}
if user.Login == nil {
return "", errors.New("Users.Get(\"\") returned empty login.")
return "", errors.New("Users.Get(\"\") returned empty login")
}

return *user.Login, nil
Expand Down
6 changes: 6 additions & 0 deletions velodrome/transform/plugins/author_filter_wrapper.go
Expand Up @@ -21,6 +21,7 @@ import (
"k8s.io/test-infra/velodrome/sql"
)

// AuthorFilterPluginWrapper ignore comments and events from some authors
type AuthorFilterPluginWrapper struct {
ignoredAuthors []string

Expand All @@ -29,12 +30,14 @@ type AuthorFilterPluginWrapper struct {

var _ Plugin = &AuthorFilterPluginWrapper{}

// NewAuthorFilterPluginWrapper is the constructor for AuthorFilterPluginWrapper
func NewAuthorFilterPluginWrapper(plugin Plugin) *AuthorFilterPluginWrapper {
return &AuthorFilterPluginWrapper{
plugin: plugin,
}
}

// AddFlags adds "ignore-authors" <authors> to the command help
func (a *AuthorFilterPluginWrapper) AddFlags(cmd *cobra.Command) {
cmd.Flags().StringSliceVar(&a.ignoredAuthors, "ignore-authors", []string{}, "Name of people to ignore")
}
Expand All @@ -48,20 +51,23 @@ func (a *AuthorFilterPluginWrapper) match(author string) bool {
return false
}

// ReceiveIssue calls plugin.ReceiveIssue() if the author is not filtered
func (a *AuthorFilterPluginWrapper) ReceiveIssue(issue sql.Issue) []Point {
if a.match(issue.User) {
return nil
}
return a.plugin.ReceiveIssue(issue)
}

// ReceiveIssueEvent calls plugin.ReceiveIssueEvent() if the author is not filtered
func (a *AuthorFilterPluginWrapper) ReceiveIssueEvent(event sql.IssueEvent) []Point {
if event.Actor != nil && a.match(*event.Actor) {
return nil
}
return a.plugin.ReceiveIssueEvent(event)
}

// ReceiveComment calls plugin.ReceiveComment() if the author is not filtered
func (a *AuthorFilterPluginWrapper) ReceiveComment(comment sql.Comment) []Point {
if a.match(comment.User) {
return nil
Expand Down

0 comments on commit c0b1332

Please sign in to comment.