fix(forge): a gitea comment names its thread without issue_url

`comment_event` read the thread number from `issue_url` alone and failed
the whole poll when it could not. The instance behind git.vhaudiquet.fr
sends `issue_url: ""` on every row of the repo-wide `/issues/comments`
feed, so the first comment row failed the pass with

    malformed forge response: comment issue_url without a thread number:

and kept failing on every poll since the watch was created — 5296
consecutive failures, no event ever reported, no comment, no pull
request, nothing. The feed being broken was invisible: a watch that has
never polled once looks exactly like a quiet repository.

The number now comes from the first URL that carries one
(`issue_url`, then `pull_request_url`, then `html_url`), and a fragment is
dropped first: a comment's `html_url` points at the comment
(`…/pulls/1#issuecomment-164`), not at its thread. `is_pr` reads the same
three URLs, so a PR comment whose `issue_url` is blank still lands on the
pull request's sequence.

A row with no number anywhere is still a loud parse error — the
fallbacks must not degrade into a silently skipped event.
This commit is contained in:
kosmos committed 2026-11-14 16:58:25 +00:00
1 parent 03bdadc2b6
commit 1cab66173f
4 files changed
+237 -13

No files matched your search

@@ -557,3 +557,58 @@ async fn notifications_poll_maps_the_subject_feed() {
assert_eq!(note.repo, RepoRef::new("acme", "widgets"));
assert_eq!(note.title.as_deref(), Some("Fix the gate"));
}
/// The instance behind `git.vhaudiquet.fr` sends `issue_url: ""` on every
/// row of the repo-wide comments feed. A poll with one such row used to
/// fail outright, so the watch it fed never reported anything at all.
#[tokio::test]
async fn poll_survives_a_comments_feed_with_blank_issue_urls() {
let server = MockServer::start().await;
for (endpoint, body) in [
("/api/v1/repos/acme/widgets/issues", json!([])),
("/api/v1/repos/acme/widgets/pulls", json!([])),
] {
Mock::given(method("GET"))
.and(path(endpoint))
.respond_with(ResponseTemplate::new(200).set_body_json(body))
.mount(&server)
.await;
}
Mock::given(method("GET"))
.and(path("/api/v1/repos/acme/widgets/issues/comments"))
.respond_with(ResponseTemplate::new(200).set_body_json(json!([
{ "id": 164, "user": { "login": "alice" }, "body": "thanks",
"created_at": "2026-10-19T08:14:39Z",
"updated_at": "2026-10-19T08:14:39Z",
"issue_url": "",
"pull_request_url": "https://forge.example/acme/widgets/pulls/1",
"html_url": "https://forge.example/acme/widgets/pulls/1#issuecomment-164" },
{ "id": 165, "user": { "login": "bob" }, "body": "still broken",
"created_at": "2026-10-19T09:00:00Z",
"updated_at": "2026-10-19T09:00:00Z",
"issue_url": "",
"pull_request_url": Value::Null,
"html_url": "https://forge.example/acme/widgets/issues/2#issuecomment-165" }
])))
.mount(&server)
.await;
let since = Timestamp::parse(SINCE).expect("cursor parses");
let page = forge(&server)
.poll(&RepoRef::new("acme", "widgets"), Some(&since))
.await
.expect("a blank issue_url is not a poll failure");
let summary: Vec<(EventKind, u64, bool)> = page
.events
.iter()
.map(|event| (event.kind, event.number, event.is_pr))
.collect();
assert_eq!(
summary,
vec![
(EventKind::Comment, 1, true),
(EventKind::Comment, 2, false)
]
);
}