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

Add retests/pr transform plugin. #2201

Merged
merged 2 commits into from
Mar 9, 2017
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
1 change: 1 addition & 0 deletions velodrome/transform/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ go_library(
"plugins.go",
"prstats.go",
"rebase.go",
"retest.go",
"transform.go",
],
tags = ["automanaged"],
Expand Down
1 change: 1 addition & 0 deletions velodrome/transform/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func NewPlugins(idb InfluxDatabase) Plugins {
NewLGTMToMergedPlugin(idb),
NewFirstCommentPlugin(idb),
NewRebasePlugin(idb),
NewRetestPlugin(idb),
}

return plugins
Expand Down
88 changes: 88 additions & 0 deletions velodrome/transform/retest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
Copyright 2017 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"regexp"
"time"

"github.com/golang/glog"

"k8s.io/test-infra/velodrome/sql"
)

var (
// Matches "@k8s-bot foo bar test this" with the capture group "foo bar".
testThisRe = regexp.MustCompile(`@k8s-bot (\w*(?: \w+)*) ?test this`)

robotNames = map[string]bool{
"k8s-merge-robot": true,
"k8s-ci-robot": true,
}
)

type Retest struct {
DB InfluxDatabase
last time.Time
// Number of requests for retest per PR.
retests map[int]int
}

// NewRetestPlugin initializes the plugin.
func NewRetestPlugin(DB InfluxDatabase) *Retest {
last, err := DB.GetLastMeasurement("retest")
if err != nil {
glog.Fatal("Failed to create Retest plugin: ", err)
}
return &Retest{
DB: DB,
last: last,
retests: make(map[int]int),
}
}

// ReceiveIssue is not used for this metric.
func (*Retest) ReceiveIssue(sql.Issue) error {
return nil
}

// ReceiveComment counts occurences of "@k8s-bot test this"-style comments.
func (r *Retest) ReceiveComment(comment sql.Comment) error {
if robotNames[comment.User] {
return nil
}
if matches := testThisRe.MatchString(comment.Body); !matches {
return nil
}
r.retests[comment.IssueID]++
return nil
}

// ReceiveIssueEvent adds to the DB when a PR is merged.
func (r *Retest) ReceiveIssueEvent(event sql.IssueEvent) error {
if !event.EventCreatedAt.After(r.last) {
return nil
}
if event.Event != "merged" {
return nil
}
return r.DB.Push(
"retest",
nil,
map[string]interface{}{"value": r.retests[event.IssueId]},
event.EventCreatedAt)
}