@kana-ai/edgar-ext-github 0.1.5 → 0.1.7
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.
- package/README.md +10 -4
- package/dist/src/index.d.ts +22 -0
- package/dist/src/index.js +2 -0
- package/dist/src/schemas/github.d.ts +53 -0
- package/dist/src/schemas/github.js +18 -0
- package/dist/src/schemas/tools.d.ts +33 -0
- package/dist/src/schemas/tools.js +32 -2
- package/dist/src/tools/owners.d.ts +34 -0
- package/dist/src/tools/owners.js +182 -0
- package/dist/src/tools/pull-request.d.ts +5 -1
- package/dist/src/tools/pull-request.js +39 -11
- package/edgar-extension.json +25 -1
- package/package.json +3 -3
- package/schemas/code_owners.in.json +11 -0
- package/schemas/code_owners.out.json +47 -0
- package/schemas/open_pull_request.in.json +8 -2
- package/schemas/request_reviewers.in.json +27 -0
- package/schemas/request_reviewers.out.json +17 -0
- package/schemas/update_pull_request.in.json +8 -2
package/README.md
CHANGED
|
@@ -12,6 +12,7 @@ The GitHub extension of EDGAR. It pushes `edgar/` branches from the run's sandbo
|
|
|
12
12
|
| `find_pull_request` | `operation_id`, `input`: the input of an `open_pull_request` call | `url`, `state` | `skipped` when the branch has no pull request. |
|
|
13
13
|
| `linked_pull_requests` | `text`, `repo` | `pull_requests`: `url`, `state`, `title`, `body`, `files` (`path`, `patch`) | Reads each pull request of `repo` that `text` links, in any spelling of the repository: the first 5 links, 100 files each, and 4,000 characters of each patch. A link to another repository is left out with no call, so a card cannot bring code from elsewhere into the project's tracker. A link that answers 404 or 403 is left out. With no link to `repo`, the tool answers `skipped`, with no call. |
|
|
14
14
|
| `note_pull_request` | `url`, `text`: one new item | `url`: the note | Adds an item to EDGAR's one note on the pull request, a comment that EDGAR finds by its hidden first line. The note's first sentence, "EDGAR's notes on this pull request, oldest first:", leads the list of items. The item keeps the lines of `text` under its bullet, so its paragraphs and lists stay. The first call makes the note. |
|
|
15
|
+
| `request_reviewers` | `url`, `reviewers`, `team_reviewers` | `url`, `requested` | Asks people (by login) and teams (by slug) to review the pull request. Skipped when both lists are empty, or when GitHub refuses the request with 422, such as for a person who can no longer review in the repository. A side effect with no undo: a review request only asks. |
|
|
15
16
|
| `update_pull_request` | `url`, `title`, `body`; optional `card`, `large_diff_lines`, `path_notices`, `checks`, `not_verified` | `url` | Gives an open pull request a new title and body, when a later change made them untrue. The body gets its notices and proof again, as `open_pull_request` writes them, and the operation line of this call. The review line of the first body is left out, because that review read the change before. A pull request that is merged or closed answers `skipped`, with no write. |
|
|
16
17
|
| `attach_screenshot` | `url`; `shot`: `path`, `bytes` and `caption` of a PNG in the sandbox, with the `url` EDGAR serves it at when it is in `[storage]` and a flow's `video`, or `missing` | `attached`; `image` or `missing` | With a `url`, puts that address in the body and writes nothing to the repository. Otherwise stores the PNG on the branch `edgar/screenshots` of the pull request's repository, at `<run id>/preview-<hash>.png`, and puts it in the body pinned to the commit that holds it. The first picture of a repository starts that branch from an empty tree, so it shares no history with the code. A picture over 1 MB, one that cannot be read, or an upload that GitHub refuses gives the body one line, "The screenshot is missing:", with the reason, and the output says it too. A flow's `video` (`path`, `bytes`) goes to the same branch, at `<run id>/flow-<hash>.mp4`, as a link under the picture; a video over 1 MB or not stored gives the line "The video is missing:" with the reason, and the picture still shows. Only an input that is not a pull request fails. `update_pull_request` keeps the picture when it rewrites the body. |
|
|
17
18
|
| `list_pull_requests` | `services`: a list of `repo`; optional `merged_within_hours` (1 to 720), and with it `unless_noted` | `pull_requests`: `url`, `branch`, `card`, `unmerged`; `complete` | One page of open pull requests per repository, read once however the services spell it (`git@github.com:o/r.git`, `https://github.com/o/r`, any letter case), on `edgar/<card>-<slug>` branches whose head is in that repository, so a fork's branch of that name is left out. With `merged_within_hours`, the pull requests merged within that many hours in place of the open ones, from one page of the 100 closed pull requests updated last. With `unless_noted` too, each merged pull request whose EDGAR note already holds that text as one of its lines is left out, after one read of its comments, so `merge_watch` handles a merge once. The engine passes the project's services. A service whose `repo` is not on github.com has none here, so `merge_watch` goes on for the others. With `merged_within_hours`, `unmerged` lists each pull request of the `Goes with:` line of the body that is not merged, as `url` and `state` (`open` or `closed`); one that answers 404 or 403 is `closed`. It is empty for the open ones and for a pull request that goes with none. With `merged_within_hours`, a pull request whose body opens the companion line of `first` has `companion: true`, so `merge_watch` leaves its card for the fix built on it. `complete` is false when the page of a repository came back full, 100 pull requests, so one past them is not listed; the runtime log names that repository. |
|
|
@@ -28,6 +29,7 @@ The GitHub extension of EDGAR. It pushes `edgar/` branches from the run's sandbo
|
|
|
28
29
|
| `wait_for_passed_checks` | `url` | as `pull_request_checks` | The recheck of a `wait` stage that only passed checks end. It answers `skipped` while a check runs and also while a check has failed, so a later push or a rerun that passes ends the wait. A closed pull request ends it as `closed`. The built-in `remediate` uses it after its last repair: no review is asked for while a check is red. |
|
|
29
30
|
| `ci_run` | `url` of a run, or of a job | `url`, `workflow`, `status`, `conclusion`, `commit`, `branch`, `attempt`, `jobs`, `logs`, `unread` | Reads a GitHub Actions run and each job of its latest attempt with its failed steps. For each failed job (`failure`, `timed_out`), at most 3, or for the job in a `/job/<id>` URL, it reads the log: the `##[error]` lines (at most 20) and an `excerpt` of the 120 lines up to the first error, at most 16,000 characters, with timestamps and colour codes removed. `gone` is `true` when GitHub no longer keeps the log. `unread` lists the failed jobs past the limit. |
|
|
30
31
|
| `pull_request_discussion` | `url` | `url`, `reviews`, `threads`, `conversation`, `complete` | `reviews` holds each verdict, and each review with words; a wordless `COMMENTED` review is left out. `threads` holds each line comment with its `path`, `line`, the last 8 lines of its `hunk` and its `replies`. `conversation` holds the issue comments. EDGAR's own remarks stay, with `by`. A failed read is the failure, never an empty discussion. |
|
|
32
|
+
| `code_owners` | `url` | `source`, `reviewers`, `team_reviewers`, `who_can_act` | Finds who should review the pull request, at most two, never a bot or its author, who is EDGAR on its own pull request. The CODEOWNERS file of the base branch (`.github/CODEOWNERS`, `CODEOWNERS` or `docs/CODEOWNERS`, the first one found) gives them when it names an owner of a changed file, by the last pattern that matches each file: `source` is `codeowners`, and an owner who owns more of the files comes first. Else the history of the files gives them: each commit of the last 12 months to a changed file counts for its author, halved for each 90 days of its age, so a person who changed the files often and lately comes before the one who made the newest change; `source` is `history`. `who_can_act` says why each one, with `github` for a login and `name` for a team. Skipped when there is none. It reads the first 100 files, and the newest 100 commits of each of the first 10 files: at most 15 requests. |
|
|
31
33
|
| `dependabot_alerts` | `repo`; optional `number`, `state`, `package`, `ghsa`, `cve`, `limit` | `alerts`, `complete` | With `number`, that alert; the filters then must be empty, or `invalid_input`. Without it, newest first, every state unless `state` names some, at most `limit` (30, at most 100). Each alert has its `package`, `ecosystem`, `severity`, `vulnerable_range`, `first_patched`, `manifest`, `scope`, `ghsa`, `cve` and `summary`. `ghsa` and `cve` match within a page of 100. |
|
|
32
34
|
| `branch_protection` | `repo`, `branch` | `branch`, `protected`, `pull_request_required`, `required_approvals`, `required_checks`, `rules`, `classic` | Joins the branch's own protection, each rule and ruleset that applies (`/rules/branches`), and the classic rule. GitHub shows the classic rule to admins only: `classic` is then `unreadable`, and `pull_request_required` and `required_approvals` are `null` unless a rule settles them. |
|
|
33
35
|
| `dismiss_dependabot_alert` | `repo`, `number`, `reason`, `comment` | `repo`, `number`, `url`, `reason`, `reopen` | Approval `always`. Side effect, undone by `reopen_dependabot_alert`, found by `find_dependabot_dismissal`. `reason` is one of GitHub's reasons: `fix_started`, `inaccurate`, `no_bandwidth`, `not_used`, `tolerable_risk`. `comment` has 1 to 280 characters. See [Dismiss a Dependabot alert](#dismiss-a-dependabot-alert). |
|
|
@@ -84,19 +86,20 @@ A later stage reads `stages.ci.output.state`, and gives a failed check's `url` t
|
|
|
84
86
|
|
|
85
87
|
Each extra is optional. With none, `open_pull_request` sends one request, as before.
|
|
86
88
|
|
|
87
|
-
- `card`: the run's card, with its `id`, `title` and `url`. The title becomes `<id>: <
|
|
89
|
+
- `card`: the run's card, with its `id`, `title` and `url`. The title becomes `<id>: <title>`, such as `ENG-12: Raise the login timeout`, and the body opens with `Card: [ENG-12](<url>)`, or `Card: ENG-12` for a card with no address. `update_pull_request` writes both the same way. The built-in workflows pass the run's card.
|
|
90
|
+
- A title past 72 characters is cut where a word ends, with no ellipsis, and a trailing tag in brackets, such as `[build-image]`, stays whole at its end: a repository can start a build from a tag in the merge commit's message, which holds the title. The built-in workflows pass the title that `implement` wrote, else the card's title.
|
|
88
91
|
- `labels`: the labels the pull request gets, with each label of `[extensions.github] pr_labels` first, added after it opens (`POST /repos/{owner}/{repo}/issues/{number}/labels`), also when a retry reads the pull request back. A refused label is written to the runtime log and the outcome stays `done`, because the change is open and a label only sorts it.
|
|
89
92
|
- `large_diff_lines`: when the change has more changed lines than this, the body says `This is a large change: 211 lines across 2 files.`
|
|
90
93
|
- `path_notices`: a list of `{ prefix, notice }`. When a changed file's path starts with `prefix`, the body carries `notice`, once.
|
|
91
94
|
|
|
92
|
-
- `checks`: the output of a check stage, such as `stages.checks.output`. The body lists each check that ended with exit code 0 under the `## Verified` heading, and says when one passed only on its second run, after a failure. Each other check goes under `## Not verified`, and a check that fails the same way on the base commit says that this change did not cause it. The lists come from the exit codes that the check stage recorded, and from no words of a model. The body shows the name and the exit code only, never the output of a check.
|
|
95
|
+
- `checks`: the output of a check stage, such as `stages.checks.output`. The body lists each check that ended with exit code 0 under the `## Verified` heading, and says when one passed only on its second run, after a failure. Each other check goes under `## Not verified`, and a check that fails the same way on the base commit says that this change did not cause it. The lists come from the exit codes that the check stage recorded, and from no words of a model. The body shows the name and the exit code only, never the output of a check. A check that sets `covers` in its service's config names the changed files it covers, such as `` `unit` passed, covering `src/a.rs` ``, or says `but it covers none of the changed files`, so a reader can tell a check that never read the change.
|
|
93
96
|
- `not_verified`: a list of things that the author of the change did not check, one line each. They go under `## Not verified`, after the checks.
|
|
94
|
-
- `proof`: the output of a `check = "proof"` stage. The body gets a `## The change's own proof` section that says whether the proof passed, failed or did not run, with its command, its exit code and the end of its output folded away. With `on_base`, it says how a proof that passed ended on the base commit: `failed`
|
|
97
|
+
- `proof`: the output of a `check = "proof"` stage. The body gets a `## The change's own proof` section that says whether the proof passed, failed or did not run, with its command, its exit code and the end of its output folded away. With `on_base`, it says how a proof that passed ended on the base commit, without the change: `failed` shows the fault and the fix, and `passed` says that the proof also passes without the change, so it does not show the fault, as `unknown` (EDGAR could not tell) does. It is advice and blocks nothing. `proof_passes` adds what the author said passing looks like.
|
|
95
98
|
- `related`: one `https:` URL, or a list of at most 5, of the pull requests that this one goes with. The body carries `Goes with: <url1>, <url2>` after the text of `body`. A list of more than 5, or a URL that is not `https:`, is refused as invalid input.
|
|
96
99
|
|
|
97
100
|
The built-in `remediate` passes `large_diff_lines = 200`, and the `[[services.<name>.path_notices]]` of the card's service.
|
|
98
101
|
|
|
99
|
-
The size and the paths come from `GET /repos/{owner}/{repo}/compare/{base}...{branch}`, read before the pull request opens. When the compare call fails, the pull request opens with no large-change line and no path notice, and the failure goes to the runtime log, because an optional warning never costs a finished fix its pull request. The notices go after `body`, then the proof, then the review
|
|
102
|
+
The size and the paths come from `GET /repos/{owner}/{repo}/compare/{base}...{branch}`, read before the pull request opens. When the compare call fails, the pull request opens with no large-change line and no path notice, and the failure goes to the runtime log, because an optional warning never costs a finished fix its pull request. The notices go after `body`, then the proof, then the review under its own `## Review` heading:
|
|
100
103
|
|
|
101
104
|
```toml
|
|
102
105
|
input = { repo = "...", branch = "...", title = "...", body = "...", review = "", labels = [
|
|
@@ -431,6 +434,7 @@ Only an App's commits are signed. With no `app`, the calls use `GITHUB_TOKEN`, a
|
|
|
431
434
|
| `attach_screenshot` | `contents: write`, `pull_requests: write` | `repo` (`public_repo` for a public repository) |
|
|
432
435
|
| `labels` of `open_pull_request` | `issues: write` or `pull_requests: write` | `repo` |
|
|
433
436
|
| `note_pull_request` | `issues: write` or `pull_requests: write` | `repo` |
|
|
437
|
+
| `request_reviewers` | `pull_requests: write` | `repo` |
|
|
434
438
|
| `pull_request_*`, `wait_for_review`, `wait_for_merge`, `find_pull_request`, `linked_pull_requests`, `list_pull_requests` | `pull_requests: read` | `repo` |
|
|
435
439
|
| `delete_closed_branches` | `contents: write`, `pull_requests: read` | `repo` (`public_repo` for a public repository) |
|
|
436
440
|
| `revert_pull_request` | `contents: write`, `pull_requests: write` | `repo` (`public_repo` for a public repository) |
|
|
@@ -440,6 +444,7 @@ Only an App's commits are signed. With no `app`, the calls use `GITHUB_TOKEN`, a
|
|
|
440
444
|
| `dependabot_alerts`, `find_dependabot_dismissal`, the Dependabot feed | `dependabot_alerts: read` | `security_events` or `repo` |
|
|
441
445
|
| `dismiss_dependabot_alert`, `reopen_dependabot_alert` | `dependabot_alerts: write` | `security_events` or `repo` |
|
|
442
446
|
| `branch_protection` | `metadata: read`; `administration: read` for the classic rule | `repo` |
|
|
447
|
+
| `code_owners` | `pull_requests: read`, `contents: read` | `repo` |
|
|
443
448
|
|
|
444
449
|
No check reads a token's rights ahead of its first call: the engine runs no extension at `edgar check`. GitHub says what a refused call needs in `X-Accepted-GitHub-Permissions` (fine-grained tokens and Apps) or `X-Accepted-OAuth-Scopes` (classic tokens). A 403 that is not a rate limit is `permanent_failure(forbidden)`, which the engine does not retry, and its message names that header's value:
|
|
445
450
|
|
|
@@ -524,6 +529,7 @@ Run on 2026-11-11 in `packages/extensions/ext-github`. The answer shapes of chec
|
|
|
524
529
|
- shortcut: the Dependabot feed closes only the cards that this process opened, so an alert fixed while EDGAR was stopped leaves its card open. Upgrade when a service can keep state.
|
|
525
530
|
- shortcut: `dismiss_dependabot_alert` reads an alert that holds its own `reason` and `comment` as its own. A person who dismissed with the same words is read as the call, so the undo opens that alert again. Upgrade when GitHub's answer says which call dismissed the alert.
|
|
526
531
|
- shortcut: the compare that the body notices read lists at most 300 files.
|
|
532
|
+
- shortcut: `code_owners` reads the first 100 files of a pull request, and the newest 100 commits of the base branch for each of its first 10 files, with no line-by-line blame. Upgrade to GraphQL blame when the owners of a large change are missed.
|
|
527
533
|
- shortcut: pull request lists and reviews read one page of 100. Upgrade to `Link` pagination when a repository holds more than 100 open pull requests.
|
|
528
534
|
- shortcut: `find_pull_request` matches by branch. The `edgar-operation` line is for people and audits. Upgrade to matching the line if two operations can share a branch.
|
|
529
535
|
- shortcut: `push_branch` pushes the sandbox's `origin` and does not compare it with `repo`. Upgrade when one sandbox holds several repositories.
|
package/dist/src/index.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export declare const tools: {
|
|
|
25
25
|
exit_code: number | null;
|
|
26
26
|
pre_existing?: boolean | undefined;
|
|
27
27
|
runs?: number | undefined;
|
|
28
|
+
covered?: string[] | undefined;
|
|
28
29
|
}[];
|
|
29
30
|
} | undefined;
|
|
30
31
|
not_verified?: string[] | undefined;
|
|
@@ -66,6 +67,7 @@ export declare const tools: {
|
|
|
66
67
|
exit_code: number | null;
|
|
67
68
|
pre_existing?: boolean | undefined;
|
|
68
69
|
runs?: number | undefined;
|
|
70
|
+
covered?: string[] | undefined;
|
|
69
71
|
}[];
|
|
70
72
|
} | undefined;
|
|
71
73
|
not_verified?: string[] | undefined;
|
|
@@ -380,6 +382,26 @@ export declare const tools: {
|
|
|
380
382
|
}[];
|
|
381
383
|
complete: boolean;
|
|
382
384
|
}, "GITHUB_TOKEN">;
|
|
385
|
+
code_owners: import("@kana-ai/edgar-sdk").Tool<{
|
|
386
|
+
url: string;
|
|
387
|
+
}, {
|
|
388
|
+
source: "codeowners" | "history";
|
|
389
|
+
reviewers: string[];
|
|
390
|
+
team_reviewers: string[];
|
|
391
|
+
who_can_act: {
|
|
392
|
+
github?: string | undefined;
|
|
393
|
+
name?: string | undefined;
|
|
394
|
+
why: string;
|
|
395
|
+
}[];
|
|
396
|
+
}, "GITHUB_TOKEN">;
|
|
397
|
+
request_reviewers: import("@kana-ai/edgar-sdk").Tool<{
|
|
398
|
+
url: string;
|
|
399
|
+
reviewers: string[];
|
|
400
|
+
team_reviewers: string[];
|
|
401
|
+
}, {
|
|
402
|
+
url: string;
|
|
403
|
+
requested: string[];
|
|
404
|
+
}, "GITHUB_TOKEN">;
|
|
383
405
|
merged_pull_request: import("@kana-ai/edgar-sdk").Tool<{
|
|
384
406
|
repo: string;
|
|
385
407
|
card: string;
|
package/dist/src/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import { alertTools } from "#tools/alerts";
|
|
|
7
7
|
import { deleteClosedBranches, pushBranch } from "#tools/branch";
|
|
8
8
|
import { checkTools } from "#tools/checks";
|
|
9
9
|
import { discussionTools } from "#tools/discussion";
|
|
10
|
+
import { ownerTools } from "#tools/owners";
|
|
10
11
|
import { pullRequestTools } from "#tools/pull-request";
|
|
11
12
|
import { repositoryTools } from "#tools/repository";
|
|
12
13
|
import { revertTools } from "#tools/revert";
|
|
@@ -20,6 +21,7 @@ export const tools = {
|
|
|
20
21
|
...pullRequestTools,
|
|
21
22
|
...checkTools,
|
|
22
23
|
...discussionTools,
|
|
24
|
+
...ownerTools,
|
|
23
25
|
...repositoryTools,
|
|
24
26
|
...revertTools,
|
|
25
27
|
...alertTools,
|
|
@@ -535,3 +535,56 @@ export declare const issueEvent: z.ZodObject<{
|
|
|
535
535
|
type: z.ZodOptional<z.ZodString>;
|
|
536
536
|
}, z.core.$strip>>>;
|
|
537
537
|
}, z.core.$strip>;
|
|
538
|
+
/** A pull request with its writer and its base branch, which `code_owners` leaves out of the people it finds and reads the history of. */
|
|
539
|
+
export declare const authoredPull: z.ZodObject<{
|
|
540
|
+
html_url: z.ZodString;
|
|
541
|
+
number: z.ZodNumber;
|
|
542
|
+
state: z.ZodEnum<{
|
|
543
|
+
closed: "closed";
|
|
544
|
+
open: "open";
|
|
545
|
+
}>;
|
|
546
|
+
merged_at: z.ZodNullable<z.ZodString>;
|
|
547
|
+
merge_commit_sha: z.ZodNullable<z.ZodString>;
|
|
548
|
+
updated_at: z.ZodString;
|
|
549
|
+
head: z.ZodObject<{
|
|
550
|
+
ref: z.ZodString;
|
|
551
|
+
sha: z.ZodString;
|
|
552
|
+
repo: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
553
|
+
full_name: z.ZodString;
|
|
554
|
+
}, z.core.$strip>>>;
|
|
555
|
+
}, z.core.$strip>;
|
|
556
|
+
user: z.ZodNullable<z.ZodObject<{
|
|
557
|
+
login: z.ZodString;
|
|
558
|
+
type: z.ZodOptional<z.ZodString>;
|
|
559
|
+
}, z.core.$strip>>;
|
|
560
|
+
base: z.ZodObject<{
|
|
561
|
+
ref: z.ZodString;
|
|
562
|
+
}, z.core.$strip>;
|
|
563
|
+
}, z.core.$strip>;
|
|
564
|
+
/** A file of `GET /repos/{owner}/{repo}/contents/{path}`, its text in base64. */
|
|
565
|
+
export declare const fileContent: z.ZodObject<{
|
|
566
|
+
content: z.ZodString;
|
|
567
|
+
encoding: z.ZodLiteral<"base64">;
|
|
568
|
+
}, z.core.$strip>;
|
|
569
|
+
/** One commit of `GET /repos/{owner}/{repo}/commits`: `author` is the GitHub user of its author, `null` when the author's email matches none. */
|
|
570
|
+
export declare const listedCommit: z.ZodObject<{
|
|
571
|
+
sha: z.ZodString;
|
|
572
|
+
author: z.ZodNullable<z.ZodObject<{
|
|
573
|
+
login: z.ZodString;
|
|
574
|
+
type: z.ZodOptional<z.ZodString>;
|
|
575
|
+
}, z.core.$strip>>;
|
|
576
|
+
commit: z.ZodObject<{
|
|
577
|
+
author: z.ZodNullable<z.ZodObject<{
|
|
578
|
+
date: z.ZodString;
|
|
579
|
+
}, z.core.$strip>>;
|
|
580
|
+
}, z.core.$strip>;
|
|
581
|
+
}, z.core.$strip>;
|
|
582
|
+
/** The answer of `POST /repos/{owner}/{repo}/pulls/{n}/requested_reviewers`: the pull request with each person and team it now asks. */
|
|
583
|
+
export declare const reviewRequest: z.ZodObject<{
|
|
584
|
+
requested_reviewers: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
585
|
+
login: z.ZodString;
|
|
586
|
+
}, z.core.$strip>>>;
|
|
587
|
+
requested_teams: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
588
|
+
slug: z.ZodString;
|
|
589
|
+
}, z.core.$strip>>>;
|
|
590
|
+
}, z.core.$strip>;
|
|
@@ -249,3 +249,21 @@ export const issueEvent = z.object({
|
|
|
249
249
|
actor: actor.nullable(),
|
|
250
250
|
assignee: actor.nullish(),
|
|
251
251
|
});
|
|
252
|
+
/** A pull request with its writer and its base branch, which `code_owners` leaves out of the people it finds and reads the history of. */
|
|
253
|
+
export const authoredPull = pull.extend({
|
|
254
|
+
user: actor.nullable(),
|
|
255
|
+
base: z.object({ ref: z.string() }),
|
|
256
|
+
});
|
|
257
|
+
/** A file of `GET /repos/{owner}/{repo}/contents/{path}`, its text in base64. */
|
|
258
|
+
export const fileContent = z.object({ content: z.string(), encoding: z.literal("base64") });
|
|
259
|
+
/** One commit of `GET /repos/{owner}/{repo}/commits`: `author` is the GitHub user of its author, `null` when the author's email matches none. */
|
|
260
|
+
export const listedCommit = z.object({
|
|
261
|
+
sha: z.string(),
|
|
262
|
+
author: actor.nullable(),
|
|
263
|
+
commit: z.object({ author: z.object({ date: z.string() }).nullable() }),
|
|
264
|
+
});
|
|
265
|
+
/** The answer of `POST /repos/{owner}/{repo}/pulls/{n}/requested_reviewers`: the pull request with each person and team it now asks. */
|
|
266
|
+
export const reviewRequest = z.object({
|
|
267
|
+
requested_reviewers: z.array(person).default([]),
|
|
268
|
+
requested_teams: z.array(z.object({ slug: z.string() })).default([]),
|
|
269
|
+
});
|
|
@@ -50,6 +50,7 @@ export declare const openPullRequest: {
|
|
|
50
50
|
exit_code: z.ZodNullable<z.ZodNumber>;
|
|
51
51
|
pre_existing: z.ZodOptional<z.ZodBoolean>;
|
|
52
52
|
runs: z.ZodOptional<z.ZodNumber>;
|
|
53
|
+
covered: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
53
54
|
}, z.core.$strip>>;
|
|
54
55
|
}, z.core.$strip>>;
|
|
55
56
|
not_verified: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
@@ -154,6 +155,7 @@ export declare const updatePullRequest: {
|
|
|
154
155
|
exit_code: z.ZodNullable<z.ZodNumber>;
|
|
155
156
|
pre_existing: z.ZodOptional<z.ZodBoolean>;
|
|
156
157
|
runs: z.ZodOptional<z.ZodNumber>;
|
|
158
|
+
covered: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
157
159
|
}, z.core.$strip>>;
|
|
158
160
|
}, z.core.$strip>>;
|
|
159
161
|
not_verified: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
@@ -487,6 +489,37 @@ export declare const ciRun: {
|
|
|
487
489
|
unread: z.ZodArray<z.ZodNumber>;
|
|
488
490
|
}, z.core.$strip>;
|
|
489
491
|
};
|
|
492
|
+
/** The input and output of `code_owners`: the people who should review a pull request, at most two, as `request_reviewers` takes them, and as the run's `who_can_act` with why each one. */
|
|
493
|
+
export declare const codeOwners: {
|
|
494
|
+
input: z.ZodObject<{
|
|
495
|
+
url: z.ZodString;
|
|
496
|
+
}, z.core.$strip>;
|
|
497
|
+
output: z.ZodObject<{
|
|
498
|
+
source: z.ZodEnum<{
|
|
499
|
+
codeowners: "codeowners";
|
|
500
|
+
history: "history";
|
|
501
|
+
}>;
|
|
502
|
+
reviewers: z.ZodArray<z.ZodString>;
|
|
503
|
+
team_reviewers: z.ZodArray<z.ZodString>;
|
|
504
|
+
who_can_act: z.ZodArray<z.ZodObject<{
|
|
505
|
+
github: z.ZodOptional<z.ZodString>;
|
|
506
|
+
name: z.ZodOptional<z.ZodString>;
|
|
507
|
+
why: z.ZodString;
|
|
508
|
+
}, z.core.$strip>>;
|
|
509
|
+
}, z.core.$strip>;
|
|
510
|
+
};
|
|
511
|
+
/** The input and output of `request_reviewers`. */
|
|
512
|
+
export declare const requestReviewers: {
|
|
513
|
+
input: z.ZodObject<{
|
|
514
|
+
url: z.ZodString;
|
|
515
|
+
reviewers: z.ZodArray<z.ZodString>;
|
|
516
|
+
team_reviewers: z.ZodArray<z.ZodString>;
|
|
517
|
+
}, z.core.$strip>;
|
|
518
|
+
output: z.ZodObject<{
|
|
519
|
+
url: z.ZodString;
|
|
520
|
+
requested: z.ZodArray<z.ZodString>;
|
|
521
|
+
}, z.core.$strip>;
|
|
522
|
+
};
|
|
490
523
|
/** The input and output of `branch_protection`. */
|
|
491
524
|
export declare const branchProtection: {
|
|
492
525
|
input: z.ZodObject<{
|
|
@@ -46,7 +46,7 @@ export const openPullRequest = {
|
|
|
46
46
|
card: z
|
|
47
47
|
.looseObject({ id: z.string().min(1), title: z.string().min(1), url: z.string().optional() })
|
|
48
48
|
.optional()
|
|
49
|
-
.describe("the run's card: the title becomes `<id>: <title>`, and the body opens with its link"),
|
|
49
|
+
.describe("the run's card: the title becomes `<id>: <title>`, at most 72 characters with a trailing `[tag]` kept whole, and the body opens with its link"),
|
|
50
50
|
large_diff_lines: z
|
|
51
51
|
.number()
|
|
52
52
|
.int()
|
|
@@ -64,10 +64,11 @@ export const openPullRequest = {
|
|
|
64
64
|
exit_code: z.number().int().nullable(),
|
|
65
65
|
pre_existing: z.boolean().optional(),
|
|
66
66
|
runs: z.number().int().positive().optional(),
|
|
67
|
+
covered: z.array(z.string()).optional(),
|
|
67
68
|
})),
|
|
68
69
|
})
|
|
69
70
|
.optional()
|
|
70
|
-
.describe("the output of a check stage: the body lists each check that passed under Verified, saying when it passed only on its second run, and each other check under Not verified, with a failure that the check gave on the base commit too named as one the change did not cause"),
|
|
71
|
+
.describe("the output of a check stage: the body lists each check that passed under Verified, saying when it passed only on its second run, and each other check under Not verified, with a failure that the check gave on the base commit too named as one the change did not cause, and the changed files each check covers, or that it covers none, when the check says which paths it covers"),
|
|
71
72
|
not_verified: z
|
|
72
73
|
.array(z.string())
|
|
73
74
|
.optional()
|
|
@@ -427,6 +428,35 @@ export const ciRun = {
|
|
|
427
428
|
.describe("failed jobs past the log limit, read with /job/<id>"),
|
|
428
429
|
}),
|
|
429
430
|
};
|
|
431
|
+
/** The input and output of `code_owners`: the people who should review a pull request, at most two, as `request_reviewers` takes them, and as the run's `who_can_act` with why each one. */
|
|
432
|
+
export const codeOwners = {
|
|
433
|
+
input: byUrl,
|
|
434
|
+
output: z.object({
|
|
435
|
+
source: z
|
|
436
|
+
.enum(["codeowners", "history"])
|
|
437
|
+
.describe("codeowners: the CODEOWNERS file names them; history: they changed the files most, and most recently"),
|
|
438
|
+
reviewers: z.array(z.string()).describe("the login of each person"),
|
|
439
|
+
team_reviewers: z.array(z.string()).describe("the slug of each team that CODEOWNERS names"),
|
|
440
|
+
who_can_act: z
|
|
441
|
+
.array(z.object({
|
|
442
|
+
github: z.string().optional().describe("the login of a person"),
|
|
443
|
+
name: z.string().optional().describe("a team, as @org/slug"),
|
|
444
|
+
why: z.string(),
|
|
445
|
+
}))
|
|
446
|
+
.min(1),
|
|
447
|
+
}),
|
|
448
|
+
};
|
|
449
|
+
/** The input and output of `request_reviewers`. */
|
|
450
|
+
export const requestReviewers = {
|
|
451
|
+
input: byUrl.extend({
|
|
452
|
+
reviewers: z.array(z.string().min(1)).describe("the login of each person to ask"),
|
|
453
|
+
team_reviewers: z.array(z.string().min(1)).describe("the slug of each team to ask"),
|
|
454
|
+
}),
|
|
455
|
+
output: z.object({
|
|
456
|
+
url: z.string(),
|
|
457
|
+
requested: z.array(z.string()).describe("each login and team slug that GitHub now asks"),
|
|
458
|
+
}),
|
|
459
|
+
};
|
|
430
460
|
/** The input and output of `branch_protection`. */
|
|
431
461
|
export const branchProtection = {
|
|
432
462
|
input: z.object({ repo: z.string().min(1), branch: z.string().min(1) }),
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** One line of a CODEOWNERS file: the paths it matches, and its owners as a login or `org/team`. */
|
|
2
|
+
export interface Rule {
|
|
3
|
+
readonly pattern: RegExp;
|
|
4
|
+
readonly owners: readonly string[];
|
|
5
|
+
}
|
|
6
|
+
/** The rules of a CODEOWNERS file in order. An owner by email is left out, since GitHub asks only a login or a team for a review. */
|
|
7
|
+
export declare function rulesOf(text: string): readonly Rule[];
|
|
8
|
+
/** How many of `paths` each owner owns, by the last rule that matches each path, as GitHub reads the file: a last rule with no owner leaves its path with none. */
|
|
9
|
+
export declare function ownersOf(rules: readonly Rule[], paths: readonly string[]): Map<string, number>;
|
|
10
|
+
/** The reviewer tools of the GitHub extension, by the name the manifest gives them. */
|
|
11
|
+
export declare const ownerTools: {
|
|
12
|
+
/** shortcut: the first 100 files of the pull request, and the newest 100 commits of the base branch for each of its first 10 files, so at most 15 reads; upgrade to GraphQL blame when a change is larger. */
|
|
13
|
+
code_owners: import("@kana-ai/edgar-sdk").Tool<{
|
|
14
|
+
url: string;
|
|
15
|
+
}, {
|
|
16
|
+
source: "codeowners" | "history";
|
|
17
|
+
reviewers: string[];
|
|
18
|
+
team_reviewers: string[];
|
|
19
|
+
who_can_act: {
|
|
20
|
+
github?: string | undefined;
|
|
21
|
+
name?: string | undefined;
|
|
22
|
+
why: string;
|
|
23
|
+
}[];
|
|
24
|
+
}, "GITHUB_TOKEN">;
|
|
25
|
+
/** GitHub refuses a request for someone who cannot review there, such as a person who is no longer a collaborator, with 422: the pull request then waits for a review as before. */
|
|
26
|
+
request_reviewers: import("@kana-ai/edgar-sdk").Tool<{
|
|
27
|
+
url: string;
|
|
28
|
+
reviewers: string[];
|
|
29
|
+
team_reviewers: string[];
|
|
30
|
+
}, {
|
|
31
|
+
url: string;
|
|
32
|
+
requested: string[];
|
|
33
|
+
}, "GITHUB_TOKEN">;
|
|
34
|
+
};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { defineTool, done, ok, skipped } from "@kana-ai/edgar-sdk";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { apiAccess, github } from "#api/client";
|
|
4
|
+
import { authoredPull, fileContent, listedCommit, pullFile, reviewRequest } from "#schemas/github";
|
|
5
|
+
import { codeOwners, requestReviewers } from "#schemas/tools";
|
|
6
|
+
import { pullOf } from "#tools/pull-request";
|
|
7
|
+
/** Where GitHub looks for the CODEOWNERS file, in its order: it uses the first one it finds. */
|
|
8
|
+
const CODEOWNERS_FILES = [".github/CODEOWNERS", "CODEOWNERS", "docs/CODEOWNERS"];
|
|
9
|
+
const DAY = 86_400_000;
|
|
10
|
+
const HALF_LIFE_DAYS = 90;
|
|
11
|
+
const WINDOW_DAYS = 365;
|
|
12
|
+
const PATHS = 10;
|
|
13
|
+
const TOP = 2;
|
|
14
|
+
/** What each part of a CODEOWNERS pattern means as a regular expression; any other character stands for itself. */
|
|
15
|
+
const TOKENS = {
|
|
16
|
+
"**/": "(?:.*/)?",
|
|
17
|
+
"/**": "/.*",
|
|
18
|
+
"**": ".*",
|
|
19
|
+
"*": "[^/]*",
|
|
20
|
+
"?": "[^/]",
|
|
21
|
+
};
|
|
22
|
+
/** A CODEOWNERS pattern with gitignore's rules: a slash at the start or in the middle anchors it at the root, a slash at the end matches a folder, and a match covers what is inside, except for a last part of `*`, which GitHub reads as one level. */
|
|
23
|
+
function patternOf(glob) {
|
|
24
|
+
const anchored = glob.startsWith("/") || glob.slice(0, -1).includes("/");
|
|
25
|
+
const body = glob
|
|
26
|
+
.replace(/^\/|\/$/g, "")
|
|
27
|
+
.replace(/\*\*\/|\/\*\*$|\*\*|\*|\?|[.+^${}()|[\]\\]/g, (part) => TOKENS[part] ?? `\\${part}`);
|
|
28
|
+
const inside = glob.endsWith("/") ? "/.*" : glob.endsWith("/*") ? "" : "(?:/.*)?";
|
|
29
|
+
return new RegExp(`^${anchored ? "" : "(?:.*/)?"}${body}${inside}$`);
|
|
30
|
+
}
|
|
31
|
+
/** The rules of a CODEOWNERS file in order. An owner by email is left out, since GitHub asks only a login or a team for a review. */
|
|
32
|
+
export function rulesOf(text) {
|
|
33
|
+
return text.split("\n").flatMap((line) => {
|
|
34
|
+
const [glob = "", ...owners] = line.replace(/#.*/, "").trim().split(/\s+/);
|
|
35
|
+
if (glob === "")
|
|
36
|
+
return [];
|
|
37
|
+
const named = owners.filter((owner) => owner.startsWith("@")).map((owner) => owner.slice(1));
|
|
38
|
+
return [{ pattern: patternOf(glob), owners: named }];
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/** How many of `paths` each owner owns, by the last rule that matches each path, as GitHub reads the file: a last rule with no owner leaves its path with none. */
|
|
42
|
+
export function ownersOf(rules, paths) {
|
|
43
|
+
const counted = new Map();
|
|
44
|
+
for (const path of paths) {
|
|
45
|
+
const rule = rules.findLast(({ pattern }) => pattern.test(path));
|
|
46
|
+
for (const owner of rule?.owners ?? [])
|
|
47
|
+
counted.set(owner, (counted.get(owner) ?? 0) + 1);
|
|
48
|
+
}
|
|
49
|
+
return counted;
|
|
50
|
+
}
|
|
51
|
+
/** Whether a login can never review: an App, or the pull request's own author, who is EDGAR on its own pull request. */
|
|
52
|
+
function leftOut(login, author, type) {
|
|
53
|
+
return type === "Bot" || login.endsWith("[bot]") || login.toLowerCase() === author.toLowerCase();
|
|
54
|
+
}
|
|
55
|
+
/** The first CODEOWNERS file of the base branch, or `undefined` when there is none. */
|
|
56
|
+
async function codeOwnersFile(ctx, repo, ref) {
|
|
57
|
+
for (const file of CODEOWNERS_FILES) {
|
|
58
|
+
const read = await github(ctx, "GET", `${repo}/contents/${file}?ref=${ref}`, fileContent);
|
|
59
|
+
if (read.ok)
|
|
60
|
+
return ok({ file, text: Buffer.from(read.value.content, "base64").toString() });
|
|
61
|
+
if (read.error.kind !== "not_found")
|
|
62
|
+
return read;
|
|
63
|
+
}
|
|
64
|
+
return ok(undefined);
|
|
65
|
+
}
|
|
66
|
+
/** The answer for the top owners, a login or `org/team` each, with why. */
|
|
67
|
+
function answer(source, top) {
|
|
68
|
+
return {
|
|
69
|
+
source,
|
|
70
|
+
reviewers: top.filter(([owner]) => !owner.includes("/")).map(([owner]) => owner),
|
|
71
|
+
team_reviewers: top
|
|
72
|
+
.filter(([owner]) => owner.includes("/"))
|
|
73
|
+
.map(([owner]) => owner.slice(owner.indexOf("/") + 1)),
|
|
74
|
+
who_can_act: top.map(([owner, why]) => owner.includes("/") ? { name: `@${owner}`, why } : { github: owner, why }),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/** Each author's weight over the commits of the window: a commit counts 1, halved for each 90 days of its age, so a steady author outweighs the one who made the newest change. Each author's commit count and newest commit go with it. */
|
|
78
|
+
function ranked(commits, now) {
|
|
79
|
+
const by = new Map();
|
|
80
|
+
for (const { login, at } of commits) {
|
|
81
|
+
const was = by.get(login) ?? { login, score: 0, commits: 0, newest: 0 };
|
|
82
|
+
by.set(login, {
|
|
83
|
+
login,
|
|
84
|
+
score: was.score + 0.5 ** ((now - at) / DAY / HALF_LIFE_DAYS),
|
|
85
|
+
commits: was.commits + 1,
|
|
86
|
+
newest: Math.max(was.newest, at),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return [...by.values()].sort((a, b) => b.score - a.score || b.newest - a.newest || a.login.localeCompare(b.login));
|
|
90
|
+
}
|
|
91
|
+
/** The reviewer tools of the GitHub extension, by the name the manifest gives them. */
|
|
92
|
+
export const ownerTools = {
|
|
93
|
+
/** shortcut: the first 100 files of the pull request, and the newest 100 commits of the base branch for each of its first 10 files, so at most 15 reads; upgrade to GraphQL blame when a change is larger. */
|
|
94
|
+
code_owners: defineTool({
|
|
95
|
+
description: "Find who should review a pull request: the owners that CODEOWNERS names for its files, else the at most two people who changed those files most and most recently in the last 12 months, never a bot or its author; skipped when there is none",
|
|
96
|
+
input: codeOwners.input,
|
|
97
|
+
output: codeOwners.output,
|
|
98
|
+
...apiAccess,
|
|
99
|
+
execute: async ({ url }, ctx) => {
|
|
100
|
+
const path = pullOf(url);
|
|
101
|
+
if (!path.ok)
|
|
102
|
+
return path.error;
|
|
103
|
+
const repo = path.value.replace(/\/pulls\/\d+$/, "");
|
|
104
|
+
const pull = await github(ctx, "GET", path.value, authoredPull);
|
|
105
|
+
if (!pull.ok)
|
|
106
|
+
return pull.error;
|
|
107
|
+
const listed = await github(ctx, "GET", `${path.value}/files?per_page=100`, z.array(pullFile));
|
|
108
|
+
if (!listed.ok)
|
|
109
|
+
return listed.error;
|
|
110
|
+
const author = pull.value.user?.login ?? "";
|
|
111
|
+
const paths = listed.value.map((file) => file.filename);
|
|
112
|
+
const ref = encodeURIComponent(pull.value.base.ref);
|
|
113
|
+
const found = await codeOwnersFile(ctx, repo, ref);
|
|
114
|
+
if (!found.ok)
|
|
115
|
+
return found.error;
|
|
116
|
+
if (found.value !== undefined) {
|
|
117
|
+
const { file, text } = found.value;
|
|
118
|
+
const owned = [...ownersOf(rulesOf(text), paths)]
|
|
119
|
+
.filter(([owner]) => !leftOut(owner, author))
|
|
120
|
+
.sort(([, a], [, b]) => b - a)
|
|
121
|
+
.slice(0, TOP);
|
|
122
|
+
if (owned.length > 0) {
|
|
123
|
+
const why = (count) => `${file} names them for ${String(count)} of the ${String(paths.length)} changed files`;
|
|
124
|
+
return done(answer("codeowners", owned.map(([owner, count]) => [owner, why(count)])));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const now = Date.now();
|
|
128
|
+
const seen = new Map();
|
|
129
|
+
for (const file of paths.slice(0, PATHS)) {
|
|
130
|
+
const query = new URLSearchParams({
|
|
131
|
+
sha: pull.value.base.ref,
|
|
132
|
+
path: file,
|
|
133
|
+
per_page: "100",
|
|
134
|
+
});
|
|
135
|
+
const read = await github(ctx, "GET", `${repo}/commits?${query.toString()}`, z.array(listedCommit));
|
|
136
|
+
if (!read.ok)
|
|
137
|
+
return read.error;
|
|
138
|
+
for (const { sha, author: by, commit } of read.value) {
|
|
139
|
+
const at = Date.parse(commit.author?.date ?? "");
|
|
140
|
+
if (by === null || leftOut(by.login, author, by.type) || !(now - at < WINDOW_DAYS * DAY))
|
|
141
|
+
continue;
|
|
142
|
+
seen.set(sha, { login: by.login, at });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const top = ranked([...seen.values()], now).slice(0, TOP);
|
|
146
|
+
if (top.length === 0)
|
|
147
|
+
return skipped();
|
|
148
|
+
const why = (commits, newest) => `${String(commits)} of the ${String(seen.size)} commits to the changed files in the last 12 months, the newest on ${new Date(newest).toISOString().slice(0, 10)}`;
|
|
149
|
+
return done(answer("history", top.map(({ login, commits, newest }) => [login, why(commits, newest)])));
|
|
150
|
+
},
|
|
151
|
+
}),
|
|
152
|
+
/** GitHub refuses a request for someone who cannot review there, such as a person who is no longer a collaborator, with 422: the pull request then waits for a review as before. */
|
|
153
|
+
request_reviewers: defineTool({
|
|
154
|
+
description: "Ask people and teams to review a pull request; skipped when there is no one to ask or GitHub cannot ask them",
|
|
155
|
+
input: requestReviewers.input,
|
|
156
|
+
output: requestReviewers.output,
|
|
157
|
+
...apiAccess,
|
|
158
|
+
side_effect: true,
|
|
159
|
+
undo: "none",
|
|
160
|
+
undo_reason: "A review request only asks; the people asked are still the right ones when a later stage is undone.",
|
|
161
|
+
execute: async ({ url, reviewers, team_reviewers }, ctx) => {
|
|
162
|
+
const path = pullOf(url);
|
|
163
|
+
if (!path.ok)
|
|
164
|
+
return path.error;
|
|
165
|
+
if (reviewers.length === 0 && team_reviewers.length === 0)
|
|
166
|
+
return skipped();
|
|
167
|
+
const asked = await github(ctx, "POST", `${path.value}/requested_reviewers`, reviewRequest, {
|
|
168
|
+
reviewers,
|
|
169
|
+
team_reviewers,
|
|
170
|
+
});
|
|
171
|
+
if (!asked.ok)
|
|
172
|
+
return asked.error.kind === "invalid" ? skipped() : asked.error;
|
|
173
|
+
return done({
|
|
174
|
+
url,
|
|
175
|
+
requested: [
|
|
176
|
+
...asked.value.requested_reviewers.map((person) => person.login),
|
|
177
|
+
...asked.value.requested_teams.map((team) => team.slug),
|
|
178
|
+
],
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
}),
|
|
182
|
+
};
|
|
@@ -27,7 +27,9 @@ export declare function changeNotices(files: readonly {
|
|
|
27
27
|
readonly prefix: string;
|
|
28
28
|
readonly notice: string;
|
|
29
29
|
}[]): string[];
|
|
30
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* A pull request's title, `<id>: <title>` for its card, so a reviewer sees the card at a glance; a title that already starts with the card's id keeps it once. Past 72 characters, the words before a trailing `[tag]` are cut where a word ends, and the tag stays whole: a repository can start a build from a tag in the merge commit's message, which holds the title.
|
|
32
|
+
*/
|
|
31
33
|
export declare function titleOf(title: string, card: Card | undefined): string;
|
|
32
34
|
/** The first line of a body for its card: its link, or its id when the card has no address. */
|
|
33
35
|
export declare function cardLine(card: Card | undefined): string;
|
|
@@ -63,6 +65,7 @@ export declare const pullRequestTools: {
|
|
|
63
65
|
exit_code: number | null;
|
|
64
66
|
pre_existing?: boolean | undefined;
|
|
65
67
|
runs?: number | undefined;
|
|
68
|
+
covered?: string[] | undefined;
|
|
66
69
|
}[];
|
|
67
70
|
} | undefined;
|
|
68
71
|
not_verified?: string[] | undefined;
|
|
@@ -105,6 +108,7 @@ export declare const pullRequestTools: {
|
|
|
105
108
|
exit_code: number | null;
|
|
106
109
|
pre_existing?: boolean | undefined;
|
|
107
110
|
runs?: number | undefined;
|
|
111
|
+
covered?: string[] | undefined;
|
|
108
112
|
}[];
|
|
109
113
|
} | undefined;
|
|
110
114
|
not_verified?: string[] | undefined;
|
|
@@ -153,9 +153,25 @@ export function changeNotices(files, largeLines, paths) {
|
|
|
153
153
|
.map((p) => p.notice);
|
|
154
154
|
return [...large, ...new Set(touched)];
|
|
155
155
|
}
|
|
156
|
-
/**
|
|
156
|
+
/** The longest title, so the merge commit's subject that holds it stays readable in `git log`. */
|
|
157
|
+
const TITLE_LIMIT = 72;
|
|
158
|
+
/**
|
|
159
|
+
* A pull request's title, `<id>: <title>` for its card, so a reviewer sees the card at a glance; a title that already starts with the card's id keeps it once. Past 72 characters, the words before a trailing `[tag]` are cut where a word ends, and the tag stays whole: a repository can start a build from a tag in the merge commit's message, which holds the title.
|
|
160
|
+
*/
|
|
157
161
|
export function titleOf(title, card) {
|
|
158
|
-
|
|
162
|
+
const own = card === undefined ? title : title.trim().replace(idPrefix(card.id), "");
|
|
163
|
+
const full = (card === undefined ? own : `${card.id}: ${own}`).trim().replaceAll(/\s+/g, " ");
|
|
164
|
+
if (full.length <= TITLE_LIMIT)
|
|
165
|
+
return full;
|
|
166
|
+
const tag = /(?: ?\[[^[\]]+\])+$/.exec(full)?.[0] ?? "";
|
|
167
|
+
const room = Math.max(0, TITLE_LIMIT - tag.length);
|
|
168
|
+
const words = full.slice(0, full.length - tag.length).slice(0, room + 1);
|
|
169
|
+
const end = words.lastIndexOf(" ");
|
|
170
|
+
const kept = (end > 0 ? words.slice(0, end) : words.slice(0, room)).replace(/[\s,;:-]+$/, "");
|
|
171
|
+
return kept === "" ? tag.trim() : `${kept}${tag}`;
|
|
172
|
+
}
|
|
173
|
+
function idPrefix(id) {
|
|
174
|
+
return new RegExp(`^${id.replaceAll(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*:\\s*`, "i");
|
|
159
175
|
}
|
|
160
176
|
/** The first line of a body for its card: its link, or its id when the card has no address. */
|
|
161
177
|
export function cardLine(card) {
|
|
@@ -173,8 +189,8 @@ export function proofOf(checks, notVerified) {
|
|
|
173
189
|
const passed = results
|
|
174
190
|
.filter((r) => r.exit_code === 0)
|
|
175
191
|
.map((r) => r.runs === 2
|
|
176
|
-
? `- ${name(r.check)} passed on its second run, after a failure`
|
|
177
|
-
: `- ${name(r.check)} passed`);
|
|
192
|
+
? `- ${name(r.check)} passed on its second run, after a failure${coverageOf(r.covered)}`
|
|
193
|
+
: `- ${name(r.check)} passed${coverageOf(r.covered)}`);
|
|
178
194
|
const open = [
|
|
179
195
|
...results
|
|
180
196
|
.filter((r) => r.exit_code !== 0)
|
|
@@ -182,7 +198,7 @@ export function proofOf(checks, notVerified) {
|
|
|
182
198
|
? `- ${name(r.check)} did not run or did not end`
|
|
183
199
|
: r.pre_existing === true
|
|
184
200
|
? `- ${name(r.check)} ended with exit code ${String(r.exit_code)}, and fails the same way on the base commit, so this change did not cause it`
|
|
185
|
-
: `- ${name(r.check)} ended with exit code ${String(r.exit_code)}`),
|
|
201
|
+
: `- ${name(r.check)} ended with exit code ${String(r.exit_code)}${coverageOf(r.covered)}`),
|
|
186
202
|
...(notVerified ?? [])
|
|
187
203
|
.map((item) => item.trim().replaceAll(/\s+/g, " "))
|
|
188
204
|
.filter((item) => item !== "")
|
|
@@ -198,6 +214,18 @@ export function proofOf(checks, notVerified) {
|
|
|
198
214
|
...(open.length === 0 ? outstanding : [section("Not verified", open.join("\n"))]),
|
|
199
215
|
];
|
|
200
216
|
}
|
|
217
|
+
/** The most changed files that one check's line names. */
|
|
218
|
+
const COVERED_SHOWN = 5;
|
|
219
|
+
/** The changed files a check covers, as the end of its line: none when the check does not say which paths it covers. */
|
|
220
|
+
function coverageOf(covered) {
|
|
221
|
+
if (covered === undefined)
|
|
222
|
+
return "";
|
|
223
|
+
if (covered.length === 0)
|
|
224
|
+
return ", but it covers none of the changed files";
|
|
225
|
+
const shown = covered.slice(0, COVERED_SHOWN).map((path) => `\`${path.replaceAll("`", "")}\``);
|
|
226
|
+
const more = covered.length - shown.length;
|
|
227
|
+
return `, covering ${shown.join(", ")}${more > 0 ? ` and ${String(more)} more` : ""}`;
|
|
228
|
+
}
|
|
201
229
|
/** A section of a body: a heading at the level that a pull request description starts its sections with, then its text. */
|
|
202
230
|
function section(heading, text) {
|
|
203
231
|
return `## ${heading}\n\n${text}`;
|
|
@@ -208,11 +236,11 @@ function fenced(text) {
|
|
|
208
236
|
const fence = "`".repeat(longest + 1);
|
|
209
237
|
return `${fence}text\n${text}\n${fence}`;
|
|
210
238
|
}
|
|
211
|
-
/** What a proof that passed says by how it ended on the base commit: only a failure there
|
|
239
|
+
/** What a proof that passed says by how it ended on the base commit: only a failure there shows the fault. */
|
|
212
240
|
const onBase = {
|
|
213
|
-
failed: "It
|
|
214
|
-
passed: "It passes on the base commit
|
|
215
|
-
unknown: "It passed, but I could not tell whether it fails on the base commit, so it does not
|
|
241
|
+
failed: "It fails on the base commit, without the change, and passes with it, so it shows the fault and the fix.",
|
|
242
|
+
passed: "It also passes on the base commit, without the change, so it does not show the fault.",
|
|
243
|
+
unknown: "It passed, but I could not tell whether it fails on the base commit, without the change, so it does not show the fault.",
|
|
216
244
|
};
|
|
217
245
|
/** How the change's own proof ended, as advice that blocks nothing: the command, its outcome from the proof stage's exit code and from no words of a model, whether a proof that passed failed on the base commit, what the author said passing looks like, and the end of its output folded away. With no `proof`, the body says nothing of it. */
|
|
218
246
|
export function ownProofOf(proof, passes) {
|
|
@@ -343,9 +371,9 @@ export const pullRequestTools = {
|
|
|
343
371
|
? ""
|
|
344
372
|
: `Merge ${input.after} first. This pull request is built on it, so its checks ran with that change, and its diff shows that change until it merges.`, input.first === undefined
|
|
345
373
|
? ""
|
|
346
|
-
: `${COMPANION_LEAD} the fix of the card is built on it, and EDGAR's note below links the fix. Why the fix needs it: ${input.first}`, ...notes, ...proofOf(input.checks, input.not_verified), ...ownProofOf(input.proof, input.proof_passes), input.review === ""
|
|
374
|
+
: `${COMPANION_LEAD} the fix of the card is built on it, and EDGAR's note below links the fix. Why the fix needs it: ${input.first}`, ...notes, ...proofOf(input.checks, input.not_verified), ...ownProofOf(input.proof, input.proof_passes), input.review.trim() === ""
|
|
347
375
|
? ""
|
|
348
|
-
: `Before I opened this, a second model reviewed the change
|
|
376
|
+
: section("Review", `Before I opened this, a second model reviewed the change.\n\n${input.review.trim()}`), `edgar-operation: ${ctx.operation_id}`);
|
|
349
377
|
const labels = [...new Set([...settings.data.pr_labels, ...(input.labels ?? [])])];
|
|
350
378
|
const made = await github(ctx, "POST", `/repos/${repo.value}/pulls`, pull, {
|
|
351
379
|
title: titleOf(input.title, input.card),
|
package/edgar-extension.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"contract": 1,
|
|
3
3
|
"name": "github",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.7",
|
|
5
5
|
"config_schema": "schemas/config.json",
|
|
6
6
|
"secrets": [
|
|
7
7
|
{
|
|
@@ -252,6 +252,30 @@
|
|
|
252
252
|
"approval": "never",
|
|
253
253
|
"disabled": false
|
|
254
254
|
},
|
|
255
|
+
{
|
|
256
|
+
"name": "code_owners",
|
|
257
|
+
"description": "Find who should review a pull request: the owners that CODEOWNERS names for its files, else the at most two people who changed those files most and most recently in the last 12 months, never a bot or its author; skipped when there is none",
|
|
258
|
+
"input_schema": "schemas/code_owners.in.json",
|
|
259
|
+
"output_schema": "schemas/code_owners.out.json",
|
|
260
|
+
"secrets": ["GITHUB_TOKEN"],
|
|
261
|
+
"capabilities": ["network:api.github.com"],
|
|
262
|
+
"side_effect": false,
|
|
263
|
+
"approval": "never",
|
|
264
|
+
"disabled": false
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
"name": "request_reviewers",
|
|
268
|
+
"description": "Ask people and teams to review a pull request; skipped when there is no one to ask or GitHub cannot ask them",
|
|
269
|
+
"input_schema": "schemas/request_reviewers.in.json",
|
|
270
|
+
"output_schema": "schemas/request_reviewers.out.json",
|
|
271
|
+
"secrets": ["GITHUB_TOKEN"],
|
|
272
|
+
"capabilities": ["network:api.github.com"],
|
|
273
|
+
"side_effect": true,
|
|
274
|
+
"undo": "none",
|
|
275
|
+
"undo_reason": "A review request only asks; the people asked are still the right ones when a later stage is undone.",
|
|
276
|
+
"approval": "never",
|
|
277
|
+
"disabled": false
|
|
278
|
+
},
|
|
255
279
|
{
|
|
256
280
|
"name": "dependabot_alerts",
|
|
257
281
|
"description": "Read the Dependabot alerts of a repository, or one alert by number: package, severity, vulnerable range, first patched version, manifest and advisory ids",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kana-ai/edgar-ext-github",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "EDGAR extension for GitHub: push edgar/ branches, open, watch, close and merge pull requests, and track GitHub issues as cards.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
".": "./dist/src/index.js"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@kana-ai/edgar-contracts": "0.1.
|
|
27
|
-
"@kana-ai/edgar-sdk": "0.1.
|
|
26
|
+
"@kana-ai/edgar-contracts": "0.1.7",
|
|
27
|
+
"@kana-ai/edgar-sdk": "0.1.7",
|
|
28
28
|
"zod": "4.6.7"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"properties": {
|
|
5
|
+
"source": {
|
|
6
|
+
"type": "string",
|
|
7
|
+
"enum": ["codeowners", "history"],
|
|
8
|
+
"description": "codeowners: the CODEOWNERS file names them; history: they changed the files most, and most recently"
|
|
9
|
+
},
|
|
10
|
+
"reviewers": {
|
|
11
|
+
"type": "array",
|
|
12
|
+
"items": {
|
|
13
|
+
"type": "string"
|
|
14
|
+
},
|
|
15
|
+
"description": "the login of each person"
|
|
16
|
+
},
|
|
17
|
+
"team_reviewers": {
|
|
18
|
+
"type": "array",
|
|
19
|
+
"items": {
|
|
20
|
+
"type": "string"
|
|
21
|
+
},
|
|
22
|
+
"description": "the slug of each team that CODEOWNERS names"
|
|
23
|
+
},
|
|
24
|
+
"who_can_act": {
|
|
25
|
+
"minItems": 1,
|
|
26
|
+
"type": "array",
|
|
27
|
+
"items": {
|
|
28
|
+
"type": "object",
|
|
29
|
+
"properties": {
|
|
30
|
+
"github": {
|
|
31
|
+
"description": "the login of a person",
|
|
32
|
+
"type": "string"
|
|
33
|
+
},
|
|
34
|
+
"name": {
|
|
35
|
+
"description": "a team, as @org/slug",
|
|
36
|
+
"type": "string"
|
|
37
|
+
},
|
|
38
|
+
"why": {
|
|
39
|
+
"type": "string"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"required": ["why"]
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"required": ["source", "reviewers", "team_reviewers", "who_can_act"]
|
|
47
|
+
}
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"card": {
|
|
37
|
-
"description": "the run's card: the title becomes `<id>: <title>`, and the body opens with its link",
|
|
37
|
+
"description": "the run's card: the title becomes `<id>: <title>`, at most 72 characters with a trailing `[tag]` kept whole, and the body opens with its link",
|
|
38
38
|
"type": "object",
|
|
39
39
|
"properties": {
|
|
40
40
|
"id": {
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
79
|
"checks": {
|
|
80
|
-
"description": "the output of a check stage: the body lists each check that passed under Verified, saying when it passed only on its second run, and each other check under Not verified, with a failure that the check gave on the base commit too named as one the change did not cause",
|
|
80
|
+
"description": "the output of a check stage: the body lists each check that passed under Verified, saying when it passed only on its second run, and each other check under Not verified, with a failure that the check gave on the base commit too named as one the change did not cause, and the changed files each check covers, or that it covers none, when the check says which paths it covers",
|
|
81
81
|
"type": "object",
|
|
82
82
|
"properties": {
|
|
83
83
|
"results": {
|
|
@@ -108,6 +108,12 @@
|
|
|
108
108
|
"type": "integer",
|
|
109
109
|
"exclusiveMinimum": 0,
|
|
110
110
|
"maximum": 9007199254740991
|
|
111
|
+
},
|
|
112
|
+
"covered": {
|
|
113
|
+
"type": "array",
|
|
114
|
+
"items": {
|
|
115
|
+
"type": "string"
|
|
116
|
+
}
|
|
111
117
|
}
|
|
112
118
|
},
|
|
113
119
|
"required": ["check", "exit_code"]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"properties": {
|
|
5
|
+
"url": {
|
|
6
|
+
"type": "string",
|
|
7
|
+
"minLength": 1
|
|
8
|
+
},
|
|
9
|
+
"reviewers": {
|
|
10
|
+
"type": "array",
|
|
11
|
+
"items": {
|
|
12
|
+
"type": "string",
|
|
13
|
+
"minLength": 1
|
|
14
|
+
},
|
|
15
|
+
"description": "the login of each person to ask"
|
|
16
|
+
},
|
|
17
|
+
"team_reviewers": {
|
|
18
|
+
"type": "array",
|
|
19
|
+
"items": {
|
|
20
|
+
"type": "string",
|
|
21
|
+
"minLength": 1
|
|
22
|
+
},
|
|
23
|
+
"description": "the slug of each team to ask"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"required": ["url", "reviewers", "team_reviewers"]
|
|
27
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"properties": {
|
|
5
|
+
"url": {
|
|
6
|
+
"type": "string"
|
|
7
|
+
},
|
|
8
|
+
"requested": {
|
|
9
|
+
"type": "array",
|
|
10
|
+
"items": {
|
|
11
|
+
"type": "string"
|
|
12
|
+
},
|
|
13
|
+
"description": "each login and team slug that GitHub now asks"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"required": ["url", "requested"]
|
|
17
|
+
}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"type": "string"
|
|
15
15
|
},
|
|
16
16
|
"card": {
|
|
17
|
-
"description": "the run's card: the title becomes `<id>: <title>`, and the body opens with its link",
|
|
17
|
+
"description": "the run's card: the title becomes `<id>: <title>`, at most 72 characters with a trailing `[tag]` kept whole, and the body opens with its link",
|
|
18
18
|
"type": "object",
|
|
19
19
|
"properties": {
|
|
20
20
|
"id": {
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
59
|
"checks": {
|
|
60
|
-
"description": "the output of a check stage: the body lists each check that passed under Verified, saying when it passed only on its second run, and each other check under Not verified, with a failure that the check gave on the base commit too named as one the change did not cause",
|
|
60
|
+
"description": "the output of a check stage: the body lists each check that passed under Verified, saying when it passed only on its second run, and each other check under Not verified, with a failure that the check gave on the base commit too named as one the change did not cause, and the changed files each check covers, or that it covers none, when the check says which paths it covers",
|
|
61
61
|
"type": "object",
|
|
62
62
|
"properties": {
|
|
63
63
|
"results": {
|
|
@@ -88,6 +88,12 @@
|
|
|
88
88
|
"type": "integer",
|
|
89
89
|
"exclusiveMinimum": 0,
|
|
90
90
|
"maximum": 9007199254740991
|
|
91
|
+
},
|
|
92
|
+
"covered": {
|
|
93
|
+
"type": "array",
|
|
94
|
+
"items": {
|
|
95
|
+
"type": "string"
|
|
96
|
+
}
|
|
91
97
|
}
|
|
92
98
|
},
|
|
93
99
|
"required": ["check", "exit_code"]
|