From a9df331469d56dc2a965b32e416b2f47d59c879f Mon Sep 17 00:00:00 2001 From: atlas Date: Fri, 27 Nov 2026 15:47:00 +0100 Subject: [PATCH] swarm-controller: move the forge concern into its own module Refs #6897 --- docs/4-implementation/scheduler/ci.md | 6 ++--- docs/4-implementation/swarm/controller.md | 8 +++---- nix/host-modules/glue-forge-controller.nix | 2 +- nix/host-modules/swarm-controller.nix | 8 +++---- swarm-controller/Cargo.toml | 10 ++++----- .../src/{ => git_forge}/config_pr.rs | 0 swarm-controller/src/{ => git_forge}/forge.rs | 0 .../{ => git_forge}/forge/agent_max_repos.rs | 0 .../src/{ => git_forge}/forge/agent_token.rs | 0 .../src/{ => git_forge}/forge/api.rs | 0 .../src/{ => git_forge}/forge/base_pulls.rs | 0 .../{ => git_forge}/forge/builder_account.rs | 0 .../forge/ci_metrics_account.rs | 0 .../forge/classifier_account.rs | 0 .../src/{ => git_forge}/forge/docs_grant.rs | 0 .../src/{ => git_forge}/forge/hive_cutoff.rs | 0 .../src/{ => git_forge}/forge/hive_token.rs | 0 .../{ => git_forge}/forge/legacy_tokens.rs | 0 .../src/{ => git_forge}/forge/meta_repo.rs | 0 .../src/{ => git_forge}/forge/objects.rs | 0 .../forge/operator_profiles.rs | 0 .../src/{ => git_forge}/forge/pr_comment.rs | 0 .../src/{ => git_forge}/forge/pr_report.rs | 0 .../src/{ => git_forge}/forge/pull_diff.rs | 0 .../src/{ => git_forge}/forge/repo_avatar.rs | 0 .../{ => git_forge}/forge/review_request.rs | 0 .../src/{ => git_forge}/forge/runner_token.rs | 0 .../{ => git_forge}/forge/service_avatars.rs | 0 .../src/{ => git_forge}/forge/site_admin.rs | 0 .../src/{ => git_forge}/forge_events.rs | 0 .../src/{ => git_forge}/issue_report.rs | 0 swarm-controller/src/git_forge/mod.rs | 11 ++++++++++ .../src/{ => git_forge}/pr_conflicts.rs | 0 .../src/{ => git_forge}/pr_report.rs | 0 swarm-controller/src/{ => git_forge}/pulls.rs | 0 .../src/{ => git_forge}/webhook.rs | 22 +++++++++---------- swarm-controller/src/main.rs | 14 +++++------- 37 files changed, 44 insertions(+), 37 deletions(-) rename swarm-controller/src/{ => git_forge}/config_pr.rs (100%) rename swarm-controller/src/{ => git_forge}/forge.rs (100%) rename swarm-controller/src/{ => git_forge}/forge/agent_max_repos.rs (100%) rename swarm-controller/src/{ => git_forge}/forge/agent_token.rs (100%) rename swarm-controller/src/{ => git_forge}/forge/api.rs (100%) rename swarm-controller/src/{ => git_forge}/forge/base_pulls.rs (100%) rename swarm-controller/src/{ => git_forge}/forge/builder_account.rs (100%) rename swarm-controller/src/{ => git_forge}/forge/ci_metrics_account.rs (100%) rename swarm-controller/src/{ => git_forge}/forge/classifier_account.rs (100%) rename swarm-controller/src/{ => git_forge}/forge/docs_grant.rs (100%) rename swarm-controller/src/{ => git_forge}/forge/hive_cutoff.rs (100%) rename swarm-controller/src/{ => git_forge}/forge/hive_token.rs (100%) rename swarm-controller/src/{ => git_forge}/forge/legacy_tokens.rs (100%) rename swarm-controller/src/{ => git_forge}/forge/meta_repo.rs (100%) rename swarm-controller/src/{ => git_forge}/forge/objects.rs (100%) rename swarm-controller/src/{ => git_forge}/forge/operator_profiles.rs (100%) rename swarm-controller/src/{ => git_forge}/forge/pr_comment.rs (100%) rename swarm-controller/src/{ => git_forge}/forge/pr_report.rs (100%) rename swarm-controller/src/{ => git_forge}/forge/pull_diff.rs (100%) rename swarm-controller/src/{ => git_forge}/forge/repo_avatar.rs (100%) rename swarm-controller/src/{ => git_forge}/forge/review_request.rs (100%) rename swarm-controller/src/{ => git_forge}/forge/runner_token.rs (100%) rename swarm-controller/src/{ => git_forge}/forge/service_avatars.rs (100%) rename swarm-controller/src/{ => git_forge}/forge/site_admin.rs (100%) rename swarm-controller/src/{ => git_forge}/forge_events.rs (100%) rename swarm-controller/src/{ => git_forge}/issue_report.rs (100%) create mode 100644 swarm-controller/src/git_forge/mod.rs rename swarm-controller/src/{ => git_forge}/pr_conflicts.rs (100%) rename swarm-controller/src/{ => git_forge}/pr_report.rs (100%) rename swarm-controller/src/{ => git_forge}/pulls.rs (100%) rename swarm-controller/src/{ => git_forge}/webhook.rs (99%) diff --git a/docs/4-implementation/scheduler/ci.md b/docs/4-implementation/scheduler/ci.md index 170ec69a8..f8fd0f3dc 100644 --- a/docs/4-implementation/scheduler/ci.md +++ b/docs/4-implementation/scheduler/ci.md @@ -83,7 +83,7 @@ needs `deploy.forgejo.enable` or a hive on its host. ## Registration -1. **swarm-controller** (`swarm-controller/src/forge/runner_token.rs`) reads +1. **swarm-controller** (`swarm-controller/src/git_forge/forge/runner_token.rs`) reads the forge's instance-wide token from `GET /api/v1/admin/runners/registration-token` at start and every five minutes, and writes it to the secret store at @@ -163,7 +163,7 @@ warns about it. The **swarm controller** seeds the mirror in its swarm-wide forge-objects -pass (`swarm-controller/src/forge/objects.rs`), beside the orgs it ensures. +pass (`swarm-controller/src/git_forge/forge/objects.rs`), beside the orgs it ensures. `glue-forge-controller.nix` forwards the effective mirror list as `SWARM_CONTROLLER_FORGE_MIRRORS` in the `swarm-controller` service environment (JSON-encoded `[{upstream, dest}]` list). It reads the list of @@ -287,7 +287,7 @@ builder — disk-pressure collection at least runs while nothing is mid-copy. ## References - `nix/host-modules/swarm-ci-runner.nix`: runner configuration, token fetch, re-registration step, container setup. -- `swarm-controller/src/forge/runner_token.rs`: publishes the registration token. +- `swarm-controller/src/git_forge/forge/runner_token.rs`: publishes the registration token. - `.forgejo/workflows/ci.yml`: workflow definition. - `docs/5-project/process/gotchas.md`: nix sandboxing limitations in containers. diff --git a/docs/4-implementation/swarm/controller.md b/docs/4-implementation/swarm/controller.md index 5a35ac868..7f1abbd00 100644 --- a/docs/4-implementation/swarm/controller.md +++ b/docs/4-implementation/swarm/controller.md @@ -387,7 +387,7 @@ drops it unanswered, which reads as a 504. `swarmctl agent agents-md get` and The controller also keeps the forge objects that are one per swarm, not one per hive. It ensures them at start and every five minutes after -(`swarm-controller/src/forge/objects.rs`): +(`swarm-controller/src/git_forge/forge/objects.rs`): - the orgs `agent-configs`, `internal` and `agents`, plus each mirror's owner org; @@ -411,12 +411,12 @@ one per hive. It ensures them at start and every five minutes after The config repos get the agent's icon too. When a build sets the agent's icon, the controller sets the avatar of `agent-configs/` from the PNG the -builder rendered (`forge/repo_avatar.rs`), as the forge admin, who may edit any +builder rendered (`git_forge/forge/repo_avatar.rs`), as the forge admin, who may edit any repo's avatar. A marker per repo (`forge-repo-avatar-`) holds the image's SHA-256, as for the service accounts below. The swarm's own forge accounts (`builder`, `ci-metrics` and `review-classifier`) -get an avatar too, from a separate pass in the controller (`forge/service_avatars.rs`). +get an avatar too, from a separate pass in the controller (`git_forge/forge/service_avatars.rs`). Each has an icon in a hexagonal frame (`branding/service-.svg`, rendered to a PNG in the assets package) and falls back to the hyperhive logo. Only an account can set its own avatar, so the pass mints a short-lived `write:user` token for it with the admin API, uploads @@ -433,7 +433,7 @@ controller is down the objects stay as they are. The controller gives each agent **read** on `internal/docs`. A `GrantDocsRead` node in the agent's create job adds it as a collaborator, unless it already holds read or more. A pass over the -store's `hive-agent-*` roster (`forge/docs_grant.rs`, at start and every five +store's `hive-agent-*` roster (`git_forge/forge/docs_grant.rs`, at start and every five minutes) adds any agent that isn't one, so an agent whose create-time grant failed gets it within five minutes. The pass only adds: a roster it can't read, a forge read that fails, or an `internal/docs` that doesn't exist (checked once per diff --git a/nix/host-modules/glue-forge-controller.nix b/nix/host-modules/glue-forge-controller.nix index 4fd8a4063..6b83d6552 100644 --- a/nix/host-modules/glue-forge-controller.nix +++ b/nix/host-modules/glue-forge-controller.nix @@ -29,7 +29,7 @@ in lib.mkDefault "https://forge.darkest.space/hyperhive/hyperhive"; # JSON-encoded list of { upstream, dest }, seeded by the controller's - # forge-objects pass (`swarm-controller/src/forge/objects.rs`). + # forge-objects pass (`swarm-controller/src/git_forge/forge/objects.rs`). systemd.services.swarm-controller.environment.SWARM_CONTROLLER_FORGE_MIRRORS = builtins.toJSON deployCfg.forgejo.effectiveMirrors; }) diff --git a/nix/host-modules/swarm-controller.nix b/nix/host-modules/swarm-controller.nix index 4cbd805b0..9a937ff70 100644 --- a/nix/host-modules/swarm-controller.nix +++ b/nix/host-modules/swarm-controller.nix @@ -220,17 +220,17 @@ let # Unconditional: every swarm has a forge, reached by name wherever it runs. # The token is not here: the daemon reads it from the swarm's secret store at - # start (`forge.rs`), and re-reads it in the background until it is there. + # start (`git_forge/forge.rs`), and re-reads it in the background until it is there. forgeEnv = { SWARM_CONTROLLER_FORGE_URL = "https://${forgeCfg.domain}"; # `agent-configs` org avatar for the forge-objects pass - # (`forge/objects.rs`). Only meaningful with forge access, hence here. + # (`git_forge/forge/objects.rs`). Only meaningful with forge access, hence here. SWARM_CONTROLLER_CONFIG_ORG_AVATAR_PNG = if deployCfg.swarm-controller.configOrgAvatarPng != null then "${deployCfg.swarm-controller.configOrgAvatarPng}" else "${config.services.hyperhive.deploy.hive-controller.assets}/share/hyperhive/branding/agent-configs.png"; - # The swarm services' own forge accounts' avatars (`forge/service_avatars.rs`). + # The swarm services' own forge accounts' avatars (`git_forge/forge/service_avatars.rs`). SWARM_CONTROLLER_SERVICE_ICON_DIR = "${config.services.hyperhive.deploy.hive-controller.assets}/share/hyperhive/branding"; }; @@ -1020,7 +1020,7 @@ in # `AF_UNIX` for the socket this daemon serves on, plus what its # outbound clients need: it mints authelia tokens and calls the forge - # over HTTPS (`auth.rs`, `forge.rs`) and reaches the queue over NATS + # over HTTPS (`auth.rs`, `git_forge/forge.rs`) and reaches the queue over NATS # (`startup.rs`, `status.rs`). `AF_NETLINK` because glibc's # `getaddrinfo` opens a netlink socket to enumerate local addresses # before it will return one. diff --git a/swarm-controller/Cargo.toml b/swarm-controller/Cargo.toml index e7f896db4..92a46cf3d 100644 --- a/swarm-controller/Cargo.toml +++ b/swarm-controller/Cargo.toml @@ -20,12 +20,12 @@ async-nats = { workspace = true, features = ["kv"] } axum.workspace = true # Builds every forgejo-api client (`forge/`), so the construction lives once. forge-client.workspace = true -# swarm-controller's own forge client (`forge.rs`) — self-contained, +# swarm-controller's own forge client (`git_forge/forge.rs`) — self-contained, # deliberately not sharing code with `hive-c0re::forge` across the crate # boundary (see #3306's design discussion: forcing that split now, over a # few idempotent CRUD-ish calls, is premature plumbing). forgejo-api.workspace = true -# `forge.rs` encodes file content for its `repo_change_files` calls and +# `git_forge/forge.rs` encodes file content for its `repo_change_files` calls and # decodes blobs it reads: forgejo's content and blob APIs carry base64, # never raw bytes. base64.workspace = true @@ -64,7 +64,7 @@ hive-jobq-metrics.workspace = true opentelemetry.workspace = true opentelemetry_sdk.workspace = true opentelemetry-otlp.workspace = true -# The forge webhook HMAC (`webhook.rs`). Kept in this crate rather than +# The forge webhook HMAC (`git_forge/webhook.rs`). Kept in this crate rather than # shared with hive-c0re's equivalent: c0re's copy is scheduled to be deleted # with its webhook routes once registration moves here, so the second holder # is departing, not arriving — see that module's docs. @@ -72,7 +72,7 @@ hmac.workspace = true sha2.workspace = true # The `{SHA}` htpasswd line `archive_access.rs` writes for the archive server. sha1.workspace = true -# `forge/pull_diff.rs` diffs a PR's changed files itself, at a context width +# `git_forge/forge/pull_diff.rs` diffs a PR's changed files itself, at a context width # the forge's own `.diff` does not offer. similar.workspace = true # The `Permission` names `/api/agents/{name}/permissions` accepts, the same @@ -84,7 +84,7 @@ similar.workspace = true # defense-in-depth, not the only gate (per an argus review finding). hive-types.workspace = true # `auth`'s bridge client — same crate the bridge itself uses to define the -# request/response shape, so the two ends cannot drift. `forge.rs` also +# request/response shape, so the two ends cannot drift. `git_forge/forge.rs` also # uses this directly for `StatusCode` in its error-classification helpers. # # `blocking` on top of the workspace default: `vcs_metrics`'s OTLP exporter diff --git a/swarm-controller/src/config_pr.rs b/swarm-controller/src/git_forge/config_pr.rs similarity index 100% rename from swarm-controller/src/config_pr.rs rename to swarm-controller/src/git_forge/config_pr.rs diff --git a/swarm-controller/src/forge.rs b/swarm-controller/src/git_forge/forge.rs similarity index 100% rename from swarm-controller/src/forge.rs rename to swarm-controller/src/git_forge/forge.rs diff --git a/swarm-controller/src/forge/agent_max_repos.rs b/swarm-controller/src/git_forge/forge/agent_max_repos.rs similarity index 100% rename from swarm-controller/src/forge/agent_max_repos.rs rename to swarm-controller/src/git_forge/forge/agent_max_repos.rs diff --git a/swarm-controller/src/forge/agent_token.rs b/swarm-controller/src/git_forge/forge/agent_token.rs similarity index 100% rename from swarm-controller/src/forge/agent_token.rs rename to swarm-controller/src/git_forge/forge/agent_token.rs diff --git a/swarm-controller/src/forge/api.rs b/swarm-controller/src/git_forge/forge/api.rs similarity index 100% rename from swarm-controller/src/forge/api.rs rename to swarm-controller/src/git_forge/forge/api.rs diff --git a/swarm-controller/src/forge/base_pulls.rs b/swarm-controller/src/git_forge/forge/base_pulls.rs similarity index 100% rename from swarm-controller/src/forge/base_pulls.rs rename to swarm-controller/src/git_forge/forge/base_pulls.rs diff --git a/swarm-controller/src/forge/builder_account.rs b/swarm-controller/src/git_forge/forge/builder_account.rs similarity index 100% rename from swarm-controller/src/forge/builder_account.rs rename to swarm-controller/src/git_forge/forge/builder_account.rs diff --git a/swarm-controller/src/forge/ci_metrics_account.rs b/swarm-controller/src/git_forge/forge/ci_metrics_account.rs similarity index 100% rename from swarm-controller/src/forge/ci_metrics_account.rs rename to swarm-controller/src/git_forge/forge/ci_metrics_account.rs diff --git a/swarm-controller/src/forge/classifier_account.rs b/swarm-controller/src/git_forge/forge/classifier_account.rs similarity index 100% rename from swarm-controller/src/forge/classifier_account.rs rename to swarm-controller/src/git_forge/forge/classifier_account.rs diff --git a/swarm-controller/src/forge/docs_grant.rs b/swarm-controller/src/git_forge/forge/docs_grant.rs similarity index 100% rename from swarm-controller/src/forge/docs_grant.rs rename to swarm-controller/src/git_forge/forge/docs_grant.rs diff --git a/swarm-controller/src/forge/hive_cutoff.rs b/swarm-controller/src/git_forge/forge/hive_cutoff.rs similarity index 100% rename from swarm-controller/src/forge/hive_cutoff.rs rename to swarm-controller/src/git_forge/forge/hive_cutoff.rs diff --git a/swarm-controller/src/forge/hive_token.rs b/swarm-controller/src/git_forge/forge/hive_token.rs similarity index 100% rename from swarm-controller/src/forge/hive_token.rs rename to swarm-controller/src/git_forge/forge/hive_token.rs diff --git a/swarm-controller/src/forge/legacy_tokens.rs b/swarm-controller/src/git_forge/forge/legacy_tokens.rs similarity index 100% rename from swarm-controller/src/forge/legacy_tokens.rs rename to swarm-controller/src/git_forge/forge/legacy_tokens.rs diff --git a/swarm-controller/src/forge/meta_repo.rs b/swarm-controller/src/git_forge/forge/meta_repo.rs similarity index 100% rename from swarm-controller/src/forge/meta_repo.rs rename to swarm-controller/src/git_forge/forge/meta_repo.rs diff --git a/swarm-controller/src/forge/objects.rs b/swarm-controller/src/git_forge/forge/objects.rs similarity index 100% rename from swarm-controller/src/forge/objects.rs rename to swarm-controller/src/git_forge/forge/objects.rs diff --git a/swarm-controller/src/forge/operator_profiles.rs b/swarm-controller/src/git_forge/forge/operator_profiles.rs similarity index 100% rename from swarm-controller/src/forge/operator_profiles.rs rename to swarm-controller/src/git_forge/forge/operator_profiles.rs diff --git a/swarm-controller/src/forge/pr_comment.rs b/swarm-controller/src/git_forge/forge/pr_comment.rs similarity index 100% rename from swarm-controller/src/forge/pr_comment.rs rename to swarm-controller/src/git_forge/forge/pr_comment.rs diff --git a/swarm-controller/src/forge/pr_report.rs b/swarm-controller/src/git_forge/forge/pr_report.rs similarity index 100% rename from swarm-controller/src/forge/pr_report.rs rename to swarm-controller/src/git_forge/forge/pr_report.rs diff --git a/swarm-controller/src/forge/pull_diff.rs b/swarm-controller/src/git_forge/forge/pull_diff.rs similarity index 100% rename from swarm-controller/src/forge/pull_diff.rs rename to swarm-controller/src/git_forge/forge/pull_diff.rs diff --git a/swarm-controller/src/forge/repo_avatar.rs b/swarm-controller/src/git_forge/forge/repo_avatar.rs similarity index 100% rename from swarm-controller/src/forge/repo_avatar.rs rename to swarm-controller/src/git_forge/forge/repo_avatar.rs diff --git a/swarm-controller/src/forge/review_request.rs b/swarm-controller/src/git_forge/forge/review_request.rs similarity index 100% rename from swarm-controller/src/forge/review_request.rs rename to swarm-controller/src/git_forge/forge/review_request.rs diff --git a/swarm-controller/src/forge/runner_token.rs b/swarm-controller/src/git_forge/forge/runner_token.rs similarity index 100% rename from swarm-controller/src/forge/runner_token.rs rename to swarm-controller/src/git_forge/forge/runner_token.rs diff --git a/swarm-controller/src/forge/service_avatars.rs b/swarm-controller/src/git_forge/forge/service_avatars.rs similarity index 100% rename from swarm-controller/src/forge/service_avatars.rs rename to swarm-controller/src/git_forge/forge/service_avatars.rs diff --git a/swarm-controller/src/forge/site_admin.rs b/swarm-controller/src/git_forge/forge/site_admin.rs similarity index 100% rename from swarm-controller/src/forge/site_admin.rs rename to swarm-controller/src/git_forge/forge/site_admin.rs diff --git a/swarm-controller/src/forge_events.rs b/swarm-controller/src/git_forge/forge_events.rs similarity index 100% rename from swarm-controller/src/forge_events.rs rename to swarm-controller/src/git_forge/forge_events.rs diff --git a/swarm-controller/src/issue_report.rs b/swarm-controller/src/git_forge/issue_report.rs similarity index 100% rename from swarm-controller/src/issue_report.rs rename to swarm-controller/src/git_forge/issue_report.rs diff --git a/swarm-controller/src/git_forge/mod.rs b/swarm-controller/src/git_forge/mod.rs new file mode 100644 index 000000000..41f7f63f3 --- /dev/null +++ b/swarm-controller/src/git_forge/mod.rs @@ -0,0 +1,11 @@ +//! The forge concern: the Forgejo client and its accounts, webhook intake, +//! forge events, and the PR and issue views built on them. + +pub(crate) mod config_pr; +pub(crate) mod forge; +pub(crate) mod forge_events; +pub(crate) mod issue_report; +pub(crate) mod pr_conflicts; +pub(crate) mod pr_report; +pub(crate) mod pulls; +pub(crate) mod webhook; diff --git a/swarm-controller/src/pr_conflicts.rs b/swarm-controller/src/git_forge/pr_conflicts.rs similarity index 100% rename from swarm-controller/src/pr_conflicts.rs rename to swarm-controller/src/git_forge/pr_conflicts.rs diff --git a/swarm-controller/src/pr_report.rs b/swarm-controller/src/git_forge/pr_report.rs similarity index 100% rename from swarm-controller/src/pr_report.rs rename to swarm-controller/src/git_forge/pr_report.rs diff --git a/swarm-controller/src/pulls.rs b/swarm-controller/src/git_forge/pulls.rs similarity index 100% rename from swarm-controller/src/pulls.rs rename to swarm-controller/src/git_forge/pulls.rs diff --git a/swarm-controller/src/webhook.rs b/swarm-controller/src/git_forge/webhook.rs similarity index 99% rename from swarm-controller/src/webhook.rs rename to swarm-controller/src/git_forge/webhook.rs index fd3bae18e..04dd2a6dc 100644 --- a/swarm-controller/src/webhook.rs +++ b/swarm-controller/src/git_forge/webhook.rs @@ -114,7 +114,7 @@ fn state_dir_from(raw: Option<&str>) -> std::path::PathBuf { /// **not** an error: it counts as absent, because a secret that cannot be /// parsed is indistinguishable from one that was never written, and failing /// startup over it would strand the daemon with no path forward. -pub(super) async fn load_or_generate_secret() -> Result { +pub(crate) async fn load_or_generate_secret() -> Result { resolve(&StoreSlot, &secret_path()).await } @@ -180,7 +180,7 @@ where } /// What the store holds at the webhook secret's path. -pub(super) enum Stored { +pub(crate) enum Stored { /// The secret. Value(String), /// Nothing is stored there. @@ -192,7 +192,7 @@ pub(super) enum Stored { /// The webhook secret's place in the store. A test stands in for the store /// through this trait. -pub(super) trait SecretSlot { +pub(crate) trait SecretSlot { /// What is stored now. fn read(&self) -> impl Future> + Send; @@ -364,14 +364,14 @@ fn write_secret_0600(path: &std::path::Path, contents: &[u8]) -> Result<()> { /// Read 32 random bytes from `/dev/urandom` and hex-encode them. /// -/// `pub(super)` rather than private: `forge::Client::ensure_agent_user` +/// `pub(crate)` rather than private: `forge::Client::ensure_agent_user` /// reuses this for the throwaway account password Forgejo's admin /// create-user API requires (unlike the `forgejo admin` CLI's /// `--random-password`, the HTTP endpoint has no "generate one for me" /// option — see that function's doc comment). Same shape as the webhook /// secret above: a value nothing ever reads back, so 32 random bytes is /// as good as any other generator. -pub(super) fn generate_hex_secret() -> Result { +pub(crate) fn generate_hex_secret() -> Result { use std::io::Read as _; let mut buf = [0u8; 32]; @@ -415,7 +415,7 @@ fn hex_decode(s: &str) -> Option> { /// registered hook gets its own `target_url`, exactly as the per-hive hooks /// do today. #[derive(Clone, Copy, Debug, PartialEq, Eq, strum::IntoStaticStr, strum::EnumString)] -pub(super) enum DeliveryKind { +pub(crate) enum DeliveryKind { /// Push events on the hive-wide knowledge repo. #[strum(serialize = "knowledge")] Knowledge, @@ -468,7 +468,7 @@ impl DeliveryKind { /// Every kind, for the registration sweep. An array rather than a /// hand-written list at the call site, so adding a kind cannot leave one /// hook unregistered. - pub(super) const ALL: [Self; 7] = [ + pub(crate) const ALL: [Self; 7] = [ Self::Knowledge, Self::ConfigPr, Self::VcsActivity, @@ -485,7 +485,7 @@ impl DeliveryKind { /// is *registered* and the route that *serves* it are the same fact in /// one place. A trailing slash on the base is tolerated — it arrives from /// config, and `https://swarm//webhook/...` would be a hook that 404s. - pub(super) fn target_url(self, public_base: &str) -> String { + pub(crate) fn target_url(self, public_base: &str) -> String { format!( "{}{ROUTE_PREFIX}{}", public_base.trim_end_matches('/'), @@ -501,7 +501,7 @@ impl DeliveryKind { /// `e.contains("unavailable")`, which couples an HTTP response to the exact /// wording of a log message. #[derive(Debug, PartialEq, Eq)] -pub(super) enum Refusal { +pub(crate) enum Refusal { /// No secret was loaded at startup: the endpoint cannot verify anything, /// which is this daemon's fault and not the caller's. 503, so a retry is /// meaningful. @@ -538,7 +538,7 @@ impl Refusal { /// The refusal messages are safe to log — they never contain the secret or /// the expected digest, so a caller can surface *why* a delivery was refused /// without handing an attacker the answer. -pub(super) fn verify( +pub(crate) fn verify( secret: Option<&str>, headers: &HeaderMap, body: &Bytes, @@ -618,7 +618,7 @@ pub(super) fn verify( ), tag = "webhook" )] -pub(super) async fn post_webhook_forge( +pub(crate) async fn post_webhook_forge( State(state): State, Path(kind): Path, headers: HeaderMap, diff --git a/swarm-controller/src/main.rs b/swarm-controller/src/main.rs index 242d042dc..9844f49c6 100644 --- a/swarm-controller/src/main.rs +++ b/swarm-controller/src/main.rs @@ -57,13 +57,10 @@ mod builder; mod cache_miss; mod claude_login; mod config_drift; -mod config_pr; mod egress_allow; mod egress_deny; -mod forge; -mod forge_events; +mod git_forge; mod inference; -mod issue_report; mod jobq; mod message_stream; mod meta_build; @@ -72,10 +69,7 @@ mod meta_flake; mod observability; mod observability_grant; mod pause_hold; -mod pr_conflicts; -mod pr_report; mod proxy_credential; -mod pulls; mod queue_identity; mod read_policy; mod review; @@ -91,12 +85,14 @@ mod term_stream; #[cfg(test)] mod test_nats; mod wanted; -mod webhook; -// The accounts, observability and review modules keep their crate-root paths (`crate::matrix_account::…`). +// The accounts, forge, observability and review modules keep their crate-root paths (`crate::matrix_account::…`). use accounts::{ forge_account, github_account, gitlab_account, link_egress, linked_accounts, matrix_account, }; +use git_forge::{ + config_pr, forge, forge_events, issue_report, pr_conflicts, pr_report, pulls, webhook, +}; use jobq::{Late, WorkerDeps, spawn_jobq_worker}; use observability::{alerts, held_deploys, otel_http_client, vcs_metrics}; use review::{notify_flows, notify_router_api, request_reviewer, review_classifier};