diff --git a/changelog.d/fixed-15683-label-description-length.md b/changelog.d/fixed-15683-label-description-length.md new file mode 100644 index 0000000000..02bec0c88d --- /dev/null +++ b/changelog.d/fixed-15683-label-description-length.md @@ -0,0 +1 @@ +- Label descriptions Hive writes to GitHub now fit the 100-character cap: the over-long `origin/governor`, `origin/selfreport` and `has-open-pr` descriptions were shortened and every label create/edit clamps the description, so `CreateIssue` no longer logs `could not ensure label … 422 description is too long` and drops the `origin/*` provenance label ([#15683](https://github.com/hivecommons/hive/issues/15683), [#15681](https://github.com/hivecommons/hive/issues/15681)). diff --git a/src/crux/config/origin_labels.go b/src/crux/config/origin_labels.go index 8f1f43114c..79e342b0a1 100644 --- a/src/crux/config/origin_labels.go +++ b/src/crux/config/origin_labels.go @@ -94,10 +94,15 @@ var KnownOriginLanes = []string{ "reviewer", "scanner", "sec-check", "strategist", "supervisor", "tester", } +// GitHubLabelDescriptionMax is GitHub's cap on a label description; a +// longer one makes the labels API answer 422 "description is too long". +const GitHubLabelDescriptionMax = 100 + // originSourceDescriptions is the label description per non-lane source. +// Every entry must fit GitHubLabelDescriptionMax. var originSourceDescriptions = map[string]string{ - OriginSourceSelfReport: "Filed by Hive from a fleet runtime self-report (provenance only; supersedes hive/selfreport as the origin marker)", - OriginSourceGovernor: "Filed by the Hive governor/automation on its own behalf (provenance only, not a routing or hold signal)", + OriginSourceSelfReport: "Filed by Hive from a fleet runtime self-report (provenance only; supersedes hive/selfreport)", + OriginSourceGovernor: "Filed by the Hive governor/automation on its own behalf (provenance only, not routing or hold)", OriginSourceDashboard: "Filed by an operator action in the Hive dashboard (provenance only, not a routing or hold signal)", OriginSourceForge: "Filed through the Hive forge issue seam (provenance only, not a routing or hold signal)", OriginSourceConvergence: "Filed by the Hive convergence finding publisher (provenance only, not a routing or hold signal)", diff --git a/src/crux/config/origin_labels_test.go b/src/crux/config/origin_labels_test.go index fcda747747..012465c65d 100644 --- a/src/crux/config/origin_labels_test.go +++ b/src/crux/config/origin_labels_test.go @@ -3,6 +3,7 @@ package config import ( "strings" "testing" + "unicode/utf8" ) // Exactly one origin/* label: a caller's label is kept and canonicalised, @@ -139,3 +140,15 @@ func TestOriginVocabularyIsConsistent(t *testing.T) { t.Fatalf("FirstOriginLabel = %q %v", got, ok) } } + +func TestOriginSourceDescriptionsFitGitHubCap(t *testing.T) { + for _, source := range KnownOriginSources() { + desc, ok := OriginLabelDescription(OriginLabel(source)) + if !ok { + t.Fatalf("no description for %q", source) + } + if n := utf8.RuneCountInString(desc); n > GitHubLabelDescriptionMax { + t.Errorf("origin/%s description is %d runes (max %d)", source, n, GitHubLabelDescriptionMax) + } + } +} diff --git a/src/pkg/config/crux_aliases.go b/src/pkg/config/crux_aliases.go index 59b3693e5a..7af2194926 100644 --- a/src/pkg/config/crux_aliases.go +++ b/src/pkg/config/crux_aliases.go @@ -182,6 +182,7 @@ var ( const ( DefaultReviewBacklogLabel = cruxconfig.DefaultReviewBacklogLabel OriginLabelPrefix = cruxconfig.OriginLabelPrefix + GitHubLabelDescriptionMax = cruxconfig.GitHubLabelDescriptionMax OriginReviewerLabel = cruxconfig.OriginReviewerLabel LegacyOriginReviewLabel = cruxconfig.LegacyOriginReviewLabel LegacyReviewBacklogLabel = cruxconfig.LegacyReviewBacklogLabel diff --git a/src/pkg/github/client.go b/src/pkg/github/client.go index 187ab29ad2..e2d526702c 100644 --- a/src/pkg/github/client.go +++ b/src/pkg/github/client.go @@ -3204,7 +3204,7 @@ func (c *Client) EnsureIssueLabel(ctx context.Context, repo, name, color, descri _, _, err := c.client.Issues.CreateLabel(ctx, owner, repoName, &gh.Label{ Name: gh.Ptr(name), Color: gh.Ptr(color), - Description: gh.Ptr(strings.TrimSpace(description)), + Description: gh.Ptr(clampLabelDescription(description)), }) if ghErr, ok := err.(*gh.ErrorResponse); ok && ghErr.Response != nil && ghErr.Response.StatusCode == http.StatusUnprocessableEntity { return nil diff --git a/src/pkg/github/issue_request_watcher.go b/src/pkg/github/issue_request_watcher.go index bd46a6545b..9276953a18 100644 --- a/src/pkg/github/issue_request_watcher.go +++ b/src/pkg/github/issue_request_watcher.go @@ -2126,7 +2126,7 @@ func (c *Client) ensureCreateIssueLabel(ctx context.Context, owner, repo, name s _, _, err := c.client.Issues.CreateLabel(ctx, owner, repo, &gh.Label{ Name: gh.Ptr(name), Color: gh.Ptr(color), - Description: gh.Ptr(description), + Description: gh.Ptr(clampLabelDescription(description)), }) if ghErr, ok := err.(*gh.ErrorResponse); ok && ghErr.Response != nil && ghErr.Response.StatusCode == http.StatusUnprocessableEntity { if _, _, getErr := c.client.Issues.GetLabel(ctx, owner, repo, name); getErr == nil { diff --git a/src/pkg/github/issue_stage_labels.go b/src/pkg/github/issue_stage_labels.go index cde33a6d0e..49e86aa014 100644 --- a/src/pkg/github/issue_stage_labels.go +++ b/src/pkg/github/issue_stage_labels.go @@ -806,13 +806,13 @@ func (c *Client) ensureStageLabelFamily(ctx context.Context, repo string) error cur, ok := existing[strings.ToLower(def.Name)] switch { case !ok: - _, _, err := c.client.Issues.CreateLabel(ctx, owner, name, &gh.Label{Name: gh.Ptr(def.Name), Color: gh.Ptr(def.Color), Description: gh.Ptr(def.Description)}) + _, _, err := c.client.Issues.CreateLabel(ctx, owner, name, &gh.Label{Name: gh.Ptr(def.Name), Color: gh.Ptr(def.Color), Description: gh.Ptr(clampLabelDescription(def.Description))}) if err != nil && !githubStatusError(err, http.StatusUnprocessableEntity) { c.noteArchivedLabelRefusal(key, err) return err } case !strings.EqualFold(cur.GetColor(), def.Color): - if _, _, err := c.client.Issues.EditLabel(ctx, owner, name, cur.GetName(), &gh.Label{Name: gh.Ptr(def.Name), Color: gh.Ptr(def.Color), Description: gh.Ptr(def.Description)}); err != nil { + if _, _, err := c.client.Issues.EditLabel(ctx, owner, name, cur.GetName(), &gh.Label{Name: gh.Ptr(def.Name), Color: gh.Ptr(def.Color), Description: gh.Ptr(clampLabelDescription(def.Description))}); err != nil { c.noteArchivedLabelRefusal(key, err) return err } diff --git a/src/pkg/github/labels.go b/src/pkg/github/labels.go index c13931f90f..3bf91b6773 100644 --- a/src/pkg/github/labels.go +++ b/src/pkg/github/labels.go @@ -12,6 +12,23 @@ type issueLabelDefinition struct { description string } +// githubLabelDescriptionMax is GitHub's cap on a label description. A +// longer value makes POST/PATCH /labels answer 422 "description is too +// long", which used to drop the label from every CreateIssue. +const githubLabelDescriptionMax = config.GitHubLabelDescriptionMax + +// clampLabelDescription trims desc and shortens it to fit GitHub's label +// description cap, ending an over-long value with an ellipsis. It counts +// runes so a multibyte description is never cut mid-character. +func clampLabelDescription(desc string) string { + desc = strings.TrimSpace(desc) + runes := []rune(desc) + if len(runes) <= githubLabelDescriptionMax { + return desc + } + return strings.TrimSpace(string(runes[:githubLabelDescriptionMax-1])) + "…" +} + // NeedsDecisionStageLabel is the single "issue parked for a human ruling" // signal (hivecommons/hive#12683): `stage/045-needs-decision`, the issue-side // parking stage. On an issue it is an INPUT as well as the stage — an agent, diff --git a/src/pkg/github/open_pr_links.go b/src/pkg/github/open_pr_links.go index e61f20e21d..1adeba88a0 100644 --- a/src/pkg/github/open_pr_links.go +++ b/src/pkg/github/open_pr_links.go @@ -30,7 +30,7 @@ const ( // — the stage engine re-derives the issue's stage from the PR itself. HasOpenPRLabel = "has-open-pr" hasOpenPRLabelColor = "0e8a16" - hasOpenPRLabelDescription = "An open pull request already links this issue with Fixes/Closes/Resolves; the hive will not dispatch it again" + hasOpenPRLabelDescription = "An open PR already links this issue with Fixes/Closes/Resolves; the hive will not dispatch it again" // ClaimBlockReasonOpenPRPrefix prefixes the IssueClaimBlockReason for an // issue an open PR already links: "open PR already linked: #14775". diff --git a/src/pkg/github/origin_labels.go b/src/pkg/github/origin_labels.go index 2798345faa..1eef20eb47 100644 --- a/src/pkg/github/origin_labels.go +++ b/src/pkg/github/origin_labels.go @@ -120,7 +120,7 @@ func (c *Client) ensureOriginLabel(ctx context.Context, owner, repo, name string _, _, err = c.client.Issues.EditLabel(ctx, owner, repo, name, &gh.Label{ Name: gh.Ptr(name), Color: gh.Ptr(def.color), - Description: gh.Ptr(def.description), + Description: gh.Ptr(clampLabelDescription(def.description)), }) return err } @@ -130,7 +130,7 @@ func (c *Client) ensureOriginLabel(ctx context.Context, owner, repo, name string _, _, err = c.client.Issues.CreateLabel(ctx, owner, repo, &gh.Label{ Name: gh.Ptr(name), Color: gh.Ptr(def.color), - Description: gh.Ptr(def.description), + Description: gh.Ptr(clampLabelDescription(def.description)), }) if githubStatusError(err, http.StatusUnprocessableEntity) { return nil diff --git a/src/pkg/github/origin_labels_test.go b/src/pkg/github/origin_labels_test.go index fbcc660bf5..991331b626 100644 --- a/src/pkg/github/origin_labels_test.go +++ b/src/pkg/github/origin_labels_test.go @@ -13,8 +13,10 @@ import ( "strings" "sync" "testing" + "unicode/utf8" "github.com/hivecommons/hive/pkg/config" + "github.com/hivecommons/hive/pkg/stagelabels" ) func TestOriginLabelDefinitionsShareOneColour(t *testing.T) { @@ -436,3 +438,62 @@ func TestOriginLabelDefinitionCoversEverySource(t *testing.T) { t.Fatal("unknown origin source must not be auto-created") } } + +// Every description Hive writes to the labels API must fit GitHub's cap; +// an over-long one makes ensure-label 422 and drops the label from every +// CreateIssue (selfreport #15681). +func TestCatalogLabelDescriptionsFitGitHubCap(t *testing.T) { + type entry struct{ name, description string } + var entries []entry + for _, source := range config.KnownOriginSources() { + name := config.OriginLabel(source) + def, ok := originLabelDefinition(name) + if !ok { + t.Fatalf("originLabelDefinition(%q) unknown", name) + } + entries = append(entries, entry{name, def.description}) + } + for name, def := range escalationIssueLabelDefinitions { + entries = append(entries, entry{name, def.description}) + } + for _, def := range stagelabels.AllLabelDefs() { + entries = append(entries, entry{def.Name, def.Description}) + } + for _, e := range []entry{ + {HasOpenPRLabel, hasOpenPRLabelDescription}, + {SupersededLabel, supersededLabelDescription}, + {SupersessionKeepOpenLabel, keepOpenLabelDescription}, + {CoveredByPRLabel, CoveredByPRLabelDescription}, + {InProgressLabel, inProgressLabelDescription}, + {advisoryLabelName, advisoryLabelDesc}, + } { + entries = append(entries, e) + } + if len(entries) < 10 { + t.Fatalf("catalog unexpectedly small: %d entries", len(entries)) + } + for _, e := range entries { + if n := utf8.RuneCountInString(e.description); n > githubLabelDescriptionMax { + t.Errorf("label %q description is %d runes (max %d): %q", e.name, n, githubLabelDescriptionMax, e.description) + } + } +} + +func TestClampLabelDescription(t *testing.T) { + short := " fits " + if got := clampLabelDescription(short); got != "fits" { + t.Fatalf("short: got %q", got) + } + exact := strings.Repeat("x", githubLabelDescriptionMax) + if got := clampLabelDescription(exact); got != exact { + t.Fatalf("exact: changed %q", got) + } + long := strings.Repeat("é", githubLabelDescriptionMax+20) + got := clampLabelDescription(long) + if n := utf8.RuneCountInString(got); n != githubLabelDescriptionMax { + t.Fatalf("long: %d runes, want %d: %q", n, githubLabelDescriptionMax, got) + } + if !utf8.ValidString(got) || !strings.HasSuffix(got, "…") || !strings.HasPrefix(got, strings.Repeat("é", githubLabelDescriptionMax-1)) { + t.Fatalf("long: unexpected clamp %q", got) + } +}