clippy: fix lints that crane's cargoClippy properly enforces (#538)
The naersk → crane swap in the parent commit flips clippy from silently passing to actually failing on `-D warnings` (naersk's `mode = "clippy"` mangled the `--` separator so the deny never took effect). This commit clears the surfaced lints so the workspace builds clean under the new enforcement — every fix is mechanical and preserves behaviour. Tests still pass (160 across the workspace). Auto-fixes via `cargo clippy --fix`: - `doc_markdown` (19 sites): bare identifiers in doc comments wrapped in backticks - `format_in_format_args`, `explicit_into_iter_loop`, `redundant_closure_for_method_calls`, `useless_conversion`, and a few more — mechanical rewrites of the kind cargo can apply safely. Hand-fixed: - `match_same_arms` (forge_notify::is_atx_heading): two arms returning `true` collapsed into a single `matches!` pattern. - `cast_sign_loss` + `format_push_string` (mcp.rs status formatter): guarded `i64 → u64` through `u64::try_from(…).unwrap_or(0)` (status timestamps are always positive in practice; clamp the skew edge to 0) and swapped `out.push_str(&format!(…))` for `write!` into the buffer with an infallible-writer `let _ =`. - `doc_lazy_continuation` in turn.rs + manager_server.rs + sh4re/lib.rs: doc paragraphs that the markdown parser was treating as list-item continuations got either a separating blank line or a `/`-for-`+` word swap so the parser stops seeing a list. - `unused_async` (manager_server::handle_request_schedule_prompt): function has no `.await`; dropped the `async` and its `.await` call site. - `needless_pass_by_value` (scheduled_prompts::submit): take `&NewSchedule` instead of moving the struct in; updated two prod callers and eight test sites to pass references. - `type_complexity` (approvals::mark_cancelled): hoisted the 7-tuple SELECT row shape into a `type CancelLookupRow = (…);` alias. Allow-with-reason for intentional patterns: - `option_option` (6 sites across dashboard / scheduled_prompts / manager_server): `Option<Option<T>>` carries three-state PATCH semantics (missing key = leave alone, `Some(None)` = clear, `Some(Some(v))` = set). Collapsing to `Option<T>` loses the "clear" state. - `dead_code` (rebuild_queue::QueueKind::Destroy / QueueSource::CrashRecover; topology::parent_of / default_seed): wire-shape variants + API surfaces kept for the upcoming features (#361 follow-ups, future `Destroy` queue routing, crash-recovery path). Allowed at the variant / function level with the rationale in `reason = "…"`. - `too_many_lines` on three specific call-sites: a 117-line exhaustive-variant test (dashboard_events::kind_tag_matches_…), the meta-flake string template renderer (meta::render_flake_with_lookup), and the notification poll loop (forge_notify::poll_once) — splitting any of them would just hide the contiguous shape they exist to keep visible. `nix flake check` formatting target is still broken on main itself (pre-existing nixfmt drift across ~28 files unrelated to this PR); left alone here so the scope stays "crane port + lints the port exposed" and the operator's review doesn't have to triage drive-by nixfmt churn.
This commit is contained in:
parent
4b6c733afb
commit
9ed58ab96d
17 changed files with 643 additions and 463 deletions
|
|
@ -162,11 +162,7 @@ pub async fn run(socket: PathBuf, is_manager: bool) {
|
|||
|
||||
/// Fetch a JSON value from a URL using the agent's forge token. Returns
|
||||
/// `None` on any HTTP or parse error (best-effort enrichment).
|
||||
async fn fetch_json(
|
||||
client: &reqwest::Client,
|
||||
url: &str,
|
||||
token: &str,
|
||||
) -> Option<serde_json::Value> {
|
||||
async fn fetch_json(client: &reqwest::Client, url: &str, token: &str) -> Option<serde_json::Value> {
|
||||
let resp = client
|
||||
.get(url)
|
||||
.header("Authorization", format!("token {token}"))
|
||||
|
|
@ -207,7 +203,7 @@ fn notif_type_label(t: &str) -> &str {
|
|||
/// (`heading\n===`) are not handled here — rarer in practice and
|
||||
/// would need multi-line lookahead; revisit if it actually shows up.
|
||||
///
|
||||
/// **ATX shape strictly:** CommonMark requires a space (or end-of-line)
|
||||
/// **ATX shape strictly:** `CommonMark` requires a space (or end-of-line)
|
||||
/// after the 1-6 leading `#`s to count as an ATX heading. Lines like
|
||||
/// `#tag`, `#123`, `#!/bin/bash` are NOT headings — passing them through
|
||||
/// untouched avoids the cosmetic noise argus flagged on PR #518 (`\#tag`
|
||||
|
|
@ -236,7 +232,7 @@ fn escape_md_headings(body: &str) -> String {
|
|||
out
|
||||
}
|
||||
|
||||
/// Strict CommonMark ATX-heading detector: 1-6 leading `#`s followed
|
||||
/// Strict `CommonMark` ATX-heading detector: 1-6 leading `#`s followed
|
||||
/// by either a space, tab, or end-of-line. Anything tighter (`#tag`,
|
||||
/// `#123`) is a non-heading line that the renderer will not promote.
|
||||
fn is_atx_heading(line: &str) -> bool {
|
||||
|
|
@ -244,11 +240,10 @@ fn is_atx_heading(line: &str) -> bool {
|
|||
if !(1..=6).contains(&hashes) {
|
||||
return false;
|
||||
}
|
||||
match line.as_bytes().get(hashes) {
|
||||
None => true, // bare `#` / `##` / ... on its own line
|
||||
Some(b' ') | Some(b'\t') => true, // proper ATX with space/tab after #s
|
||||
_ => false, // `#tag` / `#123` — not a heading
|
||||
}
|
||||
// Bare `#` / `##` / ... on its own line, or proper ATX with a
|
||||
// space/tab after the run of `#`s; anything else (`#tag` / `#123`)
|
||||
// is not a heading.
|
||||
matches!(line.as_bytes().get(hashes), None | Some(b' ' | b'\t'))
|
||||
}
|
||||
|
||||
fn truncate(s: &str, max: usize) -> String {
|
||||
|
|
@ -390,7 +385,9 @@ async fn format_notification(
|
|||
|
||||
// API URLs for fetching content
|
||||
let subject_api_url = notif["subject"]["url"].as_str().unwrap_or("");
|
||||
let comment_api_url = notif["subject"]["latest_comment_url"].as_str().unwrap_or("");
|
||||
let comment_api_url = notif["subject"]["latest_comment_url"]
|
||||
.as_str()
|
||||
.unwrap_or("");
|
||||
let comment_html_url = notif["subject"]["latest_comment_html_url"]
|
||||
.as_str()
|
||||
.unwrap_or("");
|
||||
|
|
@ -411,9 +408,27 @@ async fn format_notification(
|
|||
// by creation/state-change of the subject itself.
|
||||
let has_comment = !comment_api_url.is_empty() && comment_api_url != subject_api_url;
|
||||
|
||||
let meta = NotifMeta { title, notif_type, html_url, num, repo, meta_suffix, reason, subject, is_pr };
|
||||
let meta = NotifMeta {
|
||||
title,
|
||||
notif_type,
|
||||
html_url,
|
||||
num,
|
||||
repo,
|
||||
meta_suffix,
|
||||
reason,
|
||||
subject,
|
||||
is_pr,
|
||||
};
|
||||
if has_comment {
|
||||
format_comment_notification(client, token, &meta, comment_api_url, comment_html_url, own_login).await
|
||||
format_comment_notification(
|
||||
client,
|
||||
token,
|
||||
&meta,
|
||||
comment_api_url,
|
||||
comment_html_url,
|
||||
own_login,
|
||||
)
|
||||
.await
|
||||
} else {
|
||||
format_state_change_notification(notif, &meta, own_login)
|
||||
}
|
||||
|
|
@ -454,16 +469,28 @@ fn build_meta_suffix(subject: Option<&serde_json::Value>, is_pr: bool, reason: &
|
|||
.and_then(|s| s["requested_reviewers"].as_array())
|
||||
.map(|arr| arr.iter().filter_map(|r| r["login"].as_str()).collect())
|
||||
.unwrap_or_default();
|
||||
if reviewers.is_empty() { None } else { Some(format!("reviewer: {}", reviewers.join(", "))) }
|
||||
if reviewers.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(format!("reviewer: {}", reviewers.join(", ")))
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
// Always include reason so multiple notifications for the same event
|
||||
// (each with a different Forgejo reason) are distinguishable (closes #110).
|
||||
let reason_line = if reason.is_empty() { None } else { Some(format!("reason: {reason}")) };
|
||||
let reason_line = if reason.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(format!("reason: {reason}"))
|
||||
};
|
||||
let mut out = format!("\n{assignee_line}");
|
||||
if let Some(r) = reviewer_line { write!(out, "\n{r}").ok(); }
|
||||
if let Some(r) = reason_line { write!(out, "\n{r}").ok(); }
|
||||
if let Some(r) = reviewer_line {
|
||||
write!(out, "\n{r}").ok();
|
||||
}
|
||||
if let Some(r) = reason_line {
|
||||
write!(out, "\n{r}").ok();
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
|
|
@ -504,9 +531,24 @@ async fn format_comment_notification(
|
|||
.and_then(|c| c["state"].as_str())
|
||||
.and_then(review_state_label);
|
||||
|
||||
let url = if comment_html_url.is_empty() { meta.html_url } else { comment_html_url };
|
||||
let author = if actor_login.is_empty() { "?" } else { actor_login };
|
||||
let NotifMeta { title, notif_type, num, repo, meta_suffix, .. } = meta;
|
||||
let url = if comment_html_url.is_empty() {
|
||||
meta.html_url
|
||||
} else {
|
||||
comment_html_url
|
||||
};
|
||||
let author = if actor_login.is_empty() {
|
||||
"?"
|
||||
} else {
|
||||
actor_login
|
||||
};
|
||||
let NotifMeta {
|
||||
title,
|
||||
notif_type,
|
||||
num,
|
||||
repo,
|
||||
meta_suffix,
|
||||
..
|
||||
} = meta;
|
||||
|
||||
// Truncate the raw body first so the mention-overflow diff compares
|
||||
// like-for-like (escape_md_headings rewrites `# foo` to `\# foo`, so
|
||||
|
|
@ -574,7 +616,17 @@ fn format_state_change_notification(
|
|||
return None;
|
||||
}
|
||||
|
||||
let NotifMeta { title, notif_type, html_url, num, repo, meta_suffix, reason: _, subject, is_pr } = meta;
|
||||
let NotifMeta {
|
||||
title,
|
||||
notif_type,
|
||||
html_url,
|
||||
num,
|
||||
repo,
|
||||
meta_suffix,
|
||||
reason: _,
|
||||
subject,
|
||||
is_pr,
|
||||
} = meta;
|
||||
let label = notif_type_label(notif_type);
|
||||
let kind = match notif_state {
|
||||
"merged" => format!("{label} merged{num}{repo}"),
|
||||
|
|
@ -630,6 +682,12 @@ fn format_state_change_notification(
|
|||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[allow(
|
||||
clippy::too_many_lines,
|
||||
reason = "single-pass notification poll loop — split would obscure the \
|
||||
sequential 'fetch / classify / dispatch' rhythm and add helper \
|
||||
functions for state shared across all three phases"
|
||||
)]
|
||||
async fn poll_once(
|
||||
client: &reqwest::Client,
|
||||
forge_url: &str,
|
||||
|
|
@ -672,10 +730,15 @@ async fn poll_once(
|
|||
return;
|
||||
}
|
||||
|
||||
debug!(count = notifications.len(), "forge_notify: delivering notifications");
|
||||
debug!(
|
||||
count = notifications.len(),
|
||||
"forge_notify: delivering notifications"
|
||||
);
|
||||
|
||||
for notif in ¬ifications {
|
||||
let Some(id) = notif["id"].as_u64() else { continue };
|
||||
let Some(id) = notif["id"].as_u64() else {
|
||||
continue;
|
||||
};
|
||||
|
||||
// Reason drop-list: suppress noisy reasons (subscribed/participating).
|
||||
// null/unknown reasons pass through — directed signals are never
|
||||
|
|
@ -733,28 +796,30 @@ async fn poll_once(
|
|||
// when HIVE_FORGE_KEEP_SUBSCRIPTIONS=1 — triage and other firehose
|
||||
// consumers set this to retain broad repo visibility.
|
||||
let reason = notif["reason"].as_str().unwrap_or("");
|
||||
if !keep_subscriptions && reason == "subscribed"
|
||||
if !keep_subscriptions
|
||||
&& reason == "subscribed"
|
||||
&& let Some(repo) = notif["repository"]["full_name"].as_str()
|
||||
&& !unsubbed_repos.contains(repo) {
|
||||
let unsub_url = format!("{forge_url}/api/v1/repos/{repo}/subscription");
|
||||
match client
|
||||
.delete(&unsub_url)
|
||||
.header("Authorization", format!("token {token}"))
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(r) if r.status().is_success() || r.status().as_u16() == 404 => {
|
||||
debug!(%repo, "forge_notify: unsubscribed from repo watch");
|
||||
unsubbed_repos.insert(repo.to_owned());
|
||||
}
|
||||
Ok(r) => {
|
||||
debug!(%repo, status = %r.status(), "forge_notify: unsub non-2xx (ignored)");
|
||||
}
|
||||
Err(e) => {
|
||||
debug!(%repo, error = ?e, "forge_notify: unsub request failed (ignored)");
|
||||
}
|
||||
}
|
||||
&& !unsubbed_repos.contains(repo)
|
||||
{
|
||||
let unsub_url = format!("{forge_url}/api/v1/repos/{repo}/subscription");
|
||||
match client
|
||||
.delete(&unsub_url)
|
||||
.header("Authorization", format!("token {token}"))
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(r) if r.status().is_success() || r.status().as_u16() == 404 => {
|
||||
debug!(%repo, "forge_notify: unsubscribed from repo watch");
|
||||
unsubbed_repos.insert(repo.to_owned());
|
||||
}
|
||||
Ok(r) => {
|
||||
debug!(%repo, status = %r.status(), "forge_notify: unsub non-2xx (ignored)");
|
||||
}
|
||||
Err(e) => {
|
||||
debug!(%repo, error = ?e, "forge_notify: unsub request failed (ignored)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue