diff --git a/changelog.d/fixed-16685.md b/changelog.d/fixed-16685.md new file mode 100644 index 0000000000..d7752470be --- /dev/null +++ b/changelog.d/fixed-16685.md @@ -0,0 +1 @@ +- In-place DCO repair no longer appends the App's Signed-off-by to a collaborator's unsigned commit on a hive-authored PR: only commits GitHub links to the App bot or a hive identity are re-signed, and a hive-authored PR carrying anyone else's unsigned commit waits for a person instead ([#16685](https://github.com/hivecommons/hive/issues/16685)). diff --git a/src/pkg/github/automerge/automerge_contributor_adopt.go b/src/pkg/github/automerge/automerge_contributor_adopt.go index 4e7c9bd876..4840918aa2 100644 --- a/src/pkg/github/automerge/automerge_contributor_adopt.go +++ b/src/pkg/github/automerge/automerge_contributor_adopt.go @@ -299,16 +299,21 @@ func adoptionNeedsDCORehome(obs stageObservation, canPushInPlace, hiveAuthored b // the App's REST token, so a fork head re-homes (AdoptModeSupersede) even // when every unsigned commit is the hive's (hivecommons/hive#14666). // -// A hive-authored PR (hiveAuthored: the App bot or project.ai_author opened -// it) is never re-homed: every commit on it is the hive's to sign, so a -// pushable base-repo head is amended in place and any other head keeps its -// PR number, approvals and CI history and waits for a person (""), -// rather than restarting as a copy (hivecommons/hive#16619). +// Only the hive's own unsigned commits are ever signed in place: those GitHub +// links to the App bot or to one of the hive's identities +// (project.ai_author). A hive-authored PR (hiveAuthored: the App bot or +// project.ai_author opened it) is never re-homed: a pushable base-repo head +// whose unsigned commits are all the hive's is amended in place, and any +// other head — including one carrying a collaborator's unsigned commit, +// which the App must not sign for them (hivecommons/hive#16685) — keeps its +// PR number, approvals and CI history and waits for a person (""), rather +// than restarting as a copy (hivecommons/hive#16619). func adoptionDCORepairMode(obs stageObservation, canPushInPlace, hiveAuthored bool) string { if obs.Detail.DCO != stagelabels.DCONo || obs.Detail.DCOUnsigned <= 0 { return "" } - if canPushInPlace && headInBaseRepo(obs) && (hiveAuthored || (obs.Detail.DCOUnsignedHive == obs.Detail.DCOUnsigned && obs.Detail.DCOUnsignedOther == 0)) { + allHive := obs.Detail.DCOUnsignedOther == 0 && (hiveAuthored || obs.Detail.DCOUnsignedHive == obs.Detail.DCOUnsigned) + if canPushInPlace && headInBaseRepo(obs) && allHive { return stagelabels.AdoptModeInPlace } if hiveAuthored { diff --git a/src/pkg/github/automerge/automerge_contributor_adopt_test.go b/src/pkg/github/automerge/automerge_contributor_adopt_test.go index 37a5043e98..ccaa9b655a 100644 --- a/src/pkg/github/automerge/automerge_contributor_adopt_test.go +++ b/src/pkg/github/automerge/automerge_contributor_adopt_test.go @@ -626,14 +626,24 @@ func TestAdoptionDCORehomeDecisionAndRendering(t *testing.T) { t.Fatal("signed head does not need DCO re-home") } // A hive-authored PR (hivecommons/hive#16619) is never re-homed for - // sign-off: a pushable base-repo head is amended in place whoever the - // unsigned commits are linked to; a fork head keeps its PR and waits. + // sign-off: a pushable base-repo head whose unsigned commits are all + // the hive's is amended in place; one carrying someone else's unsigned + // commit is not signed by the App and waits (hivecommons/hive#16685); + // a fork head keeps its PR and waits. own := obs - own.Author, own.Detail.DCOUnsigned, own.Detail.DCOUnsignedOther = "thatguywob", 2, 2 + own.Author, own.Detail.DCOUnsigned, own.Detail.DCOUnsignedHive, own.Detail.DCOUnsignedOther = "thatguywob", 2, 2, 0 own.Owner, own.Repo, own.HeadRepo = "acme", "widget", "acme/widget" if got := adoptionDCORepairMode(own, true, true); got != stagelabels.AdoptModeInPlace { - t.Fatalf("hive-authored base-repo head: mode=%q, want in-place amend", got) + t.Fatalf("hive-authored base-repo head, all unsigned commits the hive's: mode=%q, want in-place amend", got) } + own.Detail.DCOUnsignedHive, own.Detail.DCOUnsignedOther = 1, 1 + if got := adoptionDCORepairMode(own, true, true); got != "" { + t.Fatalf("hive-authored base-repo head with a collaborator's unsigned commit: mode=%q, want wait for a person", got) + } + if adoptionNeedsDCORehome(own, true, true) || adoptedHeadNeedsDCORepair(own, inPlace, true, true) || adoptedHeadNeedsDCORehome(own, inPlace, true, true) { + t.Fatal("a collaborator's unsigned commit on a hive-authored PR must be neither signed by the App nor superseded") + } + own.Detail.DCOUnsignedHive, own.Detail.DCOUnsignedOther = 0, 2 own.HeadRepo = "thatguywob/widget" if got := adoptionDCORepairMode(own, false, true); got != "" { t.Fatalf("hive-authored fork head: mode=%q, want no re-home", got) diff --git a/src/pkg/github/automerge/automerge_stage_dco.go b/src/pkg/github/automerge/automerge_stage_dco.go index ec17c37b1b..d21d02a38f 100644 --- a/src/pkg/github/automerge/automerge_stage_dco.go +++ b/src/pkg/github/automerge/automerge_stage_dco.go @@ -62,6 +62,13 @@ func dcoCommitStatsDetailedForAuthor(commits []*gh.RepositoryCommit, appLogin, p // the App bot), so no signed hive commit is squash-unsafe. Unsigned commits // are still counted and rejected. func dcoCommitStatsForSquashAuthor(commits []*gh.RepositoryCommit, appLogin, prAuthor string, selfSquash bool) dcoStats { + return dcoCommitStatsForHive(commits, appLogin, prAuthor, selfSquash, nil) +} + +// dcoCommitStatsForHive is dcoCommitStatsForSquashAuthor with the hive's own +// identities (isHive, StageLabelPolicy.HiveAuthor) counted as the hive's when +// splitting unsigned commits; a nil isHive counts only the App bot. +func dcoCommitStatsForHive(commits []*gh.RepositoryCommit, appLogin, prAuthor string, selfSquash bool, isHive func(login string) bool) dcoStats { var stats dcoStats for _, rc := range commits { if rc == nil || len(rc.Parents) > 1 { @@ -71,7 +78,7 @@ func dcoCommitStatsForSquashAuthor(commits []*gh.RepositoryCommit, appLogin, prA msg := rc.GetCommit().GetMessage() if !signedOffByRE.MatchString(msg) { stats.unsigned++ - if dcoCommitByHive(rc, appLogin) { + if dcoCommitOwnedByHive(rc, appLogin, isHive) { stats.unsignedHive++ } else { stats.unsignedOther++ @@ -92,6 +99,23 @@ func dcoCommitByHive(commit *gh.RepositoryCommit, appLogin string) bool { return commitByApp(commit, appLogin) } +// dcoCommitOwnedByHive is dcoCommitByHive that also counts a commit GitHub +// links (by author login) to one of the hive's own identities (isHive: +// project.ai_author, the login the hive's agents push as). Only GitHub's +// linkage counts here too: git author names and emails never do, so a +// collaborator's unsigned commit stays "other" and is never signed by the +// App (hivecommons/hive#16685). +func dcoCommitOwnedByHive(commit *gh.RepositoryCommit, appLogin string, isHive func(login string) bool) bool { + if dcoCommitByHive(commit, appLogin) { + return true + } + if commit == nil || isHive == nil { + return false + } + login := strings.TrimSpace(commit.GetAuthor().GetLogin()) + return login != "" && isHive(login) +} + // stageDCO returns the commit check for the observation's head, reading the // commits only when the store has no result for this head (the caller // caches the result, including how many unsigned commits are the App's own, @@ -123,7 +147,7 @@ func (c *Engine) stageDCO(ctx context.Context, store *stagelabels.Store, key str if err != nil { return dcoStats{}, err } - return dcoCommitStatsForSquashAuthor(all, appLogin, obs.Author, selfSquash), nil + return dcoCommitStatsForHive(all, appLogin, obs.Author, selfSquash, policy.HiveAuthor), nil } // hiveAuthoredPR reports whether the PR is the hive's own: author/hive by diff --git a/src/pkg/github/automerge/automerge_stage_labels_test.go b/src/pkg/github/automerge/automerge_stage_labels_test.go index 6298db61de..1bc51529a3 100644 --- a/src/pkg/github/automerge/automerge_stage_labels_test.go +++ b/src/pkg/github/automerge/automerge_stage_labels_test.go @@ -2414,6 +2414,29 @@ func TestDCOCommitStatsSkipsMerges(t *testing.T) { } } +// hivecommons/hive#16685: an unsigned commit GitHub links to one of the +// hive's identities (project.ai_author) is the hive's to sign; a +// collaborator's unsigned commit is not, whatever its git author name says. +func TestDCOCommitStatsForHiveCountsHiveIdentities(t *testing.T) { + commits := []*gh.RepositoryCommit{ + {Author: &gh.User{Login: gh.Ptr("thatguywob")}, Commit: &gh.Commit{Message: gh.Ptr("hive fix")}, Parents: []*gh.Commit{{}}}, + {Author: &gh.User{Login: gh.Ptr("collaborator")}, Commit: &gh.Commit{Message: gh.Ptr("drive-by"), Author: &gh.CommitAuthor{Name: gh.Ptr("thatguywob")}}, Parents: []*gh.Commit{{}}}, + {Author: &gh.User{Login: gh.Ptr(testHiveAppBotLogin)}, Commit: &gh.Commit{Message: gh.Ptr("app fix")}, Parents: []*gh.Commit{{}}}, + } + isHive := func(login string) bool { return strings.EqualFold(login, "thatguywob") } + stats := dcoCommitStatsForHive(commits, testHiveAppBotLogin, "thatguywob", true, isHive) + if stats.unsigned != 3 || stats.unsignedHive != 2 || stats.unsignedOther != 1 { + t.Fatalf("with hive identities: %+v, want unsigned=3 hive=2 other=1", stats) + } + stats = dcoCommitStatsForHive(commits, testHiveAppBotLogin, "thatguywob", true, nil) + if stats.unsigned != 3 || stats.unsignedHive != 1 || stats.unsignedOther != 2 { + t.Fatalf("nil predicate: %+v, want unsigned=3 hive=1 other=2", stats) + } + if old := dcoCommitStatsForSquashAuthor(commits, testHiveAppBotLogin, "thatguywob", true); old != stats { + t.Fatalf("dcoCommitStatsForSquashAuthor=%+v, want App-only split %+v", old, stats) + } +} + // hivecommons/hive#12557: a gate flapping between merge-queue and a pending // stage on one unchanged head used to post a stage-regressed comment every // sweep, because each recover re-armed the dedupe. One comment per head.