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 src/changelog.d/added-merge-issue-author-credit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Every hive-performed merge (self-authored, trusted-author, contributor-lane and queue sweeps, `hive-merge` relay) now credits the human authors of the issues the PR closes: `Co-authored-by: <login> <id+login@users.noreply.github.com>` trailers are appended to the squash (or merge) commit message, so a reporter whose issue an external clanker fixed shows on the contributor graph the way hive-opened PRs already did. Bots, the PR author and logins the branch already credits are skipped; branch commit bodies and `Signed-off-by` lines are preserved ahead of the trailers; the logins are recorded as `issue_authors=` on the merge audit entry and in review-evidence `merge.issue_authors`. One cached `GET /issues/{n}` per newly referenced issue. Switch: `auto_merge.credit_issue_authors` (default on) (#14581).
3 changes: 3 additions & 0 deletions src/cmd/hive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10274,6 +10274,9 @@ func installReviewRelaySettings(client *github.Client, cfg *config.Config, logge
client.SetReviewEvidence(func(repo string) github.ReviewEvidenceSettings {
return reviewEvidenceSettings(cfg, repo)
})
// hivecommons/hive#14581: issue-author credit on every merge path, read
// live so a reload of auto_merge.credit_issue_authors applies.
client.SetCreditIssueAuthors(func(string) bool { return cfg.AutoMerge.CreditIssueAuthorsEnabled() })
// hivecommons/hive#13241: an issue a person reopens after its closing PR
// merged is a change failure on that PR's evidence record, from both the
// issues.reopened webhook and the enumeration reopen check.
Expand Down
32 changes: 32 additions & 0 deletions src/docs/hive-merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,38 @@ unattended (for example `mrbobbytables`):
A claim keeps the tier the contributor held when it was taken, so grant the
tier before the issue is leased.

### Issue-author credit at merge time

Every merge the hive performs — the self-authored, trusted-author,
contributor-lane and queue sweeps as well as `hive-merge` relay requests —
credits the humans who opened the issues the PR closes. The merge reads the
closing references the PR already carries (`Fixes|Closes|Resolves #N` in the
body) and resolves each referenced issue's author with at most one
`GET /issues/{n}` per newly seen issue, cached for the life of the process
(attributed as `hive:merge_credit` in the API-quota ledger). Bots and Apps
(`type=Bot`, `[bot]`/`-bot` suffixes, `github-actions*`), the PR author
themself, and issues that are really PRs are skipped; the remaining logins are
de-duplicated and appended as `Co-authored-by: <login>
<id+login@users.noreply.github.com>` trailers to the squash commit message. A
`merge-method/merge` PR gets the trailer on the merge commit instead; a rebase
merge has no commit to carry it and is left alone.

`Co-authored-by` is the trailer GitHub counts toward the contributor graph, so
a reporter whose issue was fixed by someone else's clanker shows up on the
repository's contributors page rather than only in the issue timeline. It is
purely additive: the branch's own commit subjects, bodies and `Signed-off-by`
lines are reproduced unchanged ahead of the new trailers, so the squash
sign-off gate and `check-squash-signoff-attribution.sh` see exactly what they
saw before plus the credit. This is the single mechanism: a hive-opened PR
already carries the trailer on its commits (`issue-coauthor.sh`,
`hive-open-pr`), and the merge recognises an existing trailer for the same
login (by noreply address or login) and does not add a duplicate. The credited
logins are recorded on the merge audit entry (`issue_authors=`) and in the PR's
review-evidence `merge.issue_authors`, so dashboards and DIBS statistics can
report them. If the branch's commits cannot be read at merge time, the hive
falls back to GitHub's default message rather than risk dropping a sign-off.
Switch it off with `auto_merge.credit_issue_authors: false` (#14581).

### Stage labels

Every sweep cycle also writes the hive-owned `stage/NNN-*` label for each PR
Expand Down
1 change: 1 addition & 0 deletions src/docs/operator-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ advanced into the merge path.
| `auto_merge.require_current_base` | unset (off) | Repo list (`owner/repo`) whose App self-merge, trusted-author and contributor lanes only merge a head that contains the current base tip. A green head tested against an older base is updated with GitHub update-branch (a merge commit; no author commit is rewritten) and merges once CI is green on the new head, so a semantic conflict with work merged since turns that PR red instead of breaking the base (#13634). Costs one compare call per merge candidate. |
| `auto_merge.merge_forward_trusted_human` | unset (off) | Repo list (`owner/repo`) where a `role/trusted` + `author/human` PR on a same-repo branch that GitHub reports as conflicting (`dirty`) gets the base merged into its head as one App-authored, signed-off merge commit via the GitHub merges API (no human commit is rewritten), then merges once CI is green on the new head. A real conflict pushes nothing and posts one `<!-- hive:merge-forward-conflict head=… -->` note naming the files both sides changed. Fork heads are never written. Attempted once per head (#13636). |
| `auto_merge.squash_only` | unset (no repo) | Repo list (`owner/repo`) whose branch policy forbids merge commits. Elsewhere, a `role/trusted` PR whose head mixes the contributor's commits with App-linked, App-signed ones (the hive's own in-place adoption fixes), every commit self-signed, is labelled `merge-method/merge` and merged with a merge commit instead of parking at `stage/085` as `adoption-stalled:hive-signoff-attribution`; a listed repo keeps squash-only policy and re-homes an in-place adoption to an App-authored superseder instead (#13975). |
| `auto_merge.credit_issue_authors` | `true` | Append `Co-authored-by: <login> <id+login@users.noreply.github.com>` for the human authors of the issues a PR closes (`Fixes|Closes|Resolves #N`) to the squash (or merge) commit message on every hive-performed merge, so reporters land on the contributor graph when an external clanker fixed their issue. Bots, the PR author and logins already credited on the branch are skipped; the logins are recorded as `issue_authors=` on the merge audit entry and in review evidence. One cached `GET /issues/{n}` per newly referenced issue. `false` leaves GitHub's default squash message untouched (#14581). |
| `auto_merge.bot_takeover.enabled` | `true` | When `github-actions[bot]` is in `auto_merge.trusted_bot_authors`, re-author its same-repo PRs whose required `pull_request` checks can never run (the bot opened them with a workflow `GITHUB_TOKEN`). After the head is older than both `min_head_age` and 30 minutes with no `pull_request` run, the App pushes the same change as one signed-off commit to `hive/takeover-<n>`, opens a PR with the original title/body plus `Supersedes #<n>`, comments `Superseded by #N` on the bot PR and closes it. One attempt per bot head SHA. See [hive-merge.md](hive-merge.md#github-actionsbot-pr-takeover). |
| `auto_merge.trusted_authors.enabled` | `false` | Enables the opt-in human-authored PR tier: Hive may merge a green PR only when the author already holds the required hive role and, by default, GitHub push/maintain/admin permission on that repo. |
| `auto_merge.trusted_authors.repos` | empty = all watched repos | Optional repo allow-list for the trusted-author tier. The dashboard renders this as a watched-repo multi-select; selecting nothing preserves the all-repos default. |
Expand Down
2 changes: 1 addition & 1 deletion src/docs/scale-envelope.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ones to:
2. **Truncation must preserve the prioritization signal, not cut an arbitrary slice.**
This holds today and is easy to assume backwards:
- Issues are sorted by actionable rank tier, then **oldest first** within each tier before any cap is applied
(`RankActionableIssues`, `src/pkg/github/client.go:4662-4676`, descending `AgeMinutes`).
(`RankActionableIssues`, `src/pkg/github/client.go:4676-4686`, descending `AgeMinutes`).
- PRs are sorted by **review class then oldest-first within class**
(`SortPullRequestsForReview`, `src/pkg/github/review_priority.go:334`;
fixes → refactors/docs → tests).
Expand Down
16 changes: 16 additions & 0 deletions src/pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package config

import (
Expand Down Expand Up @@ -7661,6 +7661,22 @@
// squash-only repo the lane keeps the squash convention and the PR goes
// back to its author (or, adopted, to stage/085 naming this policy).
SquashOnly []string `yaml:"squash_only,omitempty" json:"squash_only,omitempty"`
// CreditIssueAuthors puts `Co-authored-by: <issue author>` on the commit
// the hive's merge lands for every human who opened an issue the PR
// closes (`Fixes|Closes|Resolves #N`), minus the PR author, skipping
// bots, and never duplicating a trailer the branch already carries
// (hivecommons/hive#14581). The credit is additive — the PR author
// still authors the squash, every Signed-off-by is kept — and reaches
// the PRs external clankers open, which bypass the hive's own
// open-time attribution. nil/unset means ON; `credit_issue_authors:
// false` sends the merge with GitHub's default message as before.
CreditIssueAuthors *bool `yaml:"credit_issue_authors,omitempty" json:"credit_issue_authors,omitempty"`
}

// CreditIssueAuthorsEnabled reports the auto_merge.credit_issue_authors
// switch; unset is on.
func (a AutoMergeConfig) CreditIssueAuthorsEnabled() bool {
return a.CreditIssueAuthors == nil || *a.CreditIssueAuthors
}

// AutoMergeRepoConfig carries per-repository auto-merge overrides.
Expand Down
1 change: 1 addition & 0 deletions src/pkg/dashboard/settings_parity_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ agents.<key>.variables.<key>.type # TODO #11854
agents.<key>.variables.<key>.url # TODO #11854
agents.<key>.variables.<key>.value # TODO #11854
agents.github_api_hourly_cap # TODO #11854
auto_merge.credit_issue_authors # merge-time Co-authored-by credit (#14581); yaml-only
auto_merge.allow_unprotected_base[] # TODO #11854
auto_merge.human_merge_paths.<key> # TODO #11854
auto_merge.merge_forward_trusted_human[] # TODO #11854
Expand Down
4 changes: 4 additions & 0 deletions src/pkg/evidence/evidence.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ type MergeEvent struct {
At time.Time `json:"at"`
SHA string `json:"sha"`
OpenedAt time.Time `json:"opened_at,omitzero"`
// IssueAuthors are the human authors of the issues the PR closed whom
// the merge credited (hivecommons/hive#14581): the Co-authored-by the
// hive put on the landing commit, or that the branch already carried.
IssueAuthors []string `json:"issue_authors,omitempty"`
}

// Shadow records what shadow-mode gates would have done for the head SHA.
Expand Down
6 changes: 2 additions & 4 deletions src/pkg/github/automerge/automerge_contributor_lane.go
Original file line number Diff line number Diff line change
Expand Up @@ -1317,13 +1317,11 @@ func (c *Engine) trySweepContributorLanePR(ctx context.Context, displayRepo, own
return AutoMergeSweepEvent{}, refused, nil
}

mergeMessage, mergeOpts := c.mergeOptions(ctx, owner, repo, eval.pr, headSHA, method)
var mergeResult *gh.PullRequestMergeResult
mergeOut, err := c.executeMergeEffect(ctx, mergeClaim, owner, repo, number, func(ctx context.Context) (effects.Result, error) {
var apiErr error
mergeResult, _, apiErr = c.gh.PullRequests.Merge(ctx, owner, repo, number, "", &gh.PullRequestOptions{
SHA: headSHA,
MergeMethod: method,
})
mergeResult, _, apiErr = c.gh.PullRequests.Merge(ctx, owner, repo, number, mergeMessage, mergeOpts)
if apiErr != nil {
return effects.Result{}, mergeAPIErrorNotApplied(apiErr)
}
Expand Down
45 changes: 45 additions & 0 deletions src/pkg/github/automerge/automerge_contributor_lane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ type contributorLaneFixture struct {
// approveStatus, when set, is the status every approve returns.
approvedRuns []int64
approveStatus int
// issueAuthor is who GET issues/42 reports as the linked issue's
// author (hivecommons/hive#14581); empty serves the PR author, so the
// merge credits nobody and sends GitHub's default message.
issueAuthor string
issueAuthorID int64
issueAuthorType string
issueStatus int
issueGets int
// commitMessages are the branch commits GET pulls/7/commits serves;
// nil serves one signed commit.
commitMessages []string
commitLists int
// mergeBody is the JSON body of the last PUT pulls/7/merge.
mergeBody map[string]any
}

func newContributorLaneAPI(t *testing.T, fx *contributorLaneFixture) *httptest.Server {
Expand Down Expand Up @@ -219,6 +233,35 @@ func newContributorLaneAPI(t *testing.T, fx *contributorLaneFixture) *httptest.S
sha = fx.recheckHeadSHA
}
json.NewEncoder(w).Encode(pull(sha))
case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/issues/42":
fx.issueGets++
if fx.issueStatus != 0 {
http.Error(w, "issue error", fx.issueStatus)
return
}
issueAuthor := fx.issueAuthor
if issueAuthor == "" {
issueAuthor = author
}
userType := fx.issueAuthorType
if userType == "" {
userType = "User"
}
json.NewEncoder(w).Encode(map[string]any{
"number": 42, "state": "open",
"user": map[string]any{"login": issueAuthor, "id": fx.issueAuthorID, "type": userType},
})
case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/pulls/7/commits":
fx.commitLists++
msgs := fx.commitMessages
if msgs == nil {
msgs = []string{"Fix the widget\n\nSigned-off-by: " + author + " <" + author + "@example.com>"}
}
commits := make([]map[string]any, 0, len(msgs))
for i, msg := range msgs {
commits = append(commits, map[string]any{"sha": fmt.Sprintf("c%d", i), "commit": map[string]any{"message": msg}, "parents": []map[string]any{{"sha": "p"}}})
}
json.NewEncoder(w).Encode(commits)
case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/issues/42/comments":
if fx.issueCommentsSt != 0 {
http.Error(w, "comments error", fx.issueCommentsSt)
Expand Down Expand Up @@ -258,6 +301,8 @@ func newContributorLaneAPI(t *testing.T, fx *contributorLaneFixture) *httptest.S
json.NewEncoder(w).Encode(map[string]any{"sha": "sha7", "committer": map[string]string{"name": "c", "date": fx.headCommittedAt}})
case r.Method == http.MethodPut && r.URL.Path == "/repos/acme/widget/pulls/7/merge":
fx.merges++
fx.mergeBody = map[string]any{}
_ = json.NewDecoder(r.Body).Decode(&fx.mergeBody)
if fx.mergeStatus != 0 {
w.WriteHeader(fx.mergeStatus)
msg := fx.mergeMessage
Expand Down
38 changes: 38 additions & 0 deletions src/pkg/github/automerge/automerge_merge_credit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package automerge

import (
"context"

gh "github.com/google/go-github/v72/github"
hgithub "github.com/hivecommons/hive/pkg/github"
)

// Issue-author credit on the sweep's merges (hivecommons/hive#14581): every
// lane builds its merge request through mergeOptions, which asks the
// transport's MergeCreditor for the Co-authored-by trailers naming the human
// authors of the issues the PR closes and stashes the decision so the
// pr_merged audit and the evidence merge event can name them. A transport
// without a creditor (test stubs, no API client) merges exactly as before.

type mergeCreditTransport interface {
MergeCreditor() *hgithub.MergeCreditor
NoteMergeCredit(repo string, number int, credit hgithub.MergeCredit)
}

// mergeOptions returns the commit message and options for merging pr's
// head at headSHA with method. The message is "" (GitHub's default) unless
// the repo credits issue authors and the PR has one to credit.
func (c *Engine) mergeOptions(ctx context.Context, owner, repo string, pr *gh.PullRequest, headSHA, method string) (string, *gh.PullRequestOptions) {
opts := &gh.PullRequestOptions{SHA: headSHA, MergeMethod: method}
mt, ok := c.transport.(mergeCreditTransport)
if !ok || pr == nil {
return "", opts
}
creditor := mt.MergeCreditor()
if !creditor.Enabled(owner + "/" + repo) {
return "", opts
}
credit := creditor.Prepare(ctx, owner, repo, pr, method)
mt.NoteMergeCredit(owner+"/"+repo, pr.GetNumber(), credit)
return credit.CommitMessage, opts
}
Loading
Loading