@vite-hub/forge 0.0.0 → 0.3.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/LICENSE +201 -0
- package/README.md +115 -0
- package/dist/association-Ds6Tgs0W-Cu9_YCGq.js +19 -0
- 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-C6C7lk1x-J8VCAjEX.js +131 -0
- package/dist/events-DW3SFUDA-D2rhS9D-.js +124 -0
- package/dist/events-DjRw3KSr-C72gY7Vu.js +527 -0
- package/dist/events-DmSWTdpS-BdJBABfI.js +214 -0
- package/dist/events-uCMi3LHU-Bz79PQtq.js +354 -0
- package/dist/feed-BlzdKdNv-DbxuSgsx.js +179 -0
- package/dist/feed-BwdcTgZq-Bm_c8br8.js +248 -0
- package/dist/feed-CIaAZINm-Dpe9DxwK.js +134 -0
- package/dist/forgejo-UNPc42cY.js +2324 -0
- package/dist/gitee-BXyl2_3W-dQOAjWqr.js +113 -0
- package/dist/github-CUiEF2FK.js +4186 -0
- package/dist/gitlab-zvWb9zOi.js +2589 -0
- package/dist/graphql-BDhuP5jN-BSpB8lWf.js +541 -0
- package/dist/identity-CNTWZZuv.d.ts +27 -0
- package/dist/identity-CmVEBLP5.js +38 -0
- package/dist/index.d.ts +4140 -0
- package/dist/index.js +1183 -0
- package/dist/knot-bGebBK_B-CeDHcJUz.js +350 -0
- package/dist/tangled-8lg_73Wi-bSufNXiN.js +43 -0
- package/dist/templates-BGDqQMu4-PSB43E1j.js +125 -0
- package/dist/utils-DC7MBR65-B7Vr2hFm.js +1214 -0
- package/dist/webhooks-Bc6QhmI8-CNgCERCq.js +1890 -0
- package/package.json +67 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# @vite-hub/forge
|
|
2
|
+
|
|
3
|
+
[](https://npmx.dev/package/@vite-hub/forge)
|
|
4
|
+
[](https://npmx.dev/package/@vite-hub/forge)
|
|
5
|
+
[](https://github.com/vite-hub/vitehub/blob/main/LICENSE)
|
|
6
|
+
[](https://vitehub.dev/docs)
|
|
7
|
+
|
|
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
|
+
|
|
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).
|
|
38
|
+
|
|
39
|
+
## Server Env
|
|
40
|
+
|
|
41
|
+
Each field reads its `VITEHUB_` name first, then the `FORGES_` name that the `forges` library reads.
|
|
42
|
+
|
|
43
|
+
| Field | Names |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| `github.token` | `VITEHUB_GITHUB_TOKEN`, `FORGES_GITHUB_TOKEN` |
|
|
46
|
+
| `github.appId` | `VITEHUB_GITHUB_APP_ID`, `FORGES_GITHUB_APP_ID` |
|
|
47
|
+
| `github.privateKey` | `VITEHUB_GITHUB_PRIVATE_KEY`, `FORGES_GITHUB_PRIVATE_KEY` |
|
|
48
|
+
| `github.privateKeyPath` | `VITEHUB_GITHUB_PRIVATE_KEY_PATH` |
|
|
49
|
+
| `github.installationId` | `VITEHUB_GITHUB_INSTALLATION_ID`, `FORGES_GITHUB_INSTALLATION_ID` |
|
|
50
|
+
| `github.appOwner` | `VITEHUB_GITHUB_APP_OWNER` |
|
|
51
|
+
| `github.appInstallations` | `VITEHUB_GITHUB_APP_INSTALLATIONS` |
|
|
52
|
+
| `github.webhookSecret` | `VITEHUB_GITHUB_WEBHOOK_SECRET`, `FORGES_GITHUB_WEBHOOK_SECRET` |
|
|
53
|
+
| `gitlab.baseUrl`, `gitlab.token`, `gitlab.webhookSecret` | `VITEHUB_GITLAB_*`, `FORGES_GITLAB_*` |
|
|
54
|
+
| `forgejo.baseUrl`, `forgejo.token`, `forgejo.webhookSecret` | `VITEHUB_FORGEJO_*`, `FORGES_FORGEJO_*` |
|
|
55
|
+
|
|
56
|
+
`GH_TOKEN` and `GITHUB_TOKEN` are not read. In GitHub Actions, set `VITEHUB_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}`.
|
|
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
|
+
|
|
62
|
+
## Public imports
|
|
63
|
+
|
|
64
|
+
`useForge()` is the app API. The other exports are the building blocks that ViteHub packages use.
|
|
65
|
+
|
|
66
|
+
| Import | Use |
|
|
67
|
+
| --- | --- |
|
|
68
|
+
| `useForge(options)` | The Forge identity of the app, as above. |
|
|
69
|
+
| `forgeEnv` | The Server Env table above. |
|
|
70
|
+
| `readForgeEnv(field, env)` | The first value set for one `forgeEnv` field, from an env record or a lookup function. |
|
|
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. |
|
|
73
|
+
| `githubBranchRuleDetails(rules)` | GitHub only. Required workflows, ruleset merge methods and the classic protection source from the result of `provider.repos.branchRules()`. |
|
|
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`. |
|
|
76
|
+
| `ForgeApiError`, `ForgeTimeoutError`, `MergeBlockedError`, `NotFoundError`, `RateLimitedError`, `repoRef` | The bundled `forges` classes and helper. Import them from here, so that `instanceof` matches errors from `forgeProvider()`. |
|
|
77
|
+
| `githubAppCredentials(input)` | GitHub App installation tokens, installation lookup and App metadata. Tokens are cached until one minute before they expire. |
|
|
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. |
|
|
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. |
|
|
82
|
+
| `forgeGitCredentials({ forge, baseUrl, token, repository })` | The Git smart HTTP remote and the basic auth pair for one repository. |
|
|
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. |
|
|
84
|
+
| `forgeBlob(provider, repo, sha, { signal })` | The bytes of one blob by sha. GitHub only. |
|
|
85
|
+
| `forgeCommitFiles(provider, repo, input, options)` | `contents.commitFiles()` that can also set git file modes (`100644`, `100755`, `120000`). Returns the commit sha. |
|
|
86
|
+
| `BranchMovedError` | The bundled `forges` error for a branch that moved before a commit. |
|
|
87
|
+
| `forgeErrorStatus(error)`, `isForgeResponseError(error)` | Classify Forge request failures. |
|
|
88
|
+
| `withSignal(promise, signal)`, `abortError(signal)` | Cancellation helpers for Forge calls. |
|
|
89
|
+
|
|
90
|
+
## Diagnostics
|
|
91
|
+
|
|
92
|
+
| Code | Cause |
|
|
93
|
+
| --- | --- |
|
|
94
|
+
| `FORGE_R0001` | The GitHub App installation lookup failed, or the App is not installed on the repository. |
|
|
95
|
+
| `FORGE_R0002` | `forgeArchive()` was called for a Forge other than GitHub. |
|
|
96
|
+
| `FORGE_R0003` | `forgeGitCredentials()` received a base URL that is not HTTP or a repository that is not `owner/name`. |
|
|
97
|
+
| `FORGE_R0004` | `forgeBlob()` was called for a Forge other than GitHub. |
|
|
98
|
+
| `FORGE_R0005` | `forgeCommitFiles()` received a file mode for a Forge other than GitHub. |
|
|
99
|
+
| `FORGE_R0006` | A GitHub-only helper got a provider for another Forge. |
|
|
100
|
+
| `FORGE_R0007` | `githubBranchRuleDetails()` got branch rules that are not complete GitHub rulesets or classic protection. |
|
|
101
|
+
| `FORGE_R0009` | A GitHub-only helper got a reference that is not a numbered pull request, or an empty input. |
|
|
102
|
+
|
|
103
|
+
## Gaps in `forges`
|
|
104
|
+
|
|
105
|
+
`src/gaps/` holds small helpers for operations that `forges` does not have yet. Each one has the signature that we propose upstream.
|
|
106
|
+
|
|
107
|
+
| Helper | Gap |
|
|
108
|
+
| --- | --- |
|
|
109
|
+
| `forgeArchive()` | No `contents.archive()`. |
|
|
110
|
+
| `forgeBlob()` | `contents.getFile()` reads by path, not by blob sha. |
|
|
111
|
+
| `forgeCommitFiles()` | `contents.commitFiles()` cannot set a file mode. |
|
|
112
|
+
| `forgeGitCredentials()`, `forgeGitAuthHeader()` | `Repo.cloneUrls` has no transport credential. |
|
|
113
|
+
| `githubBranchRuleDetails()` | `BranchRules` has no required workflows, ruleset merge methods or classic protection source. |
|
|
114
|
+
| `retargetPullRequest()` | No pull request base change. |
|
|
115
|
+
| `forgeMerge()` | `threads.merge()` cannot bypass branch rules. |
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/association-Ds6Tgs0W.mjs
|
|
2
|
+
const AUTHOR_ASSOCIATIONS = {
|
|
3
|
+
OWNER: "owner",
|
|
4
|
+
MEMBER: "member",
|
|
5
|
+
COLLABORATOR: "collaborator",
|
|
6
|
+
CONTRIBUTOR: "contributor",
|
|
7
|
+
FIRST_TIME_CONTRIBUTOR: "first_time_contributor",
|
|
8
|
+
FIRST_TIMER: "first_timer",
|
|
9
|
+
MANNEQUIN: "none",
|
|
10
|
+
NONE: "none"
|
|
11
|
+
};
|
|
12
|
+
function toAuthorAssociation(raw) {
|
|
13
|
+
return raw ? {
|
|
14
|
+
authorAssociation: AUTHOR_ASSOCIATIONS[raw] ?? "unknown",
|
|
15
|
+
authorAssociationRaw: raw
|
|
16
|
+
} : {};
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { toAuthorAssociation as t };
|
|
@@ -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
|
@@ -0,0 +1,131 @@
|
|
|
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
|
+
const EVENT_HEADER = "x-tangled-event";
|
|
6
|
+
const PULL_ACTIONS = {
|
|
7
|
+
created: "opened",
|
|
8
|
+
resubmitted: "synchronised"
|
|
9
|
+
};
|
|
10
|
+
/** A ref that did not exist before the push, or no longer exists after it. */
|
|
11
|
+
const ZERO_SHA = "0000000000000000000000000000000000000000";
|
|
12
|
+
const PULL_STATES = {
|
|
13
|
+
created: "open",
|
|
14
|
+
reopened: "open",
|
|
15
|
+
merged: "merged",
|
|
16
|
+
closed: "closed"
|
|
17
|
+
};
|
|
18
|
+
const PULL_KINDS = {
|
|
19
|
+
created: "state_change",
|
|
20
|
+
merged: "state_change",
|
|
21
|
+
closed: "state_change",
|
|
22
|
+
reopened: "state_change",
|
|
23
|
+
resubmitted: "commit"
|
|
24
|
+
};
|
|
25
|
+
function translateTangledWebhook(instance, delivery, webUrl) {
|
|
26
|
+
const event = headerValue(delivery.headers, EVENT_HEADER);
|
|
27
|
+
if (!event) throw new WebhookVerificationError(`Missing ${EVENT_HEADER} header`, {
|
|
28
|
+
forge: FORGE,
|
|
29
|
+
instance
|
|
30
|
+
});
|
|
31
|
+
const deliveryId = headerValue(delivery.headers, "x-tangled-delivery") ?? crypto.randomUUID();
|
|
32
|
+
const payload = JSON.parse(bodyText(delivery.body));
|
|
33
|
+
const ownerDid = payload.repository?.owner?.did ?? payload.repository?.full_name?.split("/")[0];
|
|
34
|
+
const repo = payload.repository && ownerDid ? {
|
|
35
|
+
forge: FORGE,
|
|
36
|
+
instance,
|
|
37
|
+
owner: ownerDid,
|
|
38
|
+
name: payload.repository.name
|
|
39
|
+
} : void 0;
|
|
40
|
+
const actorDid = payload.sender?.did ?? payload.pusher?.did;
|
|
41
|
+
const actor = actorDid ? {
|
|
42
|
+
forge: FORGE,
|
|
43
|
+
instance,
|
|
44
|
+
login: actorDid,
|
|
45
|
+
id: actorDid,
|
|
46
|
+
url: `${webUrl}/${actorDid}`,
|
|
47
|
+
isBotHint: false
|
|
48
|
+
} : void 0;
|
|
49
|
+
const who = actor?.login ?? "someone";
|
|
50
|
+
if (event.startsWith("pull_request:") && payload.pull_request) {
|
|
51
|
+
const action = payload.action ?? event.slice(13);
|
|
52
|
+
const pull = payload.pull_request;
|
|
53
|
+
const state = pull.state === "open" || pull.state === "closed" || pull.state === "merged" ? pull.state : void 0;
|
|
54
|
+
return [{
|
|
55
|
+
forge: FORGE,
|
|
56
|
+
instance,
|
|
57
|
+
id: deliveryId,
|
|
58
|
+
kind: PULL_KINDS[action] ?? "other",
|
|
59
|
+
...PULL_STATES[action] ? { detail: {
|
|
60
|
+
type: "state_change",
|
|
61
|
+
state: PULL_STATES[action]
|
|
62
|
+
} } : {},
|
|
63
|
+
kindRaw: event,
|
|
64
|
+
action: PULL_ACTIONS[action] ?? eventAction(action),
|
|
65
|
+
actionRaw: action,
|
|
66
|
+
summary: `${who} ${action === "resubmitted" ? "pushed a new round to" : action} pull request #${payload.pull_request.number}`,
|
|
67
|
+
...eventTime(action === "created" ? toDate(payload.pull_request.created_at) : void 0),
|
|
68
|
+
actor,
|
|
69
|
+
repo,
|
|
70
|
+
thread: repo ? {
|
|
71
|
+
forge: FORGE,
|
|
72
|
+
instance,
|
|
73
|
+
repo,
|
|
74
|
+
kind: "pull_request",
|
|
75
|
+
typeRaw: "sh.tangled.repo.pull",
|
|
76
|
+
displayNumber: String(payload.pull_request.number)
|
|
77
|
+
} : void 0,
|
|
78
|
+
threadSnapshot: threadSnapshot({
|
|
79
|
+
title: pull.title,
|
|
80
|
+
body: pull.body,
|
|
81
|
+
state,
|
|
82
|
+
stateRaw: pull.state,
|
|
83
|
+
author: pull.owner && toActor(instance, { did: pull.owner.did }, webUrl),
|
|
84
|
+
url: pull.html_url,
|
|
85
|
+
branches: pull.target_branch && pull.source?.branch ? {
|
|
86
|
+
head: {
|
|
87
|
+
ref: pull.source.branch,
|
|
88
|
+
sha: pull.source.sha
|
|
89
|
+
},
|
|
90
|
+
base: { ref: pull.target_branch }
|
|
91
|
+
} : void 0
|
|
92
|
+
}),
|
|
93
|
+
source: "webhook",
|
|
94
|
+
payload
|
|
95
|
+
}];
|
|
96
|
+
}
|
|
97
|
+
const base = {
|
|
98
|
+
forge: FORGE,
|
|
99
|
+
instance,
|
|
100
|
+
id: deliveryId,
|
|
101
|
+
kindRaw: event,
|
|
102
|
+
occurredAt: /* @__PURE__ */ new Date(),
|
|
103
|
+
undated: true,
|
|
104
|
+
actor,
|
|
105
|
+
repo,
|
|
106
|
+
source: "webhook",
|
|
107
|
+
payload
|
|
108
|
+
};
|
|
109
|
+
if (event === "push" && payload.ref) return [{
|
|
110
|
+
...base,
|
|
111
|
+
...refEvent(who, {
|
|
112
|
+
ref: payload.ref,
|
|
113
|
+
before: payload.before,
|
|
114
|
+
after: payload.after,
|
|
115
|
+
created: payload.before === ZERO_SHA,
|
|
116
|
+
deleted: payload.after === ZERO_SHA,
|
|
117
|
+
commits: (payload.commits ?? []).map((commit) => ({
|
|
118
|
+
sha: commit.sha ?? commit.id ?? "",
|
|
119
|
+
message: commit.message,
|
|
120
|
+
author: commit.author?.did ?? commit.author?.name
|
|
121
|
+
}))
|
|
122
|
+
})
|
|
123
|
+
}];
|
|
124
|
+
return [{
|
|
125
|
+
...base,
|
|
126
|
+
kind: "other",
|
|
127
|
+
summary: `${who} ${event}`
|
|
128
|
+
}];
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
export { translateTangledWebhook };
|