feat(foreman): provider-neutral CodeHost/WorkItems/ChangePolicy seams (#1158)#1161
Merged
Defilan merged 1 commit intoJul 19, 2026
Merged
Conversation
…defilantech#1158) Introduce three provider-neutral interfaces in pkg/foreman/agent so the agent executor no longer calls the GitHub packages directly. This is the enabling refactor for supporting non-GitHub integrations (Forgejo, Linear, Woodpecker); GitHub remains the only implementation and behavior is unchanged. - codehost.CodeHost: clone-URL resolution, change-request (PR) creation, and head-commit subject. GitHubCodeHost wraps githubpr.Ensurer and the github.com clone-URL template. - worktracker.WorkItems: fetch a work item by string ID. GitHubWorkItems wraps githubissue.Fetcher, mapping the issue number to/from a string ID at the adapter boundary. - changepolicy.ChangePolicy: classify changed paths into work classes and gate human review. Mirrors the logic in workclass.go / verdict_policy.go. The executor reaches all three through accessor methods that prefer the injected seam and otherwise wrap the legacy IssueFetcher / PREnsurer fields (threading the run's git-auth token), so existing callers and tests keep working. upstreamURLForRepo now delegates to codehost.ResolveCloneURL and applyVerdictPolicy classifies through changepolicy, so all three packages are live. cmd/foreman-agent wires the GitHub-backed implementations. Phase 1 of defilantech#1158 is the interface extraction only. The CRD work-item ID int->string migration and the Forgejo/Linear implementations are separate follow-ups. Part of defilantech#1158 Signed-off-by: Christopher Maher <chris@mahercode.io>
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Introduce three provider-neutral interfaces in
pkg/foreman/agent—codehost.CodeHost,worktracker.WorkItems, andchangepolicy.ChangePolicy— and route the agent executor through them instead of calling the GitHub packages directly. GitHub remains the only implementation; no behavior change.Why
Foreman's node-side agent is hard-wired to GitHub across three concerns: code hosting (repo/PR), work tracking (issues), and change policy (path classification for human review). Decoupling these behind interfaces is the enabling refactor for non-GitHub setups (e.g. Forgejo + Linear + Woodpecker). Part of #1158.
How
codehost.CodeHost— clone-URL resolution, change-request (PR) creation, and head-commit subject.GitHubCodeHostwrapsgithubpr.Ensurerand the github.com clone-URL template.worktracker.WorkItems— fetch a work item by string ID.GitHubWorkItemswrapsgithubissue.Fetcher, mapping the issue number to/from a string ID at the adapter boundary.changepolicy.ChangePolicy— classify changed paths into work classes and gate human review; mirrorsworkclass.go/verdict_policy.go.IssueFetcher/PREnsurerfields (threading the run's git-auth token), so existing callers and tests keep working.upstreamURLForReponow delegates tocodehost.ResolveCloneURLandapplyVerdictPolicyclassifies viachangepolicy, so all three packages are live.cmd/foreman-agentwires the GitHub-backed implementations.Scope: Phase 1 = interface extraction only. The CRD work-item ID
int→stringmigration and the Forgejo/Linear implementations are separate follow-ups; that migration ripples across the controller, CLI, audit, and generated CRDs, so it is kept out here to bound the blast radius. TheAgenticTaskPayload.Issuefield staysint32(converted to a string at theworktrackerboundary).Testing
go build ./...— clean onGOOS=darwinandGOOS=linux.golangci-lint run(repo-pinned v2.12.2) on the touched packages — 0 issues, darwin and linux.go test ./pkg/foreman/agent/...including the three new packages — passing. Behavior is preserved: the existing executor PR, issue-fetch, and verdict-policy tests pass with only the mechanical signature updates.Checklist
AI-assisted (Claude Code) under the project's AI contribution policy; authored and reviewed by @Defilan.