@vite-hub/forge 0.1.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -7
- package/dist/{association-Cm0dUTDU-CDDhJnIh.js → association-Ds6Tgs0W-Cu9_YCGq.js} +1 -1
- package/dist/build/node.d.ts +12 -0
- package/dist/build/node.js +106 -0
- package/dist/build.d.ts +2 -0
- package/dist/build.js +2 -0
- package/dist/{events-saDWbqbf-VX_k8jtr.js → events-C6C7lk1x-J8VCAjEX.js} +4 -4
- package/dist/{events-DudKM7vq-Cj_PCDdt.js → events-DW3SFUDA-D2rhS9D-.js} +4 -4
- package/dist/{events-CeChclTf-CX-gD8oy.js → events-DjRw3KSr-C72gY7Vu.js} +4 -4
- package/dist/{events-CRaLy7U3-3PNNp5WZ.js → events-DmSWTdpS-BdJBABfI.js} +4 -4
- package/dist/{events-7EBoeIPd-A2RUkJi5.js → events-uCMi3LHU-Bz79PQtq.js} +4 -4
- package/dist/{feed-Dyf730Ys-D0HgBba6.js → feed-BlzdKdNv-DbxuSgsx.js} +4 -4
- package/dist/{feed-DsC7Vws1-M_de2nSK.js → feed-BwdcTgZq-Bm_c8br8.js} +4 -4
- package/dist/{feed-CmBoYS3Z-CuC4i0fH.js → feed-CIaAZINm-Dpe9DxwK.js} +4 -4
- package/dist/{forgejo-BN8ItCfl.js → forgejo-UNPc42cY.js} +50 -8
- package/dist/{gitee-DExkQP6X-BxJS2dRY.js → gitee-BXyl2_3W-dQOAjWqr.js} +2 -2
- package/dist/{github-DtncTfmv.js → github-CUiEF2FK.js} +65 -40
- package/dist/{gitlab-BoDm8-BC.js → gitlab-zvWb9zOi.js} +65 -8
- package/dist/{graphql-DG5aJBT3-DceyFYdM.js → graphql-BDhuP5jN-BSpB8lWf.js} +59 -7
- package/dist/identity-CNTWZZuv.d.ts +27 -0
- package/dist/identity-CmVEBLP5.js +38 -0
- package/dist/index.d.ts +332 -110
- package/dist/index.js +815 -313
- package/dist/{knot-BpyTK9D7-CVIsX4I2.js → knot-bGebBK_B-CeDHcJUz.js} +16 -9
- package/dist/{tangled-DPt_0u21-zS41xdG5.js → tangled-8lg_73Wi-bSufNXiN.js} +1 -1
- package/dist/{templates-Bn8a-pd2-D9DhJEVD.js → templates-BGDqQMu4-PSB43E1j.js} +2 -2
- package/dist/{utils-CA_4WJhJ-DNgT61X2.js → utils-DC7MBR65-B7Vr2hFm.js} +3 -306
- package/dist/{webhooks-DgHwxxYz-D1V2LOr1.js → webhooks-Bc6QhmI8-CNgCERCq.js} +326 -5
- package/package.json +19 -8
package/README.md
CHANGED
|
@@ -5,9 +5,36 @@
|
|
|
5
5
|
[](https://github.com/vite-hub/vitehub/blob/main/LICENSE)
|
|
6
6
|
[](https://vitehub.dev/docs)
|
|
7
7
|
|
|
8
|
-
`@vite-hub/forge` is the one Forge
|
|
8
|
+
`@vite-hub/forge` is the one Forge identity of ViteHub. Apps call `useForge()` to act as their GitHub App, or with their GitLab or Forgejo token. Channels, Capabilities, Workspaces and Sources read the same env names. It is built on [`forges`](https://forges.link). User docs: [Forge](https://vitehub.dev/docs/forge).
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
The GitHub Channel, the `forge()` Capability, and the Workspace GitHub store mint App installation tokens through `useForge()`. GitHub Sources use only `VITEHUB_GITHUB_TOKEN` (or `FORGES_GITHUB_TOKEN`). Channels, Workspaces and Sources list `@vite-hub/forge` as an optional peer and load it only on a Forge path, so an app without a Forge does not install it. Such an app that uses a Forge Channel, the `forge()` Capability, a GitHub Store or a GitHub Source fails with `INTERNAL_FORGE_NOT_INSTALLED` until it runs `pnpm add @vite-hub/forge`.
|
|
11
|
+
|
|
12
|
+
## Use it in an app
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @vite-hub/forge
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Import it from `vite-hub/forge`, which re-exports this package:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { useForge } from "vite-hub/forge"
|
|
22
|
+
|
|
23
|
+
const forge = useForge()
|
|
24
|
+
const [error, github] = await forge.provider({ repository: "acme/web" })
|
|
25
|
+
if (error) throw error
|
|
26
|
+
await github.request("POST", "/repos/acme/web/issues", { body: { title: "Nightly build failed" } })
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
| Call | Returns |
|
|
30
|
+
| --- | --- |
|
|
31
|
+
| `useForge({ forge, baseUrl, env, fetch, userAgent, conditionalRequests })` | The Forge of this deployment. `conditionalRequests: false` stops GitHub providers from revalidating repeated GETs with ETags. `forge` defaults to `"github"`. `env` defaults to the active Cloudflare bindings, then `process.env`. Throws `FORGE_MISSING_ENV` or `FORGE_INVALID_ENV` when the env cannot work. |
|
|
32
|
+
| `forge.kind`, `forge.auth`, `forge.baseUrl` | The Forge, `"app"` or `"token"`, and the API base. |
|
|
33
|
+
| `forge.token({ repository, installation, refresh, minLifetime, signal })` | `[error, { token, expiresAt }]`. With a GitHub App, an installation token for `installation`, such as `installation.id` of a webhook delivery, else for the owner of `repository` (see [Installations](https://vitehub.dev/docs/forge/configure#installations)), or for `VITEHUB_GITHUB_INSTALLATION_ID` without `repository`. Cached until `minLifetime` milliseconds (default one minute) before it expires. |
|
|
34
|
+
| `forge.provider({ repository, installation, refresh, minLifetime, signal })` | `[error, provider]`, a `forges` provider that sends `token()`. A GitHub provider has `graphql()`. |
|
|
35
|
+
| `forge.app({ signal })` | `[error, { id, slug, login }]` of the GitHub App. Throws `FORGE_NOT_APP` with a token. |
|
|
36
|
+
|
|
37
|
+
GitHub uses the App when `VITEHUB_GITHUB_APP_ID` is set, and `VITEHUB_GITHUB_TOKEN` otherwise. Runtime errors are `FORGE_APP_NOT_INSTALLED` and `FORGE_REQUEST_FAILED`. A cancelled call rejects with the abort reason. The codes are documented at [Forge limits and errors](https://vitehub.dev/docs/forge/limits-and-errors).
|
|
11
38
|
|
|
12
39
|
## Server Env
|
|
13
40
|
|
|
@@ -28,26 +55,36 @@ Each field reads its `VITEHUB_` name first, then the `FORGES_` name that the `fo
|
|
|
28
55
|
|
|
29
56
|
`GH_TOKEN` and `GITHUB_TOKEN` are not read. In GitHub Actions, set `VITEHUB_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}`.
|
|
30
57
|
|
|
58
|
+
## Build identity
|
|
59
|
+
|
|
60
|
+
`@vite-hub/forge/build/node` exports `readForgeBuild(root, env)`, the commit, branch, repository and pull request of a build, from the CI or host, else Git. `VITEHUB_BUILD_COMMIT`, `VITEHUB_BUILD_BRANCH` and `VITEHUB_BUILD_REPOSITORY` each replace their own field. `@vite-hub/forge/build` has no Node code and exports `buildMetaName`, `buildMetaContent(build)` and `parseBuildMeta(content)` for the `<meta name="vitehub:build">` tag. The tag is a claim; check it against the Forge. See [Name the build of a page](https://vitehub.dev/docs/forge/server-api#name-the-build-of-a-page).
|
|
61
|
+
|
|
31
62
|
## Public imports
|
|
32
63
|
|
|
64
|
+
`useForge()` is the app API. The other exports are the building blocks that ViteHub packages use.
|
|
65
|
+
|
|
33
66
|
| Import | Use |
|
|
34
67
|
| --- | --- |
|
|
68
|
+
| `useForge(options)` | The Forge identity of the app, as above. |
|
|
35
69
|
| `forgeEnv` | The Server Env table above. |
|
|
36
70
|
| `readForgeEnv(field, env)` | The first value set for one `forgeEnv` field, from an env record or a lookup function. |
|
|
37
|
-
| `forgeProvider(connection)` | A `forges` provider for one Forge. Return it from a public API only where that API owns the Forge credentials. A GitHub provider has `graphql()`. |
|
|
71
|
+
| `forgeProvider(connection)` | A `forges` provider for one Forge. Return it from a public API only where that API owns the Forge credentials. A GitHub provider has `graphql()`. GitHub providers revalidate repeated GETs with `If-None-Match`, so unchanged responses come back as `304`s that GitHub doesn't charge; `conditionalRequests: false` turns it off, and `{ identity, cache }` sets who shares entries and where they live. |
|
|
72
|
+
| `conditionalFetch(fetch, { identity, cache })`, `forgeMemoryCache({ maxSize, maxEntrySize })` | The `fetch` wrapper behind `conditionalRequests`, and its in-memory LRU. The default cache is shared by the process, holds up to 32 MiB of bodies, and skips bodies over 1 MiB. |
|
|
38
73
|
| `githubBranchRuleDetails(rules)` | GitHub only. Required workflows, ruleset merge methods and the classic protection source from the result of `provider.repos.branchRules()`. |
|
|
39
|
-
| `listReviewThreads(provider, pull)`, `getReviewThread(provider, id)` | GitHub only. List the review conversations of a pull request, or look up one by id. |
|
|
40
74
|
| `retargetPullRequest(provider, pull, base)` | GitHub only. Change the base branch of a pull request. |
|
|
75
|
+
| `forgeMerge(provider, pull, options)` | `threads.merge()` with `bypassRules`. GitHub only with `bypassRules: true`: merge past failing branch rules, as an admin or a ruleset bypass actor. It needs `method` and `sha`. |
|
|
41
76
|
| `ForgeApiError`, `ForgeTimeoutError`, `MergeBlockedError`, `NotFoundError`, `RateLimitedError`, `repoRef` | The bundled `forges` classes and helper. Import them from here, so that `instanceof` matches errors from `forgeProvider()`. |
|
|
42
77
|
| `githubAppCredentials(input)` | GitHub App installation tokens, installation lookup and App metadata. Tokens are cached until one minute before they expire. |
|
|
43
78
|
| `readGitHubAppPrivateKey(inline, path)` | Read a PEM key from a value or a file. |
|
|
79
|
+
| `githubInstallationRouting({ installationId, appOwner, appInstallations })` | Read the [installation routing](https://vitehub.dev/docs/forge/configure#installations) from Server Env values. Throws `FORGE_INVALID_ENV`. |
|
|
80
|
+
| `githubInstallationFor(routing, repository)` | The configured installation for `repository`, or `undefined` when GitHub must find it. |
|
|
44
81
|
| `forgeArchive(provider, repo, { ref, signal })` | The repository tree at `ref` as a `tar.gz` stream. GitHub only. Anonymous github.com reads go to `codeload.github.com` and do not use the API limit. |
|
|
45
82
|
| `forgeGitCredentials({ forge, baseUrl, token, repository })` | The Git smart HTTP remote and the basic auth pair for one repository. |
|
|
46
83
|
| `forgeGitAuthHeader(credentials)` | The `http.<remote>.extraheader` entry for `GIT_CONFIG_KEY_<n>` and `GIT_CONFIG_VALUE_<n>`. It keeps the token out of process arguments. |
|
|
47
84
|
| `forgeBlob(provider, repo, sha, { signal })` | The bytes of one blob by sha. GitHub only. |
|
|
48
85
|
| `forgeCommitFiles(provider, repo, input, options)` | `contents.commitFiles()` that can also set git file modes (`100644`, `100755`, `120000`). Returns the commit sha. |
|
|
49
86
|
| `BranchMovedError` | The bundled `forges` error for a branch that moved before a commit. |
|
|
50
|
-
| `forgeErrorStatus(error)`, `
|
|
87
|
+
| `forgeErrorStatus(error)`, `isForgeResponseError(error)` | Classify Forge request failures. |
|
|
51
88
|
| `withSignal(promise, signal)`, `abortError(signal)` | Cancellation helpers for Forge calls. |
|
|
52
89
|
|
|
53
90
|
## Diagnostics
|
|
@@ -61,7 +98,6 @@ Each field reads its `VITEHUB_` name first, then the `FORGES_` name that the `fo
|
|
|
61
98
|
| `FORGE_R0005` | `forgeCommitFiles()` received a file mode for a Forge other than GitHub. |
|
|
62
99
|
| `FORGE_R0006` | A GitHub-only helper got a provider for another Forge. |
|
|
63
100
|
| `FORGE_R0007` | `githubBranchRuleDetails()` got branch rules that are not complete GitHub rulesets or classic protection. |
|
|
64
|
-
| `FORGE_R0008` | GitHub did not return complete review threads. |
|
|
65
101
|
| `FORGE_R0009` | A GitHub-only helper got a reference that is not a numbered pull request, or an empty input. |
|
|
66
102
|
|
|
67
103
|
## Gaps in `forges`
|
|
@@ -75,5 +111,5 @@ Each field reads its `VITEHUB_` name first, then the `FORGES_` name that the `fo
|
|
|
75
111
|
| `forgeCommitFiles()` | `contents.commitFiles()` cannot set a file mode. |
|
|
76
112
|
| `forgeGitCredentials()`, `forgeGitAuthHeader()` | `Repo.cloneUrls` has no transport credential. |
|
|
77
113
|
| `githubBranchRuleDetails()` | `BranchRules` has no required workflows, ruleset merge methods or classic protection source. |
|
|
78
|
-
| `listReviewThreads()`, `getReviewThread()` | No review thread listing. |
|
|
79
114
|
| `retargetPullRequest()` | No pull request base change. |
|
|
115
|
+
| `forgeMerge()` | `threads.merge()` cannot bypass branch rules. |
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/forges@
|
|
1
|
+
//#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/association-Ds6Tgs0W.mjs
|
|
2
2
|
const AUTHOR_ASSOCIATIONS = {
|
|
3
3
|
OWNER: "owner",
|
|
4
4
|
MEMBER: "member",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { a as buildMetaName, i as buildMetaContent, n as ForgeBuild, o as parseBuildMeta, r as buildIdentity, t as BuildIdentity } from "../identity-CNTWZZuv.js";
|
|
2
|
+
//#region src/build/read.d.ts
|
|
3
|
+
/** `owner/name` of a GitHub or Enterprise remote. The forge's API URL selects the server at runtime. */
|
|
4
|
+
export declare function githubRepository(remote: string | undefined): string | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* The build of the app, from the CI or host, else from Git: the commit and branch, the GitHub repository, and the pull
|
|
7
|
+
* request when the host names it. `VITEHUB_BUILD_COMMIT` and `VITEHUB_BUILD_REPOSITORY` win over the rest, for builds
|
|
8
|
+
* that have neither CI variables nor `.git`, such as a Docker build. Empty outside a Git checkout.
|
|
9
|
+
*/
|
|
10
|
+
export declare function readForgeBuild(root: string, env?: Record<string, string | undefined>): Promise<ForgeBuild>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { type BuildIdentity, type ForgeBuild, buildIdentity, buildMetaContent, buildMetaName, parseBuildMeta };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { i as parseBuildMeta, n as buildMetaContent, r as buildMetaName, t as buildIdentity } from "../identity-CmVEBLP5.js";
|
|
2
|
+
import { execFile } from "node:child_process";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
//#region ../internal/src/build/revision.ts
|
|
6
|
+
/** CI and host variables that name the commit and branch of a build, in the order they are read. */
|
|
7
|
+
const buildVariables = [
|
|
8
|
+
["VERCEL_GIT_COMMIT_SHA", "VERCEL_GIT_COMMIT_REF"],
|
|
9
|
+
["WORKERS_CI_COMMIT_SHA", "WORKERS_CI_BRANCH"],
|
|
10
|
+
["CF_PAGES_COMMIT_SHA", "CF_PAGES_BRANCH"],
|
|
11
|
+
["COMMIT_REF", "BRANCH"],
|
|
12
|
+
["GITHUB_SHA", "GITHUB_HEAD_REF"],
|
|
13
|
+
["CI_COMMIT_SHA", "CI_COMMIT_REF_NAME"],
|
|
14
|
+
["RENDER_GIT_COMMIT", "RENDER_GIT_BRANCH"]
|
|
15
|
+
];
|
|
16
|
+
/** The trimmed output of a Git command in `root`, or `undefined` when Git fails or prints nothing. */
|
|
17
|
+
async function readGit(root, args) {
|
|
18
|
+
try {
|
|
19
|
+
const { stdout } = await promisify(execFile)("git", args, {
|
|
20
|
+
cwd: root,
|
|
21
|
+
encoding: "utf8",
|
|
22
|
+
timeout: 3e3
|
|
23
|
+
});
|
|
24
|
+
return stdout.trim() || void 0;
|
|
25
|
+
} catch {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* On a GitHub Actions `pull_request` event, `GITHUB_SHA` is the test merge commit, which matches no deployment of the
|
|
31
|
+
* pull request. The event payload names the head commit.
|
|
32
|
+
*/
|
|
33
|
+
async function pullRequestHead(env) {
|
|
34
|
+
if (!env.GITHUB_EVENT_NAME?.startsWith("pull_request") || !env.GITHUB_EVENT_PATH) return void 0;
|
|
35
|
+
try {
|
|
36
|
+
const sha = JSON.parse(await readFile(env.GITHUB_EVENT_PATH, "utf8")).pull_request?.head?.sha;
|
|
37
|
+
return typeof sha === "string" && sha ? sha : void 0;
|
|
38
|
+
} catch {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** The commit and branch that the CI or host names, else Git's. Empty outside a Git checkout. */
|
|
43
|
+
async function discoveredRevision(env, git) {
|
|
44
|
+
for (const [commitName, branchName] of buildVariables) {
|
|
45
|
+
const commit = commitName === "GITHUB_SHA" ? await pullRequestHead(env) ?? env.GITHUB_SHA : env[commitName];
|
|
46
|
+
if (!commit) continue;
|
|
47
|
+
const branch = env[branchName] || (commitName === "GITHUB_SHA" ? env.GITHUB_REF_NAME : void 0);
|
|
48
|
+
return {
|
|
49
|
+
commit,
|
|
50
|
+
...branch ? { branch } : {}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const [commit, branch] = await Promise.all([git(["rev-parse", "HEAD"]), git([
|
|
54
|
+
"rev-parse",
|
|
55
|
+
"--abbrev-ref",
|
|
56
|
+
"HEAD"
|
|
57
|
+
])]);
|
|
58
|
+
return {
|
|
59
|
+
...commit ? { commit } : {},
|
|
60
|
+
...branch && branch !== "HEAD" ? { branch } : {}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The commit and branch of the build, from the CI or host, else from Git. `VITEHUB_BUILD_COMMIT` and
|
|
65
|
+
* `VITEHUB_BUILD_BRANCH` each replace their own field. Empty outside a Git checkout.
|
|
66
|
+
*/
|
|
67
|
+
async function readBuildRevision(root, env = process.env, git = (args) => readGit(root, args)) {
|
|
68
|
+
const { VITEHUB_BUILD_COMMIT: commit, VITEHUB_BUILD_BRANCH: branch } = env;
|
|
69
|
+
return {
|
|
70
|
+
...commit && branch ? {} : await discoveredRevision(env, git),
|
|
71
|
+
...commit ? { commit } : {},
|
|
72
|
+
...branch ? { branch } : {}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/build/read.ts
|
|
77
|
+
/** `owner/name` of a GitHub or Enterprise remote. The forge's API URL selects the server at runtime. */
|
|
78
|
+
function githubRepository(remote) {
|
|
79
|
+
return remote ? /^(?:(?:https?|ssh|git):\/\/[^/]+\/|(?:[^@/:]+@)?[\w.-]+:)([\w.-]+\/[\w.-]+?)(?:\.git)?\/?$/.exec(remote.trim())?.[1] : void 0;
|
|
80
|
+
}
|
|
81
|
+
/** The pull request that the CI or host builds, when it names one. */
|
|
82
|
+
function pullRequestOf(env) {
|
|
83
|
+
const value = env.VERCEL_GIT_PULL_REQUEST_ID || (env.PULL_REQUEST === "true" ? env.REVIEW_ID : void 0) || /^refs\/pull\/(\d+)\//.exec(env.GITHUB_REF ?? "")?.[1];
|
|
84
|
+
const number = Number(value);
|
|
85
|
+
return Number.isSafeInteger(number) && number > 0 ? number : void 0;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The build of the app, from the CI or host, else from Git: the commit and branch, the GitHub repository, and the pull
|
|
89
|
+
* request when the host names it. `VITEHUB_BUILD_COMMIT` and `VITEHUB_BUILD_REPOSITORY` win over the rest, for builds
|
|
90
|
+
* that have neither CI variables nor `.git`, such as a Docker build. Empty outside a Git checkout.
|
|
91
|
+
*/
|
|
92
|
+
async function readForgeBuild(root, env = process.env) {
|
|
93
|
+
const repository = env.VITEHUB_BUILD_REPOSITORY || env.GITHUB_REPOSITORY || (env.VERCEL_GIT_PROVIDER === "github" && env.VERCEL_GIT_REPO_OWNER && env.VERCEL_GIT_REPO_SLUG ? `${env.VERCEL_GIT_REPO_OWNER}/${env.VERCEL_GIT_REPO_SLUG}` : void 0) || githubRepository(env.REPOSITORY_URL) || githubRepository(await readGit(root, [
|
|
94
|
+
"remote",
|
|
95
|
+
"get-url",
|
|
96
|
+
"origin"
|
|
97
|
+
]));
|
|
98
|
+
const pullRequest = pullRequestOf(env);
|
|
99
|
+
return {
|
|
100
|
+
...await readBuildRevision(root, env),
|
|
101
|
+
...repository ? { repository } : {},
|
|
102
|
+
...pullRequest ? { pullRequest } : {}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
//#endregion
|
|
106
|
+
export { buildIdentity, buildMetaContent, buildMetaName, githubRepository, parseBuildMeta, readForgeBuild };
|
package/dist/build.d.ts
ADDED
package/dist/build.js
ADDED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { $ as toDate, _ as WebhookVerificationError } from "./utils-
|
|
2
|
-
import {
|
|
3
|
-
import { n as toActor, t as FORGE } from "./tangled-
|
|
4
|
-
//#region ../../node_modules/.pnpm/forges@
|
|
1
|
+
import { $ as toDate, _ as WebhookVerificationError } from "./utils-DC7MBR65-B7Vr2hFm.js";
|
|
2
|
+
import { A as headerValue, d as eventTime, i as refEvent, k as bodyText, u as eventAction, x as threadSnapshot } from "./webhooks-Bc6QhmI8-CNgCERCq.js";
|
|
3
|
+
import { n as toActor, t as FORGE } from "./tangled-8lg_73Wi-bSufNXiN.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/events-C6C7lk1x.mjs
|
|
5
5
|
const EVENT_HEADER = "x-tangled-event";
|
|
6
6
|
const PULL_ACTIONS = {
|
|
7
7
|
created: "opened",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { $ as toDate } from "./utils-
|
|
2
|
-
import {
|
|
3
|
-
import { a as toRepoRef, i as toPullThread, n as toActor, r as toIssueThread, t as FORGE } from "./gitee-
|
|
4
|
-
//#region ../../node_modules/.pnpm/forges@
|
|
1
|
+
import { $ as toDate } from "./utils-DC7MBR65-B7Vr2hFm.js";
|
|
2
|
+
import { A as headerValue, d as eventTime, i as refEvent, k as bodyText, v as snapshotOfThread } from "./webhooks-Bc6QhmI8-CNgCERCq.js";
|
|
3
|
+
import { a as toRepoRef, i as toPullThread, n as toActor, r as toIssueThread, t as FORGE } from "./gitee-BXyl2_3W-dQOAjWqr.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/events-DW3SFUDA.mjs
|
|
5
5
|
const STATES = {
|
|
6
6
|
open: "open",
|
|
7
7
|
reopen: "open",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { $ as toDate, _ as WebhookVerificationError, rt as toPullStats } from "./utils-
|
|
2
|
-
import {
|
|
3
|
-
import { a as toRepoRef, i as toLabels, n as toActor, o as toThreadState, r as toIssueType, t as FORGE } from "./github-
|
|
4
|
-
//#region ../../node_modules/.pnpm/forges@
|
|
1
|
+
import { $ as toDate, _ as WebhookVerificationError, rt as toPullStats } from "./utils-DC7MBR65-B7Vr2hFm.js";
|
|
2
|
+
import { A as headerValue, _ as reviewState, d as eventTime, i as refEvent, k as bodyText, u as eventAction, x as threadSnapshot } from "./webhooks-Bc6QhmI8-CNgCERCq.js";
|
|
3
|
+
import { a as toRepoRef, i as toLabels, n as toActor, o as toThreadState, r as toIssueType, t as FORGE } from "./github-CUiEF2FK.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/events-DjRw3KSr.mjs
|
|
5
5
|
const EVENT_HEADER = "x-github-event";
|
|
6
6
|
const DELIVERY_HEADER = "x-github-delivery";
|
|
7
7
|
function visibilityChange(isPublic, who, payload) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { $ as toDate, _ as WebhookVerificationError } from "./utils-
|
|
2
|
-
import { _ as reviewState, d as eventTime, i as refEvent, n as firstHeader, u as eventAction, v as snapshotOfThread
|
|
3
|
-
import { i as toThread, n as toActor, r as toRepoRef, t as FORGEJO_HEADERS } from "./forgejo-
|
|
4
|
-
//#region ../../node_modules/.pnpm/forges@
|
|
1
|
+
import { $ as toDate, _ as WebhookVerificationError } from "./utils-DC7MBR65-B7Vr2hFm.js";
|
|
2
|
+
import { _ as reviewState, d as eventTime, i as refEvent, k as bodyText, n as firstHeader, u as eventAction, v as snapshotOfThread } from "./webhooks-Bc6QhmI8-CNgCERCq.js";
|
|
3
|
+
import { i as toThread, n as toActor, r as toRepoRef, t as FORGEJO_HEADERS } from "./forgejo-UNPc42cY.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/events-DmSWTdpS.mjs
|
|
5
5
|
const EVENT_KINDS = {
|
|
6
6
|
issue_comment: "comment",
|
|
7
7
|
pull_request_comment: "comment",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { $ as toDate, _ as WebhookVerificationError } from "./utils-
|
|
2
|
-
import {
|
|
3
|
-
import { a as toRepoRef, i as toLabel, n as approvalId, o as toState, r as toActor, t as FORGE } from "./gitlab-
|
|
4
|
-
//#region ../../node_modules/.pnpm/forges@
|
|
1
|
+
import { $ as toDate, _ as WebhookVerificationError } from "./utils-DC7MBR65-B7Vr2hFm.js";
|
|
2
|
+
import { A as headerValue, d as eventTime, i as refEvent, k as bodyText, u as eventAction, x as threadSnapshot } from "./webhooks-Bc6QhmI8-CNgCERCq.js";
|
|
3
|
+
import { a as toRepoRef, i as toLabel, n as approvalId, o as toState, r as toActor, t as FORGE } from "./gitlab-zvWb9zOi.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/events-uCMi3LHU.mjs
|
|
5
5
|
const EVENT_HEADER = "x-gitlab-event";
|
|
6
6
|
function snapshotOf(instance, raw) {
|
|
7
7
|
return raw && threadSnapshot({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { $ as toDate } from "./utils-
|
|
2
|
-
import { d as eventTime, i as refEvent, u as eventAction } from "./webhooks-
|
|
3
|
-
import { n as approvalId, r as toActor, s as toThreadKind, t as FORGE } from "./gitlab-
|
|
4
|
-
//#region ../../node_modules/.pnpm/forges@
|
|
1
|
+
import { $ as toDate } from "./utils-DC7MBR65-B7Vr2hFm.js";
|
|
2
|
+
import { d as eventTime, i as refEvent, u as eventAction } from "./webhooks-Bc6QhmI8-CNgCERCq.js";
|
|
3
|
+
import { n as approvalId, r as toActor, s as toThreadKind, t as FORGE } from "./gitlab-zvWb9zOi.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/feed-BlzdKdNv.mjs
|
|
5
5
|
const FEED_STATES = {
|
|
6
6
|
opened: {
|
|
7
7
|
action: "opened",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { $ as toDate } from "./utils-
|
|
2
|
-
import { d as eventTime, i as refEvent } from "./webhooks-
|
|
3
|
-
import { n as toActor, r as toRepoRef } from "./forgejo-
|
|
4
|
-
//#region ../../node_modules/.pnpm/forges@
|
|
1
|
+
import { $ as toDate } from "./utils-DC7MBR65-B7Vr2hFm.js";
|
|
2
|
+
import { d as eventTime, i as refEvent } from "./webhooks-Bc6QhmI8-CNgCERCq.js";
|
|
3
|
+
import { n as toActor, r as toRepoRef } from "./forgejo-UNPc42cY.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/feed-BwdcTgZq.mjs
|
|
5
5
|
/** Activity types about an issue or a pull request, whose `content` starts with its number. */
|
|
6
6
|
const FEED_THREAD_OPS = {
|
|
7
7
|
create_issue: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { $ as toDate } from "./utils-
|
|
2
|
-
import { d as eventTime, i as refEvent, u as eventAction } from "./webhooks-
|
|
3
|
-
import { a as toRepoRef, n as toActor, t as FORGE } from "./gitee-
|
|
4
|
-
//#region ../../node_modules/.pnpm/forges@
|
|
1
|
+
import { $ as toDate } from "./utils-DC7MBR65-B7Vr2hFm.js";
|
|
2
|
+
import { d as eventTime, i as refEvent, u as eventAction } from "./webhooks-Bc6QhmI8-CNgCERCq.js";
|
|
3
|
+
import { a as toRepoRef, n as toActor, t as FORGE } from "./gitee-BXyl2_3W-dQOAjWqr.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/feed-CIaAZINm.mjs
|
|
5
5
|
/** Summaries of the feed event types that have no shared kind. */
|
|
6
6
|
const FEED_SUMMARIES = { WatchEvent: "watched the repository" };
|
|
7
7
|
const THREAD_TYPES = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { $ as toDate, A as hexColour, B as milestoneId, C as createListing, F as latestCommentOf, G as requireIssueOrPull, I as mapConcurrent, K as requireThread, L as memo, M as isFirstPage, O as getManyConcurrently, Q as teamOrg, R as memoBy, U as rateLimitPart, X as summariseChecks, Y as soleMergeMethod,
|
|
2
|
-
import { C as verb, S as toFileContent, _ as reviewState, a as verifyHmacSignature, c as changeBase64, d as eventTime, f as existingFiles, g as perKind, l as defineForgeProvider, m as inDirectories, p as fromBase64, r as nativeEventsFor, s as WRITE_VERBS, t as eventKindsOf } from "./webhooks-
|
|
3
|
-
//#region ../../node_modules/.pnpm/forges@
|
|
1
|
+
import { $ as toDate, A as hexColour, B as milestoneId, C as createListing, F as latestCommentOf, G as requireIssueOrPull, I as mapConcurrent, K as requireThread, L as memo, M as isFirstPage, O as getManyConcurrently, Q as teamOrg, R as memoBy, U as rateLimitPart, X as summariseChecks, Y as soleMergeMethod, at as versionAtLeast, ct as isNamespaceRef, d as NotFoundError, et as toFileStatus, g as UnsupportedOperationError, it as toWarning, j as hostOf, k as hasEveryLabel, n as BranchMovedError, nt as toPage, o as ForgeError, pt as reactionContent, q as resolveToken, rt as toPullStats, tt as toMergeError, y as actorLogin } from "./utils-DC7MBR65-B7Vr2hFm.js";
|
|
2
|
+
import { C as verb, S as toFileContent, T as githubShapedWeb, _ as reviewState, a as verifyHmacSignature, c as changeBase64, d as eventTime, f as existingFiles, g as perKind, l as defineForgeProvider, m as inDirectories, p as fromBase64, r as nativeEventsFor, s as WRITE_VERBS, t as eventKindsOf } from "./webhooks-Bc6QhmI8-CNgCERCq.js";
|
|
3
|
+
//#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/web-khKJ7nW8.mjs
|
|
4
4
|
const RESERVED_PATHS = [
|
|
5
5
|
"-",
|
|
6
6
|
".well-known",
|
|
@@ -50,7 +50,7 @@ function forgejoWeb(forge, baseUrl) {
|
|
|
50
50
|
}
|
|
51
51
|
const FORGEJO_WEB = /* @__PURE__ */ forgejoWeb("forgejo", "https://codeberg.org");
|
|
52
52
|
//#endregion
|
|
53
|
-
//#region ../../node_modules/.pnpm/forges@
|
|
53
|
+
//#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/definition-0wjaAw2i.mjs
|
|
54
54
|
const FORGEJO_HEADERS = {
|
|
55
55
|
signature: ["x-forgejo-signature", "x-gitea-signature"],
|
|
56
56
|
event: [
|
|
@@ -784,13 +784,46 @@ function toReviewComment(thread, raw) {
|
|
|
784
784
|
body: raw.body ?? "",
|
|
785
785
|
author: toActor(thread, raw.user),
|
|
786
786
|
path: raw.path,
|
|
787
|
-
line: raw.position
|
|
787
|
+
line: raw.position || raw.original_position || void 0,
|
|
788
788
|
side: raw.position ? "right" : raw.original_position ? "left" : void 0,
|
|
789
789
|
createdAt: toDate(raw.created_at),
|
|
790
790
|
url: raw.html_url,
|
|
791
791
|
raw
|
|
792
792
|
};
|
|
793
793
|
}
|
|
794
|
+
/** One conversation per file, side and line, as the web UI groups them; its first comment holds the id and the resolver. */
|
|
795
|
+
function toReviewThreads(thread, raws) {
|
|
796
|
+
const conversations = /* @__PURE__ */ new Map();
|
|
797
|
+
for (const raw of raws.toSorted((left, right) => left.id - right.id)) {
|
|
798
|
+
const key = JSON.stringify([
|
|
799
|
+
raw.path,
|
|
800
|
+
raw.position ? "right" : "left",
|
|
801
|
+
raw.position || raw.original_position
|
|
802
|
+
]);
|
|
803
|
+
conversations.set(key, [...conversations.get(key) ?? [], raw]);
|
|
804
|
+
}
|
|
805
|
+
return [...conversations.values()].map((comments) => {
|
|
806
|
+
const first = comments[0];
|
|
807
|
+
const id = String(first.id);
|
|
808
|
+
const resolved = Boolean(first.resolver);
|
|
809
|
+
const { path, line, side } = toReviewComment(thread, first);
|
|
810
|
+
return {
|
|
811
|
+
id,
|
|
812
|
+
resolved,
|
|
813
|
+
path,
|
|
814
|
+
line,
|
|
815
|
+
side,
|
|
816
|
+
comments: comments.map((raw) => ({
|
|
817
|
+
...toReviewComment(thread, raw),
|
|
818
|
+
thread: {
|
|
819
|
+
id,
|
|
820
|
+
resolved
|
|
821
|
+
}
|
|
822
|
+
})),
|
|
823
|
+
raw: comments
|
|
824
|
+
};
|
|
825
|
+
});
|
|
826
|
+
}
|
|
794
827
|
function toReview(thread, raw, comments) {
|
|
795
828
|
return {
|
|
796
829
|
ref: {
|
|
@@ -989,7 +1022,7 @@ function forgejoWebhooks(profile) {
|
|
|
989
1022
|
return ({ options, origin }) => ({
|
|
990
1023
|
events: FORGEJO_WEBHOOK_EVENTS,
|
|
991
1024
|
verify: (delivery) => verifyForgejoSignature(delivery, options.webhookSecret, profile.headers),
|
|
992
|
-
translate: async (delivery) => (await import("./events-
|
|
1025
|
+
translate: async (delivery) => (await import("./events-DmSWTdpS-BdJBABfI.js")).translateForgejoWebhook(origin, delivery, profile.headers)
|
|
993
1026
|
});
|
|
994
1027
|
}
|
|
995
1028
|
const YAML_FILE = /\.ya?ml$/i;
|
|
@@ -1490,7 +1523,7 @@ function setupForgejo({ options, origin, fetcher: baseFetcher, baseUrl }, profil
|
|
|
1490
1523
|
return released(isGitea ? giteaMinimum : forgejoMinimum);
|
|
1491
1524
|
}
|
|
1492
1525
|
async function feedPage(path, listOptions, query) {
|
|
1493
|
-
const { toFeedEvent } = await import("./feed-
|
|
1526
|
+
const { toFeedEvent } = await import("./feed-BwdcTgZq-Bm_c8br8.js");
|
|
1494
1527
|
return list(path, listOptions, (raw) => toFeedEvent(origin, raw), { query });
|
|
1495
1528
|
}
|
|
1496
1529
|
async function setBlocked(scope, login, blocked, options) {
|
|
@@ -1914,6 +1947,15 @@ function setupForgejo({ options, origin, fetcher: baseFetcher, baseUrl }, profil
|
|
|
1914
1947
|
...rateLimitPart(result.response)
|
|
1915
1948
|
};
|
|
1916
1949
|
}),
|
|
1950
|
+
/** A conversation takes replies from several reviews, so every review is read and the conversations come in one page. */
|
|
1951
|
+
reviewThreadsPage: verb("emulated", async (thread, listOptions = {}) => {
|
|
1952
|
+
const ref = requirePull(thread, "read for review threads");
|
|
1953
|
+
const reviews = await Array.fromAsync(fetcher.items(`${pullPath(ref)}/reviews`, {
|
|
1954
|
+
query: { limit: 50 },
|
|
1955
|
+
signal: listOptions.signal
|
|
1956
|
+
}));
|
|
1957
|
+
return { items: toReviewThreads(ref, (await mapConcurrent(reviews.filter((review) => review.comments_count !== 0), 4, async (review) => (await fetcher.json(`${pullPath(ref)}/reviews/${encodeURIComponent(review.id)}/comments`, { signal: listOptions.signal })).data ?? [])).flat()) };
|
|
1958
|
+
}),
|
|
1917
1959
|
getReview: verb(true, async (ref, options) => {
|
|
1918
1960
|
const pull = requirePull(ref.thread, "reviewed");
|
|
1919
1961
|
const { data } = await fetcher.json(`${pullPath(pull)}/reviews/${encodeURIComponent(ref.id)}`, { signal: options?.signal });
|
|
@@ -2275,7 +2317,7 @@ function forgejoScopesFor(verb) {
|
|
|
2275
2317
|
return {};
|
|
2276
2318
|
}
|
|
2277
2319
|
//#endregion
|
|
2278
|
-
//#region ../../node_modules/.pnpm/forges@
|
|
2320
|
+
//#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/forgejo/index.mjs
|
|
2279
2321
|
/** Creates a Forgejo provider for Codeberg or any self-hosted Forgejo instance. */
|
|
2280
2322
|
const forgejo = /* @__PURE__ */ defineForgeProvider(/* @__PURE__ */ forgejoDefinition(FORGEJO_PROFILE));
|
|
2281
2323
|
//#endregion
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $ as toDate } from "./utils-
|
|
2
|
-
//#region ../../node_modules/.pnpm/forges@
|
|
1
|
+
import { $ as toDate } from "./utils-DC7MBR65-B7Vr2hFm.js";
|
|
2
|
+
//#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/gitee-BXyl2_3W.mjs
|
|
3
3
|
const FORGE = "gitee";
|
|
4
4
|
function toActor(instance, user) {
|
|
5
5
|
if (!user) return;
|