Skip to content

Commit 5a3a2df

Browse files
committed
gaby: labels page: skip labels authored by bots
For #64. Change-Id: I9db76f39f41d2ad734257beb01b55d6de6705cfa Reviewed-on: https://go-review.googlesource.com/c/oscar/+/634976 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
1 parent d565474 commit 5a3a2df

File tree

3 files changed

+47
-21
lines changed

3 files changed

+47
-21
lines changed

internal/gaby/labels.go

+21-10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type labelsPage struct {
3131

3232
type labelsResult struct {
3333
*github.Issue // the issue we're reporting on
34+
Problem string
3435
Category labels.Category
3536
Explanation string
3637
BodyHTML safehtml.HTML
@@ -93,17 +94,22 @@ func (g *Gaby) populateLabelsPage(r *http.Request) *labelsPage {
9394

9495
// Find issues in database.
9596
for i := range github.LookupIssues(g.db, project, issueMin, issueMax) {
96-
cat, exp, err := labels.IssueCategory(r.Context(), g.llm, i)
97-
if err != nil {
98-
p.Error = err
99-
return p
97+
lr := &labelsResult{Issue: i}
98+
if i.PullRequest != nil {
99+
lr.Problem = "skipping: pull request"
100+
} else if isBot(i.User.Login) {
101+
lr.Problem = "skipping: author is a bot"
102+
} else {
103+
cat, exp, err := labels.IssueCategory(r.Context(), g.llm, i)
104+
if err != nil {
105+
p.Error = err
106+
return p
107+
}
108+
lr.Category = cat
109+
lr.Explanation = exp
110+
lr.BodyHTML = htmlutil.MarkdownToSafeHTML(i.Body)
100111
}
101-
p.Results = append(p.Results, &labelsResult{
102-
Issue: i,
103-
Category: cat,
104-
Explanation: exp,
105-
BodyHTML: htmlutil.MarkdownToSafeHTML(i.Body),
106-
})
112+
p.Results = append(p.Results, lr)
107113
}
108114
return p
109115
}
@@ -135,3 +141,8 @@ func (pm *labelsParams) inputs() []FormInput {
135141
},
136142
}
137143
}
144+
145+
func isBot(author string) bool {
146+
// TODO: generalize.
147+
return author == "gopherbot" || author == "gabyhelp"
148+
}

internal/gaby/static/labels.css

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
Copyright 2024 The Go Authors. All rights reserved.
3+
Use of this source code is governed by a BSD-style
4+
license that can be found in the LICENSE file.
5+
*/
6+
td {
7+
text-align: left;
8+
vertical-align: top;
9+
}
10+
11+

internal/gaby/tmpl/labelspage.tmpl

+15-11
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,21 @@ license that can be found in the LICENSE file.
1818
<table width="40%">
1919
<tr><td>Issue</td><td><a href="{{.HTMLURL}}">#{{.Number}}</a></td></tr>
2020
<tr><td>Title</td><td><strong>{{.Title}}</strong></td></tr>
21-
<tr><td valign="top">Body</td>
22-
<td><details><summary>Contents</Summary>{{.BodyHTML}}</details></td>
23-
</tr>
24-
<tr><td>Author</td><td>{{.User.Login}}</td></tr>
25-
<tr><td>State</td><td>{{.State}}</td></tr>
26-
<tr><td>Labels</td>
27-
<td>{{range .Labels}}{{.Name}} {{end}}</td>
28-
</tr>
29-
<tr><td colspan=2 height="10rem"></td><tr>
30-
<tr><td>Category</td><td>{{.Category.Name}} ({{.Category.Description}})</td></tr>
31-
<tr><td valign="top">Explanation</td><td>{{.Explanation}}</td></tr>
21+
{{with .Problem}}
22+
<tr><td>Skipped</td><td>{{.}}</td></tr>
23+
{{else}}
24+
<tr><td>Body</td>
25+
<td><details><summary>Contents</Summary>{{.BodyHTML}}</details></td>
26+
</tr>
27+
<tr><td>Author</td><td>{{.User.Login}}</td></tr>
28+
<tr><td>State</td><td>{{.State}}</td></tr>
29+
<tr><td>Labels</td>
30+
<td>{{range .Labels}}{{.Name}} {{end}}</td>
31+
</tr>
32+
<tr><td colspan=2 height="10rem"></td><tr>
33+
<tr><td>Category</td><td>{{.Category.Name}} ({{.Category.Description}})</td></tr>
34+
<tr><td valign="top">Explanation</td><td>{{.Explanation}}</td></tr>
35+
{{end}}
3236
</table>
3337
</div>
3438
{{- end}}

0 commit comments

Comments
 (0)