forked from vhaudiquet/rhema-claw
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
@@ -380,6 +380,46 @@ impl Timestamp {
|
||||
pub fn epoch_secs(&self) -> i64 {
|
||||
self.secs
|
||||
}
|
||||
|
||||
/// The instant `millis` milliseconds past the Unix epoch, in the
|
||||
/// canonical `YYYY-MM-DDThh:mm:ss[.mmm]Z` spelling.
|
||||
///
|
||||
/// This is how a cursor is born without a forge: a subsystem that
|
||||
/// starts watching *now* (rather than replaying a feed's history)
|
||||
/// needs a `since` spelled the way the forges spell theirs, and this
|
||||
/// is the one place that conversion lives.
|
||||
pub fn from_epoch_millis(millis: i64) -> Option<Self> {
|
||||
let secs = millis.div_euclid(1000);
|
||||
let sub_millis = millis.rem_euclid(1000);
|
||||
let (days, of_day) = (secs.div_euclid(86_400), secs.rem_euclid(86_400));
|
||||
let (year, month, day) = civil_from_days(days);
|
||||
let (hour, minute, second) = (of_day / 3_600, (of_day / 60) % 60, of_day % 60);
|
||||
let raw = if sub_millis == 0 {
|
||||
format!("{year:04}-{month:02}-{day:02}T{hour:02}:{minute:02}:{second:02}Z")
|
||||
} else {
|
||||
format!(
|
||||
"{year:04}-{month:02}-{day:02}T{hour:02}:{minute:02}:{second:02}.{sub_millis:03}Z"
|
||||
)
|
||||
};
|
||||
Self::parse(&raw)
|
||||
}
|
||||
}
|
||||
|
||||
/// The civil date `days` days past 1970-01-01, as `(year, month, day)` —
|
||||
/// the inverse of [`days_from_civil`] (Howard Hinnant's algorithm).
|
||||
fn civil_from_days(days: i64) -> (i64, u32, u32) {
|
||||
let z = days + 719_468;
|
||||
let era = if z >= 0 { z } else { z - 146_096 } / 146_097;
|
||||
let day_of_era = z - era * 146_097;
|
||||
let year_of_era =
|
||||
(day_of_era - day_of_era / 1_460 + day_of_era / 36_524 - day_of_era / 146_096) / 365;
|
||||
let year = year_of_era + era * 400;
|
||||
let day_of_year = day_of_era - (365 * year_of_era + year_of_era / 4 - year_of_era / 100);
|
||||
let mp = (5 * day_of_year + 2) / 153;
|
||||
let day = day_of_year - (153 * mp + 2) / 5 + 1;
|
||||
let month = if mp < 10 { mp + 3 } else { mp - 9 };
|
||||
let year = if month <= 2 { year + 1 } else { year };
|
||||
(year, month as u32, day as u32)
|
||||
}
|
||||
|
||||
/// A run of ASCII digits at `range`, as its number.
|
||||
@@ -524,4 +564,32 @@ mod tests {
|
||||
.expect("deserializes");
|
||||
assert_eq!(round, event);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_timestamp_is_born_from_epoch_millis() {
|
||||
// The whole-second spelling the forges send, and the fractional
|
||||
// one GitLab sends: both round-trip back to the same instant.
|
||||
let whole =
|
||||
Timestamp::from_epoch_millis(1_791_417_600_000).expect("a millis instant parses");
|
||||
assert_eq!(whole.raw(), "2026-10-08T00:00:00Z");
|
||||
assert_eq!(whole.epoch_secs(), 1_791_417_600);
|
||||
|
||||
let fractional =
|
||||
Timestamp::from_epoch_millis(1_791_417_600_081).expect("a millis instant parses");
|
||||
assert_eq!(fractional.raw(), "2026-10-08T00:00:00.081Z");
|
||||
assert_eq!(fractional.epoch_secs(), whole.epoch_secs());
|
||||
|
||||
// The epoch itself, and a leap day, so the civil-date inverse is
|
||||
// exercised somewhere other than "today".
|
||||
assert_eq!(
|
||||
Timestamp::from_epoch_millis(0).expect("parses").raw(),
|
||||
"1970-01-01T00:00:00Z"
|
||||
);
|
||||
assert_eq!(
|
||||
Timestamp::from_epoch_millis(1_709_164_800_000)
|
||||
.expect("parses")
|
||||
.raw(),
|
||||
"2024-02-29T00:00:00Z"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user