@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/test/rawFile.spec.ts
DELETED
|
@@ -1,382 +0,0 @@
|
|
|
1
|
-
// Import Node.js Dependencies
|
|
2
|
-
import { describe, it, beforeEach, afterEach } from "node:test";
|
|
3
|
-
import assert from "node:assert/strict";
|
|
4
|
-
|
|
5
|
-
// Import Third-party Dependencies
|
|
6
|
-
import { MockAgent, setGlobalDispatcher, getGlobalDispatcher, type Dispatcher } from "undici";
|
|
7
|
-
|
|
8
|
-
// Import Internal Dependencies
|
|
9
|
-
import { fetchRawFile } from "../src/api/rawFile.ts";
|
|
10
|
-
import { GithubClient } from "../src/class/GithubClient.ts";
|
|
11
|
-
|
|
12
|
-
// CONSTANTS
|
|
13
|
-
const kRawGithubOrigin = "https://raw.githubusercontent.com";
|
|
14
|
-
|
|
15
|
-
describe("fetchRawFile()", () => {
|
|
16
|
-
let mockAgent: MockAgent;
|
|
17
|
-
let originalDispatcher: Dispatcher;
|
|
18
|
-
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
originalDispatcher = getGlobalDispatcher();
|
|
21
|
-
mockAgent = new MockAgent();
|
|
22
|
-
mockAgent.disableNetConnect();
|
|
23
|
-
setGlobalDispatcher(mockAgent);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
afterEach(async() => {
|
|
27
|
-
await mockAgent.close();
|
|
28
|
-
setGlobalDispatcher(originalDispatcher);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe("raw text (no parser)", () => {
|
|
32
|
-
it("should return the raw file content as a string", async() => {
|
|
33
|
-
mockAgent
|
|
34
|
-
.get(kRawGithubOrigin)
|
|
35
|
-
.intercept({ path: "/octocat/hello-world/HEAD/README.md", method: "GET" })
|
|
36
|
-
.reply(200, "# Hello World\n");
|
|
37
|
-
|
|
38
|
-
const result = await fetchRawFile("octocat/hello-world", "README.md");
|
|
39
|
-
|
|
40
|
-
assert.equal(result, "# Hello World\n");
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("should default to ref HEAD", async() => {
|
|
44
|
-
mockAgent
|
|
45
|
-
.get(kRawGithubOrigin)
|
|
46
|
-
.intercept({ path: "/octocat/hello-world/HEAD/README.md", method: "GET" })
|
|
47
|
-
.reply(200, "content");
|
|
48
|
-
|
|
49
|
-
await assert.doesNotReject(
|
|
50
|
-
fetchRawFile("octocat/hello-world", "README.md")
|
|
51
|
-
);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("should use the provided ref", async() => {
|
|
55
|
-
mockAgent
|
|
56
|
-
.get(kRawGithubOrigin)
|
|
57
|
-
.intercept({ path: "/octocat/hello-world/main/README.md", method: "GET" })
|
|
58
|
-
.reply(200, "content on main");
|
|
59
|
-
|
|
60
|
-
const result = await fetchRawFile("octocat/hello-world", "README.md", { ref: "main" });
|
|
61
|
-
|
|
62
|
-
assert.equal(result, "content on main");
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("should support file paths with directory segments", async() => {
|
|
66
|
-
mockAgent
|
|
67
|
-
.get(kRawGithubOrigin)
|
|
68
|
-
.intercept({ path: "/octocat/hello-world/HEAD/src/index.ts", method: "GET" })
|
|
69
|
-
.reply(200, "export {};\n");
|
|
70
|
-
|
|
71
|
-
const result = await fetchRawFile("octocat/hello-world", "src/index.ts");
|
|
72
|
-
|
|
73
|
-
assert.equal(result, "export {};\n");
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
describe("parser: \"json\"", () => {
|
|
78
|
-
it("should parse and return the file content as a JSON object", async() => {
|
|
79
|
-
const pkg = { name: "hello-world", version: "1.0.0" };
|
|
80
|
-
|
|
81
|
-
mockAgent
|
|
82
|
-
.get(kRawGithubOrigin)
|
|
83
|
-
.intercept({ path: "/octocat/hello-world/HEAD/package.json", method: "GET" })
|
|
84
|
-
.reply(200, JSON.stringify(pkg));
|
|
85
|
-
|
|
86
|
-
const result = await fetchRawFile<{ name: string; version: string; }>(
|
|
87
|
-
"octocat/hello-world",
|
|
88
|
-
"package.json",
|
|
89
|
-
{ parser: "json" }
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
assert.deepEqual(result, pkg);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("should return unknown by default when parser is \"json\"", async() => {
|
|
96
|
-
mockAgent
|
|
97
|
-
.get(kRawGithubOrigin)
|
|
98
|
-
.intercept({ path: "/octocat/hello-world/HEAD/data.json", method: "GET" })
|
|
99
|
-
.reply(200, JSON.stringify([1, 2, 3]));
|
|
100
|
-
|
|
101
|
-
const result = await fetchRawFile("octocat/hello-world", "data.json", { parser: "json" });
|
|
102
|
-
|
|
103
|
-
assert.deepEqual(result, [1, 2, 3]);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
describe("custom parser function", () => {
|
|
108
|
-
it("should apply a custom parser to the raw content", async() => {
|
|
109
|
-
mockAgent
|
|
110
|
-
.get(kRawGithubOrigin)
|
|
111
|
-
.intercept({ path: "/octocat/hello-world/HEAD/VERSION", method: "GET" })
|
|
112
|
-
.reply(200, "2.3.1\n");
|
|
113
|
-
|
|
114
|
-
const result = await fetchRawFile(
|
|
115
|
-
"octocat/hello-world",
|
|
116
|
-
"VERSION",
|
|
117
|
-
{ parser: (content) => content.trim() }
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
assert.equal(result, "2.3.1");
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("should pass the raw string content to the parser", async() => {
|
|
124
|
-
const rawContent = "key=value\nfoo=bar\n";
|
|
125
|
-
const captured: string[] = [];
|
|
126
|
-
|
|
127
|
-
mockAgent
|
|
128
|
-
.get(kRawGithubOrigin)
|
|
129
|
-
.intercept({ path: "/octocat/hello-world/HEAD/.env", method: "GET" })
|
|
130
|
-
.reply(200, rawContent);
|
|
131
|
-
|
|
132
|
-
await fetchRawFile(
|
|
133
|
-
"octocat/hello-world",
|
|
134
|
-
".env",
|
|
135
|
-
{
|
|
136
|
-
parser: (content) => {
|
|
137
|
-
captured.push(content);
|
|
138
|
-
|
|
139
|
-
return content;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
assert.equal(captured[0], rawContent);
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
describe("headers", () => {
|
|
149
|
-
it("should send the default User-Agent header", async() => {
|
|
150
|
-
mockAgent
|
|
151
|
-
.get(kRawGithubOrigin)
|
|
152
|
-
.intercept({
|
|
153
|
-
path: "/octocat/hello-world/HEAD/README.md",
|
|
154
|
-
method: "GET",
|
|
155
|
-
headers: { "user-agent": "@openally/github.sdk/1.0.0" }
|
|
156
|
-
})
|
|
157
|
-
.reply(200, "content");
|
|
158
|
-
|
|
159
|
-
await assert.doesNotReject(
|
|
160
|
-
fetchRawFile("octocat/hello-world", "README.md")
|
|
161
|
-
);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it("should send a custom User-Agent when provided", async() => {
|
|
165
|
-
mockAgent
|
|
166
|
-
.get(kRawGithubOrigin)
|
|
167
|
-
.intercept({
|
|
168
|
-
path: "/octocat/hello-world/HEAD/README.md",
|
|
169
|
-
method: "GET",
|
|
170
|
-
headers: { "user-agent": "my-app/2.0" }
|
|
171
|
-
})
|
|
172
|
-
.reply(200, "content");
|
|
173
|
-
|
|
174
|
-
await assert.doesNotReject(
|
|
175
|
-
fetchRawFile("octocat/hello-world", "README.md", { userAgent: "my-app/2.0" })
|
|
176
|
-
);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it("should send the Authorization header when a token is provided", async() => {
|
|
180
|
-
mockAgent
|
|
181
|
-
.get(kRawGithubOrigin)
|
|
182
|
-
.intercept({
|
|
183
|
-
path: "/octocat/hello-world/HEAD/README.md",
|
|
184
|
-
method: "GET",
|
|
185
|
-
headers: { authorization: "token secret123" }
|
|
186
|
-
})
|
|
187
|
-
.reply(200, "content");
|
|
188
|
-
|
|
189
|
-
await assert.doesNotReject(
|
|
190
|
-
fetchRawFile("octocat/hello-world", "README.md", { token: "secret123" })
|
|
191
|
-
);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it("should succeed without an Authorization header when no token is provided", async() => {
|
|
195
|
-
// undici's MockAgent will reject the request if the intercepted headers
|
|
196
|
-
// do not match — here we assert no `authorization` key is present by
|
|
197
|
-
// confirming the request succeeds against an interceptor that has no
|
|
198
|
-
// header constraint at all (the positive case with a token is separately tested).
|
|
199
|
-
mockAgent
|
|
200
|
-
.get(kRawGithubOrigin)
|
|
201
|
-
.intercept({ path: "/octocat/hello-world/HEAD/README.md", method: "GET" })
|
|
202
|
-
.reply(200, "content");
|
|
203
|
-
|
|
204
|
-
await assert.doesNotReject(
|
|
205
|
-
fetchRawFile("octocat/hello-world", "README.md")
|
|
206
|
-
);
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
describe("error handling", () => {
|
|
211
|
-
it("should throw on a 404 response", async() => {
|
|
212
|
-
mockAgent
|
|
213
|
-
.get(kRawGithubOrigin)
|
|
214
|
-
.intercept({ path: "/octocat/hello-world/HEAD/missing.txt", method: "GET" })
|
|
215
|
-
.reply(404, "Not Found");
|
|
216
|
-
|
|
217
|
-
await assert.rejects(
|
|
218
|
-
fetchRawFile("octocat/hello-world", "missing.txt"),
|
|
219
|
-
(err: Error) => {
|
|
220
|
-
assert.ok(err.message.includes("404"));
|
|
221
|
-
|
|
222
|
-
return true;
|
|
223
|
-
}
|
|
224
|
-
);
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it("should throw on a 500 response", async() => {
|
|
228
|
-
mockAgent
|
|
229
|
-
.get(kRawGithubOrigin)
|
|
230
|
-
.intercept({ path: "/octocat/hello-world/HEAD/README.md", method: "GET" })
|
|
231
|
-
.reply(500, "Internal Server Error");
|
|
232
|
-
|
|
233
|
-
await assert.rejects(
|
|
234
|
-
fetchRawFile("octocat/hello-world", "README.md"),
|
|
235
|
-
(err: Error) => {
|
|
236
|
-
assert.ok(err.message.includes("500"));
|
|
237
|
-
|
|
238
|
-
return true;
|
|
239
|
-
}
|
|
240
|
-
);
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
it("should include the repository, ref, and file path in the error message", async() => {
|
|
244
|
-
mockAgent
|
|
245
|
-
.get(kRawGithubOrigin)
|
|
246
|
-
.intercept({ path: "/octocat/hello-world/HEAD/missing.txt", method: "GET" })
|
|
247
|
-
.reply(404, "Not Found");
|
|
248
|
-
|
|
249
|
-
await assert.rejects(
|
|
250
|
-
fetchRawFile("octocat/hello-world", "missing.txt"),
|
|
251
|
-
(err: Error) => {
|
|
252
|
-
assert.ok(err.message.includes("missing.txt"));
|
|
253
|
-
assert.ok(err.message.includes("octocat/hello-world"));
|
|
254
|
-
assert.ok(err.message.includes("HEAD"));
|
|
255
|
-
|
|
256
|
-
return true;
|
|
257
|
-
}
|
|
258
|
-
);
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
describe("GithubClient.fetchRawFile()", () => {
|
|
264
|
-
let mockAgent: MockAgent;
|
|
265
|
-
let originalDispatcher: Dispatcher;
|
|
266
|
-
|
|
267
|
-
beforeEach(() => {
|
|
268
|
-
originalDispatcher = getGlobalDispatcher();
|
|
269
|
-
mockAgent = new MockAgent();
|
|
270
|
-
mockAgent.disableNetConnect();
|
|
271
|
-
setGlobalDispatcher(mockAgent);
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
afterEach(async() => {
|
|
275
|
-
await mockAgent.close();
|
|
276
|
-
setGlobalDispatcher(originalDispatcher);
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
it("should fetch raw content using the client's token", async() => {
|
|
280
|
-
const client = new GithubClient({ token: "clienttoken" });
|
|
281
|
-
|
|
282
|
-
mockAgent
|
|
283
|
-
.get(kRawGithubOrigin)
|
|
284
|
-
.intercept({
|
|
285
|
-
path: "/octocat/hello-world/HEAD/README.md",
|
|
286
|
-
method: "GET",
|
|
287
|
-
headers: { authorization: "token clienttoken" }
|
|
288
|
-
})
|
|
289
|
-
.reply(200, "# Hello");
|
|
290
|
-
|
|
291
|
-
await assert.doesNotReject(
|
|
292
|
-
client.fetchRawFile("octocat/hello-world", "README.md")
|
|
293
|
-
);
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
it("should fetch raw content using the client's userAgent", async() => {
|
|
297
|
-
const client = new GithubClient({ userAgent: "my-client/1.0" });
|
|
298
|
-
|
|
299
|
-
mockAgent
|
|
300
|
-
.get(kRawGithubOrigin)
|
|
301
|
-
.intercept({
|
|
302
|
-
path: "/octocat/hello-world/HEAD/README.md",
|
|
303
|
-
method: "GET",
|
|
304
|
-
headers: { "user-agent": "my-client/1.0" }
|
|
305
|
-
})
|
|
306
|
-
.reply(200, "# Hello");
|
|
307
|
-
|
|
308
|
-
await assert.doesNotReject(
|
|
309
|
-
client.fetchRawFile("octocat/hello-world", "README.md")
|
|
310
|
-
);
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
it("should parse JSON when parser is \"json\"", async() => {
|
|
314
|
-
const client = new GithubClient();
|
|
315
|
-
const pkg = { name: "hello-world", version: "1.0.0" };
|
|
316
|
-
|
|
317
|
-
mockAgent
|
|
318
|
-
.get(kRawGithubOrigin)
|
|
319
|
-
.intercept({ path: "/octocat/hello-world/HEAD/package.json", method: "GET" })
|
|
320
|
-
.reply(200, JSON.stringify(pkg));
|
|
321
|
-
|
|
322
|
-
const result = await client.fetchRawFile<{ name: string; version: string; }>(
|
|
323
|
-
"octocat/hello-world",
|
|
324
|
-
"package.json",
|
|
325
|
-
{ parser: "json" }
|
|
326
|
-
);
|
|
327
|
-
|
|
328
|
-
assert.deepEqual(result, pkg);
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
it("should apply a custom parser function", async() => {
|
|
332
|
-
const client = new GithubClient();
|
|
333
|
-
|
|
334
|
-
mockAgent
|
|
335
|
-
.get(kRawGithubOrigin)
|
|
336
|
-
.intercept({ path: "/octocat/hello-world/main/VERSION", method: "GET" })
|
|
337
|
-
.reply(200, "3.0.0\n");
|
|
338
|
-
|
|
339
|
-
const result = await client.fetchRawFile(
|
|
340
|
-
"octocat/hello-world",
|
|
341
|
-
"VERSION",
|
|
342
|
-
{ ref: "main", parser: (s) => s.trim() }
|
|
343
|
-
);
|
|
344
|
-
|
|
345
|
-
assert.equal(result, "3.0.0");
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
it("should use the ref option when provided", async() => {
|
|
349
|
-
const client = new GithubClient();
|
|
350
|
-
|
|
351
|
-
mockAgent
|
|
352
|
-
.get(kRawGithubOrigin)
|
|
353
|
-
.intercept({ path: "/octocat/hello-world/v2.0.0/CHANGELOG.md", method: "GET" })
|
|
354
|
-
.reply(200, "## v2.0.0\n");
|
|
355
|
-
|
|
356
|
-
const result = await client.fetchRawFile(
|
|
357
|
-
"octocat/hello-world",
|
|
358
|
-
"CHANGELOG.md",
|
|
359
|
-
{ ref: "v2.0.0" }
|
|
360
|
-
);
|
|
361
|
-
|
|
362
|
-
assert.equal(result, "## v2.0.0\n");
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
it("should throw when the file is not found", async() => {
|
|
366
|
-
const client = new GithubClient();
|
|
367
|
-
|
|
368
|
-
mockAgent
|
|
369
|
-
.get(kRawGithubOrigin)
|
|
370
|
-
.intercept({ path: "/octocat/hello-world/HEAD/missing.txt", method: "GET" })
|
|
371
|
-
.reply(404, "Not Found");
|
|
372
|
-
|
|
373
|
-
await assert.rejects(
|
|
374
|
-
client.fetchRawFile("octocat/hello-world", "missing.txt"),
|
|
375
|
-
(err: Error) => {
|
|
376
|
-
assert.ok(err.message.includes("404"));
|
|
377
|
-
|
|
378
|
-
return true;
|
|
379
|
-
}
|
|
380
|
-
);
|
|
381
|
-
});
|
|
382
|
-
});
|
package/test/repos.spec.ts
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
// Import Node.js Dependencies
|
|
2
|
-
import { describe, it, beforeEach, afterEach } from "node:test";
|
|
3
|
-
import assert from "node:assert/strict";
|
|
4
|
-
|
|
5
|
-
// Import Third-party Dependencies
|
|
6
|
-
import { MockAgent, setGlobalDispatcher, getGlobalDispatcher, type Dispatcher } from "undici";
|
|
7
|
-
|
|
8
|
-
// Import Internal Dependencies
|
|
9
|
-
import { ApiEndpoint } from "../src/class/ApiEndpoint.ts";
|
|
10
|
-
import { repos, createReposProxy } from "../src/api/repos.ts";
|
|
11
|
-
|
|
12
|
-
// CONSTANTS
|
|
13
|
-
const kGithubOrigin = "https://api.github.com";
|
|
14
|
-
|
|
15
|
-
describe("Repos API", () => {
|
|
16
|
-
let mockAgent: MockAgent;
|
|
17
|
-
let originalDispatcher: Dispatcher;
|
|
18
|
-
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
originalDispatcher = getGlobalDispatcher();
|
|
21
|
-
mockAgent = new MockAgent();
|
|
22
|
-
mockAgent.disableNetConnect();
|
|
23
|
-
setGlobalDispatcher(mockAgent);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
afterEach(async() => {
|
|
27
|
-
await mockAgent.close();
|
|
28
|
-
setGlobalDispatcher(originalDispatcher);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe("createReposProxy()", () => {
|
|
32
|
-
it("should return an ApiEndpoint for each simple repo endpoint", () => {
|
|
33
|
-
const proxy = createReposProxy();
|
|
34
|
-
const methods = proxy.owner.myrepo;
|
|
35
|
-
|
|
36
|
-
assert.ok(methods.tags() instanceof ApiEndpoint);
|
|
37
|
-
assert.ok(methods.pulls() instanceof ApiEndpoint);
|
|
38
|
-
assert.ok(methods.issues() instanceof ApiEndpoint);
|
|
39
|
-
assert.ok(methods.commits() instanceof ApiEndpoint);
|
|
40
|
-
assert.ok(methods.workflows() instanceof ApiEndpoint);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("should return an ApiEndpoint from workflowRuns() with a string workflow id", () => {
|
|
44
|
-
const endpoint = createReposProxy().owner.myrepo.workflowRuns("ci.yml");
|
|
45
|
-
|
|
46
|
-
assert.ok(endpoint instanceof ApiEndpoint);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("should return an ApiEndpoint from workflowRuns() with a numeric workflow id", () => {
|
|
50
|
-
const endpoint = createReposProxy().owner.myrepo.workflowRuns(42);
|
|
51
|
-
|
|
52
|
-
assert.ok(endpoint instanceof ApiEndpoint);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("should return an ApiEndpoint from runJobs()", () => {
|
|
56
|
-
const endpoint = createReposProxy().owner.myrepo.runJobs(123);
|
|
57
|
-
|
|
58
|
-
assert.ok(endpoint instanceof ApiEndpoint);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("should return an ApiEndpoint from runArtifacts()", () => {
|
|
62
|
-
const endpoint = createReposProxy().owner.myrepo.runArtifacts(456);
|
|
63
|
-
|
|
64
|
-
assert.ok(endpoint instanceof ApiEndpoint);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("should create a new ApiEndpoint on each method call", () => {
|
|
68
|
-
const proxy = createReposProxy();
|
|
69
|
-
|
|
70
|
-
assert.notStrictEqual(proxy.owner.myrepo.tags(), proxy.owner.myrepo.tags());
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("should pass the token from config to ApiEndpoints", async() => {
|
|
74
|
-
const proxy = createReposProxy({ token: "repotoken" });
|
|
75
|
-
|
|
76
|
-
mockAgent
|
|
77
|
-
.get(kGithubOrigin)
|
|
78
|
-
.intercept({
|
|
79
|
-
path: "/repos/owner/myrepo/tags",
|
|
80
|
-
method: "GET",
|
|
81
|
-
headers: { authorization: "token repotoken" }
|
|
82
|
-
})
|
|
83
|
-
.reply(200, JSON.stringify([]), {
|
|
84
|
-
headers: { "content-type": "application/json" }
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
await assert.doesNotReject(proxy.owner.myrepo.tags().all());
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
describe("repos (default export)", () => {
|
|
92
|
-
it("should fetch tags for a repo", async() => {
|
|
93
|
-
mockAgent
|
|
94
|
-
.get(kGithubOrigin)
|
|
95
|
-
.intercept({ path: "/repos/octocat/hello-world/tags", method: "GET" })
|
|
96
|
-
.reply(200, JSON.stringify([{ name: "v1.0.0" }, { name: "v1.1.0" }]), {
|
|
97
|
-
headers: { "content-type": "application/json" }
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
const result = await repos.octocat["hello-world"].tags().all();
|
|
101
|
-
|
|
102
|
-
assert.deepEqual(result, [{ name: "v1.0.0" }, { name: "v1.1.0" }]);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it("should fetch pull requests for a repo", async() => {
|
|
106
|
-
mockAgent
|
|
107
|
-
.get(kGithubOrigin)
|
|
108
|
-
.intercept({ path: "/repos/octocat/hello-world/pulls", method: "GET" })
|
|
109
|
-
.reply(200, JSON.stringify([{ number: 1, title: "Fix bug" }]), {
|
|
110
|
-
headers: { "content-type": "application/json" }
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
const result = await repos.octocat["hello-world"].pulls().all();
|
|
114
|
-
|
|
115
|
-
assert.deepEqual(result, [{ number: 1, title: "Fix bug" }]);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("should fetch issues for a repo", async() => {
|
|
119
|
-
mockAgent
|
|
120
|
-
.get(kGithubOrigin)
|
|
121
|
-
.intercept({ path: "/repos/octocat/hello-world/issues", method: "GET" })
|
|
122
|
-
.reply(200, JSON.stringify([{ number: 5, title: "Bug report" }]), {
|
|
123
|
-
headers: { "content-type": "application/json" }
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
const result = await repos.octocat["hello-world"].issues().all();
|
|
127
|
-
|
|
128
|
-
assert.deepEqual(result, [{ number: 5, title: "Bug report" }]);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it("should fetch commits for a repo", async() => {
|
|
132
|
-
mockAgent
|
|
133
|
-
.get(kGithubOrigin)
|
|
134
|
-
.intercept({ path: "/repos/octocat/hello-world/commits", method: "GET" })
|
|
135
|
-
.reply(200, JSON.stringify([{ sha: "abc123" }]), {
|
|
136
|
-
headers: { "content-type": "application/json" }
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
const result = await repos.octocat["hello-world"].commits().all();
|
|
140
|
-
|
|
141
|
-
assert.deepEqual(result, [{ sha: "abc123" }]);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it("should fetch workflows using the extractor", async() => {
|
|
145
|
-
mockAgent
|
|
146
|
-
.get(kGithubOrigin)
|
|
147
|
-
.intercept({ path: "/repos/octocat/hello-world/actions/workflows", method: "GET" })
|
|
148
|
-
.reply(200, JSON.stringify({ total_count: 1, workflows: [{ id: 1, name: "CI" }] }), {
|
|
149
|
-
headers: { "content-type": "application/json" }
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
const result = await repos.octocat["hello-world"].workflows().all();
|
|
153
|
-
|
|
154
|
-
assert.deepEqual(result, [{ id: 1, name: "CI" }]);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it("should fetch workflow runs by string workflow id using the extractor", async() => {
|
|
158
|
-
mockAgent
|
|
159
|
-
.get(kGithubOrigin)
|
|
160
|
-
.intercept({
|
|
161
|
-
path: "/repos/octocat/hello-world/actions/workflows/ci.yml/runs",
|
|
162
|
-
method: "GET"
|
|
163
|
-
})
|
|
164
|
-
.reply(200, JSON.stringify({ total_count: 1, workflow_runs: [{ id: 100, status: "completed" }] }), {
|
|
165
|
-
headers: { "content-type": "application/json" }
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
const result = await repos.octocat["hello-world"].workflowRuns("ci.yml").all();
|
|
169
|
-
|
|
170
|
-
assert.deepEqual(result, [{ id: 100, status: "completed" }]);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it("should fetch workflow runs by numeric workflow id using the extractor", async() => {
|
|
174
|
-
mockAgent
|
|
175
|
-
.get(kGithubOrigin)
|
|
176
|
-
.intercept({
|
|
177
|
-
path: "/repos/octocat/hello-world/actions/workflows/42/runs",
|
|
178
|
-
method: "GET"
|
|
179
|
-
})
|
|
180
|
-
.reply(200, JSON.stringify({ total_count: 2, workflow_runs: [{ id: 200 }, { id: 201 }] }), {
|
|
181
|
-
headers: { "content-type": "application/json" }
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
const result = await repos.octocat["hello-world"].workflowRuns(42).all();
|
|
185
|
-
|
|
186
|
-
assert.deepEqual(result, [{ id: 200 }, { id: 201 }]);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it("should fetch run jobs using the extractor", async() => {
|
|
190
|
-
mockAgent
|
|
191
|
-
.get(kGithubOrigin)
|
|
192
|
-
.intercept({
|
|
193
|
-
path: "/repos/octocat/hello-world/actions/runs/999/jobs",
|
|
194
|
-
method: "GET"
|
|
195
|
-
})
|
|
196
|
-
.reply(200, JSON.stringify({ total_count: 1, jobs: [{ id: 10, name: "build" }] }), {
|
|
197
|
-
headers: { "content-type": "application/json" }
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
const result = await repos.octocat["hello-world"].runJobs(999).all();
|
|
201
|
-
|
|
202
|
-
assert.deepEqual(result, [{ id: 10, name: "build" }]);
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it("should fetch run artifacts using the extractor", async() => {
|
|
206
|
-
mockAgent
|
|
207
|
-
.get(kGithubOrigin)
|
|
208
|
-
.intercept({
|
|
209
|
-
path: "/repos/octocat/hello-world/actions/runs/999/artifacts",
|
|
210
|
-
method: "GET"
|
|
211
|
-
})
|
|
212
|
-
.reply(200, JSON.stringify({ total_count: 1, artifacts: [{ id: 55, name: "build-output" }] }), {
|
|
213
|
-
headers: { "content-type": "application/json" }
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
const result = await repos.octocat["hello-world"].runArtifacts(999).all();
|
|
217
|
-
|
|
218
|
-
assert.deepEqual(result, [{ id: 55, name: "build-output" }]);
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
});
|