@mark1russell7/canon-ontology 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { R as pathOfId, r as ONTOLOGY_REPOSITORY } from "./targets-BwC2nZGy.mjs";
1
+ import { R as pathOfId, r as ONTOLOGY_REPOSITORY } from "./targets-DFXTvFDm.mjs";
2
2
  // src/board.ts
3
3
  /** The label of each issue of the board. */
4
4
  const TARGET_LABEL = "target";
@@ -224,4 +224,4 @@ function decideClaim(input) {
224
224
  }
225
225
  export { applyBoard as a, decideClaim as c, planBoard as d, targetOfIssue as f, actionComment as i, isExpired as l, CLAIM_HOURS as n, claimCommandOf as o, TARGET_LABEL as r, claimEnd as s, BOARD_LIMIT as t, issueText as u };
226
226
 
227
- //# sourceMappingURL=board-DAKpkjvV.mjs.map
227
+ //# sourceMappingURL=board-7NZb3yv_.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"board-DAKpkjvV.mjs","names":[],"sources":["../src/board.ts"],"sourcesContent":["// The target board: one GitHub issue for each claimable target, and the claims on the issues. The plan and the claim\n// decision are pure functions. The sync and the claim send the requests through an IssueApi.\nimport { pathOfId } from \"./ids.ts\";\nimport { ONTOLOGY_REPOSITORY, type TargetRecord } from \"./targets.ts\";\n\n/** The label of each issue of the board. */\nexport const TARGET_LABEL = \"target\";\n\n/** The time of a claim with no pull request, in hours. */\nexport const CLAIM_HOURS = 48;\n\n/** The most open issues of the board. */\nexport const BOARD_LIMIT = 20;\n\n/** The start of the hidden line of an issue body that has the id of its target. */\nconst MARK = \"<!-- canon-target: \";\n\n/** The end of the hidden line. */\nconst MARK_END = \" -->\";\n\n/** An issue of the board, as the API of the issues gives it. */\nexport interface BoardIssue {\n readonly number: number;\n readonly title: string;\n readonly body: string;\n readonly state: \"open\" | \"closed\";\n readonly labels: readonly string[];\n readonly assignees: readonly string[];\n /** This time is the start of the claim of an open issue with an assignee, in milliseconds since 1970. */\n readonly claimedAt?: number | undefined;\n}\n\n/** The title, the body and the labels of the issue of a target. */\nexport interface IssueText {\n readonly title: string;\n readonly body: string;\n readonly labels: readonly string[];\n}\n\n/** A change of an issue. Each field that is not here does not change. */\nexport interface IssueChange {\n readonly title?: string;\n readonly body?: string;\n readonly labels?: readonly string[];\n readonly state?: \"open\" | \"closed\";\n readonly stateReason?: \"completed\" | \"not_planned\" | \"reopened\";\n /** This list replaces the assignees of the issue. */\n readonly assignees?: readonly string[];\n}\n\n/** The API of the issues of one repository. A test gives a fake, and `githubIssueApi` gives the API of GitHub. */\nexport interface IssueApi {\n /** This method gives each issue with the label `target`, open and closed, with the start of each claim. */\n issues(): Promise<readonly BoardIssue[]>;\n /** This method tells if an open pull request names the target id. */\n hasOpenPull(targetId: string): Promise<boolean>;\n /** This method makes each label that does not exist. */\n ensureLabels(names: readonly string[]): Promise<void>;\n /** This method opens an issue, and gives its number. */\n create(text: IssueText): Promise<number>;\n /** This method changes an issue, and gives the issue after the change. */\n update(number: number, change: IssueChange): Promise<BoardIssue>;\n /** This method writes a comment on an issue. */\n comment(number: number, text: string): Promise<void>;\n}\n\n/** One step of the sync of the board. */\nexport type BoardAction =\n | { readonly kind: \"create\"; readonly target: string; readonly text: IssueText }\n | { readonly kind: \"update\"; readonly number: number; readonly target: string; readonly text: IssueText; readonly reopen: boolean }\n | { readonly kind: \"close\"; readonly number: number; readonly target: string; readonly reason: \"completed\" | \"not_planned\" }\n | { readonly kind: \"release\"; readonly number: number; readonly target: string; readonly users: readonly string[] };\n\n/** The inputs of the plan of the board. */\nexport interface BoardInput {\n /** Each target of the target query, in the order of `compareTargets`. */\n readonly targets: readonly TargetRecord[];\n readonly issues: readonly BoardIssue[];\n /** This time is the time of the decision, in milliseconds since 1970. */\n readonly now: number;\n /** The ids of the targets that an open pull request names. */\n readonly pulls: ReadonlySet<string>;\n /** The most open issues. The default is `BOARD_LIMIT`. */\n readonly limit?: number | undefined;\n}\n\n/** This function gives the id of the target of an issue body, or undefined when the body has no hidden line. */\nexport function targetOfIssue(body: string): string | undefined {\n const start = body.indexOf(MARK);\n if (start < 0) return undefined;\n const end = body.indexOf(MARK_END, start + MARK.length);\n const id = end < 0 ? \"\" : body.slice(start + MARK.length, end).trim();\n return id === \"\" || /\\s/.test(id) ? undefined : id;\n}\n\n/** This function gives the time of the end of a claim, as an ISO 8601 text to the minute. */\nexport function claimEnd(claimedAt: number): string {\n return `${new Date(claimedAt + CLAIM_HOURS * 3_600_000).toISOString().slice(0, 16)}Z`;\n}\n\n/** This function tells if a claim is older than `CLAIM_HOURS`. A claim with no known start is live. */\nexport function isExpired(issue: BoardIssue, now: number): boolean {\n return issue.assignees.length > 0 && issue.claimedAt !== undefined && now - issue.claimedAt >= CLAIM_HOURS * 3_600_000;\n}\n\n/** This function gives the title, the body and the labels of the issue of a target. */\nexport function issueText(target: TargetRecord, repository: string = ONTOLOGY_REPOSITORY): IssueText {\n const { attrs } = target;\n const path = pathOfId(target.id);\n const body = [\n `${MARK}${target.id}${MARK_END}`,\n `**Target:** \\`${target.id}\\``,\n \"\",\n \"| Gap | Home | Size | Area |\",\n \"| --- | --- | --- | --- |\",\n `| \\`${attrs.gap}\\` | [${attrs.home}](https://github.com/${attrs.home}) | ${attrs.size} | ${attrs.area === undefined ? \"\" : `\\`${attrs.area}\\``} |`,\n \"\",\n \"## Acceptance\",\n \"\",\n attrs.acceptance.text,\n \"\",\n ...attrs.acceptance.checks.map((check) => `- [ ] ${check}`),\n \"\",\n \"## Why\",\n \"\",\n attrs.why,\n \"\",\n \"## Claim and close\",\n \"\",\n `1. Write the comment \\`/claim\\` on this issue. A claim stops after ${String(CLAIM_HOURS)} hours with no open pull request.`,\n `2. Do the work. [\\`AGENTS.md\\`](https://github.com/${repository}/blob/main/AGENTS.md) tells how.`,\n `3. In the pull request, write the line \\`Target: ${target.id}\\`.`,\n \"\",\n `The record of the target is [\\`${path}\\`](https://github.com/${repository}/blob/main/${path}). Write \\`/unclaim\\` to stop your claim.`,\n \"\",\n ].join(\"\\n\");\n return { title: attrs.title, body, labels: [TARGET_LABEL, `gap:${attrs.gap}`] };\n}\n\n/** This function tells if an issue has the text of a target: the same title, body and labels. */\nfunction sameText(issue: BoardIssue, text: IssueText): boolean {\n const labels = [...issue.labels].sort();\n const wanted = [...text.labels].sort();\n return issue.title === text.title && issue.body === text.body && labels.length === wanted.length && labels.every((label, index) => label === wanted[index]);\n}\n\n/**\n * This function gives the steps that make the board agree with the target query.\n *\n * - The board keeps the open issue of each claimable target. It adds other claimable targets, up to the limit. An issue\n * does not close because new targets come before it.\n * - Each added target is the first claimable target of the gap with the fewest targets on the board. So one gap with\n * many targets does not fill the board.\n * - An issue whose target is not claimable closes: `completed` when the target is gone, else `not_planned`.\n * - A claim older than `CLAIM_HOURS` stops when no open pull request names its target.\n * - An issue with no hidden line is not an issue of the board. Of two issues of one target, the board uses the first.\n */\nexport function planBoard(input: BoardInput): readonly BoardAction[] {\n const limit = input.limit ?? BOARD_LIMIT;\n const known = new Set(input.targets.map((target) => target.id));\n const claimable = input.targets.filter((target) => target.attrs.claimable);\n const byTarget = new Map<string, BoardIssue>();\n for (const issue of [...input.issues].sort((a, b) => a.number - b.number)) {\n const id = targetOfIssue(issue.body);\n if (id !== undefined && !byTarget.has(id)) byTarget.set(id, issue);\n }\n const board = new Set(claimable.filter((target) => byTarget.get(target.id)?.state === \"open\").map((target) => target.id));\n const gaps = new Map<string, number>();\n for (const target of claimable) if (board.has(target.id)) gaps.set(target.attrs.gap, (gaps.get(target.attrs.gap) ?? 0) + 1);\n const waiting = claimable.filter((target) => !board.has(target.id));\n while (board.size < limit && waiting.length > 0) {\n let best = 0;\n for (let index = 1; index < waiting.length; index += 1) {\n if ((gaps.get(waiting[index]?.attrs.gap ?? \"\") ?? 0) < (gaps.get(waiting[best]?.attrs.gap ?? \"\") ?? 0)) best = index;\n }\n const [next] = waiting.splice(best, 1);\n if (next === undefined) break;\n board.add(next.id);\n gaps.set(next.attrs.gap, (gaps.get(next.attrs.gap) ?? 0) + 1);\n }\n const actions: BoardAction[] = [];\n for (const target of claimable.filter((candidate) => board.has(candidate.id))) {\n const text = issueText(target);\n const issue = byTarget.get(target.id);\n if (issue === undefined) {\n actions.push({ kind: \"create\", target: target.id, text });\n continue;\n }\n if (issue.state === \"closed\" || !sameText(issue, text)) actions.push({ kind: \"update\", number: issue.number, target: target.id, text, reopen: issue.state === \"closed\" });\n if (issue.state === \"open\" && isExpired(issue, input.now) && !input.pulls.has(target.id)) {\n actions.push({ kind: \"release\", number: issue.number, target: target.id, users: issue.assignees });\n }\n }\n for (const [target, issue] of byTarget) {\n if (issue.state === \"open\" && !board.has(target)) actions.push({ kind: \"close\", number: issue.number, target, reason: known.has(target) ? \"not_planned\" : \"completed\" });\n }\n return actions;\n}\n\n/** The comment of a step of the board, or undefined for a step with no comment. */\nexport function actionComment(action: BoardAction): string | undefined {\n if (action.kind === \"release\") {\n return `The claim of ${action.users.map((user) => `\\`${user}\\``).join(\", \")} stopped: ${String(CLAIM_HOURS)} hours passed with no open pull request. Another contributor can claim the target now.`;\n }\n if (action.kind === \"close\") {\n return action.reason === \"completed\"\n ? \"The target query does not give this target now, so the gap is closed.\"\n : \"The target query does not give this target as claimable now. The issue opens again when the target is claimable.\";\n }\n return undefined;\n}\n\n/** This function applies the steps of the board through the API, in their order. It gives the number of each new issue. */\nexport async function applyBoard(api: IssueApi, actions: readonly BoardAction[]): Promise<readonly number[]> {\n const labels = new Set(actions.flatMap((action) => (action.kind === \"create\" || action.kind === \"update\" ? action.text.labels : [])));\n if (labels.size > 0) await api.ensureLabels([...labels].sort());\n const created: number[] = [];\n for (const action of actions) {\n if (action.kind === \"create\") {\n created.push(await api.create(action.text));\n continue;\n }\n if (action.kind === \"update\") {\n const { title, body, labels: issueLabels } = action.text;\n await api.update(action.number, { title, body, labels: issueLabels, ...(action.reopen ? { state: \"open\", stateReason: \"reopened\" } : {}) });\n continue;\n }\n if (action.kind === \"release\") await api.update(action.number, { assignees: [] });\n const comment = actionComment(action);\n if (comment !== undefined) await api.comment(action.number, comment);\n if (action.kind === \"close\") await api.update(action.number, { state: \"closed\", stateReason: action.reason });\n }\n return created;\n}\n\n/** The command of a claim comment. */\nexport type ClaimCommand = \"claim\" | \"unclaim\";\n\n/** This function gives the command of a comment: its first word is `/claim` or `/unclaim`. */\nexport function claimCommandOf(comment: string): ClaimCommand | undefined {\n const first = comment.trim().split(/\\s/, 1)[0];\n return first === \"/claim\" ? \"claim\" : first === \"/unclaim\" ? \"unclaim\" : undefined;\n}\n\n/** The inputs of the decision on a claim comment. */\nexport interface ClaimInput {\n readonly command: ClaimCommand;\n /** The login of the author of the comment. */\n readonly user: string;\n readonly issue: BoardIssue;\n /** The target of the issue, or undefined when the target query does not give it. */\n readonly target: TargetRecord | undefined;\n /** Each issue of the board, with the start of each claim. */\n readonly issues: readonly BoardIssue[];\n /** This time is the time of the decision, in milliseconds since 1970. */\n readonly now: number;\n}\n\n/** The decision on a claim comment: the new assignees and a comment, or a refusal with its reason. */\nexport type ClaimDecision =\n | { readonly kind: \"set\"; readonly assignees: readonly string[]; readonly comment: string }\n | { readonly kind: \"refuse\"; readonly comment: string };\n\n/**\n * This function decides a claim comment. A contributor claims one target at a time, and a claim stops after\n * `CLAIM_HOURS` with no pull request. A claim that stopped does not block a new claim, also before the board removes it.\n */\nexport function decideClaim(input: ClaimInput): ClaimDecision {\n const { command, user, issue, target, now } = input;\n const who = `\\`${user}\\``;\n if (issue.state !== \"open\") return { kind: \"refuse\", comment: \"This issue is closed, so its target has no claim.\" };\n if (target === undefined || !target.attrs.claimable) {\n return { kind: \"refuse\", comment: \"The target of this issue is not claimable now. `AGENTS.md` tells which targets are claimable.\" };\n }\n const has = issue.assignees.includes(user);\n if (command === \"unclaim\") {\n return has\n ? { kind: \"set\", assignees: issue.assignees.filter((login) => login !== user), comment: `${who} stopped the claim. Another contributor can claim the target now.` }\n : { kind: \"refuse\", comment: `${who} has no claim on this target.` };\n }\n const until = issue.claimedAt === undefined ? \"the end of the claim\" : claimEnd(issue.claimedAt);\n if (has) return { kind: \"refuse\", comment: `${who} has the claim already, until ${until}.` };\n if (issue.assignees.length > 0 && !isExpired(issue, now)) {\n const holders = issue.assignees.map((login) => `\\`${login}\\``).join(\", \");\n return { kind: \"refuse\", comment: `${holders} has the claim until ${until}. Claim another target, or claim this target after that time.` };\n }\n const other = input.issues.find((candidate) => candidate.number !== issue.number && candidate.state === \"open\" && candidate.assignees.includes(user) && !isExpired(candidate, now));\n if (other !== undefined) {\n return { kind: \"refuse\", comment: `${who} has a claim on #${String(other.number)} already. Claim one target at a time. Write \\`/unclaim\\` on #${String(other.number)} to stop that claim.` };\n }\n return {\n kind: \"set\",\n assignees: [user],\n comment: `${who} claims this target until ${claimEnd(now)}. Open the pull request before that time, with the line \\`Target: ${target.id}\\`.`,\n };\n}\n"],"mappings":";;;AAMA,MAAa,eAAe;;AAG5B,MAAa,cAAc;;AAG3B,MAAa,cAAc;;AAG3B,MAAM,OAAO;;AAGb,MAAM,WAAW;;AAqEjB,SAAgB,cAAc,MAAkC;CAC9D,MAAM,QAAQ,KAAK,QAAQ,IAAI;CAC/B,IAAI,QAAQ,GAAG,OAAO,KAAA;CACtB,MAAM,MAAM,KAAK,QAAQ,UAAU,QAAQ,EAAW;CACtD,MAAM,KAAK,MAAM,IAAI,KAAK,KAAK,MAAM,QAAQ,IAAa,GAAG,CAAC,CAAC,KAAK;CACpE,OAAO,OAAO,MAAM,KAAK,KAAK,EAAE,IAAI,KAAA,IAAY;AAClD;;AAGA,SAAgB,SAAS,WAA2B;CAClD,OAAO,GAAG,IAAI,KAAK,YAAA,MAAmC,CAAC,CAAC,YAAY,CAAC,CAAC,MAAM,GAAG,EAAE,EAAE;AACrF;;AAGA,SAAgB,UAAU,OAAmB,KAAsB;CACjE,OAAO,MAAM,UAAU,SAAS,KAAK,MAAM,cAAc,KAAA,KAAa,MAAM,MAAM,aAAA;AACpF;;AAGA,SAAgB,UAAU,QAAsB,aAAqB,q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M;EAAO,WAAW,MAAM,UAAU,QAAQ,UAAU,UAAU,IAAI;EAAG,SAAS,GAAG,IAAI;CAAmE,IAChK;EAAE,MAAM;EAAU,SAAS,GAAG,IAAI;CAA+B;CAEvE,MAAM,QAAQ,MAAM,cAAc,KAAA,IAAY,yBAAyB,SAAS,MAAM,SAAS;CAC/F,IAAI,KAAK,OAAO;EAAE,MAAM;EAAU,SAAS,GAAG,IAAI,gCAAgC,MAAM;CAAG;CAC3F,IAAI,MAAM,UAAU,SAAS,KAAK,CAAC,UAAU,OAAO,GAAG,GAErD,OAAO;EAAE,MAAM;EAAU,SAAS,GADlB,MAAM,UAAU,KAAK,UAAU,KAAK,MAAM,GAAG,CAAC,CAAC,KAAK,IACzB,EAAE,uBAAuB,MAAM;CAA+D;CAE3I,MAAM,QAAQ,MAAM,OAAO,MAAM,cAAc,UAAU,WAAW,MAAM,UAAU,UAAU,UAAU,UAAU,UAAU,UAAU,SAAS,IAAI,KAAK,CAAC,UAAU,WAAW,GAAG,CAAC;CAClL,IAAI,UAAU,KAAA,GACZ,OAAO;EAAE,MAAM;EAAU,SAAS,GAAG,IAAI,mBAAmB,OAAO,MAAM,MAAM,EAAE,+DAA+D,OAAO,MAAM,MAAM,EAAE;CAAsB;CAE7L,OAAO;EACL,MAAM;EACN,WAAW,CAAC,IAAI;EAChB,SAAS,GAAG,IAAI,4BAA4B,SAAS,GAAG,EAAE,oEAAoE,OAAO,GAAG;CAC1I;AACF"}
1
+ {"version":3,"file":"board-7NZb3yv_.mjs","names":[],"sources":["../src/board.ts"],"sourcesContent":["// The target board: one GitHub issue for each claimable target, and the claims on the issues. The plan and the claim\n// decision are pure functions. The sync and the claim send the requests through an IssueApi.\nimport { pathOfId } from \"./ids.ts\";\nimport { ONTOLOGY_REPOSITORY, type TargetRecord } from \"./targets.ts\";\n\n/** The label of each issue of the board. */\nexport const TARGET_LABEL = \"target\";\n\n/** The time of a claim with no pull request, in hours. */\nexport const CLAIM_HOURS = 48;\n\n/** The most open issues of the board. */\nexport const BOARD_LIMIT = 20;\n\n/** The start of the hidden line of an issue body that has the id of its target. */\nconst MARK = \"<!-- canon-target: \";\n\n/** The end of the hidden line. */\nconst MARK_END = \" -->\";\n\n/** An issue of the board, as the API of the issues gives it. */\nexport interface BoardIssue {\n readonly number: number;\n readonly title: string;\n readonly body: string;\n readonly state: \"open\" | \"closed\";\n readonly labels: readonly string[];\n readonly assignees: readonly string[];\n /** This time is the start of the claim of an open issue with an assignee, in milliseconds since 1970. */\n readonly claimedAt?: number | undefined;\n}\n\n/** The title, the body and the labels of the issue of a target. */\nexport interface IssueText {\n readonly title: string;\n readonly body: string;\n readonly labels: readonly string[];\n}\n\n/** A change of an issue. Each field that is not here does not change. */\nexport interface IssueChange {\n readonly title?: string;\n readonly body?: string;\n readonly labels?: readonly string[];\n readonly state?: \"open\" | \"closed\";\n readonly stateReason?: \"completed\" | \"not_planned\" | \"reopened\";\n /** This list replaces the assignees of the issue. */\n readonly assignees?: readonly string[];\n}\n\n/** The API of the issues of one repository. A test gives a fake, and `githubIssueApi` gives the API of GitHub. */\nexport interface IssueApi {\n /** This method gives each issue with the label `target`, open and closed, with the start of each claim. */\n issues(): Promise<readonly BoardIssue[]>;\n /** This method tells if an open pull request names the target id. */\n hasOpenPull(targetId: string): Promise<boolean>;\n /** This method makes each label that does not exist. */\n ensureLabels(names: readonly string[]): Promise<void>;\n /** This method opens an issue, and gives its number. */\n create(text: IssueText): Promise<number>;\n /** This method changes an issue, and gives the issue after the change. */\n update(number: number, change: IssueChange): Promise<BoardIssue>;\n /** This method writes a comment on an issue. */\n comment(number: number, text: string): Promise<void>;\n}\n\n/** One step of the sync of the board. */\nexport type BoardAction =\n | { readonly kind: \"create\"; readonly target: string; readonly text: IssueText }\n | { readonly kind: \"update\"; readonly number: number; readonly target: string; readonly text: IssueText; readonly reopen: boolean }\n | { readonly kind: \"close\"; readonly number: number; readonly target: string; readonly reason: \"completed\" | \"not_planned\" }\n | { readonly kind: \"release\"; readonly number: number; readonly target: string; readonly users: readonly string[] };\n\n/** The inputs of the plan of the board. */\nexport interface BoardInput {\n /** Each target of the target query, in the order of `compareTargets`. */\n readonly targets: readonly TargetRecord[];\n readonly issues: readonly BoardIssue[];\n /** This time is the time of the decision, in milliseconds since 1970. */\n readonly now: number;\n /** The ids of the targets that an open pull request names. */\n readonly pulls: ReadonlySet<string>;\n /** The most open issues. The default is `BOARD_LIMIT`. */\n readonly limit?: number | undefined;\n}\n\n/** This function gives the id of the target of an issue body, or undefined when the body has no hidden line. */\nexport function targetOfIssue(body: string): string | undefined {\n const start = body.indexOf(MARK);\n if (start < 0) return undefined;\n const end = body.indexOf(MARK_END, start + MARK.length);\n const id = end < 0 ? \"\" : body.slice(start + MARK.length, end).trim();\n return id === \"\" || /\\s/.test(id) ? undefined : id;\n}\n\n/** This function gives the time of the end of a claim, as an ISO 8601 text to the minute. */\nexport function claimEnd(claimedAt: number): string {\n return `${new Date(claimedAt + CLAIM_HOURS * 3_600_000).toISOString().slice(0, 16)}Z`;\n}\n\n/** This function tells if a claim is older than `CLAIM_HOURS`. A claim with no known start is live. */\nexport function isExpired(issue: BoardIssue, now: number): boolean {\n return issue.assignees.length > 0 && issue.claimedAt !== undefined && now - issue.claimedAt >= CLAIM_HOURS * 3_600_000;\n}\n\n/** This function gives the title, the body and the labels of the issue of a target. */\nexport function issueText(target: TargetRecord, repository: string = ONTOLOGY_REPOSITORY): IssueText {\n const { attrs } = target;\n const path = pathOfId(target.id);\n const body = [\n `${MARK}${target.id}${MARK_END}`,\n `**Target:** \\`${target.id}\\``,\n \"\",\n \"| Gap | Home | Size | Area |\",\n \"| --- | --- | --- | --- |\",\n `| \\`${attrs.gap}\\` | [${attrs.home}](https://github.com/${attrs.home}) | ${attrs.size} | ${attrs.area === undefined ? \"\" : `\\`${attrs.area}\\``} |`,\n \"\",\n \"## Acceptance\",\n \"\",\n attrs.acceptance.text,\n \"\",\n ...attrs.acceptance.checks.map((check) => `- [ ] ${check}`),\n \"\",\n \"## Why\",\n \"\",\n attrs.why,\n \"\",\n \"## Claim and close\",\n \"\",\n `1. Write the comment \\`/claim\\` on this issue. A claim stops after ${String(CLAIM_HOURS)} hours with no open pull request.`,\n `2. Do the work. [\\`AGENTS.md\\`](https://github.com/${repository}/blob/main/AGENTS.md) tells how.`,\n `3. In the pull request, write the line \\`Target: ${target.id}\\`.`,\n \"\",\n `The record of the target is [\\`${path}\\`](https://github.com/${repository}/blob/main/${path}). Write \\`/unclaim\\` to stop your claim.`,\n \"\",\n ].join(\"\\n\");\n return { title: attrs.title, body, labels: [TARGET_LABEL, `gap:${attrs.gap}`] };\n}\n\n/** This function tells if an issue has the text of a target: the same title, body and labels. */\nfunction sameText(issue: BoardIssue, text: IssueText): boolean {\n const labels = [...issue.labels].sort();\n const wanted = [...text.labels].sort();\n return issue.title === text.title && issue.body === text.body && labels.length === wanted.length && labels.every((label, index) => label === wanted[index]);\n}\n\n/**\n * This function gives the steps that make the board agree with the target query.\n *\n * - The board keeps the open issue of each claimable target. It adds other claimable targets, up to the limit. An issue\n * does not close because new targets come before it.\n * - Each added target is the first claimable target of the gap with the fewest targets on the board. So one gap with\n * many targets does not fill the board.\n * - An issue whose target is not claimable closes: `completed` when the target is gone, else `not_planned`.\n * - A claim older than `CLAIM_HOURS` stops when no open pull request names its target.\n * - An issue with no hidden line is not an issue of the board. Of two issues of one target, the board uses the first.\n */\nexport function planBoard(input: BoardInput): readonly BoardAction[] {\n const limit = input.limit ?? BOARD_LIMIT;\n const known = new Set(input.targets.map((target) => target.id));\n const claimable = input.targets.filter((target) => target.attrs.claimable);\n const byTarget = new Map<string, BoardIssue>();\n for (const issue of [...input.issues].sort((a, b) => a.number - b.number)) {\n const id = targetOfIssue(issue.body);\n if (id !== undefined && !byTarget.has(id)) byTarget.set(id, issue);\n }\n const board = new Set(claimable.filter((target) => byTarget.get(target.id)?.state === \"open\").map((target) => target.id));\n const gaps = new Map<string, number>();\n for (const target of claimable) if (board.has(target.id)) gaps.set(target.attrs.gap, (gaps.get(target.attrs.gap) ?? 0) + 1);\n const waiting = claimable.filter((target) => !board.has(target.id));\n while (board.size < limit && waiting.length > 0) {\n let best = 0;\n for (let index = 1; index < waiting.length; index += 1) {\n if ((gaps.get(waiting[index]?.attrs.gap ?? \"\") ?? 0) < (gaps.get(waiting[best]?.attrs.gap ?? \"\") ?? 0)) best = index;\n }\n const [next] = waiting.splice(best, 1);\n if (next === undefined) break;\n board.add(next.id);\n gaps.set(next.attrs.gap, (gaps.get(next.attrs.gap) ?? 0) + 1);\n }\n const actions: BoardAction[] = [];\n for (const target of claimable.filter((candidate) => board.has(candidate.id))) {\n const text = issueText(target);\n const issue = byTarget.get(target.id);\n if (issue === undefined) {\n actions.push({ kind: \"create\", target: target.id, text });\n continue;\n }\n if (issue.state === \"closed\" || !sameText(issue, text)) actions.push({ kind: \"update\", number: issue.number, target: target.id, text, reopen: issue.state === \"closed\" });\n if (issue.state === \"open\" && isExpired(issue, input.now) && !input.pulls.has(target.id)) {\n actions.push({ kind: \"release\", number: issue.number, target: target.id, users: issue.assignees });\n }\n }\n for (const [target, issue] of byTarget) {\n if (issue.state === \"open\" && !board.has(target)) actions.push({ kind: \"close\", number: issue.number, target, reason: known.has(target) ? \"not_planned\" : \"completed\" });\n }\n return actions;\n}\n\n/** The comment of a step of the board, or undefined for a step with no comment. */\nexport function actionComment(action: BoardAction): string | undefined {\n if (action.kind === \"release\") {\n return `The claim of ${action.users.map((user) => `\\`${user}\\``).join(\", \")} stopped: ${String(CLAIM_HOURS)} hours passed with no open pull request. Another contributor can claim the target now.`;\n }\n if (action.kind === \"close\") {\n return action.reason === \"completed\"\n ? \"The target query does not give this target now, so the gap is closed.\"\n : \"The target query does not give this target as claimable now. The issue opens again when the target is claimable.\";\n }\n return undefined;\n}\n\n/** This function applies the steps of the board through the API, in their order. It gives the number of each new issue. */\nexport async function applyBoard(api: IssueApi, actions: readonly BoardAction[]): Promise<readonly number[]> {\n const labels = new Set(actions.flatMap((action) => (action.kind === \"create\" || action.kind === \"update\" ? action.text.labels : [])));\n if (labels.size > 0) await api.ensureLabels([...labels].sort());\n const created: number[] = [];\n for (const action of actions) {\n if (action.kind === \"create\") {\n created.push(await api.create(action.text));\n continue;\n }\n if (action.kind === \"update\") {\n const { title, body, labels: issueLabels } = action.text;\n await api.update(action.number, { title, body, labels: issueLabels, ...(action.reopen ? { state: \"open\", stateReason: \"reopened\" } : {}) });\n continue;\n }\n if (action.kind === \"release\") await api.update(action.number, { assignees: [] });\n const comment = actionComment(action);\n if (comment !== undefined) await api.comment(action.number, comment);\n if (action.kind === \"close\") await api.update(action.number, { state: \"closed\", stateReason: action.reason });\n }\n return created;\n}\n\n/** The command of a claim comment. */\nexport type ClaimCommand = \"claim\" | \"unclaim\";\n\n/** This function gives the command of a comment: its first word is `/claim` or `/unclaim`. */\nexport function claimCommandOf(comment: string): ClaimCommand | undefined {\n const first = comment.trim().split(/\\s/, 1)[0];\n return first === \"/claim\" ? \"claim\" : first === \"/unclaim\" ? \"unclaim\" : undefined;\n}\n\n/** The inputs of the decision on a claim comment. */\nexport interface ClaimInput {\n readonly command: ClaimCommand;\n /** The login of the author of the comment. */\n readonly user: string;\n readonly issue: BoardIssue;\n /** The target of the issue, or undefined when the target query does not give it. */\n readonly target: TargetRecord | undefined;\n /** Each issue of the board, with the start of each claim. */\n readonly issues: readonly BoardIssue[];\n /** This time is the time of the decision, in milliseconds since 1970. */\n readonly now: number;\n}\n\n/** The decision on a claim comment: the new assignees and a comment, or a refusal with its reason. */\nexport type ClaimDecision =\n | { readonly kind: \"set\"; readonly assignees: readonly string[]; readonly comment: string }\n | { readonly kind: \"refuse\"; readonly comment: string };\n\n/**\n * This function decides a claim comment. A contributor claims one target at a time, and a claim stops after\n * `CLAIM_HOURS` with no pull request. A claim that stopped does not block a new claim, also before the board removes it.\n */\nexport function decideClaim(input: ClaimInput): ClaimDecision {\n const { command, user, issue, target, now } = input;\n const who = `\\`${user}\\``;\n if (issue.state !== \"open\") return { kind: \"refuse\", comment: \"This issue is closed, so its target has no claim.\" };\n if (target === undefined || !target.attrs.claimable) {\n return { kind: \"refuse\", comment: \"The target of this issue is not claimable now. `AGENTS.md` tells which targets are claimable.\" };\n }\n const has = issue.assignees.includes(user);\n if (command === \"unclaim\") {\n return has\n ? { kind: \"set\", assignees: issue.assignees.filter((login) => login !== user), comment: `${who} stopped the claim. Another contributor can claim the target now.` }\n : { kind: \"refuse\", comment: `${who} has no claim on this target.` };\n }\n const until = issue.claimedAt === undefined ? \"the end of the claim\" : claimEnd(issue.claimedAt);\n if (has) return { kind: \"refuse\", comment: `${who} has the claim already, until ${until}.` };\n if (issue.assignees.length > 0 && !isExpired(issue, now)) {\n const holders = issue.assignees.map((login) => `\\`${login}\\``).join(\", \");\n return { kind: \"refuse\", comment: `${holders} has the claim until ${until}. Claim another target, or claim this target after that time.` };\n }\n const other = input.issues.find((candidate) => candidate.number !== issue.number && candidate.state === \"open\" && candidate.assignees.includes(user) && !isExpired(candidate, now));\n if (other !== undefined) {\n return { kind: \"refuse\", comment: `${who} has a claim on #${String(other.number)} already. Claim one target at a time. Write \\`/unclaim\\` on #${String(other.number)} to stop that claim.` };\n }\n return {\n kind: \"set\",\n assignees: [user],\n comment: `${who} claims this target until ${claimEnd(now)}. Open the pull request before that time, with the line \\`Target: ${target.id}\\`.`,\n };\n}\n"],"mappings":";;;AAMA,MAAa,eAAe;;AAG5B,MAAa,cAAc;;AAG3B,MAAa,cAAc;;AAG3B,MAAM,OAAO;;AAGb,MAAM,WAAW;;AAqEjB,SAAgB,cAAc,MAAkC;CAC9D,MAAM,QAAQ,KAAK,QAAQ,IAAI;CAC/B,IAAI,QAAQ,GAAG,OAAO,KAAA;CACtB,MAAM,MAAM,KAAK,QAAQ,UAAU,QAAQ,EAAW;CACtD,MAAM,KAAK,MAAM,IAAI,KAAK,KAAK,MAAM,QAAQ,IAAa,GAAG,CAAC,CAAC,KAAK;CACpE,OAAO,OAAO,MAAM,KAAK,KAAK,EAAE,IAAI,KA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644,8 +644,10 @@ export declare function checkMatches(pattern: string, name: string): boolean;
644
644
  * - mutation: a lane file (`mutation.json`, or the input `lane` of the caller) and a job that calls `reusable-mutation.yml`.
645
645
  * - property: a package file that names `fast-check` or `@mark1russell7/rigor-testkit`. Its checks are the checks of
646
646
  * each job that calls `reusable-ci.yml` or starts the tests, and of each job that needs such a job.
647
- * - speed: a package file that names `@mark1russell7/rigor-bench`, and a job that starts a bench. A bench job uses the
648
- * action `stamp-gate`, the bin `rigor-gate-line` or `rigor-stamp`, or a command with the word `bench`.
647
+ * - speed: a package file that names `@mark1russell7/rigor-bench`, and a job that starts a bench. A summary job with
648
+ * `gate: speed` (the marker of `gate-summary`) gives the bench jobs. With no marker in the repository, the read uses
649
+ * a word rule. Then a bench job uses the action `stamp-gate`, a bin of the bench or a command with the word `bench`.
650
+ * The bins are `rigor-gate-line` and `rigor-stamp`.
649
651
  * - rigs: the file `docs/rigs.json` and a job that calls `reusable-rigs.yml`.
650
652
  *
651
653
  * A file with no answer, or a file that the read cannot parse, gives a no read for each gate that needs it.
@@ -657,7 +659,7 @@ export declare function gatesOf(tree: Tree, answers: ReadonlyMap<string, HomeAns
657
659
  * This function reads the test gates of each repository. The default fetch is `politeFetch` with no token, so each
658
660
  * request goes at the pace of its host. The read makes two rounds of requests:
659
661
  *
660
- * 1. the tree and the rules of the branch of each repository, from the API of GitHub,
662
+ * 1. the tree, the rules and the classic protection of the branch of each repository, from the API of GitHub,
661
663
  * 2. each workflow file and each package file of each tree, from the host of raw files. Two files with the same content
662
664
  * id give one request.
663
665
  *
package/build/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { arrayOf, booleanOf, isRecord, numberOf, readArray, readText, recordOf, textOf, timeOf } from "@mark1russell7/optional/read";
2
- import { A as GRAMMAR_FILE, C as scopeText, D as kindOf, E as isLive, F as makeId, I as npmPackageId, L as npmPurl, M as RECORD_SCHEMA_FILE, N as idPart, O as lineageOf, P as kindOfId, R as pathOfId, S as sameScope, T as isKindIn, _ as scopeOf, a as SIZES, b as inScope, c as targetsOf, d as leanKey, f as problemIdOf, g as resultClaimsOf, h as hasFullScope, i as PLACES_SHOWN, j as ONTOLOGY_FOLDER, k as relationOf, l as findProblem, m as claimFails, n as NECESSARY_GATES, o as compareTargets, p as CLAIM_STATUSES, r as ONTOLOGY_REPOSITORY, s as targetId, u as formalKeyOf, v as SCOPE_MODULUS_LIMIT, w as edgesOf, x as readScope, y as canonicalScope, z as repositoryId } from "./targets-BwC2nZGy.mjs";
3
- import { a as applyBoard, c as decideClaim, d as planBoard, f as targetOfIssue, i as actionComment, l as isExpired, n as CLAIM_HOURS, o as claimCommandOf, r as TARGET_LABEL, s as claimEnd, t as BOARD_LIMIT, u as issueText } from "./board-DAKpkjvV.mjs";
2
+ import { A as GRAMMAR_FILE, C as scopeText, D as kindOf, E as isLive, F as makeId, I as npmPackageId, L as npmPurl, M as RECORD_SCHEMA_FILE, N as idPart, O as lineageOf, P as kindOfId, R as pathOfId, S as sameScope, T as isKindIn, _ as scopeOf, a as SIZES, b as inScope, c as targetsOf, d as leanKey, f as problemIdOf, g as resultClaimsOf, h as hasFullScope, i as PLACES_SHOWN, j as ONTOLOGY_FOLDER, k as relationOf, l as findProblem, m as claimFails, n as NECESSARY_GATES, o as compareTargets, p as CLAIM_STATUSES, r as ONTOLOGY_REPOSITORY, s as targetId, u as formalKeyOf, v as SCOPE_MODULUS_LIMIT, w as edgesOf, x as readScope, y as canonicalScope, z as repositoryId } from "./targets-DFXTvFDm.mjs";
3
+ import { a as applyBoard, c as decideClaim, d as planBoard, f as targetOfIssue, i as actionComment, l as isExpired, n as CLAIM_HOURS, o as claimCommandOf, r as TARGET_LABEL, s as claimEnd, t as BOARD_LIMIT, u as issueText } from "./board-7NZb3yv_.mjs";
4
4
  import { Ajv2020 } from "ajv/dist/2020.js";
5
5
  import formats from "ajv-formats";
6
6
  import { countOf, listOf } from "@mark1russell7/text/english";
@@ -1336,6 +1336,13 @@ function treeUrl(repository) {
1336
1336
  function rulesUrl(repository) {
1337
1337
  return `https://api.github.com/repos/${repository.owner}/${repository.name}/rules/branches/${branchPath(repository.branch)}?per_page=${String(100)}`;
1338
1338
  }
1339
+ /**
1340
+ * This function gives the URL of the branch of a repository. Its answer has the classic protection of the branch, with
1341
+ * its necessary checks. GitHub gives it with no token.
1342
+ */
1343
+ function branchUrl(repository) {
1344
+ return `https://api.github.com/repos/${repository.owner}/${repository.name}/branches/${branchPath(repository.branch)}`;
1345
+ }
1339
1346
  /** This function gives the URL of the text of one file of the branch. The host of raw files is not the API. */
1340
1347
  function fileUrl(repository, path) {
1341
1348
  return `https://raw.githubusercontent.com/${repository.owner}/${repository.name}/${branchPath(repository.branch)}/${path.split("/").map(encodeURIComponent).join("/")}`;
@@ -1388,6 +1395,31 @@ function necessaryChecksOf(answer) {
1388
1395
  }
1389
1396
  return { checks: [...checks].sort() };
1390
1397
  }
1398
+ /**
1399
+ * This function reads the names of the necessary checks of the classic protection from the answer for a branch. A
1400
+ * branch with no classic protection, or with checks that are not enforced, gives no check.
1401
+ */
1402
+ function classicChecksOf(answer) {
1403
+ const read = textOrReason(answer, "the branch");
1404
+ if ("no_read" in read) return read;
1405
+ const branch = jsonOf(read.text);
1406
+ if (!isRecord(branch)) return { no_read: "The answer for the branch is not a JSON object." };
1407
+ const protection = recordOf(branch, "protection");
1408
+ const required = recordOf(protection, "required_status_checks");
1409
+ if (booleanOf(protection, "enabled") !== true || required === void 0 || textOf(required, "enforcement_level") === "off") return { checks: [] };
1410
+ const contexts = arrayOf(required, "contexts", readText) ?? [];
1411
+ const checks = arrayOf(required, "checks", (item) => textOf(item, "context")) ?? [];
1412
+ return { checks: [.../* @__PURE__ */ new Set([...contexts, ...checks])].sort() };
1413
+ }
1414
+ /**
1415
+ * This function gives the necessary checks of a branch: the checks of its rulesets and of its classic protection. A
1416
+ * no read of one of the two is a no read, because the missing part can make a check necessary.
1417
+ */
1418
+ function branchChecksOf(rules, classic) {
1419
+ if ("no_read" in rules) return rules;
1420
+ if ("no_read" in classic) return classic;
1421
+ return { checks: [.../* @__PURE__ */ new Set([...rules.checks, ...classic.checks])].sort() };
1422
+ }
1391
1423
  /** This function tells if a path is a workflow of GitHub Actions. GitHub reads only the files at the top of the folder. */
1392
1424
  function isWorkflowPath(path) {
1393
1425
  return /^\.github\/workflows\/[^/]+\.ya?ml$/.test(path);
@@ -1423,7 +1455,8 @@ function workflowOf(path, text) {
1423
1455
  needs: typeof needs === "string" ? [needs] : arrayOf(job, "needs", readText) ?? [],
1424
1456
  steps: arrayOf(job, "steps", (step) => isRecord(step) ? {
1425
1457
  uses: textOf(step, "uses"),
1426
- run: textOf(step, "run")
1458
+ run: textOf(step, "run"),
1459
+ with: recordOf(step, "with")
1427
1460
  } : void 0) ?? []
1428
1461
  };
1429
1462
  })
@@ -1434,6 +1467,25 @@ function callsTemplate(job, file) {
1434
1467
  const uses = job.uses ?? "";
1435
1468
  return (uses.startsWith("mark1russell7/template/") || uses.startsWith("./")) && new RegExp(`(^|/)\\.github/workflows/${file.replaceAll(".", "\\.")}(@|$)`).test(uses);
1436
1469
  }
1470
+ /** The paths of the action `gate-summary`: in the template, and in the copy of the template itself. */
1471
+ const GATE_SUMMARY = ["mark1russell7/template/.github/actions/gate-summary", "./.github/actions/gate-summary"];
1472
+ /** This function tells if a step uses the action `gate-summary` of the template, at a commit or with no ref. */
1473
+ function usesGateSummary(step) {
1474
+ const uses = step.uses ?? "";
1475
+ const at = uses.indexOf("@");
1476
+ return GATE_SUMMARY.includes(at === -1 ? uses : uses.slice(0, at));
1477
+ }
1478
+ /**
1479
+ * This function gives the kind of gate that the job marks: the input `gate` of its step `gate-summary` of the
1480
+ * template. A job with no marker, or with a word that is not a gate, gives undefined.
1481
+ */
1482
+ function markedGate(job) {
1483
+ for (const step of job.steps) {
1484
+ const gate = usesGateSummary(step) ? step.with?.["gate"] : void 0;
1485
+ const kind = GATE_NAMES.find((name) => name === gate);
1486
+ if (kind !== void 0) return kind;
1487
+ }
1488
+ }
1437
1489
  /** A command that starts the tests of a package. */
1438
1490
  const TEST_COMMAND = /\b(vitest|(pnpm|npm|yarn)(\s+-r|\s+--recursive)?\s+(run\s+)?test)\b/;
1439
1491
  /** A command or a step that starts a bench of `@mark1russell7/rigor-bench`. */
@@ -1598,8 +1650,10 @@ function factOf(parts, checks, rules) {
1598
1650
  * - mutation: a lane file (`mutation.json`, or the input `lane` of the caller) and a job that calls `reusable-mutation.yml`.
1599
1651
  * - property: a package file that names `fast-check` or `@mark1russell7/rigor-testkit`. Its checks are the checks of
1600
1652
  * each job that calls `reusable-ci.yml` or starts the tests, and of each job that needs such a job.
1601
- * - speed: a package file that names `@mark1russell7/rigor-bench`, and a job that starts a bench. A bench job uses the
1602
- * action `stamp-gate`, the bin `rigor-gate-line` or `rigor-stamp`, or a command with the word `bench`.
1653
+ * - speed: a package file that names `@mark1russell7/rigor-bench`, and a job that starts a bench. A summary job with
1654
+ * `gate: speed` (the marker of `gate-summary`) gives the bench jobs. With no marker in the repository, the read uses
1655
+ * a word rule. Then a bench job uses the action `stamp-gate`, a bin of the bench or a command with the word `bench`.
1656
+ * The bins are `rigor-gate-line` and `rigor-stamp`.
1603
1657
  * - rigs: the file `docs/rigs.json` and a job that calls `reusable-rigs.yml`.
1604
1658
  *
1605
1659
  * A file with no answer, or a file that the read cannot parse, gives a no read for each gate that needs it.
@@ -1641,12 +1695,13 @@ function gatesOf(tree, answers, rules) {
1641
1695
  files: propertyFiles,
1642
1696
  no_read: workflowFault
1643
1697
  } : factOf([propertyPart], testJobs.checks, rules);
1644
- const benchJobs = pickJobs(workflows, (job) => job.steps.some((step) => (step.uses ?? "").includes("/.github/actions/stamp-gate") || BENCH_COMMAND.test(step.run ?? "")));
1698
+ const marked = workflows.some((workflow) => workflow.jobs.some((job) => markedGate(job) === "speed"));
1699
+ const benchJobs = pickJobs(workflows, (job) => marked ? markedGate(job) === "speed" : job.steps.some((step) => (step.uses ?? "").includes("/.github/actions/stamp-gate") || BENCH_COMMAND.test(step.run ?? "")));
1645
1700
  const speed = (packageFault ?? workflowFault) !== void 0 ? { no_read: packageFault ?? workflowFault ?? "" } : factOf([{
1646
1701
  missing: `a package file that names \`${BENCH_PACKAGE}\` in its dependencies`,
1647
1702
  files: naming([BENCH_PACKAGE])
1648
1703
  }, {
1649
- missing: "a job that starts a bench: the action `stamp-gate`, the bin `rigor-gate-line` or `rigor-stamp`, or a command `bench`",
1704
+ missing: "a job that starts a bench: a summary job with `gate: speed`, the action `stamp-gate`, the bin `rigor-gate-line` or `rigor-stamp`, or a command `bench`",
1650
1705
  files: benchJobs.files
1651
1706
  }], benchJobs.checks, rules);
1652
1707
  const rigsJobs = pickJobs(workflows, (job) => callsTemplate(job, "reusable-rigs.yml"));
@@ -1682,18 +1737,22 @@ function noReadOfEach(reason) {
1682
1737
  * This function reads the test gates of each repository. The default fetch is `politeFetch` with no token, so each
1683
1738
  * request goes at the pace of its host. The read makes two rounds of requests:
1684
1739
  *
1685
- * 1. the tree and the rules of the branch of each repository, from the API of GitHub,
1740
+ * 1. the tree, the rules and the classic protection of the branch of each repository, from the API of GitHub,
1686
1741
  * 2. each workflow file and each package file of each tree, from the host of raw files. Two files with the same content
1687
1742
  * id give one request.
1688
1743
  *
1689
1744
  * A repository whose tree has no read gives a no read for each gate. The read does not throw for one repository.
1690
1745
  */
1691
1746
  async function readTestGates(repositories, fetch = politeFetch(), now = Date.now) {
1692
- const first = await fetch(repositories.flatMap((repository) => [treeUrl(repository), rulesUrl(repository)]));
1747
+ const first = await fetch(repositories.flatMap((repository) => [
1748
+ treeUrl(repository),
1749
+ rulesUrl(repository),
1750
+ branchUrl(repository)
1751
+ ]));
1693
1752
  const trees = repositories.map((repository) => ({
1694
1753
  repository,
1695
1754
  tree: treeOf(first.get(treeUrl(repository))),
1696
- rules: necessaryChecksOf(first.get(rulesUrl(repository)))
1755
+ rules: branchChecksOf(necessaryChecksOf(first.get(rulesUrl(repository))), classicChecksOf(first.get(branchUrl(repository))))
1697
1756
  }));
1698
1757
  const urlOfContent = /* @__PURE__ */ new Map();
1699
1758
  for (const { repository, tree } of trees) {