@shivaedev/github 0.9.0 → 0.10.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 +18 -0
- package/README.md +95 -5
- package/dist/GitHub.d.ts +262 -3
- package/dist/GitHub.d.ts.map +1 -1
- package/dist/GitHub.js +15 -5
- package/dist/GitHub.js.map +1 -1
- package/dist/adapters/resolveApiUrl.d.ts +2 -0
- package/dist/adapters/resolveApiUrl.d.ts.map +1 -0
- package/dist/adapters/resolveApiUrl.js +6 -0
- package/dist/adapters/resolveApiUrl.js.map +1 -0
- package/dist/adapters/zipEntries.d.ts +17 -0
- package/dist/adapters/zipEntries.d.ts.map +1 -0
- package/dist/adapters/zipEntries.js +57 -0
- package/dist/adapters/zipEntries.js.map +1 -0
- package/dist/appTokens.d.ts.map +1 -1
- package/dist/appTokens.js +2 -1
- package/dist/appTokens.js.map +1 -1
- package/dist/artifactErrors.d.ts +34 -0
- package/dist/artifactErrors.d.ts.map +1 -0
- package/dist/artifactErrors.js +27 -0
- package/dist/artifactErrors.js.map +1 -0
- package/dist/artifactExtraction.d.ts +12 -0
- package/dist/artifactExtraction.d.ts.map +1 -0
- package/dist/artifactExtraction.js +40 -0
- package/dist/artifactExtraction.js.map +1 -0
- package/dist/artifactPaths.d.ts +4 -0
- package/dist/artifactPaths.d.ts.map +1 -0
- package/dist/artifactPaths.js +35 -0
- package/dist/artifactPaths.js.map +1 -0
- package/dist/artifacts.d.ts +13 -8
- package/dist/artifacts.d.ts.map +1 -1
- package/dist/artifacts.js +15 -8
- package/dist/artifacts.js.map +1 -1
- package/dist/checkRuns.d.ts.map +1 -1
- package/dist/checkRuns.js +5 -3
- package/dist/checkRuns.js.map +1 -1
- package/dist/gitSchemas.d.ts +195 -0
- package/dist/gitSchemas.d.ts.map +1 -0
- package/dist/gitSchemas.js +45 -0
- package/dist/gitSchemas.js.map +1 -0
- package/dist/installationClients.d.ts +278 -2
- package/dist/installationClients.d.ts.map +1 -1
- package/dist/installationClients.js +14 -5
- package/dist/installationClients.js.map +1 -1
- package/dist/pagedLists.d.ts +15 -0
- package/dist/pagedLists.d.ts.map +1 -0
- package/dist/pagedLists.js +16 -0
- package/dist/pagedLists.js.map +1 -0
- package/dist/repositoryReads.d.ts +261 -0
- package/dist/repositoryReads.d.ts.map +1 -0
- package/dist/repositoryReads.js +30 -0
- package/dist/repositoryReads.js.map +1 -0
- package/dist/repositorySchemas.d.ts +73 -0
- package/dist/repositorySchemas.d.ts.map +1 -0
- package/dist/repositorySchemas.js +38 -0
- package/dist/repositorySchemas.js.map +1 -0
- package/dist/representations.d.ts.map +1 -1
- package/dist/representations.js +3 -2
- package/dist/representations.js.map +1 -1
- package/dist/viewerRepositoryAccess.d.ts +46 -0
- package/dist/viewerRepositoryAccess.d.ts.map +1 -0
- package/dist/viewerRepositoryAccess.js +54 -0
- package/dist/viewerRepositoryAccess.js.map +1 -0
- package/package.json +11 -4
- package/src/GitHub.ts +17 -10
- package/src/adapters/resolveApiUrl.ts +5 -0
- package/src/adapters/zipEntries.ts +69 -0
- package/src/appTokens.ts +2 -1
- package/src/artifactErrors.ts +26 -0
- package/src/artifactExtraction.ts +62 -0
- package/src/artifactPaths.ts +36 -0
- package/src/artifacts.ts +36 -39
- package/src/checkRuns.ts +5 -5
- package/src/gitSchemas.ts +52 -0
- package/src/installationClients.ts +18 -12
- package/src/pagedLists.ts +40 -0
- package/src/repositoryReads.ts +61 -0
- package/src/repositorySchemas.ts +43 -0
- package/src/representations.ts +3 -2
- package/src/viewerRepositoryAccess.ts +66 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
export const User = Schema.Struct({
|
|
4
|
+
avatarUrl: Schema.String,
|
|
5
|
+
htmlUrl: Schema.String,
|
|
6
|
+
id: Schema.Number,
|
|
7
|
+
login: Schema.String,
|
|
8
|
+
type: Schema.String,
|
|
9
|
+
}).pipe(Schema.encodeKeys({ avatarUrl: "avatar_url", htmlUrl: "html_url" }));
|
|
10
|
+
|
|
11
|
+
export const Issue = Schema.Struct({
|
|
12
|
+
body: Schema.NullOr(Schema.String),
|
|
13
|
+
closedAt: Schema.NullOr(Schema.String),
|
|
14
|
+
createdAt: Schema.String,
|
|
15
|
+
htmlUrl: Schema.String,
|
|
16
|
+
id: Schema.Number,
|
|
17
|
+
labels: Schema.Array(Schema.Union([Schema.String, Schema.Struct({ name: Schema.optional(Schema.String) })])),
|
|
18
|
+
number: Schema.Number,
|
|
19
|
+
pullRequest: Schema.optional(Schema.Struct({ url: Schema.String })),
|
|
20
|
+
state: Schema.Literals(["open", "closed"]),
|
|
21
|
+
title: Schema.String,
|
|
22
|
+
updatedAt: Schema.String,
|
|
23
|
+
user: Schema.NullOr(User),
|
|
24
|
+
}).pipe(
|
|
25
|
+
Schema.encodeKeys({ closedAt: "closed_at", createdAt: "created_at", htmlUrl: "html_url", pullRequest: "pull_request", updatedAt: "updated_at" }),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export const PullRequestFile = Schema.Struct({
|
|
29
|
+
additions: Schema.Number,
|
|
30
|
+
changes: Schema.Number,
|
|
31
|
+
deletions: Schema.Number,
|
|
32
|
+
filename: Schema.String,
|
|
33
|
+
patch: Schema.optional(Schema.String),
|
|
34
|
+
previousFilename: Schema.optional(Schema.String),
|
|
35
|
+
sha: Schema.String,
|
|
36
|
+
status: Schema.String,
|
|
37
|
+
}).pipe(Schema.encodeKeys({ previousFilename: "previous_filename" }));
|
|
38
|
+
|
|
39
|
+
export const CollaboratorPermission = Schema.Struct({
|
|
40
|
+
permission: Schema.String,
|
|
41
|
+
roleName: Schema.String,
|
|
42
|
+
user: User,
|
|
43
|
+
}).pipe(Schema.encodeKeys({ roleName: "role_name" }));
|
package/src/representations.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { HttpClient, HttpClientRequest, type HttpClientResponse } from "effect/h
|
|
|
3
3
|
import type { ServiceUnavailable } from "@shivaedev/errors/taxonomy.ts";
|
|
4
4
|
import { nextLink } from "@shivaedev/http/nextLink.ts";
|
|
5
5
|
import { paginate } from "@shivaedev/http/paginate.ts";
|
|
6
|
+
import { resolveApiUrl } from "#adapters/resolveApiUrl.ts";
|
|
6
7
|
import type { CachedResponse } from "#cache.ts";
|
|
7
8
|
import { jsonResponse } from "#json.ts";
|
|
8
9
|
import type { requests } from "#requests.ts";
|
|
@@ -14,7 +15,7 @@ export function representations(
|
|
|
14
15
|
responseByteLimit = 1024 * 1024,
|
|
15
16
|
) {
|
|
16
17
|
function get(path: string, accept = "application/vnd.github+json") {
|
|
17
|
-
return HttpClientRequest.get(
|
|
18
|
+
return HttpClientRequest.get(resolveApiUrl(apiUrl, path), { headers: { Accept: accept } });
|
|
18
19
|
}
|
|
19
20
|
function readRepresentation(path: string, byteLimit = responseByteLimit) {
|
|
20
21
|
return Effect.map(request(get(path), byteLimit), jsonResponse);
|
|
@@ -46,7 +47,7 @@ export function representations(
|
|
|
46
47
|
);
|
|
47
48
|
}
|
|
48
49
|
function writeRepresentation(method: "POST" | "PATCH" | "PUT" | "DELETE", path: string, body?: unknown, byteLimit = responseByteLimit) {
|
|
49
|
-
return HttpClientRequest.make(method)(
|
|
50
|
+
return HttpClientRequest.make(method)(resolveApiUrl(apiUrl, path), { headers: { Accept: "application/vnd.github+json" } }).pipe(
|
|
50
51
|
(input) => (body === undefined ? Effect.succeed(input) : HttpClientRequest.bodyJson(input, body)),
|
|
51
52
|
Effect.flatMap((input) => request(input, byteLimit)),
|
|
52
53
|
Effect.map(jsonResponse),
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Cache, Effect, Exit, Schema, Stream } from "effect";
|
|
2
|
+
import { decodedPages } from "#pagedLists.ts";
|
|
3
|
+
import type { Representations } from "#representations.ts";
|
|
4
|
+
|
|
5
|
+
export const InstalledRepository = Schema.Struct({
|
|
6
|
+
htmlUrl: Schema.String,
|
|
7
|
+
id: Schema.Number,
|
|
8
|
+
name: Schema.String,
|
|
9
|
+
owner: Schema.Struct({ login: Schema.String }),
|
|
10
|
+
private: Schema.Boolean,
|
|
11
|
+
}).pipe(Schema.encodeKeys({ htmlUrl: "html_url" }));
|
|
12
|
+
|
|
13
|
+
export interface ViewerRepositoryAccess {
|
|
14
|
+
readonly administrable: readonly (typeof InstalledRepository.Type & { readonly installationId: number })[];
|
|
15
|
+
readonly readable: readonly (typeof InstalledRepository.Type & { readonly installationId: number })[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const Account = Schema.Struct({ login: Schema.String });
|
|
19
|
+
const Installation = Schema.Struct({ id: Schema.Number });
|
|
20
|
+
const Permission = Schema.Struct({ permission: Schema.String });
|
|
21
|
+
|
|
22
|
+
const installationAccess = Effect.fnUntraced(function* (client: Representations, installationId: number, login: string) {
|
|
23
|
+
const pages = yield* decodedPages(client, "/installation/repositories?per_page=100", InstalledRepository, {
|
|
24
|
+
arrayKey: "repositories",
|
|
25
|
+
}).pipe(Stream.runCollect);
|
|
26
|
+
const readable: ViewerRepositoryAccess["readable"][number][] = [];
|
|
27
|
+
const administrable: ViewerRepositoryAccess["administrable"][number][] = [];
|
|
28
|
+
for (const repository of pages.flatMap((page) => page.items)) {
|
|
29
|
+
const permissionPath = `/repos/${encodeURIComponent(repository.owner.login)}/${encodeURIComponent(repository.name)}/collaborators/${encodeURIComponent(login)}/permission`;
|
|
30
|
+
const permission = yield* Effect.flatMap(client.read(permissionPath), (response) => response.decode(Permission)).pipe(
|
|
31
|
+
Effect.map((grant) => grant.permission),
|
|
32
|
+
Effect.catchTag("RemoteNotFound", () => Effect.succeed("none")),
|
|
33
|
+
);
|
|
34
|
+
const installed = { ...repository, installationId };
|
|
35
|
+
if (!repository.private || ["read", "triage", "write", "maintain", "admin"].includes(permission)) {
|
|
36
|
+
readable.push(installed);
|
|
37
|
+
}
|
|
38
|
+
if (permission === "admin") {
|
|
39
|
+
administrable.push(installed);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return { administrable, readable } satisfies ViewerRepositoryAccess;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export function viewerRepositoryAccess(app: Representations, installation: (id: number) => Effect.Effect<Representations>) {
|
|
46
|
+
const lookup = Effect.fnUntraced(function* (account: string) {
|
|
47
|
+
const path = account.startsWith("id:") ? `/user/${account.slice(3)}` : `/users/${encodeURIComponent(account.slice(6))}`;
|
|
48
|
+
const installations = yield* decodedPages(app, "/app/installations?per_page=100", Installation).pipe(Stream.runCollect);
|
|
49
|
+
const first = installations.flatMap((page) => page.items)[0];
|
|
50
|
+
if (first === undefined) {
|
|
51
|
+
return { administrable: [], readable: [] } satisfies ViewerRepositoryAccess;
|
|
52
|
+
}
|
|
53
|
+
const resolver = yield* installation(first.id);
|
|
54
|
+
const { login } = yield* Effect.flatMap(resolver.read(path), (response) => response.decode(Account));
|
|
55
|
+
const readable: ViewerRepositoryAccess["readable"][number][] = [];
|
|
56
|
+
const administrable: ViewerRepositoryAccess["administrable"][number][] = [];
|
|
57
|
+
for (const { id } of installations.flatMap((page) => page.items)) {
|
|
58
|
+
const client = yield* installation(id);
|
|
59
|
+
const access = yield* installationAccess(client, id, login);
|
|
60
|
+
readable.push(...access.readable);
|
|
61
|
+
administrable.push(...access.administrable);
|
|
62
|
+
}
|
|
63
|
+
return { administrable, readable } satisfies ViewerRepositoryAccess;
|
|
64
|
+
});
|
|
65
|
+
return Cache.makeWith(lookup, { capacity: 100, timeToLive: (exit) => (Exit.isSuccess(exit) ? "60 seconds" : 0) });
|
|
66
|
+
}
|