gcb-host 0.5.0 → 0.7.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/CHANGELOG.md +50 -0
- package/lib/broker.d.ts.map +1 -1
- package/lib/broker.js +91 -4
- package/lib/broker.js.map +1 -1
- package/lib/commands/config.d.ts +1 -1
- package/lib/commands/config.d.ts.map +1 -1
- package/lib/commands/config.js +258 -12
- package/lib/commands/config.js.map +1 -1
- package/lib/commands/host.d.ts +3 -1
- package/lib/commands/host.d.ts.map +1 -1
- package/lib/commands/host.js +212 -21
- package/lib/commands/host.js.map +1 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +38 -1
- package/lib/config.js.map +1 -1
- package/lib/gh.d.ts +6 -0
- package/lib/gh.d.ts.map +1 -1
- package/lib/gh.js +57 -23
- package/lib/gh.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/providers/github-app.d.ts.map +1 -1
- package/lib/providers/github-app.js +99 -2
- package/lib/providers/github-app.js.map +1 -1
- package/lib/public-repo.d.ts +36 -0
- package/lib/public-repo.d.ts.map +1 -0
- package/lib/public-repo.js +94 -0
- package/lib/public-repo.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { ProviderConfigError } from 'gcb-core';
|
|
2
|
+
/** How long one visibility check may take, including the body. */
|
|
3
|
+
const CHECK_TIMEOUT_MS = 10_000;
|
|
4
|
+
/**
|
|
5
|
+
* Run one unauthenticated repository request with a deadline and no redirects.
|
|
6
|
+
*
|
|
7
|
+
* @param fetchImpl - the transport for this host's proxy choice.
|
|
8
|
+
* @param apiBaseUrl - the API base, without a trailing path.
|
|
9
|
+
* @param repository - `owner/name`.
|
|
10
|
+
* @param options - API version, deadline and a label for the timeout message.
|
|
11
|
+
* @param handle - reads the response while the deadline is still active.
|
|
12
|
+
* @returns whatever the handler returns.
|
|
13
|
+
*/
|
|
14
|
+
export async function withRepositoryResponse(fetchImpl, apiBaseUrl, repository, options, handle) {
|
|
15
|
+
const controller = new AbortController();
|
|
16
|
+
const timer = setTimeout(() => controller.abort(), options.timeoutMs ?? CHECK_TIMEOUT_MS);
|
|
17
|
+
try {
|
|
18
|
+
const response = await fetchImpl(`${apiBaseUrl}/repos/${repository}`, {
|
|
19
|
+
method: 'GET',
|
|
20
|
+
headers: {
|
|
21
|
+
accept: 'application/vnd.github+json',
|
|
22
|
+
'x-github-api-version': options.apiVersion ?? '2022-11-28',
|
|
23
|
+
'user-agent': 'gcb',
|
|
24
|
+
},
|
|
25
|
+
signal: controller.signal,
|
|
26
|
+
redirect: 'error',
|
|
27
|
+
});
|
|
28
|
+
if (response.status === 403 || response.status === 429) {
|
|
29
|
+
const exhausted = response.status === 429 ||
|
|
30
|
+
response.headers.get('x-ratelimit-remaining') === '0' ||
|
|
31
|
+
response.headers.get('retry-after') !== null;
|
|
32
|
+
const label = options.label ?? 'repository';
|
|
33
|
+
throw new ProviderConfigError(exhausted
|
|
34
|
+
? `GitHub rate-limited the unauthenticated ${label} check; retry later or allowlist the repository`
|
|
35
|
+
: `GitHub refused the unauthenticated ${label} check; check the access policy or allowlist the repository`);
|
|
36
|
+
}
|
|
37
|
+
return await handle(response);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (controller.signal.aborted) {
|
|
41
|
+
throw new ProviderConfigError(`GitHub timed out during the ${options.label ?? 'repository'} check; retry later`);
|
|
42
|
+
}
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
clearTimeout(timer);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Check a repository with no credential; only a confirmed public result is true. */
|
|
50
|
+
export async function isPublicRepository(fetchImpl, apiBaseUrl, repository, apiVersion = '2022-11-28', timeoutMs = CHECK_TIMEOUT_MS) {
|
|
51
|
+
return withRepositoryResponse(fetchImpl, apiBaseUrl, repository, { apiVersion, timeoutMs, label: 'public-repository' }, async (response) => {
|
|
52
|
+
if (!response.ok)
|
|
53
|
+
return false;
|
|
54
|
+
const text = await response.text();
|
|
55
|
+
try {
|
|
56
|
+
const body = JSON.parse(text);
|
|
57
|
+
return body?.private === false;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Check whether a public repository is a fork of another, with no credential.
|
|
66
|
+
*
|
|
67
|
+
* @param fetchImpl - the transport for this host's proxy choice.
|
|
68
|
+
* @param apiBaseUrl - the API base, without a trailing path.
|
|
69
|
+
* @param repository - the possible fork, `owner/name`.
|
|
70
|
+
* @param parent - the possible parent/source, `owner/name`.
|
|
71
|
+
* @param apiVersion - GitHub API version header.
|
|
72
|
+
* @param timeoutMs - whole-request deadline.
|
|
73
|
+
* @returns true only when GitHub confirms the fork relationship.
|
|
74
|
+
*/
|
|
75
|
+
export async function isForkOfRepository(fetchImpl, apiBaseUrl, repository, parent, apiVersion = '2022-11-28', timeoutMs = CHECK_TIMEOUT_MS) {
|
|
76
|
+
return withRepositoryResponse(fetchImpl, apiBaseUrl, repository, { apiVersion, timeoutMs, label: 'fork' }, async (response) => {
|
|
77
|
+
if (!response.ok)
|
|
78
|
+
return false;
|
|
79
|
+
const text = await response.text();
|
|
80
|
+
try {
|
|
81
|
+
const body = JSON.parse(text);
|
|
82
|
+
if (body?.fork !== true)
|
|
83
|
+
return false;
|
|
84
|
+
const names = [body.parent?.full_name, body.source?.full_name]
|
|
85
|
+
.filter((name) => typeof name === 'string')
|
|
86
|
+
.map((name) => name.toLowerCase());
|
|
87
|
+
return names.includes(parent.toLowerCase());
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=public-repo.js.map
|
|
@@ -0,0 +1 @@
|
|
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AAG,gBAAgB;IAE5B,OAAO,sBAAsB,CAC3B,SAAS,EACT,UAAU,EACV,UAAU,EACV,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,EACxC,KAAK,EAAE,QAAQ,EAAE,EAAE;QACjB,IAAI,CAAC,QAAQ,CAAC,EAAE;YAAE,OAAO,KAAK,CAAC;QAC/B,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnC,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAIpB,CAAC;YACT,IAAI,IAAI,EAAE,IAAI,KAAK,IAAI;gBAAE,OAAO,KAAK,CAAC;YACtC,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC;iBAC3D,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC;iBAC1D,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;YACrC,OAAO,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;QAC9C,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gcb-host",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Host-side gcb broker, configuration, providers and administration commands.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "JounQin <admin@1stg.me>",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"gcb-core": "0.
|
|
30
|
+
"gcb-core": "0.7.0",
|
|
31
31
|
"node-fetch-native": "^1.6.7",
|
|
32
32
|
"x-fetch": "^0.3.0",
|
|
33
33
|
"yaml": "^2.9.1"
|