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:
1 parent
03bdadc2b6
commit
1cab66173f
4 files changed
+237
-13
No files matched your search
@@ -477,20 +477,17 @@ fn review_event(
|
||||
/// The comment event a repo-wide comments row carries.
|
||||
fn comment_event(row: &WireComment, repo: &RepoRef) -> Result<Option<ForgeEvent>, ForgeError> {
|
||||
let id = required(row.id, "comment id")?;
|
||||
let issue_url = required(row.issue_url.clone(), "comment issue_url")?;
|
||||
let number = parent_number(&issue_url).ok_or_else(|| {
|
||||
let number = comment_parent(row).ok_or_else(|| {
|
||||
ForgeError::Parse(format!(
|
||||
"comment issue_url without a thread number: {issue_url}"
|
||||
"comment {id} names no thread: issue_url {:?}, pull_request_url {:?}, html_url {:?}",
|
||||
row.issue_url, row.pull_request_url, row.html_url
|
||||
))
|
||||
})?;
|
||||
let timestamp = required(
|
||||
row.updated_at.clone().or_else(|| row.created_at.clone()),
|
||||
"comment timestamp",
|
||||
)?;
|
||||
let is_pr = row
|
||||
.pull_request_url
|
||||
.as_deref()
|
||||
.is_some_and(|url| !url.is_empty());
|
||||
let is_pr = comment_is_pr(row);
|
||||
Ok(Some(ForgeEvent {
|
||||
id: format!("gitea:comment:{id}"),
|
||||
kind: EventKind::Comment,
|
||||
@@ -505,9 +502,48 @@ fn comment_event(row: &WireComment, repo: &RepoRef) -> Result<Option<ForgeEvent>
|
||||
}))
|
||||
}
|
||||
|
||||
/// The parent thread number: a forge thread URL's trailing segment.
|
||||
/// Every URL a comment row carries, most specific first.
|
||||
fn comment_urls(row: &WireComment) -> [Option<&str>; 3] {
|
||||
[
|
||||
row.issue_url.as_deref(),
|
||||
row.pull_request_url.as_deref(),
|
||||
row.html_url.as_deref(),
|
||||
]
|
||||
}
|
||||
|
||||
/// The thread number a comment row names.
|
||||
///
|
||||
/// `issue_url` is the field the API documents for it, but it is not
|
||||
/// reliable: the instance behind `git.vhaudiquet.fr` (28.3.0) sends it
|
||||
/// as an empty string on every row of the repo-wide `/issues/comments`
|
||||
/// feed, while `pull_request_url` and `html_url` stay populated. The
|
||||
/// number is therefore read from the first URL that carries one, in
|
||||
/// order of directness.
|
||||
fn comment_parent(row: &WireComment) -> Option<u64> {
|
||||
comment_urls(row)
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.find_map(parent_number)
|
||||
}
|
||||
|
||||
/// [`comment_parent`]'s "is it a pull request" half: `pull_request_url`
|
||||
/// is set exactly on PR conversation comments, and stays set on the
|
||||
/// instances whose `issue_url` is blank — but a row that lost both still
|
||||
/// says so in its `html_url` path.
|
||||
fn comment_is_pr(row: &WireComment) -> bool {
|
||||
comment_urls(row)
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.any(|url| url.contains("/pulls/") || url.contains("/pull/"))
|
||||
}
|
||||
|
||||
/// The parent thread number: a forge thread URL's trailing segment,
|
||||
/// with any fragment dropped first — a comment's `html_url` points at
|
||||
/// the comment (`…/pulls/1#issuecomment-164`), and its fragment is not
|
||||
/// a number at all.
|
||||
fn parent_number(url: &str) -> Option<u64> {
|
||||
url.trim_end_matches('/').rsplit('/').next()?.parse().ok()
|
||||
let path = url.split('#').next()?;
|
||||
path.trim_end_matches('/').rsplit('/').next()?.parse().ok()
|
||||
}
|
||||
|
||||
/// The fixed [`NotificationReason::Other`] spelling every reason-less
|
||||
@@ -895,4 +931,57 @@ mod tests {
|
||||
.expect("comment carries an event");
|
||||
assert!(!event.is_pr);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_comment_with_a_blank_issue_url_still_names_its_thread() {
|
||||
// git.vhaudiquet.fr (28.3.0) sends `issue_url: ""` on every row
|
||||
// of the repo-wide comments feed. The poll used to fail on the
|
||||
// first such row, which is why that watch never reported a single
|
||||
// event: a PR comment must still resolve to its pull request.
|
||||
let comment: WireComment = serde_json::from_str(
|
||||
r#"{"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/3",
|
||||
"html_url": "https://forge.example/acme/widgets/pulls/3#issuecomment-164"}"#,
|
||||
)
|
||||
.expect("comment fixture parses");
|
||||
let event = comment_event(&comment, &repo())
|
||||
.expect("a blank issue_url is not a parse failure")
|
||||
.expect("comment carries an event");
|
||||
assert_eq!(event.number, 3);
|
||||
assert!(event.is_pr);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_comment_with_only_an_html_url_reads_the_thread_off_its_path() {
|
||||
// The last resort: no issue_url and no pull_request_url. The
|
||||
// html_url points at the comment, so the fragment has to go
|
||||
// before the trailing segment means anything.
|
||||
let comment: WireComment = serde_json::from_str(
|
||||
r#"{"id": 165, "created_at": "2026-10-19T09:00:00Z",
|
||||
"updated_at": "2026-10-19T09:00:00Z",
|
||||
"html_url": "https://forge.example/acme/widgets/issues/7#issuecomment-165"}"#,
|
||||
)
|
||||
.expect("comment fixture parses");
|
||||
let event = comment_event(&comment, &repo())
|
||||
.expect("maps")
|
||||
.expect("comment carries an event");
|
||||
assert_eq!(event.number, 7);
|
||||
assert!(!event.is_pr);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_comment_whose_urls_name_no_thread_is_still_loud() {
|
||||
// The fallbacks must not degrade into a silent skip: a row with
|
||||
// no number anywhere is a vocabulary gap, and the poll says so.
|
||||
let comment: WireComment = serde_json::from_str(
|
||||
r#"{"id": 166, "created_at": "2026-10-19T09:00:00Z",
|
||||
"issue_url": "", "html_url": "https://forge.example/acme/widgets/issues/"}"#,
|
||||
)
|
||||
.expect("comment fixture parses");
|
||||
let err = comment_event(&comment, &repo()).expect_err("no thread number names a thread");
|
||||
assert!(matches!(err, ForgeError::Parse(_)), "got {err:?}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user