Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-15683-label-description-length.md
Original file line number Diff line number Diff line change
@@ -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)).
9 changes: 7 additions & 2 deletions src/crux/config/origin_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
13 changes: 13 additions & 0 deletions src/crux/config/origin_labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"strings"
"testing"
"unicode/utf8"
)

// Exactly one origin/* label: a caller's label is kept and canonicalised,
Expand Down Expand Up @@ -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)
}
}
}
1 change: 1 addition & 0 deletions src/pkg/config/crux_aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ var (
const (
DefaultReviewBacklogLabel = cruxconfig.DefaultReviewBacklogLabel
OriginLabelPrefix = cruxconfig.OriginLabelPrefix
GitHubLabelDescriptionMax = cruxconfig.GitHubLabelDescriptionMax
OriginReviewerLabel = cruxconfig.OriginReviewerLabel
LegacyOriginReviewLabel = cruxconfig.LegacyOriginReviewLabel
LegacyReviewBacklogLabel = cruxconfig.LegacyReviewBacklogLabel
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/github/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/github/issue_request_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/github/issue_stage_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
17 changes: 17 additions & 0 deletions src/pkg/github/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/github/open_pr_links.go
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/github/origin_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down
61 changes: 61 additions & 0 deletions src/pkg/github/origin_labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}
Loading