Skip to content

Commit

Permalink
maintner/maintnerd: return TRY= comment directives in Run-TryBot votes
Browse files Browse the repository at this point in the history
For slowbots support.

Updates golang/go#34501

Change-Id: I6f8a8b187c3ce4531498f106d62e29e1d1f421d8
Reviewed-on: https://go-review.googlesource.com/c/build/+/201204
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
bradfitz authored and codebien committed Nov 13, 2019
1 parent 3be2d7c commit 338f7d7
Show file tree
Hide file tree
Showing 4 changed files with 217 additions and 66 deletions.
144 changes: 100 additions & 44 deletions maintner/maintnerd/apipb/api.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions maintner/maintnerd/apipb/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ message GerritTryWorkItem {
string change_id = 3; // "I1a27695838409259d1586a0adfa9f92bccf7ceba"
string commit = 4; // "ecf3dffc81dc21408fb02159af352651882a8383"

int32 version = 9; // which Gerrit revision number commit is

// go_commit is set for subrepos and is the Go commit(s) to test against.
// go_branch is a branch name of go_commit, for showing to users when
// a try set fails.
Expand All @@ -65,6 +67,15 @@ message GerritTryWorkItem {
// For Go repo, it contains exactly one element.
// For subrepos, it contains elements that correspond to go_commit.
repeated MajorMinor go_version = 7;

// try_message is the list of TRY=xxxx messages associated with Run-TryBot votes.
repeated TryVoteMessage try_message = 8;
}

message TryVoteMessage {
string message = 1; // just the part after "TRY=" until end of line, without \n
int64 author_id = 2; // Gerrit-internal ID
int32 version = 3; // revision number comment was for
}

message MajorMinor {
Expand Down
93 changes: 76 additions & 17 deletions maintner/maintnerd/maintapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
"errors"
"fmt"
"log"
"regexp"
"sort"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -95,13 +97,63 @@ func tryBotStatus(cl *maintner.GerritCL, forStaging bool) (try, done bool) {
return
}

func tryWorkItem(cl *maintner.GerritCL) *apipb.GerritTryWorkItem {
return &apipb.GerritTryWorkItem{
var (
tryCommentRx = regexp.MustCompile(`(?m)^TRY=(.*)$`)
patchSetRx = regexp.MustCompile(`^Patch Set (\d{1,4}):`)
)

func tryWorkItem(cl *maintner.GerritCL, ci *gerrit.ChangeInfo) *apipb.GerritTryWorkItem {
work := &apipb.GerritTryWorkItem{
Project: cl.Project.Project(),
Branch: strings.TrimPrefix(cl.Branch(), "refs/heads/"),
ChangeId: cl.ChangeID(),
Commit: cl.Commit.Hash.String(),
}
if ci != nil {
if ci.CurrentRevision != "" {
// In case maintner is behind.
work.Commit = ci.CurrentRevision
work.Version = int32(ci.Revisions[ci.CurrentRevision].PatchSetNumber)
}
// Also include any "TRY=foo" comments (just the "foo"
// aprt) from messages that accompany Run-TryBot+1
// votes.
for _, m := range ci.Messages {
// msg is like:
// "Patch Set 2: Run-TryBot+1\n\nTRY=foo2"
// "Patch Set 2: Run-TryBot+1 Code-Review-2"
// "Uploaded patch set 2."
// "Removed Run-TryBot+1 by Brad Fitzpatrick <[email protected]>\n"
// "Patch Set 1: Run-TryBot+1\n\nTRY=baz"
msg := m.Message
if !strings.Contains(msg, "\n\nTRY=") ||
!strings.HasPrefix(msg, "Patch Set ") ||
!strings.Contains(firstLine(msg), "Run-TryBot+1") {
continue
}
pm := patchSetRx.FindStringSubmatch(msg)
var patchSet int
if pm != nil {
patchSet, _ = strconv.Atoi(pm[1])
}
if tm := tryCommentRx.FindStringSubmatch(msg); tm != nil && patchSet > 0 {
work.TryMessage = append(work.TryMessage, &apipb.TryVoteMessage{
Message: tm[1],
AuthorId: m.Author.NumericID,
Version: int32(patchSet),
})
}
}
}
return work
}

func firstLine(s string) string {
if nl := strings.Index(s, "\n"); nl < 0 {
return s
} else {
return s[:nl]
}
}

func (s apiService) GetRef(ctx context.Context, req *apipb.GetRefRequest) (*apipb.GetRefResponse, error) {
Expand Down Expand Up @@ -160,33 +212,45 @@ func (s apiService) GoFindTryWork(ctx context.Context, req *apipb.GoFindTryWorkR

ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()

res, err := goFindTryWork(ctx, tryBotGerrit, s.c)
if err != nil {
log.Printf("maintnerd: goFindTryWork: %v", err)
return nil, err
}

tryCache.val = res
tryCache.forNumChanges = sumChanges

log.Printf("maintnerd: GetTryWork: for label changes of %d, cached %d trywork items.",
sumChanges, len(res.Waiting))

return res, nil
}

func goFindTryWork(ctx context.Context, gerritc *gerrit.Client, maintc *maintner.Corpus) (*apipb.GoFindTryWorkResponse, error) {
const query = "label:Run-TryBot=1 label:TryBot-Result=0 status:open"
cis, err := tryBotGerrit.QueryChanges(ctx, query, gerrit.QueryChangesOpt{
Fields: []string{"CURRENT_REVISION", "CURRENT_COMMIT"},
cis, err := gerritc.QueryChanges(ctx, query, gerrit.QueryChangesOpt{
Fields: []string{"CURRENT_REVISION", "CURRENT_COMMIT", "MESSAGES"},
})
if err != nil {
return nil, err
}
tryCache.forNumChanges = sumChanges

goProj := s.c.Gerrit().Project("go.googlesource.com", "go")
goProj := maintc.Gerrit().Project("go.googlesource.com", "go")
supportedReleases, err := supportedGoReleases(goProj)
if err != nil {
return nil, err
}

res := new(apipb.GoFindTryWorkResponse)
for _, ci := range cis {
cl := s.c.Gerrit().Project("go.googlesource.com", ci.Project).CL(int32(ci.ChangeNumber))
cl := maintc.Gerrit().Project("go.googlesource.com", ci.Project).CL(int32(ci.ChangeNumber))
if cl == nil {
log.Printf("nil Gerrit CL %v", ci.ChangeNumber)
continue
}
work := tryWorkItem(cl)
if ci.CurrentRevision != "" {
// In case maintner is behind.
work.Commit = ci.CurrentRevision
}
work := tryWorkItem(cl, ci)
if work.Project == "go" {
// Trybot on Go repo. Set the GoVersion field based on branch name.
if work.Branch == "master" {
Expand Down Expand Up @@ -229,11 +293,6 @@ func (s apiService) GoFindTryWork(ctx context.Context, req *apipb.GoFindTryWorkR
sort.Slice(res.Waiting, func(i, j int) bool {
return res.Waiting[i].Commit < res.Waiting[j].Commit
})
tryCache.val = res

log.Printf("maintnerd: GetTryWork: for label changes of %d, cached %d trywork items.",
sumChanges, len(res.Waiting))

return res, nil
}

Expand Down
Loading

0 comments on commit 338f7d7

Please sign in to comment.