With the poll the only announcer of a merge, its cost showed: every 30 s it asked every repository for its pull requests, a pass outlasted the tick, and passes piled up beside each other — a merge was announced four and a half minutes late, and two passes at once could each announce it. A pass now asks only repositories updated since a minute before the last look, and the next pass starts when this one ends. hq issue 250.
37 lines
1.9 KiB
TypeScript
37 lines
1.9 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { test } from "node:test";
|
|
import { createServer } from "node:http";
|
|
import { GiteaClient } from "../client.ts";
|
|
|
|
test("every page of a pull request's files is read, though the forge caps a page at fifty", async () => {
|
|
const total = 59;
|
|
const server = createServer((req, res) => {
|
|
const url = new URL(req.url ?? "", "http://x");
|
|
const page = Number(url.searchParams.get("page") ?? "1");
|
|
const start = (page - 1) * 50;
|
|
const files = Array.from({ length: Math.max(0, Math.min(50, total - start)) }, (_, i) => ({ filename: `modules/m${start + i}/x` }));
|
|
res.setHeader("content-type", "application/json");
|
|
res.end(JSON.stringify(files));
|
|
});
|
|
await new Promise<void>((r) => server.listen(0, r));
|
|
const port = (server.address() as any).port;
|
|
const client = new GiteaClient(`http://127.0.0.1:${port}`, "t");
|
|
const got = await client.listPullFiles("novox", "mesh-catalog", 60);
|
|
server.close();
|
|
assert.equal(got.paths.length, total);
|
|
assert.equal(got.truncated, false);
|
|
assert.equal(new Set(got.paths).size, total);
|
|
});
|
|
|
|
test("a pass asks only the repositories that moved since the last look, every one before the first", async () => {
|
|
const { movedSince } = await import("../client.ts");
|
|
const repos = [
|
|
{ full_name: "a/old", name: "old", owner: "a", private: false, html_url: "", updated_at: "2026-10-05T10:00:00Z" },
|
|
{ full_name: "a/new", name: "new", owner: "a", private: false, html_url: "", updated_at: "2026-10-05T16:10:02Z" },
|
|
{ full_name: "a/unknown", name: "unknown", owner: "a", private: false, html_url: "" },
|
|
];
|
|
assert.deepEqual(movedSince(repos, "").map((r) => r.name), ["old", "new", "unknown"]);
|
|
assert.deepEqual(movedSince(repos, "2026-10-05T16:09:00.000Z").map((r) => r.name), ["new", "unknown"]);
|
|
assert.deepEqual(movedSince(repos, "2026-10-05T18:10:02+02:00").map((r) => r.name), ["new", "unknown"], "an offset is a moment, not a string");
|
|
});
|