@openally/github.sdk 1.1.0 → 1.1.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/dist/api/rawFile.d.ts +20 -0
- package/dist/api/rawFile.d.ts.map +1 -0
- package/dist/api/rawFile.js +25 -0
- package/dist/api/rawFile.js.map +1 -0
- package/dist/api/repos.d.ts +21 -0
- package/dist/api/repos.d.ts.map +1 -0
- package/dist/api/repos.js +32 -0
- package/dist/api/repos.js.map +1 -0
- package/dist/api/users.d.ts +21 -0
- package/dist/api/users.d.ts.map +1 -0
- package/dist/api/users.js +20 -0
- package/dist/api/users.js.map +1 -0
- package/dist/class/ApiEndpoint.d.ts +20 -0
- package/dist/class/ApiEndpoint.d.ts.map +1 -0
- package/dist/class/ApiEndpoint.js +60 -0
- package/dist/class/ApiEndpoint.js.map +1 -0
- package/dist/class/GithubClient.d.ts +22 -0
- package/dist/class/GithubClient.d.ts.map +1 -0
- package/dist/class/GithubClient.js +21 -0
- package/dist/class/GithubClient.js.map +1 -0
- package/dist/class/HttpLinkParser.d.ts +4 -0
- package/dist/class/HttpLinkParser.d.ts.map +1 -0
- package/dist/class/HttpLinkParser.js +14 -0
- package/dist/class/HttpLinkParser.js.map +1 -0
- package/dist/class/createApiProxy.d.ts +2 -0
- package/dist/class/createApiProxy.d.ts.map +1 -0
- package/dist/class/createApiProxy.js +8 -0
- package/dist/class/createApiProxy.js.map +1 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -0
- package/{src/constants.ts → dist/constants.js} +1 -0
- package/dist/constants.js.map +1 -0
- package/{src/index.ts → dist/index.d.ts} +2 -5
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/{src/types.ts → dist/types.d.ts} +14 -27
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +5 -2
- package/.all-contributorsrc +0 -16
- package/.editorconfig +0 -14
- package/.github/dependabot.yml +0 -25
- package/.github/workflows/codeql.yml +0 -78
- package/.github/workflows/node.js.yml +0 -52
- package/.github/workflows/publish.yml +0 -29
- package/.github/workflows/scorecards.yml +0 -76
- package/SECURITY.md +0 -5
- package/docs/api/ApiEndpoint.md +0 -66
- package/docs/api/GithubClient.md +0 -50
- package/docs/api/fetchRawFile.md +0 -106
- package/docs/api/repos.md +0 -97
- package/docs/api/users.md +0 -76
- package/eslint.config.mjs +0 -3
- package/src/api/rawFile.ts +0 -73
- package/src/api/repos.ts +0 -88
- package/src/api/users.ts +0 -51
- package/src/class/ApiEndpoint.ts +0 -108
- package/src/class/GithubClient.ts +0 -62
- package/src/class/HttpLinkParser.ts +0 -17
- package/src/class/createApiProxy.ts +0 -9
- package/test/ApiEndpoint.spec.ts +0 -362
- package/test/GithubClient.spec.ts +0 -185
- package/test/HttpLinkParser.spec.ts +0 -78
- package/test/createApiProxy.spec.ts +0 -58
- package/test/rawFile.spec.ts +0 -382
- package/test/repos.spec.ts +0 -221
- package/test/tsconfig.json +0 -11
- package/test/users.spec.ts +0 -159
- package/tsconfig.json +0 -11
package/src/api/rawFile.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
// Import Internal Dependencies
|
|
2
|
-
import {
|
|
3
|
-
DEFAULT_USER_AGENT,
|
|
4
|
-
GITHUB_RAW_API
|
|
5
|
-
} from "../constants.ts";
|
|
6
|
-
import type { RequestConfig } from "../types.ts";
|
|
7
|
-
|
|
8
|
-
// CONSTANTS
|
|
9
|
-
const kDefaultRef = "HEAD";
|
|
10
|
-
|
|
11
|
-
export interface FetchRawFileOptions extends RequestConfig {
|
|
12
|
-
/**
|
|
13
|
-
* Branch, tag, or commit SHA.
|
|
14
|
-
* @default "HEAD"
|
|
15
|
-
*/
|
|
16
|
-
ref?: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type FetchRawFileClientOptions = Omit<FetchRawFileOptions, "token" | "userAgent">;
|
|
20
|
-
export type RawFileParser<T> = "json" | ((content: string) => T);
|
|
21
|
-
|
|
22
|
-
export function fetchRawFile(
|
|
23
|
-
repository: `${string}/${string}`,
|
|
24
|
-
filePath: string,
|
|
25
|
-
options?: FetchRawFileOptions & { parser?: undefined; }
|
|
26
|
-
): Promise<string>;
|
|
27
|
-
export function fetchRawFile<T = unknown>(
|
|
28
|
-
repository: `${string}/${string}`,
|
|
29
|
-
filePath: string,
|
|
30
|
-
options: FetchRawFileOptions & { parser: "json"; }
|
|
31
|
-
): Promise<T>;
|
|
32
|
-
export function fetchRawFile<T>(
|
|
33
|
-
repository: `${string}/${string}`,
|
|
34
|
-
filePath: string,
|
|
35
|
-
options: FetchRawFileOptions & { parser: (content: string) => T; }
|
|
36
|
-
): Promise<T>;
|
|
37
|
-
export async function fetchRawFile<T>(
|
|
38
|
-
repository: `${string}/${string}`,
|
|
39
|
-
filePath: string,
|
|
40
|
-
options: FetchRawFileOptions & { parser?: RawFileParser<T>; } = {}
|
|
41
|
-
): Promise<string | T> {
|
|
42
|
-
const {
|
|
43
|
-
ref = kDefaultRef,
|
|
44
|
-
token,
|
|
45
|
-
userAgent = DEFAULT_USER_AGENT,
|
|
46
|
-
parser
|
|
47
|
-
} = options;
|
|
48
|
-
|
|
49
|
-
const url = new URL(`${repository}/${ref}/${filePath}`, GITHUB_RAW_API);
|
|
50
|
-
const headers: Record<string, string> = {
|
|
51
|
-
"User-Agent": userAgent,
|
|
52
|
-
...(typeof token === "string" ? { Authorization: `token ${token}` } : {})
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const response = await fetch(url, { headers });
|
|
56
|
-
|
|
57
|
-
if (!response.ok) {
|
|
58
|
-
throw new Error(
|
|
59
|
-
`Failed to fetch raw file '${filePath}' from ${repository}@${ref}: HTTP ${response.status}`
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const content = await response.text();
|
|
64
|
-
|
|
65
|
-
if (parser === "json") {
|
|
66
|
-
return JSON.parse(content) as T;
|
|
67
|
-
}
|
|
68
|
-
if (typeof parser === "function") {
|
|
69
|
-
return parser(content);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return content;
|
|
73
|
-
}
|
package/src/api/repos.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
// Import Internal Dependencies
|
|
2
|
-
import { ApiEndpoint } from "../class/ApiEndpoint.ts";
|
|
3
|
-
import { createApiProxy } from "../class/createApiProxy.ts";
|
|
4
|
-
import type {
|
|
5
|
-
Tag,
|
|
6
|
-
PullRequest,
|
|
7
|
-
Issue,
|
|
8
|
-
Commit,
|
|
9
|
-
Workflow,
|
|
10
|
-
WorkflowRun,
|
|
11
|
-
Job,
|
|
12
|
-
Artifact,
|
|
13
|
-
WorkflowsResponse,
|
|
14
|
-
WorkflowRunsResponse,
|
|
15
|
-
JobsResponse,
|
|
16
|
-
ArtifactsResponse,
|
|
17
|
-
RequestConfig
|
|
18
|
-
} from "../types.ts";
|
|
19
|
-
|
|
20
|
-
type RepoEndpointMethods = {
|
|
21
|
-
tags: () => ApiEndpoint<Tag>;
|
|
22
|
-
pulls: () => ApiEndpoint<PullRequest>;
|
|
23
|
-
issues: () => ApiEndpoint<Issue>;
|
|
24
|
-
commits: () => ApiEndpoint<Commit>;
|
|
25
|
-
workflows: () => ApiEndpoint<Workflow>;
|
|
26
|
-
workflowRuns: (workflowId: string | number) => ApiEndpoint<WorkflowRun>;
|
|
27
|
-
runJobs: (runId: number) => ApiEndpoint<Job>;
|
|
28
|
-
runArtifacts: (runId: number) => ApiEndpoint<Artifact>;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export type ReposProxy = {
|
|
32
|
-
[owner: string]: {
|
|
33
|
-
[repo: string]: RepoEndpointMethods;
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
function createRepoProxy(
|
|
38
|
-
owner: string,
|
|
39
|
-
repo: string,
|
|
40
|
-
config: RequestConfig = {}
|
|
41
|
-
): RepoEndpointMethods {
|
|
42
|
-
return {
|
|
43
|
-
tags: () => new ApiEndpoint<Tag>(`/repos/${owner}/${repo}/tags`, config),
|
|
44
|
-
pulls: () => new ApiEndpoint<PullRequest>(`/repos/${owner}/${repo}/pulls`, config),
|
|
45
|
-
issues: () => new ApiEndpoint<Issue>(`/repos/${owner}/${repo}/issues`, config),
|
|
46
|
-
commits: () => new ApiEndpoint<Commit>(`/repos/${owner}/${repo}/commits`, config),
|
|
47
|
-
workflows: () => new ApiEndpoint<Workflow>(
|
|
48
|
-
`/repos/${owner}/${repo}/actions/workflows`,
|
|
49
|
-
{
|
|
50
|
-
...config,
|
|
51
|
-
extractor: (raw: WorkflowsResponse) => raw.workflows
|
|
52
|
-
}
|
|
53
|
-
),
|
|
54
|
-
workflowRuns: (workflowId: string | number) => new ApiEndpoint<WorkflowRun>(
|
|
55
|
-
`/repos/${owner}/${repo}/actions/workflows/${workflowId}/runs`,
|
|
56
|
-
{
|
|
57
|
-
...config,
|
|
58
|
-
extractor: (raw: WorkflowRunsResponse) => raw.workflow_runs
|
|
59
|
-
}
|
|
60
|
-
),
|
|
61
|
-
runJobs: (runId: number) => new ApiEndpoint<Job>(
|
|
62
|
-
`/repos/${owner}/${repo}/actions/runs/${runId}/jobs`,
|
|
63
|
-
{
|
|
64
|
-
...config,
|
|
65
|
-
extractor: (raw: JobsResponse) => raw.jobs
|
|
66
|
-
}
|
|
67
|
-
),
|
|
68
|
-
runArtifacts: (runId: number) => new ApiEndpoint<Artifact>(
|
|
69
|
-
`/repos/${owner}/${repo}/actions/runs/${runId}/artifacts`,
|
|
70
|
-
{
|
|
71
|
-
...config,
|
|
72
|
-
extractor: (raw: ArtifactsResponse) => raw.artifacts
|
|
73
|
-
}
|
|
74
|
-
)
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function createReposProxy(
|
|
79
|
-
config: RequestConfig = {}
|
|
80
|
-
): ReposProxy {
|
|
81
|
-
return createApiProxy(
|
|
82
|
-
(owner) => createApiProxy(
|
|
83
|
-
(repo) => createRepoProxy(owner, repo, config)
|
|
84
|
-
)
|
|
85
|
-
) as ReposProxy;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export const repos = createReposProxy();
|
package/src/api/users.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
// Import Internal Dependencies
|
|
2
|
-
import { ApiEndpoint } from "../class/ApiEndpoint.ts";
|
|
3
|
-
import { createApiProxy } from "../class/createApiProxy.ts";
|
|
4
|
-
import type {
|
|
5
|
-
UserOrg,
|
|
6
|
-
UserRepo,
|
|
7
|
-
UserGist,
|
|
8
|
-
UserFollower,
|
|
9
|
-
UserFollowing,
|
|
10
|
-
UserStarred,
|
|
11
|
-
RequestConfig
|
|
12
|
-
} from "../types.ts";
|
|
13
|
-
|
|
14
|
-
// CONSTANTS
|
|
15
|
-
const kUserEndpointResponseMap = {
|
|
16
|
-
orgs: {} as UserOrg,
|
|
17
|
-
repos: {} as UserRepo,
|
|
18
|
-
gists: {} as UserGist,
|
|
19
|
-
followers: {} as UserFollower,
|
|
20
|
-
following: {} as UserFollowing,
|
|
21
|
-
starred: {} as UserStarred
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
type UserEndpoint = keyof typeof kUserEndpointResponseMap;
|
|
25
|
-
type UserEndpointMethods = {
|
|
26
|
-
[K in UserEndpoint]: () => ApiEndpoint<typeof kUserEndpointResponseMap[K]>;
|
|
27
|
-
};
|
|
28
|
-
export type UsersProxy = {
|
|
29
|
-
[username: string]: UserEndpointMethods;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
function createUserProxy(
|
|
33
|
-
username: string,
|
|
34
|
-
config: RequestConfig = {}
|
|
35
|
-
) {
|
|
36
|
-
return Object.fromEntries(
|
|
37
|
-
Object.keys(kUserEndpointResponseMap).map(
|
|
38
|
-
(endpoint) => [endpoint, () => new ApiEndpoint(`/users/${username}/${endpoint}`, config)]
|
|
39
|
-
)
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function createUsersProxy(
|
|
44
|
-
config: RequestConfig = {}
|
|
45
|
-
): UsersProxy {
|
|
46
|
-
return createApiProxy(
|
|
47
|
-
(username) => createUserProxy(username, config)
|
|
48
|
-
) as UsersProxy;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export const users = createUsersProxy();
|
package/src/class/ApiEndpoint.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
// Import Internal Dependencies
|
|
2
|
-
import { HttpLinkParser } from "./HttpLinkParser.ts";
|
|
3
|
-
import {
|
|
4
|
-
DEFAULT_USER_AGENT,
|
|
5
|
-
GITHUB_API
|
|
6
|
-
} from "../constants.ts";
|
|
7
|
-
import type { RequestConfig } from "../types.ts";
|
|
8
|
-
|
|
9
|
-
export interface ApiEndpointOptions<T> extends RequestConfig {
|
|
10
|
-
/**
|
|
11
|
-
* By default, the raw response from the GitHub API is returned as-is.
|
|
12
|
-
* You can provide a custom extractor function to transform the raw response
|
|
13
|
-
* into an array of type T.
|
|
14
|
-
*/
|
|
15
|
-
extractor?: (raw: any) => T[];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class ApiEndpoint<T> {
|
|
19
|
-
#userAgent: string;
|
|
20
|
-
#bearerToken?: string;
|
|
21
|
-
|
|
22
|
-
#nextURL: string | null = null;
|
|
23
|
-
#apiEndpoint: string | URL;
|
|
24
|
-
#extractor: (raw: any) => T[];
|
|
25
|
-
|
|
26
|
-
constructor(
|
|
27
|
-
apiEndpoint: string | URL,
|
|
28
|
-
options: ApiEndpointOptions<T> = {}
|
|
29
|
-
) {
|
|
30
|
-
const {
|
|
31
|
-
userAgent = DEFAULT_USER_AGENT,
|
|
32
|
-
token,
|
|
33
|
-
extractor = ((raw) => raw as T[])
|
|
34
|
-
} = options;
|
|
35
|
-
|
|
36
|
-
this.#userAgent = userAgent;
|
|
37
|
-
this.#bearerToken = token;
|
|
38
|
-
this.#apiEndpoint = apiEndpoint;
|
|
39
|
-
this.#extractor = extractor;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
setBearerToken(
|
|
43
|
-
token: string
|
|
44
|
-
): this {
|
|
45
|
-
this.#bearerToken = token;
|
|
46
|
-
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
setAgent(
|
|
51
|
-
userAgent: string
|
|
52
|
-
): this {
|
|
53
|
-
this.#userAgent = userAgent;
|
|
54
|
-
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async #next(): Promise<T[]> {
|
|
59
|
-
const headers = {
|
|
60
|
-
"User-Agent": this.#userAgent,
|
|
61
|
-
Accept: "application/vnd.github.v3.raw",
|
|
62
|
-
...(
|
|
63
|
-
typeof this.#bearerToken === "string" ?
|
|
64
|
-
{ Authorization: `token ${this.#bearerToken}` } :
|
|
65
|
-
{}
|
|
66
|
-
)
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const url = this.#nextURL === null ?
|
|
70
|
-
new URL(this.#apiEndpoint, GITHUB_API) :
|
|
71
|
-
new URL(this.#nextURL, GITHUB_API);
|
|
72
|
-
const response = await fetch(
|
|
73
|
-
url,
|
|
74
|
-
{ headers }
|
|
75
|
-
);
|
|
76
|
-
const rawData = await response.json();
|
|
77
|
-
|
|
78
|
-
const linkHeader = response.headers.get("link");
|
|
79
|
-
this.#nextURL = linkHeader
|
|
80
|
-
? HttpLinkParser.parse(linkHeader).get("next") ?? null
|
|
81
|
-
: null;
|
|
82
|
-
|
|
83
|
-
return this.#extractor(rawData);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async* iterate(): AsyncIterableIterator<T> {
|
|
87
|
-
do {
|
|
88
|
-
const pageResults = await this.#next();
|
|
89
|
-
|
|
90
|
-
yield* pageResults;
|
|
91
|
-
} while (this.#nextURL !== null);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
[Symbol.asyncIterator](): AsyncIterableIterator<T> {
|
|
95
|
-
return this.iterate();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
all(): Promise<T[]> {
|
|
99
|
-
return Array.fromAsync(this.iterate());
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
then<TResult1 = T[], TResult2 = never>(
|
|
103
|
-
onfulfilled?: ((value: T[]) => TResult1 | PromiseLike<TResult1>) | null,
|
|
104
|
-
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
|
|
105
|
-
): Promise<TResult1 | TResult2> {
|
|
106
|
-
return this.all().then(onfulfilled, onrejected);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
// Import Internal Dependencies
|
|
2
|
-
import {
|
|
3
|
-
createUsersProxy,
|
|
4
|
-
type UsersProxy
|
|
5
|
-
} from "../api/users.ts";
|
|
6
|
-
import {
|
|
7
|
-
createReposProxy,
|
|
8
|
-
type ReposProxy
|
|
9
|
-
} from "../api/repos.ts";
|
|
10
|
-
import {
|
|
11
|
-
fetchRawFile,
|
|
12
|
-
type FetchRawFileClientOptions,
|
|
13
|
-
type RawFileParser
|
|
14
|
-
} from "../api/rawFile.ts";
|
|
15
|
-
import type { RequestConfig } from "../types.ts";
|
|
16
|
-
|
|
17
|
-
export interface GithubClientOptions extends RequestConfig {}
|
|
18
|
-
|
|
19
|
-
export class GithubClient {
|
|
20
|
-
readonly users: UsersProxy;
|
|
21
|
-
readonly repos: ReposProxy;
|
|
22
|
-
#config: RequestConfig;
|
|
23
|
-
|
|
24
|
-
constructor(
|
|
25
|
-
options: GithubClientOptions = {}
|
|
26
|
-
) {
|
|
27
|
-
this.#config = {
|
|
28
|
-
token: options.token,
|
|
29
|
-
userAgent: options.userAgent
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
this.users = createUsersProxy(this.#config);
|
|
33
|
-
this.repos = createReposProxy(this.#config);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
fetchRawFile(
|
|
37
|
-
repository: `${string}/${string}`,
|
|
38
|
-
filePath: string,
|
|
39
|
-
options?: FetchRawFileClientOptions & { parser?: undefined; }
|
|
40
|
-
): Promise<string>;
|
|
41
|
-
fetchRawFile<T = unknown>(
|
|
42
|
-
repository: `${string}/${string}`,
|
|
43
|
-
filePath: string,
|
|
44
|
-
options: FetchRawFileClientOptions & { parser: "json"; }
|
|
45
|
-
): Promise<T>;
|
|
46
|
-
fetchRawFile<T>(
|
|
47
|
-
repository: `${string}/${string}`,
|
|
48
|
-
filePath: string,
|
|
49
|
-
options: FetchRawFileClientOptions & { parser: (content: string) => T; }
|
|
50
|
-
): Promise<T>;
|
|
51
|
-
fetchRawFile<T>(
|
|
52
|
-
repository: `${string}/${string}`,
|
|
53
|
-
filePath: string,
|
|
54
|
-
options: FetchRawFileClientOptions & { parser?: RawFileParser<T>; } = {}
|
|
55
|
-
): Promise<string | T> {
|
|
56
|
-
return fetchRawFile<T>(
|
|
57
|
-
repository,
|
|
58
|
-
filePath,
|
|
59
|
-
{ ...this.#config, ...options } as any
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export class HttpLinkParser {
|
|
2
|
-
static parse(
|
|
3
|
-
headerValue: string
|
|
4
|
-
): Map<string, string> {
|
|
5
|
-
const result = new Map<string, string>();
|
|
6
|
-
|
|
7
|
-
for (const part of headerValue.split(", ")) {
|
|
8
|
-
const urlMatch = part.match(/^<([^>]+)>/);
|
|
9
|
-
const relMatch = part.match(/rel="([^"]+)"/);
|
|
10
|
-
if (urlMatch && relMatch) {
|
|
11
|
-
result.set(relMatch[1], urlMatch[1]);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return result;
|
|
16
|
-
}
|
|
17
|
-
}
|