Skip to content

Commit e7b8bbc

Browse files
committed
maintner/maintnerd: return TRY= comment directives in Run-TryBot votes
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]>
1 parent 4e9e211 commit e7b8bbc

File tree

4 files changed

+217
-66
lines changed

4 files changed

+217
-66
lines changed

maintner/maintnerd/apipb/api.pb.go

Lines changed: 100 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

maintner/maintnerd/apipb/api.proto

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ message GerritTryWorkItem {
5555
string change_id = 3; // "I1a27695838409259d1586a0adfa9f92bccf7ceba"
5656
string commit = 4; // "ecf3dffc81dc21408fb02159af352651882a8383"
5757

58+
int32 version = 9; // which Gerrit revision number commit is
59+
5860
// go_commit is set for subrepos and is the Go commit(s) to test against.
5961
// go_branch is a branch name of go_commit, for showing to users when
6062
// a try set fails.
@@ -65,6 +67,15 @@ message GerritTryWorkItem {
6567
// For Go repo, it contains exactly one element.
6668
// For subrepos, it contains elements that correspond to go_commit.
6769
repeated MajorMinor go_version = 7;
70+
71+
// try_message is the list of TRY=xxxx messages associated with Run-TryBot votes.
72+
repeated TryVoteMessage try_message = 8;
73+
}
74+
75+
message TryVoteMessage {
76+
string message = 1; // just the part after "TRY=" until end of line, without \n
77+
int64 author_id = 2; // Gerrit-internal ID
78+
int32 version = 3; // revision number comment was for
6879
}
6980

7081
message MajorMinor {

maintner/maintnerd/maintapi/api.go

Lines changed: 76 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import (
1010
"errors"
1111
"fmt"
1212
"log"
13+
"regexp"
1314
"sort"
15+
"strconv"
1416
"strings"
1517
"sync"
1618
"time"
@@ -95,13 +97,63 @@ func tryBotStatus(cl *maintner.GerritCL, forStaging bool) (try, done bool) {
9597
return
9698
}
9799

98-
func tryWorkItem(cl *maintner.GerritCL) *apipb.GerritTryWorkItem {
99-
return &apipb.GerritTryWorkItem{
100+
var (
101+
tryCommentRx = regexp.MustCompile(`(?m)^TRY=(.*)$`)
102+
patchSetRx = regexp.MustCompile(`^Patch Set (\d{1,4}):`)
103+
)
104+
105+
func tryWorkItem(cl *maintner.GerritCL, ci *gerrit.ChangeInfo) *apipb.GerritTryWorkItem {
106+
work := &apipb.GerritTryWorkItem{
100107
Project: cl.Project.Project(),
101108
Branch: strings.TrimPrefix(cl.Branch(), "refs/heads/"),
102109
ChangeId: cl.ChangeID(),
103110
Commit: cl.Commit.Hash.String(),
104111
}
112+
if ci != nil {
113+
if ci.CurrentRevision != "" {
114+
// In case maintner is behind.
115+
work.Commit = ci.CurrentRevision
116+
work.Version = int32(ci.Revisions[ci.CurrentRevision].PatchSetNumber)
117+
}
118+
// Also include any "TRY=foo" comments (just the "foo"
119+
// aprt) from messages that accompany Run-TryBot+1
120+
// votes.
121+
for _, m := range ci.Messages {
122+
// msg is like:
123+
// "Patch Set 2: Run-TryBot+1\n\nTRY=foo2"
124+
// "Patch Set 2: Run-TryBot+1 Code-Review-2"
125+
// "Uploaded patch set 2."
126+
// "Removed Run-TryBot+1 by Brad Fitzpatrick <[email protected]>\n"
127+
// "Patch Set 1: Run-TryBot+1\n\nTRY=baz"
128+
msg := m.Message
129+
if !strings.Contains(msg, "\n\nTRY=") ||
130+
!strings.HasPrefix(msg, "Patch Set ") ||
131+
!strings.Contains(firstLine(msg), "Run-TryBot+1") {
132+
continue
133+
}
134+
pm := patchSetRx.FindStringSubmatch(msg)
135+
var patchSet int
136+
if pm != nil {
137+
patchSet, _ = strconv.Atoi(pm[1])
138+
}
139+
if tm := tryCommentRx.FindStringSubmatch(msg); tm != nil && patchSet > 0 {
140+
work.TryMessage = append(work.TryMessage, &apipb.TryVoteMessage{
141+
Message: tm[1],
142+
AuthorId: m.Author.NumericID,
143+
Version: int32(patchSet),
144+
})
145+
}
146+
}
147+
}
148+
return work
149+
}
150+
151+
func firstLine(s string) string {
152+
if nl := strings.Index(s, "\n"); nl < 0 {
153+
return s
154+
} else {
155+
return s[:nl]
156+
}
105157
}
106158

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

161213
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
162214
defer cancel()
215+
216+
res, err := goFindTryWork(ctx, tryBotGerrit, s.c)
217+
if err != nil {
218+
log.Printf("maintnerd: goFindTryWork: %v", err)
219+
return nil, err
220+
}
221+
222+
tryCache.val = res
223+
tryCache.forNumChanges = sumChanges
224+
225+
log.Printf("maintnerd: GetTryWork: for label changes of %d, cached %d trywork items.",
226+
sumChanges, len(res.Waiting))
227+
228+
return res, nil
229+
}
230+
231+
func goFindTryWork(ctx context.Context, gerritc *gerrit.Client, maintc *maintner.Corpus) (*apipb.GoFindTryWorkResponse, error) {
163232
const query = "label:Run-TryBot=1 label:TryBot-Result=0 status:open"
164-
cis, err := tryBotGerrit.QueryChanges(ctx, query, gerrit.QueryChangesOpt{
165-
Fields: []string{"CURRENT_REVISION", "CURRENT_COMMIT"},
233+
cis, err := gerritc.QueryChanges(ctx, query, gerrit.QueryChangesOpt{
234+
Fields: []string{"CURRENT_REVISION", "CURRENT_COMMIT", "MESSAGES"},
166235
})
167236
if err != nil {
168237
return nil, err
169238
}
170-
tryCache.forNumChanges = sumChanges
171239

172-
goProj := s.c.Gerrit().Project("go.googlesource.com", "go")
240+
goProj := maintc.Gerrit().Project("go.googlesource.com", "go")
173241
supportedReleases, err := supportedGoReleases(goProj)
174242
if err != nil {
175243
return nil, err
176244
}
177245

178246
res := new(apipb.GoFindTryWorkResponse)
179247
for _, ci := range cis {
180-
cl := s.c.Gerrit().Project("go.googlesource.com", ci.Project).CL(int32(ci.ChangeNumber))
248+
cl := maintc.Gerrit().Project("go.googlesource.com", ci.Project).CL(int32(ci.ChangeNumber))
181249
if cl == nil {
182250
log.Printf("nil Gerrit CL %v", ci.ChangeNumber)
183251
continue
184252
}
185-
work := tryWorkItem(cl)
186-
if ci.CurrentRevision != "" {
187-
// In case maintner is behind.
188-
work.Commit = ci.CurrentRevision
189-
}
253+
work := tryWorkItem(cl, ci)
190254
if work.Project == "go" {
191255
// Trybot on Go repo. Set the GoVersion field based on branch name.
192256
if work.Branch == "master" {
@@ -229,11 +293,6 @@ func (s apiService) GoFindTryWork(ctx context.Context, req *apipb.GoFindTryWorkR
229293
sort.Slice(res.Waiting, func(i, j int) bool {
230294
return res.Waiting[i].Commit < res.Waiting[j].Commit
231295
})
232-
tryCache.val = res
233-
234-
log.Printf("maintnerd: GetTryWork: for label changes of %d, cached %d trywork items.",
235-
sumChanges, len(res.Waiting))
236-
237296
return res, nil
238297
}
239298

0 commit comments

Comments
 (0)