Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | 33x 33x 33x 33x 33x 33x 33x 12x 12x 2x 2x 2x 33x 12x 33x 11x 11x 18x 1x 17x 6x 33x 9x 7x 33x 11x 33x 33x 20x 33x 33x 10x 10x | import { repoApiUrl } from "./github.ts";
const FENCE = /```[\s\S]*?```/g;
const HTML_COMMENT = /<!--[\s\S]*?-->/g;
const LINK = /\[([^[\]]*)\]\([^()]*\)/g;
const CHECKBOX = /^[ \t]*[-*][ \t]+\[[ x]\][ \t]*/gim;
const BULLET = /^[ \t]*[-*>#]+[ \t]*/gm;
const EMPHASIS = /[*_`~]+/g;
/** One open issue normalized from the browser-side GitHub read. */
export interface Issue {
number: number;
title: string;
body: string;
url: string;
labels: string[];
assignees: string[];
createdAt: string;
updatedAt: string;
}
/** One line of an issue body for a row, its markdown syntax stripped rather than rendered. */
export const summarize = (body: string, length = 140): string => {
const text = body
.replace(FENCE, " ")
.replace(HTML_COMMENT, " ")
.replace(LINK, "$1")
.replace(CHECKBOX, "")
.replace(BULLET, "")
.replace(EMPHASIS, "")
.replace(/\s+/g, " ")
.trim();
if (text.length <= length) return text;
const cut = text.slice(0, length);
const space = cut.lastIndexOf(" ");
return `${(space > length * 0.6 ? cut.slice(0, space) : cut).trimEnd()}…`;
};
export const labelsOf = (issues: Issue[]): string[] =>
[...new Set(issues.flatMap((issue) => issue.labels))].sort((a, b) => a.localeCompare(b));
interface IssueFilter {
label?: string;
search?: string;
}
export const filterIssues = (issues: Issue[], filter: IssueFilter): Issue[] => {
const needle = filter.search?.trim().toLowerCase() ?? "";
return issues.filter((issue) => {
if (filter.label && filter.label !== "all" && !issue.labels.includes(filter.label))
return false;
if (needle.length === 0) return true;
return `#${issue.number} ${issue.title} ${issue.body}`.toLowerCase().includes(needle);
});
};
/** The half of GitHub's REST issue payload this app reads; everything else is dropped. */
export interface GithubIssue {
number: number;
title: string;
body: string | null;
html_url: string;
labels: { name: string }[];
assignees: { login: string }[];
created_at: string;
updated_at: string;
/** Set only on a pull request, which the issues endpoint returns alongside the issues. */
pull_request?: unknown;
}
/** `html_url`, not `url` — the latter is the API's own address for the issue and renders as JSON. */
const toIssue = (issue: GithubIssue): Issue => ({
number: issue.number,
title: issue.title,
body: issue.body ?? "",
url: issue.html_url,
labels: issue.labels.map(({ name }) => name),
assignees: issue.assignees.map(({ login }) => login),
createdAt: issue.created_at,
updatedAt: issue.updated_at,
});
/** A pull request is an issue to this endpoint and is not one here. */
export const toIssues = (payload: GithubIssue[]): Issue[] =>
payload.filter((item) => item.pull_request === undefined).map(toIssue);
export const issuesApiUrl = (repoUrl: string): string | null => repoApiUrl(repoUrl, "issues");
/** The browser-side GitHub read, including a displayable error when it could not complete. */
export interface IssuesRead {
fetchedAt: string;
error: string | null;
issues: Issue[];
}
export const sortIssues = (issues: Issue[]): Issue[] =>
issues.slice().sort((a, b) => b.updatedAt.localeCompare(a.updatedAt) || b.number - a.number);
const AREA_PREFIX = new Map([
["apps", "app"],
["packages", "package"],
["infrastructure", "infra"],
]);
/** The `app:`/`package:`/`infra:` label a project's issues are filed under, from its root. */
export const areaLabel = (root: string): string => {
const [kind = "", folder = ""] = root.split("/");
return `${AREA_PREFIX.get(kind) ?? "infra"}:${folder}`;
};
|