@framers/agentos-ext-github 0.7.0 → 0.8.0
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 +33 -3
- package/dist/__tests__/links.test.d.ts +8 -0
- package/dist/__tests__/links.test.d.ts.map +1 -0
- package/dist/__tests__/links.test.js +182 -0
- package/dist/__tests__/links.test.js.map +1 -0
- package/dist/__tests__/refs.test.d.ts +7 -0
- package/dist/__tests__/refs.test.d.ts.map +1 -0
- package/dist/__tests__/refs.test.js +420 -0
- package/dist/__tests__/refs.test.js.map +1 -0
- package/dist/documents/GitHubDocumentsConnector.d.ts +74 -17
- package/dist/documents/GitHubDocumentsConnector.d.ts.map +1 -1
- package/dist/documents/GitHubDocumentsConnector.js +118 -20
- package/dist/documents/GitHubDocumentsConnector.js.map +1 -1
- package/dist/documents/index.d.ts +16 -6
- package/dist/documents/index.d.ts.map +1 -1
- package/dist/documents/index.js +16 -6
- package/dist/documents/index.js.map +1 -1
- package/dist/documents/links.d.ts +50 -0
- package/dist/documents/links.d.ts.map +1 -0
- package/dist/documents/links.js +216 -0
- package/dist/documents/links.js.map +1 -0
- package/dist/documents/tree.d.ts +44 -0
- package/dist/documents/tree.d.ts.map +1 -1
- package/dist/documents/tree.js +68 -0
- package/dist/documents/tree.js.map +1 -1
- package/manifest.json +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -351,7 +351,7 @@ Top-level pull request comments use the issues API. `github_pr_comment_list` ret
|
|
|
351
351
|
|
|
352
352
|
The `./documents` entry reads repositories through a GitHub App instead of one personal token. Every call goes to GitHub's REST API over the `fetch` you pass (the global `fetch` by default) with `X-GitHub-Api-Version: 2026-03-10`, so tests point it at a stand-in with `{ fetchImpl, apiBase }`.
|
|
353
353
|
|
|
354
|
-
A repository is read by its id, at `/repositories/<id>/branches/<branch>`, `/repositories/<id>/git/trees/<sha>` and `/repositories/<id>/
|
|
354
|
+
A repository is read by its id, at `/repositories/<id>/branches/<branch>`, `/repositories/<id>/git/trees/<sha>`, `/repositories/<id>/contents/<path>` and `/repositories/<id>/git/matching-refs/heads/<name>`, the address GitHub's own redirects for a renamed or moved repository lead to, and never by its name. A name can come to mean another repository: a renamed repository's old name can be taken again, and an account's old login claimed by another account, which ends GitHub's redirects to it; and GitHub answers a public repository's branch, tree and files to any token, an installation token narrowed to other repositories included. The full name builds a read's attribution link and nothing else.
|
|
355
355
|
|
|
356
356
|
```ts
|
|
357
357
|
import { readFileSync } from 'node:fs';
|
|
@@ -450,9 +450,11 @@ Every call runs under a deadline, 30 seconds by default (`GITHUB_TIMEOUT_MS`), i
|
|
|
450
450
|
| `verifyWebhookSignature(body, header, secret)` | Checks `X-Hub-Signature-256` against the HMAC SHA-256 of the raw body in constant time; an empty or missing secret throws a `TypeError`, since anyone can sign a delivery under an empty key |
|
|
451
451
|
| `readWebhookRequest(request, secret, { maxBytes })`, `readWebhookDelivery({ headers, body }, secret, { maxBytes })` | Read a delivery under a cap, check its signature and id, and answer it as a typed event, or throw `WebhookDeliveryRefused` with its reason |
|
|
452
452
|
| `reconcileInstallations(credential, links, { since })` | Answers the linked installations GitHub no longer has (`gone`: missing from the listing and answered 404 at their own address, since an installation removed while the listing is read can move another past a page's end), those GitHub has suspended (`suspended`, whose repositories it does not read), the repositories whose default branch moved past the head last read, the repositories it could not read, and asks again for each event since `since` that no delivery attempt delivered, reporting GitHub's refusals of that step in `deliveries`; a rate limit ends it, with `retryAt` |
|
|
453
|
-
| `GitHubDocumentsConnector` | An `AccountSourceConnector` of `@framers/agentos-ext-account-sources` over one installation's linked repositories |
|
|
453
|
+
| `GitHubDocumentsConnector` | An `AccountSourceConnector` of `@framers/agentos-ext-account-sources` over one installation's linked repositories, at each one's default branch or at the branch or commit a selection's `at` names; `resolveRef(repositoryId, refAndPath)` settles where a link's branch name ends |
|
|
454
|
+
| `parseGitHubLink(text)` | The repository, folder or file a GitHub address names, read without a request; `refused` for any other address on GitHub's hosts, `null` for another host's |
|
|
454
455
|
| `readTree`, `pathFilter`, `TreeTooLarge` | A tree at a commit within a request budget, `readTree(fetchImpl, token, repositoryId, commit)` reading the repository by its id (a full name is taken too, and reads whatever repository holds that name; a number that is not a positive integer is a `TypeError` before any request), and the filter that keeps documentation, and code when asked (`includeCode`); `TreeTooLarge` carries `reason`, `budget` or `truncated` |
|
|
455
456
|
| `CODE_EXTENSIONS`, `GENERATED_CODE_ENDINGS`, `isGeneratedCode(path)` | The source files a filter that includes code keeps, and the endings of the code files a tool writes (minified and bundled files, generated Protocol Buffers and Dart files), which it leaves out |
|
|
457
|
+
| `planTree(blobs, options)`, `IMAGE_EXTENSIONS` | Every file of a tree with its outcome under `pathFilter`'s filter: a note, or skipped with the reason it is left out |
|
|
456
458
|
| `GitHubApiError` | An answer outside 2xx; carries the status, `rateLimited` and `retryAt`, and nothing of the body |
|
|
457
459
|
| `GitHubListingChanged` | An installation's repositories changed during each of three reads of their listing (its pages disagreed on `total_count`), so no read is whole; its message names nothing of the installation |
|
|
458
460
|
| `GitHubNoAnswer` | A call that got no answer, by its `reason`: `timeout`, `cancelled` or `network` |
|
|
@@ -474,10 +476,38 @@ The connector's filter, `new GitHubDocumentsConnector(credential, installationId
|
|
|
474
476
|
| `maxFileBytes` | `10485760` (10 MiB): larger files are left out of a listing, and a read past it is answered gone |
|
|
475
477
|
| `maxTreeRequests` | `50` tree requests to list one commit |
|
|
476
478
|
|
|
477
|
-
An item's id is `<repositoryId>:<path>` and its version `<blob>@<commit>`. A tree is asked for recursively; when GitHub answers it truncated (past 100,000 entries or 7 MB), its top level is read and each subtree is asked for the same way, never walking a skipped folder. `TreeTooLarge` is thrown rather than pass `maxTreeRequests` (`reason: 'budget'`), and at a level GitHub answers truncated when it is asked for alone as well (`reason: 'truncated'`), before any folder under it is asked for: no part of a tree is answered, since the files it left out would read as removed. Files are read through the contents endpoint's raw media type as a stream cut at `maxFileBytes`: PDF, Word and HTML as bytes with their media type, the rest as UTF-8 text, each with a `github` source reference whose `url` is the file at the commit, the commit or branch encoded segment by segment as the path is, so a branch named `docs#1` links as `docs%231`. An item whose version names no commit (none, or no `@<commit>` part) is read at the default branch, and its reference names the branch. `changesSince` takes the cursor it answered last (each documentation path's blob), never reads a push's commit list, so a force push is read like any other, and answers a push to another branch than the
|
|
479
|
+
An item's id is `<repositoryId>:<path>` and its version `<blob>@<commit>`. A tree is asked for recursively; when GitHub answers it truncated (past 100,000 entries or 7 MB), its top level is read and each subtree is asked for the same way, never walking a skipped folder. `TreeTooLarge` is thrown rather than pass `maxTreeRequests` (`reason: 'budget'`), and at a level GitHub answers truncated when it is asked for alone as well (`reason: 'truncated'`), before any folder under it is asked for: no part of a tree is answered, since the files it left out would read as removed. Files are read through the contents endpoint's raw media type as a stream cut at `maxFileBytes`: PDF, Word and HTML as bytes with their media type, the rest as UTF-8 text, each with a `github` source reference whose `url` is the file at the commit, the commit or branch encoded segment by segment as the path is, so a branch named `docs#1` links as `docs%231`. An item whose version names no commit (none, or no `@<commit>` part) is read at the default branch, and its reference names the branch. `changesSince` takes the cursor it answered last (each documentation path's blob), never reads a push's commit list, so a force push is read like any other, and answers a push to another branch than the one it follows with no change. `listing(repositoryId, commit)` lets a caller keep a commit's listing and pass it to `changesSince` as `listing`, with that commit as `after`; it then reads no tree. A cursor `changesSince` did not answer throws a `TypeError` that quotes none of it, whatever the push's branch. A file read GitHub refuses for a rate limit throws `GitHubApiError` with its `retryAt`, never an answer that the file is gone, and so does a refused installation token (404 for an installation GitHub no longer has): only the contents read's own 404 answers a file `removed`, so a lost installation never reads as every file gone.
|
|
478
480
|
|
|
479
481
|
The connector refuses, before any request, what it cannot answer whole, and no refusal quotes a cursor, an item id or a path. A repository id, in a selection or in an item id, is a positive integer in decimal (`77`; never `077`, `0x4d` or ` 77`), else a `TypeError`. `list` checks every id of its selection before it reads any repository, so a selection is listed whole or not at all: a repository named twice is a `TypeError`, and one outside the link an `Error` naming its number. `read` throws a `TypeError` for an item id that names no file: one without a path, or whose path has an empty, `.` or `..` segment. `changesSince` compares one repository a call: a selection of none or several, an empty `after`, or a `listing` without the `after` commit it was read at is a `TypeError`, so call it once per repository, each with that repository's own cursor. A call whose signal is already aborted throws `GitHubNoAnswer` (`cancelled`) before it checks anything else, so every aborted call answers alike, whatever its inputs.
|
|
480
482
|
|
|
483
|
+
`list`, `changesSince` and `head` follow the default branch, or the branch or commit a selection's `at` names (`head(repositoryId, at, signal)`; `head(repositoryId, signal)` reads the default branch as before). A branch's head is read when the call is made; a commit, 40 hexadecimal characters in either case, is read as it is with no branch read, in lower case, and never changes. `list({ ids: [String(repositoryId)], at: 'release/1.0' })` lists one repository at that branch's head, each item's version `<blob>@<commit>` at it. `changesSince` compares at the followed branch's head when the call names no `after`, answers a push whose `ref` is not `refs/heads/<at>` with no change (the default branch's push included, while `at` names another branch), and answers any push with no change when `at` is a commit; without a push, an `after` naming another commit than `at`'s is a `TypeError`. An `at` that is neither a commit nor a branch name by [git's rules](https://git-scm.com/docs/git-check-ref-format) (no `..`, `@{`, space, control character, `~`, `^`, `:`, `?`, `*`, `[` or `\`; no part empty, starting with a dot or ending in `.lock`; not ending with a dot, not starting with a dash, neither `@` nor `HEAD`), and an `at` beside other than one repository in `list`, throw a `TypeError` before any request.
|
|
484
|
+
|
|
485
|
+
`parseGitHubLink(text)` reads the GitHub address a person pastes, without a request:
|
|
486
|
+
|
|
487
|
+
| Address | Answered as |
|
|
488
|
+
| --- | --- |
|
|
489
|
+
| `github.com/<owner>/<repo>`, with or without `.git`; `git@github.com:<owner>/<repo>.git` | `{ kind: 'github_repository', owner, repo }` |
|
|
490
|
+
| `github.com/<owner>/<repo>/tree/<ref>/<path>`, and `/blob/<ref>` with no path, which GitHub shows as the folder | `{ kind: 'github_folder', owner, repo, refAndPath }` |
|
|
491
|
+
| `github.com/<owner>/<repo>/blob/<ref>/<path>` and `/raw/<ref>/<path>`; `raw.githubusercontent.com/<owner>/<repo>/<ref>/<path>` | `{ kind: 'github_file', owner, repo, refAndPath, raw }`, `raw` true for the two raw forms |
|
|
492
|
+
| Any other address on `github.com`, `www.github.com`, `gist.github.com`, `api.github.com`, `codeload.github.com`, `uploads.github.com` or a host under `githubusercontent.com`: an account, an issue, a pull request, a wiki, a release, a commit, a tag (`refs/tags/`), a gist, GitHub's own pages, an address that carries credentials, with a scheme or without one (`<user>:<password>@github.com/...`, which a browser opens as an `https://` address) | `{ kind: 'refused' }` |
|
|
493
|
+
| An address on any other host, an opaque address such as `mailto:someone@github.com`, and text that is no address | `null` |
|
|
494
|
+
|
|
495
|
+
The scheme, or its absence, a port, the dots that end a host (`github.com.`, `github.com..`), a trailing slash, a query and a fragment are ignored; `www.github.com` is read as `github.com`, and GitHub's form of a branch by its full name, `refs/heads/<branch>`, as the branch. Each segment is decoded, and an address whose path has an empty segment, an escape that does not decode, or a `.` or `..` segment or a control character once decoded is refused. A folder's and a file's ref and path are one text, `refAndPath`, since a branch name may hold a slash. `connector.resolveRef(repositoryId, refAndPath)` settles it as `{ ref, path, commit }`: a first segment of 40 hexadecimal characters is a commit (`commit: true`, in lower case) and `HEAD` the default branch, with no request; otherwise one request to GitHub's [matching references](https://docs.github.com/en/rest/git/refs#list-matching-references), which answers every branch whose name starts with that segment, and the longest branch name that is the text or starts it at a slash is the ref, the rest the path (`''` for the ref's root). Git keeps no branch beside one under its name (`release` beside `release/1.0`), so at most one such branch exists. A first segment no branch has is answered as the ref all the same, and a listing at it throws GitHub's 404 as `GitHubApiError`; so does 409 for a repository with no commit. A `/blob/` address whose text has no slash (`/blob/main`) names its ref alone and is answered as the folder, since GitHub redirects it to `/tree/main`; one whose text has a slash is a file, and when `resolveRef` settles the whole text as the ref (`/blob/release/1.0` in a repository with a `release/1.0` branch), the path is `''`: the address names a ref and no file, which GitHub answers 404.
|
|
496
|
+
|
|
497
|
+
```ts
|
|
498
|
+
import { parseGitHubLink } from '@framers/agentos-ext-github/documents';
|
|
499
|
+
|
|
500
|
+
const link = parseGitHubLink('https://github.com/acme-team/handbook/tree/release/1.0/docs');
|
|
501
|
+
if (link?.kind === 'github_folder') {
|
|
502
|
+
// repositoryId: the linked repository whose full name is `${link.owner}/${link.repo}`.
|
|
503
|
+
const { ref, path } = await connector.resolveRef(repositoryId, link.refAndPath); // 'release/1.0' and 'docs'
|
|
504
|
+
const { items } = await connector.list({ ids: [String(repositoryId)], at: ref });
|
|
505
|
+
const inFolder = items.filter((item) => path === '' || item.title.startsWith(`${path}/`));
|
|
506
|
+
}
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
`planTree(blobs, options)` answers every file of a tree (`readTree`'s blobs) in path order, each a new object with its `path`, `sha`, `size` and `outcome`: `'note'`, or `{ skipped }` with the first reason the file is left out. `folder` under a skipped folder; `kind` for a file that is neither documentation, code nor an image (data, configuration, a binary, a file with no extension); `image` for `IMAGE_EXTENSIONS`, or the `imageExtensions` given; `code` for code while `includeCode` is off; `generated` for code a tool wrote while `includeCode` is on; `size` past `maxFileBytes`, or past `maxCodeBytes` for a file of a code extension while `includeCode` is on, whatever `extensions` names (`maxFileBytes` when absent, a non-negative integer, else a `TypeError`); `count` past `maxFiles`, the documentation keeping its places first and the code taking the room left. The notes are exactly what `pathFilter` keeps under the same filter, a code file past `maxCodeBytes` aside, so a caller can show what is left out and why from one listing, and turn code on or off without reading the tree again. An extension the filter's `extensions` names is documentation, an image's included.
|
|
510
|
+
|
|
481
511
|
## License
|
|
482
512
|
|
|
483
513
|
Apache-2.0
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview `parseGitHubLink` over the addresses a person pastes: a repository, a folder and a file on github.com and
|
|
3
|
+
* a file on raw.githubusercontent.com, each with and without `.git`, a trailing slash, a fragment and a query, under
|
|
4
|
+
* http, with a port and without a scheme; the GitHub addresses the pack does not read, each refused and never answered
|
|
5
|
+
* as another site's; and the addresses of other hosts, which are not GitHub's.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=links.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"links.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/links.test.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview `parseGitHubLink` over the addresses a person pastes: a repository, a folder and a file on github.com and
|
|
3
|
+
* a file on raw.githubusercontent.com, each with and without `.git`, a trailing slash, a fragment and a query, under
|
|
4
|
+
* http, with a port and without a scheme; the GitHub addresses the pack does not read, each refused and never answered
|
|
5
|
+
* as another site's; and the addresses of other hosts, which are not GitHub's.
|
|
6
|
+
*/
|
|
7
|
+
import { describe, expect, it } from 'vitest';
|
|
8
|
+
import { parseGitHubLink } from '../documents/index.js';
|
|
9
|
+
const COMMIT = '9f2c4e6a'.repeat(5);
|
|
10
|
+
const REPOSITORY = { kind: 'github_repository', owner: 'acme-team', repo: 'handbook' };
|
|
11
|
+
const REFUSED = { kind: 'refused' };
|
|
12
|
+
/** A folder of the handbook at `refAndPath`. */
|
|
13
|
+
function folder(refAndPath) {
|
|
14
|
+
return { kind: 'github_folder', owner: 'acme-team', repo: 'handbook', refAndPath };
|
|
15
|
+
}
|
|
16
|
+
/** A file of the handbook at `refAndPath`, raw when the address served its bytes alone. */
|
|
17
|
+
function file(refAndPath, raw = false) {
|
|
18
|
+
return { kind: 'github_file', owner: 'acme-team', repo: 'handbook', refAndPath, raw };
|
|
19
|
+
}
|
|
20
|
+
describe('parseGitHubLink', () => {
|
|
21
|
+
it('reads a repository whatever its scheme, port, .git, trailing slash, query or fragment', () => {
|
|
22
|
+
const forms = [
|
|
23
|
+
'https://github.com/acme-team/handbook',
|
|
24
|
+
'https://github.com/acme-team/handbook/',
|
|
25
|
+
'https://github.com/acme-team/handbook.git',
|
|
26
|
+
'https://github.com/acme-team/handbook.git/',
|
|
27
|
+
'https://github.com/acme-team/handbook#readme',
|
|
28
|
+
'https://github.com/acme-team/handbook?tab=readme-ov-file',
|
|
29
|
+
'http://github.com/acme-team/handbook',
|
|
30
|
+
'https://github.com:8443/acme-team/handbook',
|
|
31
|
+
'https://www.github.com/acme-team/handbook',
|
|
32
|
+
'HTTPS://GitHub.COM/acme-team/handbook',
|
|
33
|
+
' https://github.com/acme-team/handbook\n',
|
|
34
|
+
'github.com/acme-team/handbook',
|
|
35
|
+
'github.com:8443/acme-team/handbook/',
|
|
36
|
+
'//github.com/acme-team/handbook',
|
|
37
|
+
'git://github.com/acme-team/handbook.git',
|
|
38
|
+
'ssh://git@github.com/acme-team/handbook.git',
|
|
39
|
+
'git@github.com:acme-team/handbook.git',
|
|
40
|
+
'https://github.com./acme-team/handbook',
|
|
41
|
+
// An address's host may end in more than one dot (https://url.spec.whatwg.org/#host-parsing keeps them all).
|
|
42
|
+
'https://github.com../acme-team/handbook',
|
|
43
|
+
'github.com...:8443/acme-team/handbook',
|
|
44
|
+
];
|
|
45
|
+
for (const form of forms)
|
|
46
|
+
expect(parseGitHubLink(form), form).toEqual(REPOSITORY);
|
|
47
|
+
});
|
|
48
|
+
it("reads a folder's ref and path as one text, a branch's own slashes included, for the connector to settle", () => {
|
|
49
|
+
const forms = [
|
|
50
|
+
['https://github.com/acme-team/handbook/tree/release/1.0/docs', folder('release/1.0/docs')],
|
|
51
|
+
['https://github.com/acme-team/handbook/tree/release/1.0/docs/', folder('release/1.0/docs')],
|
|
52
|
+
['https://github.com/acme-team/handbook/tree/release/1.0/docs#top', folder('release/1.0/docs')],
|
|
53
|
+
['https://github.com/acme-team/handbook/tree/release/1.0/docs?plain=1', folder('release/1.0/docs')],
|
|
54
|
+
['http://github.com:80/acme-team/handbook/tree/main/docs', folder('main/docs')],
|
|
55
|
+
['github.com/acme-team/handbook/tree/main/docs', folder('main/docs')],
|
|
56
|
+
['https://github.com/acme-team/handbook.git/tree/main/docs', folder('main/docs')],
|
|
57
|
+
['https://github.com/acme-team/handbook/tree/main', folder('main')],
|
|
58
|
+
// GitHub's own form of a branch by its full name, read as the branch.
|
|
59
|
+
['https://github.com/acme-team/handbook/tree/refs/heads/release/1.0/docs', folder('release/1.0/docs')],
|
|
60
|
+
// Each segment decoded: a branch holding a "#", a folder holding a space.
|
|
61
|
+
['https://github.com/acme-team/handbook/tree/docs%231/guide%20one', folder('docs#1/guide one')],
|
|
62
|
+
[`https://github.com/acme-team/handbook/tree/${COMMIT}/docs`, folder(`${COMMIT}/docs`)],
|
|
63
|
+
// GitHub shows the folder for a blob address that names no path.
|
|
64
|
+
['https://github.com/acme-team/handbook/blob/main', folder('main')],
|
|
65
|
+
];
|
|
66
|
+
for (const [form, link] of forms)
|
|
67
|
+
expect(parseGitHubLink(form), form).toEqual(link);
|
|
68
|
+
});
|
|
69
|
+
it("reads a file on github.com and on raw.githubusercontent.com, GitHub's raw addresses marked raw", () => {
|
|
70
|
+
const forms = [
|
|
71
|
+
['https://github.com/acme-team/handbook/blob/main/docs/agenda.md', file('main/docs/agenda.md')],
|
|
72
|
+
['https://github.com/acme-team/handbook/blob/main/docs/agenda.md#L3-L4', file('main/docs/agenda.md')],
|
|
73
|
+
['https://github.com/acme-team/handbook/blob/main/docs/agenda.md?plain=1', file('main/docs/agenda.md')],
|
|
74
|
+
['http://www.github.com/acme-team/handbook/blob/main/docs/agenda.md', file('main/docs/agenda.md')],
|
|
75
|
+
[`https://github.com/acme-team/handbook/blob/${COMMIT}/docs/agenda.md`, file(`${COMMIT}/docs/agenda.md`)],
|
|
76
|
+
['https://github.com/acme-team/handbook/blob/refs/heads/main/docs/agenda.md', file('main/docs/agenda.md')],
|
|
77
|
+
['https://github.com/acme-team/handbook/raw/main/docs/agenda.md', file('main/docs/agenda.md', true)],
|
|
78
|
+
['https://github.com/acme-team/handbook/raw/refs/heads/main/docs/agenda.md', file('main/docs/agenda.md', true)],
|
|
79
|
+
['https://raw.githubusercontent.com/acme-team/handbook/main/docs/agenda.md', file('main/docs/agenda.md', true)],
|
|
80
|
+
['https://raw.githubusercontent.com/acme-team/handbook/refs/heads/main/docs/agenda.md', file('main/docs/agenda.md', true)],
|
|
81
|
+
['http://raw.githubusercontent.com:8443/acme-team/handbook/main/README.md', file('main/README.md', true)],
|
|
82
|
+
['raw.githubusercontent.com/acme-team/handbook/main/README.md', file('main/README.md', true)],
|
|
83
|
+
// The text may be a branch alone (release/1.0): resolveRef settles it, answering an empty path for a ref alone.
|
|
84
|
+
['https://github.com/acme-team/handbook/blob/release/1.0', file('release/1.0')],
|
|
85
|
+
];
|
|
86
|
+
for (const [form, link] of forms)
|
|
87
|
+
expect(parseGitHubLink(form), form).toEqual(link);
|
|
88
|
+
});
|
|
89
|
+
it('refuses a GitHub address that names no repository, folder or file the pack reads', () => {
|
|
90
|
+
const forms = [
|
|
91
|
+
'https://github.com/acme-team/handbook/issues/12',
|
|
92
|
+
'https://github.com/acme-team/handbook/pull/3',
|
|
93
|
+
'https://github.com/acme-team/handbook/pulls',
|
|
94
|
+
'https://github.com/acme-team/handbook/wiki',
|
|
95
|
+
'https://github.com/acme-team/handbook/wiki/Home',
|
|
96
|
+
'https://github.com/acme-team/handbook/releases',
|
|
97
|
+
'https://github.com/acme-team/handbook/releases/tag/v1.0',
|
|
98
|
+
'https://github.com/acme-team/handbook/actions',
|
|
99
|
+
`https://github.com/acme-team/handbook/commit/${COMMIT}`,
|
|
100
|
+
'https://github.com/acme-team/handbook/compare/main...release',
|
|
101
|
+
'https://github.com/acme-team/handbook/discussions/4',
|
|
102
|
+
'https://github.com/acme-team/handbook/tree',
|
|
103
|
+
'https://github.com/acme-team/handbook/blob',
|
|
104
|
+
'https://github.com/acme-team/handbook/raw/main',
|
|
105
|
+
'https://github.com/acme-team/handbook/tree/refs/tags/v1.0/docs',
|
|
106
|
+
'https://github.com/acme-team/handbook/tree/refs/pull/3/head',
|
|
107
|
+
'https://github.com/acme-team/handbook/tree/main//docs',
|
|
108
|
+
'https://github.com/acme-team/handbook/tree/main/%2E%2E%2Fsecret',
|
|
109
|
+
'https://github.com/acme-team/handbook/tree/main/a%00b',
|
|
110
|
+
'https://github.com/acme-team/hand%ZZbook',
|
|
111
|
+
'https://github.com/acme-team/hand%20book',
|
|
112
|
+
'https://github.com/acme-team/.git',
|
|
113
|
+
'https://github.com/-acme/handbook',
|
|
114
|
+
'https://github.com/acme-team',
|
|
115
|
+
'https://github.com',
|
|
116
|
+
'https://github.com/',
|
|
117
|
+
'https://github.com/settings/profile',
|
|
118
|
+
'https://github.com/orgs/acme-team',
|
|
119
|
+
'https://github.com/topics/python',
|
|
120
|
+
'https://github.com/marketplace/actions',
|
|
121
|
+
'https://github.com/sponsors/someone',
|
|
122
|
+
'https://gist.github.com/someone/0123abcd',
|
|
123
|
+
'https://api.github.com/repos/acme-team/handbook',
|
|
124
|
+
'https://codeload.github.com/acme-team/handbook/zip/refs/heads/main',
|
|
125
|
+
'https://gist.githubusercontent.com/someone/0123abcd/raw/notes.md',
|
|
126
|
+
'https://objects.githubusercontent.com/github-production-release-asset/1',
|
|
127
|
+
'https://raw.githubusercontent.com/acme-team/handbook',
|
|
128
|
+
'https://raw.githubusercontent.com/acme-team/handbook/main',
|
|
129
|
+
'https://ghp_secret@github.com/acme-team/handbook',
|
|
130
|
+
'https://someone:secret@github.com/acme-team/handbook',
|
|
131
|
+
'https://git:secret@github.com/acme-team/handbook',
|
|
132
|
+
'someone@github.com:acme-team/handbook.git',
|
|
133
|
+
'git@gist.github.com:0123abcd.git',
|
|
134
|
+
// Credentials before a GitHub host with no scheme, which a browser opens as an https address.
|
|
135
|
+
'x-access-token:ghs_secret@github.com/acme-team/handbook',
|
|
136
|
+
'someone:secret@github.com/acme-team/handbook/tree/main/docs',
|
|
137
|
+
'someone:secret@www.github.com:443/acme-team/handbook',
|
|
138
|
+
'someone:secret@raw.githubusercontent.com/acme-team/handbook/main/README.md',
|
|
139
|
+
];
|
|
140
|
+
for (const form of forms)
|
|
141
|
+
expect(parseGitHubLink(form), form).toEqual(REFUSED);
|
|
142
|
+
});
|
|
143
|
+
it('answers a GitHub host as a GitHub form or refused, never as another site, whatever the scheme, port, path or trailing dots', () => {
|
|
144
|
+
const hosts = ['github.com', 'www.github.com', 'gist.github.com', 'api.github.com', 'codeload.github.com', 'raw.githubusercontent.com', 'gist.githubusercontent.com'];
|
|
145
|
+
for (const host of hosts.flatMap((name) => [name, `${name}.`, `${name}..`])) {
|
|
146
|
+
for (const scheme of ['https://', 'http://', '']) {
|
|
147
|
+
for (const port of ['', ':8080']) {
|
|
148
|
+
for (const path of ['/', '/x', '/a/b/c/d/e/f', '/a/b/unknown/x', '/a/b?x=1#y']) {
|
|
149
|
+
const form = `${scheme}${host}${port}${path}`;
|
|
150
|
+
expect(parseGitHubLink(form), form).not.toBeNull();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
it("answers null for an address that is not GitHub's, and for text that is no address", () => {
|
|
157
|
+
const forms = [
|
|
158
|
+
'https://example.com/acme-team/handbook',
|
|
159
|
+
'https://docs.github.com/en/rest/git/refs',
|
|
160
|
+
'https://acme-team.github.io/handbook/',
|
|
161
|
+
'https://github.blog/changelog/',
|
|
162
|
+
'https://notgithub.com/acme-team/handbook',
|
|
163
|
+
'https://evilgithub.com/acme-team/handbook',
|
|
164
|
+
'https://github.com.example.org/acme-team/handbook',
|
|
165
|
+
'https://githubusercontent.com.example.org/acme-team/handbook',
|
|
166
|
+
'https://drive.google.com/file/d/1AbC/view',
|
|
167
|
+
'git@gitlab.com:acme-team/handbook.git',
|
|
168
|
+
'mailto:someone@github.com',
|
|
169
|
+
'javascript:alert(1)',
|
|
170
|
+
'not a link',
|
|
171
|
+
'',
|
|
172
|
+
' ',
|
|
173
|
+
];
|
|
174
|
+
for (const form of forms)
|
|
175
|
+
expect(parseGitHubLink(form), form).toBeNull();
|
|
176
|
+
});
|
|
177
|
+
it('refuses a value that is not text with a TypeError', () => {
|
|
178
|
+
expect(() => parseGitHubLink(42)).toThrow(TypeError);
|
|
179
|
+
expect(() => parseGitHubLink(null)).toThrow(TypeError);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
//# sourceMappingURL=links.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"links.test.js","sourceRoot":"","sources":["../../src/__tests__/links.test.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAmB,MAAM,uBAAuB,CAAC;AAEzE,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACpC,MAAM,UAAU,GAAe,EAAE,IAAI,EAAE,mBAAmB,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;AACnG,MAAM,OAAO,GAAe,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAEhD,gDAAgD;AAChD,SAAS,MAAM,CAAC,UAAkB;IAChC,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC;AACrF,CAAC;AAED,2FAA2F;AAC3F,SAAS,IAAI,CAAC,UAAkB,EAAE,GAAG,GAAG,KAAK;IAC3C,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC;AACxF,CAAC;AAED,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,uFAAuF,EAAE,GAAG,EAAE;QAC/F,MAAM,KAAK,GAAG;YACZ,uCAAuC;YACvC,wCAAwC;YACxC,2CAA2C;YAC3C,4CAA4C;YAC5C,8CAA8C;YAC9C,0DAA0D;YAC1D,sCAAsC;YACtC,4CAA4C;YAC5C,2CAA2C;YAC3C,uCAAuC;YACvC,2CAA2C;YAC3C,+BAA+B;YAC/B,qCAAqC;YACrC,iC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IAAyB,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview A link's ref settled through GitHub's matching references, a tree planned with what it leaves out and
|
|
3
|
+
* why, and a repository's documentation listed and compared at a named branch or commit, over a fetch stand-in that
|
|
4
|
+
* answers a repository's branches, references and trees and records each request.
|
|
5
|
+
*/
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=refs.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refs.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/refs.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|