Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions apps/web/src/lib/deliveryPullRequest.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { describe, expect, it } from "vite-plus/test";

import { deliveryCiRun } from "./deliveryPullRequest";

describe("deliveryCiRun", () => {
it("builds a GitHub Actions URL for a positive numeric run ID", () => {
expect(deliveryCiRun("InTheta-tools/t3.code_fork", 43_772_162_509)).toEqual({
label: "run 43772162509",
href: "https://github.com/InTheta-tools/t3.code_fork/actions/runs/43772162509",
});
});

it.each([undefined, null, "123", 0, -1, 1.5, Infinity, Number.MAX_SAFE_INTEGER + 1])(
"rejects invalid run ID %s",
(runId) => {
expect(deliveryCiRun("InTheta/t3code", runId)).toBeNull();
},
);

it.each([
"",
"InTheta",
"/t3code",
"InTheta/",
"./t3code",
"../t3code",
"InTheta/.",
"InTheta/..",
"InTheta/%2e%2e",
"InTheta/t3code/actions",
"InTheta//t3code",
"InTheta/t3code?x",
"InTheta/t3code#x",
"InTheta/t3code\n",
"InTheta\\other/t3code",
"https://example.org/t3code",
"//example.org/t3code",
"example.org/t3code",
"github.com@example.org/t3code",
])("keeps the run label without a link for invalid repository path %j", (repository) => {
expect(deliveryCiRun(repository, 123)).toEqual({ label: "run 123", href: null });
});
});
22 changes: 22 additions & 0 deletions apps/web/src/lib/deliveryPullRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,25 @@ export function parseDeliveryPullRequestUrl(value: string) {
return null;
}
}

export function deliveryCiRun(repository: string, runId: unknown) {
if (typeof runId !== "number" || !Number.isSafeInteger(runId) || runId <= 0) return null;

const label = `run ${runId}`;
const parts = repository.split("/");
const [owner, repo] = parts;
if (
parts.length !== 2 ||
!owner ||
!repo ||
/[^a-z0-9-]/i.test(owner) ||
owner.startsWith("-") ||
owner.endsWith("-") ||
/[^a-z0-9_.-]/i.test(repo) ||
repo === "." ||
repo === ".."
) {
return { label, href: null };
}
return { label, href: `https://github.com/${owner}/${repo}/actions/runs/${runId}` };
}
37 changes: 31 additions & 6 deletions apps/web/src/routes/_chat.delivery.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { createFileRoute, useNavigate, useRouter, useRouterState } from "@tanstack/react-router";

import { parseDeliveryPullRequestUrl } from "~/lib/deliveryPullRequest";
import type { ReactNode } from "react";

import { deliveryCiRun, parseDeliveryPullRequestUrl } from "~/lib/deliveryPullRequest";

interface Delivery {
version: 1;
Expand Down Expand Up @@ -101,23 +103,46 @@ async function readPullRequestDelivery(value: string, signal: AbortSignal) {
}
}

function CiRunLink({ repository, runId }: { repository: string; runId?: number | undefined }) {
const run = deliveryCiRun(repository, runId);
if (!run) return null;
if (!run.href) return ` · ${run.label}`;
return (
<>
{" · "}
<a className="underline" href={run.href} target="_blank" rel="noreferrer">
{run.label}
</a>
</>
);
}

function PullRequestEvidence({ delivery }: { delivery: PullRequestDelivery }) {
const { pullRequest, candidate, qa, ci } = delivery;
const fields = [
const fields: ReadonlyArray<readonly [string, ReactNode]> = [
["Current PR commit", pullRequest.head],
["Verified candidate", candidate ?? "No managed candidate"],
["QA reviewed commit", qa.head ?? "Unavailable"],
["Independent QA", qa.freshness === "stale" ? `${qa.status} (stale)` : qa.status],
["CI tested commit", ci.head ?? "Unavailable"],
["CI", ci.head && ci.head !== pullRequest.head ? "stale" : ci.status],
[
"CI",
<>
{ci.head && ci.head !== pullRequest.head ? "stale" : ci.status}
<CiRunLink repository={pullRequest.repository} runId={ci.runId} />
</>,
],
...(delivery.previousCi && delivery.previousCi.head !== pullRequest.head
? [
? ([
["Previous CI commit", delivery.previousCi.head],
[
"Previous CI",
delivery.previousCi.runId ? `stale · run ${delivery.previousCi.runId}` : "stale",
<>
stale
<CiRunLink repository={pullRequest.repository} runId={delivery.previousCi.runId} />
</>,
],
]
] as const)
: []),
];
return (
Expand Down
Loading