internal/rules: use ../labels' categorization directly
Instead of having a separate categorization setup for this package.
Change-Id: I1927b7d00777f0c2c34d29a48830b86aa9d23de4
Reviewed-on: https://go-review.googlesource.com/c/oscar/+/642601
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/internal/gaby/rules.go b/internal/gaby/rules.go
index 6ed7526..d6cf204 100644
--- a/internal/gaby/rules.go
+++ b/internal/gaby/rules.go
@@ -77,7 +77,7 @@
return p
}
- rules, err := rules.Issue(r.Context(), g.llm, i, true)
+ rules, err := rules.Issue(r.Context(), g.db, g.llm, i, true)
if err != nil {
p.Error = err
return p
diff --git a/internal/rules/rules.go b/internal/rules/rules.go
index 1936b65..1f57805 100644
--- a/internal/rules/rules.go
+++ b/internal/rules/rules.go
@@ -134,7 +134,7 @@
return p.post, nil
}
p.slog.Info("rules.Poster considering", "issue", i.Number)
- r, err := Issue(ctx, p.llm, i, false /*debug*/)
+ r, err := Issue(ctx, p.db, p.llm, i, false /*debug*/)
if err != nil {
p.slog.Info("rules engine failed", "error", err)
return false, nil
@@ -250,7 +250,7 @@
// Issue returns text describing the set of rules that the issue does not currently satisfy.
// If debug==true, then response contains additional llm debugging info.
-func Issue(ctx context.Context, cgen llm.ContentGenerator, i *github.Issue, debug bool) (*IssueResult, error) {
+func Issue(ctx context.Context, db storage.DB, cgen llm.ContentGenerator, i *github.Issue, debug bool) (*IssueResult, error) {
var result IssueResult
if i.PullRequest != nil {
@@ -260,7 +260,7 @@
return &result, nil
}
- kind, reasoning, err := Classify(ctx, cgen, i)
+ kind, reasoning, err := Classify(ctx, db, cgen, i)
if err != nil {
return nil, err
}
@@ -346,18 +346,8 @@
// Classify returns the kind of issue we're dealing with.
// Returns a description of the classification and a string describing
// the llm's reasoning.
-func Classify(ctx context.Context, cgen llm.ContentGenerator, i *github.Issue) (IssueKind, string, error) {
- // TODO: use the default github label categories, and adjust
- // the rule file to match.
- var cats []labels.Category
- for _, kind := range rulesConfig.IssueKinds {
- cats = append(cats, labels.Category{
- Name: kind.Name,
- Description: kind.Text,
- Extra: kind.Details,
- })
- }
- cat, explanation, err := labels.IssueCategoryFromLists(ctx, cgen, i, cats, nil)
+func Classify(ctx context.Context, db storage.DB, cgen llm.ContentGenerator, i *github.Issue) (IssueKind, string, error) {
+ cat, explanation, err := labels.IssueCategory(ctx, db, cgen, i)
if err != nil {
return IssueKind{}, "", err
}
diff --git a/internal/rules/rules_test.go b/internal/rules/rules_test.go
index 404bf69..c94df45 100644
--- a/internal/rules/rules_test.go
+++ b/internal/rules/rules_test.go
@@ -21,17 +21,19 @@
func TestIssue(t *testing.T) {
ctx := context.Background()
+ db := storage.MemDB()
llm := ruleTestGenerator()
// Construct a test issue.
i := new(github.Issue)
+ i.URL = "https://api.github.com/repos/golang/go/" // for project name
i.Number = 999
i.User = github.User{Login: "user"}
i.Title = "title"
i.Body = "body"
// Ask about rule violations.
- r, err := Issue(ctx, llm, i, false)
+ r, err := Issue(ctx, db, llm, i, false)
if err != nil {
t.Fatalf("IssueRules failed with %v", err)
}
@@ -47,17 +49,19 @@
func TestClassify(t *testing.T) {
ctx := context.Background()
+ db := storage.MemDB()
llm := ruleTestGenerator()
// Construct a test issue.
i := new(github.Issue)
+ i.URL = "https://api.github.com/repos/golang/go/" // for project name
i.Number = 999
i.User = github.User{Login: "user"}
i.Title = "title"
i.Body = "body"
// Run classifier.
- r, _, err := Classify(ctx, llm, i)
+ r, _, err := Classify(ctx, db, llm, i)
if err != nil {
t.Fatalf("Classify failed with %v", err)
}
@@ -109,10 +113,10 @@
Body: "body",
CreatedAt: time.Now().Add(-1 * time.Hour).UTC().Format(time.RFC3339),
}
- tc.AddIssue("test/project", testIssue)
+ tc.AddIssue("golang/go", testIssue)
p := New(lg, db, gh, llm, "postname")
- p.EnableProject("test/project")
+ p.EnableProject("golang/go")
p.EnablePosts()
check(p.Run(ctx))
@@ -128,7 +132,7 @@
if err := json.Unmarshal(e.Action, &a); err != nil {
t.Fatal(err)
}
- if got, want := a.Issue.Project(), "test/project"; got != want {
+ if got, want := a.Issue.Project(), "golang/go"; got != want {
t.Fatalf("posted to unexpected project: got %s, want %s", got, want)
return
}
@@ -165,10 +169,10 @@
Body: "body",
CreatedAt: time.Now().Add(-100 * time.Hour).UTC().Format(time.RFC3339),
}
- tc.AddIssue("test/project", testIssue)
+ tc.AddIssue("golang/go", testIssue)
p := New(lg, db, gh, llm, "postname")
- p.EnableProject("test/project")
+ p.EnableProject("golang/go")
p.EnablePosts()
check(p.Run(ctx))
@@ -196,10 +200,10 @@
CreatedAt: time.Now().Add(-1 * time.Hour).UTC().Format(time.RFC3339),
State: "closed",
}
- tc.AddIssue("test/project", testIssue)
+ tc.AddIssue("golang/go", testIssue)
p := New(lg, db, gh, llm, "postname")
- p.EnableProject("test/project")
+ p.EnableProject("golang/go")
p.EnablePosts()
check(p.Run(ctx))
@@ -226,10 +230,10 @@
Body: "body",
CreatedAt: time.Now().Add(-1 * time.Hour).UTC().Format(time.RFC3339),
}
- tc.AddIssue("test/project1", testIssue)
+ tc.AddIssue("golang/go1", testIssue)
p := New(lg, db, gh, llm, "postname")
- p.EnableProject("test/project2")
+ p.EnableProject("golang/go2")
p.EnablePosts()
check(p.Run(ctx))
@@ -256,10 +260,10 @@
Body: "Hello. ### What did you expect to see?\n\n### Goodbye.",
CreatedAt: time.Now().Add(-1 * time.Hour).UTC().Format(time.RFC3339),
}
- tc.AddIssue("test/project", testIssue)
+ tc.AddIssue("golang/go", testIssue)
p := New(lg, db, gh, llm, "postname")
- p.EnableProject("test/project")
+ p.EnableProject("golang/go")
p.EnablePosts()
check(p.Run(ctx))
@@ -275,7 +279,7 @@
if err := json.Unmarshal(e.Action, &a); err != nil {
t.Fatal(err)
}
- if got, want := a.Issue.Project(), "test/project"; got != want {
+ if got, want := a.Issue.Project(), "golang/go"; got != want {
t.Fatalf("posted to unexpected project: got %s, want %s", got, want)
return
}
@@ -315,10 +319,10 @@
Body: "Hello. ### What did you expect to see?\n\nSomething\n\n### Goodbye.",
CreatedAt: time.Now().Add(-1 * time.Hour).UTC().Format(time.RFC3339),
}
- tc.AddIssue("test/project", testIssue)
+ tc.AddIssue("golang/go", testIssue)
p := New(lg, db, gh, llm, "postname")
- p.EnableProject("test/project")
+ p.EnableProject("golang/go")
p.EnablePosts()
check(p.Run(ctx))
@@ -334,7 +338,7 @@
if err := json.Unmarshal(e.Action, &a); err != nil {
t.Fatal(err)
}
- if got, want := a.Issue.Project(), "test/project"; got != want {
+ if got, want := a.Issue.Project(), "golang/go"; got != want {
t.Fatalf("posted to unexpected project: got %s, want %s", got, want)
return
}
diff --git a/internal/rules/static/ruleset.json b/internal/rules/static/ruleset.json
index 4a6d280..b71ce45 100644
--- a/internal/rules/static/ruleset.json
+++ b/internal/rules/static/ruleset.json
@@ -2,8 +2,6 @@
"IssueKinds": [
{
"Name": "bug",
- "Text": "This issue describes a bug in the Go implementation.",
- "Details": "",
"Rules": [
{
"Text": "The issue title must start with a package name followed by a colon.",
@@ -24,9 +22,7 @@
]
},
{
- "Name": "language proposal",
- "Text": "This issue describes a requested change to the Go language specification.",
- "Details": "",
+ "Name": "languageProposal",
"Rules": [
{
"Text": "The issue title must start with \"proposal:\"."
@@ -40,9 +36,7 @@
]
},
{
- "Name": "library proposal",
- "Text": "This issue describes a requested change to the Go standard library or x/ libraries.",
- "Details": "",
+ "Name": "libraryProposal",
"Rules": [
{
"Text": "The issue title must start with \"proposal:\"."
@@ -56,54 +50,13 @@
]
},
{
- "Name": "implementation",
- "Text": "This issue describes a semantics-preserving change to the Go implementation."
- },
- {
- "Name": "access request",
- "Text": "This issue is a request for builder or gomote access."
- },
- {
- "Name": "pkgsite removal request",
- "Text": "This issue is a pkgsite removal request."
- },
- {
- "Name": "go website",
- "Text": "This issue is about the behavior of the Go website (*.golang.org)."
- },
- {
- "Name": "automation",
- "Text": "This issue is created by gopherbot, watchflakes, or stacks automation."
- },
- {
- "Name": "backport",
- "Text": "This issue is created for requesting a backport of a change to a previous Go version."
- },
- {
- "Name": "builders",
- "Text": "This issue is about the running of the Go builders."
- },
- {
- "Name": "gopls",
- "Text": "This issue is about gopls behavior."
- },
- {
"Name": "question",
- "Text": "This issue is a question about using Go.",
"Rules": [
{
"Text": "This issue appears to be more of a question than a bug report. Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only. For questions please refer to [our Questions page](https://go.dev/wiki/Questions).",
"Description":"This rule should never be satisfied."
}
]
- },
- {
- "Name": "invalid",
- "Text": "This issue is empty, incomplete, or spam."
- },
- {
- "Name": "other",
- "Text": "None of the above."
}
]
}