@slates-integrations/github 0.2.0-rc.4 → 0.2.0-rc.7

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.
Files changed (46) hide show
  1. package/dist/index.js +16 -0
  2. package/dist/index.js.map +1 -0
  3. package/dist/package.json +3 -0
  4. package/dist/sourcemap-register.cjs +1 -0
  5. package/package.json +10 -4
  6. package/slate.json +1 -4
  7. package/src/auth.ts +0 -347
  8. package/src/config.ts +0 -4
  9. package/src/index.ts +0 -78
  10. package/src/lib/client.ts +0 -991
  11. package/src/spec.ts +0 -13
  12. package/src/tools/comment-on-issue.ts +0 -46
  13. package/src/tools/create-commit-status.ts +0 -97
  14. package/src/tools/create-release.ts +0 -69
  15. package/src/tools/create-repository.ts +0 -70
  16. package/src/tools/get-issue.ts +0 -67
  17. package/src/tools/get-repository.ts +0 -75
  18. package/src/tools/get-user.ts +0 -64
  19. package/src/tools/index.ts +0 -24
  20. package/src/tools/list-branches.ts +0 -54
  21. package/src/tools/list-commits.ts +0 -70
  22. package/src/tools/list-issues.ts +0 -90
  23. package/src/tools/list-pull-requests.ts +0 -82
  24. package/src/tools/list-repositories.ts +0 -102
  25. package/src/tools/manage-collaborators.ts +0 -88
  26. package/src/tools/manage-file-content.ts +0 -117
  27. package/src/tools/manage-gist.ts +0 -183
  28. package/src/tools/manage-issue.ts +0 -94
  29. package/src/tools/manage-labels.ts +0 -93
  30. package/src/tools/manage-pull-request.ts +0 -111
  31. package/src/tools/manage-workflow.ts +0 -242
  32. package/src/tools/merge-pull-request.ts +0 -61
  33. package/src/tools/review-pull-request.ts +0 -90
  34. package/src/tools/search.ts +0 -72
  35. package/src/tools/star-repository.ts +0 -57
  36. package/src/tools/update-repository.ts +0 -56
  37. package/src/triggers/index.ts +0 -8
  38. package/src/triggers/issue-comment.ts +0 -94
  39. package/src/triggers/issues.ts +0 -111
  40. package/src/triggers/pull-request-review.ts +0 -95
  41. package/src/triggers/pull-request.ts +0 -123
  42. package/src/triggers/push.ts +0 -117
  43. package/src/triggers/release.ts +0 -103
  44. package/src/triggers/star.ts +0 -71
  45. package/src/triggers/workflow-run.ts +0 -112
  46. package/tsconfig.json +0 -23
package/src/lib/client.ts DELETED
@@ -1,991 +0,0 @@
1
- import { createAxios } from 'slates';
2
-
3
- export interface GitHubClientConfig {
4
- token: string;
5
- instanceUrl?: string;
6
- }
7
-
8
- export class GitHubClient {
9
- private http: ReturnType<typeof createAxios>;
10
- private instanceUrl: string;
11
- private apiBaseUrl: string;
12
-
13
- constructor(private config: GitHubClientConfig) {
14
- this.instanceUrl = config.instanceUrl?.replace(/\/+$/, '') || 'https://github.com';
15
- this.apiBaseUrl =
16
- this.instanceUrl === 'https://github.com'
17
- ? 'https://api.github.com'
18
- : `${this.instanceUrl}/api/v3`;
19
-
20
- this.http = createAxios({
21
- baseURL: this.apiBaseUrl,
22
- headers: {
23
- Authorization: `Bearer ${config.token}`,
24
- Accept: 'application/vnd.github+json',
25
- 'X-GitHub-Api-Version': '2022-11-28'
26
- }
27
- });
28
- }
29
-
30
- getRepositoryHtmlUrl(owner: string, repo: string) {
31
- return `${this.instanceUrl}/${owner}/${repo}`;
32
- }
33
-
34
- // ─── Repositories ──────────────────────────────────────────────
35
-
36
- async listRepositories(
37
- params: {
38
- type?: string;
39
- sort?: string;
40
- direction?: string;
41
- perPage?: number;
42
- page?: number;
43
- } = {}
44
- ) {
45
- let response = await this.http.get('/user/repos', { params });
46
- return response.data;
47
- }
48
-
49
- async getRepository(owner: string, repo: string) {
50
- let response = await this.http.get(`/repos/${owner}/${repo}`);
51
- return response.data;
52
- }
53
-
54
- async createRepository(data: {
55
- name: string;
56
- description?: string;
57
- private?: boolean;
58
- autoInit?: boolean;
59
- gitignoreTemplate?: string;
60
- licenseTemplate?: string;
61
- org?: string;
62
- }) {
63
- let { org, autoInit, gitignoreTemplate, licenseTemplate, ...rest } = data;
64
- let body = {
65
- ...rest,
66
- auto_init: autoInit,
67
- gitignore_template: gitignoreTemplate,
68
- license_template: licenseTemplate
69
- };
70
-
71
- let url = org ? `/orgs/${org}/repos` : '/user/repos';
72
- let response = await this.http.post(url, body);
73
- return response.data;
74
- }
75
-
76
- async updateRepository(
77
- owner: string,
78
- repo: string,
79
- data: {
80
- name?: string;
81
- description?: string;
82
- homepage?: string;
83
- private?: boolean;
84
- hasIssues?: boolean;
85
- hasProjects?: boolean;
86
- hasWiki?: boolean;
87
- defaultBranch?: string;
88
- archived?: boolean;
89
- }
90
- ) {
91
- let body: Record<string, any> = {};
92
- if (data.name !== undefined) body.name = data.name;
93
- if (data.description !== undefined) body.description = data.description;
94
- if (data.homepage !== undefined) body.homepage = data.homepage;
95
- if (data.private !== undefined) body.private = data.private;
96
- if (data.hasIssues !== undefined) body.has_issues = data.hasIssues;
97
- if (data.hasProjects !== undefined) body.has_projects = data.hasProjects;
98
- if (data.hasWiki !== undefined) body.has_wiki = data.hasWiki;
99
- if (data.defaultBranch !== undefined) body.default_branch = data.defaultBranch;
100
- if (data.archived !== undefined) body.archived = data.archived;
101
-
102
- let response = await this.http.patch(`/repos/${owner}/${repo}`, body);
103
- return response.data;
104
- }
105
-
106
- async deleteRepository(owner: string, repo: string) {
107
- await this.http.delete(`/repos/${owner}/${repo}`);
108
- }
109
-
110
- // ─── Issues ────────────────────────────────────────────────────
111
-
112
- async listIssues(
113
- owner: string,
114
- repo: string,
115
- params: {
116
- state?: string;
117
- labels?: string;
118
- sort?: string;
119
- direction?: string;
120
- since?: string;
121
- perPage?: number;
122
- page?: number;
123
- assignee?: string;
124
- milestone?: string;
125
- } = {}
126
- ) {
127
- let response = await this.http.get(`/repos/${owner}/${repo}/issues`, {
128
- params: {
129
- ...params,
130
- per_page: params.perPage
131
- }
132
- });
133
- return response.data;
134
- }
135
-
136
- async getIssue(owner: string, repo: string, issueNumber: number) {
137
- let response = await this.http.get(`/repos/${owner}/${repo}/issues/${issueNumber}`);
138
- return response.data;
139
- }
140
-
141
- async createIssue(
142
- owner: string,
143
- repo: string,
144
- data: {
145
- title: string;
146
- body?: string;
147
- assignees?: string[];
148
- labels?: string[];
149
- milestone?: number;
150
- }
151
- ) {
152
- let response = await this.http.post(`/repos/${owner}/${repo}/issues`, data);
153
- return response.data;
154
- }
155
-
156
- async updateIssue(
157
- owner: string,
158
- repo: string,
159
- issueNumber: number,
160
- data: {
161
- title?: string;
162
- body?: string;
163
- state?: string;
164
- stateReason?: string;
165
- assignees?: string[];
166
- labels?: string[];
167
- milestone?: number | null;
168
- }
169
- ) {
170
- let body: Record<string, any> = { ...data };
171
- if (data.stateReason !== undefined) {
172
- body.state_reason = data.stateReason;
173
- delete body.stateReason;
174
- }
175
- let response = await this.http.patch(
176
- `/repos/${owner}/${repo}/issues/${issueNumber}`,
177
- body
178
- );
179
- return response.data;
180
- }
181
-
182
- async createIssueComment(owner: string, repo: string, issueNumber: number, body: string) {
183
- let response = await this.http.post(
184
- `/repos/${owner}/${repo}/issues/${issueNumber}/comments`,
185
- { body }
186
- );
187
- return response.data;
188
- }
189
-
190
- async listIssueComments(
191
- owner: string,
192
- repo: string,
193
- issueNumber: number,
194
- params: {
195
- perPage?: number;
196
- page?: number;
197
- since?: string;
198
- } = {}
199
- ) {
200
- let response = await this.http.get(
201
- `/repos/${owner}/${repo}/issues/${issueNumber}/comments`,
202
- {
203
- params: { per_page: params.perPage, page: params.page, since: params.since }
204
- }
205
- );
206
- return response.data;
207
- }
208
-
209
- // ─── Pull Requests ─────────────────────────────────────────────
210
-
211
- async listPullRequests(
212
- owner: string,
213
- repo: string,
214
- params: {
215
- state?: string;
216
- head?: string;
217
- base?: string;
218
- sort?: string;
219
- direction?: string;
220
- perPage?: number;
221
- page?: number;
222
- } = {}
223
- ) {
224
- let response = await this.http.get(`/repos/${owner}/${repo}/pulls`, {
225
- params: { ...params, per_page: params.perPage }
226
- });
227
- return response.data;
228
- }
229
-
230
- async getPullRequest(owner: string, repo: string, pullNumber: number) {
231
- let response = await this.http.get(`/repos/${owner}/${repo}/pulls/${pullNumber}`);
232
- return response.data;
233
- }
234
-
235
- async createPullRequest(
236
- owner: string,
237
- repo: string,
238
- data: {
239
- title: string;
240
- head: string;
241
- base: string;
242
- body?: string;
243
- draft?: boolean;
244
- maintainerCanModify?: boolean;
245
- }
246
- ) {
247
- let body: Record<string, any> = {
248
- title: data.title,
249
- head: data.head,
250
- base: data.base,
251
- body: data.body,
252
- draft: data.draft,
253
- maintainer_can_modify: data.maintainerCanModify
254
- };
255
- let response = await this.http.post(`/repos/${owner}/${repo}/pulls`, body);
256
- return response.data;
257
- }
258
-
259
- async updatePullRequest(
260
- owner: string,
261
- repo: string,
262
- pullNumber: number,
263
- data: {
264
- title?: string;
265
- body?: string;
266
- state?: string;
267
- base?: string;
268
- maintainerCanModify?: boolean;
269
- }
270
- ) {
271
- let body: Record<string, any> = {};
272
- if (data.title !== undefined) body.title = data.title;
273
- if (data.body !== undefined) body.body = data.body;
274
- if (data.state !== undefined) body.state = data.state;
275
- if (data.base !== undefined) body.base = data.base;
276
- if (data.maintainerCanModify !== undefined)
277
- body.maintainer_can_modify = data.maintainerCanModify;
278
-
279
- let response = await this.http.patch(`/repos/${owner}/${repo}/pulls/${pullNumber}`, body);
280
- return response.data;
281
- }
282
-
283
- async mergePullRequest(
284
- owner: string,
285
- repo: string,
286
- pullNumber: number,
287
- data: {
288
- commitTitle?: string;
289
- commitMessage?: string;
290
- mergeMethod?: string;
291
- sha?: string;
292
- } = {}
293
- ) {
294
- let body: Record<string, any> = {};
295
- if (data.commitTitle) body.commit_title = data.commitTitle;
296
- if (data.commitMessage) body.commit_message = data.commitMessage;
297
- if (data.mergeMethod) body.merge_method = data.mergeMethod;
298
- if (data.sha) body.sha = data.sha;
299
-
300
- let response = await this.http.put(
301
- `/repos/${owner}/${repo}/pulls/${pullNumber}/merge`,
302
- body
303
- );
304
- return response.data;
305
- }
306
-
307
- async listPullRequestReviews(owner: string, repo: string, pullNumber: number) {
308
- let response = await this.http.get(`/repos/${owner}/${repo}/pulls/${pullNumber}/reviews`);
309
- return response.data;
310
- }
311
-
312
- async createPullRequestReview(
313
- owner: string,
314
- repo: string,
315
- pullNumber: number,
316
- data: {
317
- body?: string;
318
- event: string;
319
- comments?: Array<{ path: string; position?: number; body: string }>;
320
- }
321
- ) {
322
- let response = await this.http.post(
323
- `/repos/${owner}/${repo}/pulls/${pullNumber}/reviews`,
324
- data
325
- );
326
- return response.data;
327
- }
328
-
329
- async requestReviewers(
330
- owner: string,
331
- repo: string,
332
- pullNumber: number,
333
- data: {
334
- reviewers?: string[];
335
- teamReviewers?: string[];
336
- }
337
- ) {
338
- let body: Record<string, any> = {};
339
- if (data.reviewers) body.reviewers = data.reviewers;
340
- if (data.teamReviewers) body.team_reviewers = data.teamReviewers;
341
-
342
- let response = await this.http.post(
343
- `/repos/${owner}/${repo}/pulls/${pullNumber}/requested_reviewers`,
344
- body
345
- );
346
- return response.data;
347
- }
348
-
349
- // ─── Branches ──────────────────────────────────────────────────
350
-
351
- async listBranches(
352
- owner: string,
353
- repo: string,
354
- params: {
355
- perPage?: number;
356
- page?: number;
357
- protected?: boolean;
358
- } = {}
359
- ) {
360
- let response = await this.http.get(`/repos/${owner}/${repo}/branches`, {
361
- params: { per_page: params.perPage, page: params.page, protected: params.protected }
362
- });
363
- return response.data;
364
- }
365
-
366
- async getBranch(owner: string, repo: string, branch: string) {
367
- let response = await this.http.get(`/repos/${owner}/${repo}/branches/${branch}`);
368
- return response.data;
369
- }
370
-
371
- // ─── Contents ──────────────────────────────────────────────────
372
-
373
- async getContent(owner: string, repo: string, path: string, ref?: string) {
374
- let response = await this.http.get(`/repos/${owner}/${repo}/contents/${path}`, {
375
- params: ref ? { ref } : undefined
376
- });
377
- return response.data;
378
- }
379
-
380
- async createOrUpdateFile(
381
- owner: string,
382
- repo: string,
383
- path: string,
384
- data: {
385
- message: string;
386
- content: string;
387
- sha?: string;
388
- branch?: string;
389
- }
390
- ) {
391
- let response = await this.http.put(`/repos/${owner}/${repo}/contents/${path}`, data);
392
- return response.data;
393
- }
394
-
395
- async deleteFile(
396
- owner: string,
397
- repo: string,
398
- path: string,
399
- data: {
400
- message: string;
401
- sha: string;
402
- branch?: string;
403
- }
404
- ) {
405
- let response = await this.http.delete(`/repos/${owner}/${repo}/contents/${path}`, {
406
- data
407
- });
408
- return response.data;
409
- }
410
-
411
- // ─── Labels ────────────────────────────────────────────────────
412
-
413
- async listLabels(
414
- owner: string,
415
- repo: string,
416
- params: { perPage?: number; page?: number } = {}
417
- ) {
418
- let response = await this.http.get(`/repos/${owner}/${repo}/labels`, {
419
- params: { per_page: params.perPage, page: params.page }
420
- });
421
- return response.data;
422
- }
423
-
424
- async createLabel(
425
- owner: string,
426
- repo: string,
427
- data: { name: string; color?: string; description?: string }
428
- ) {
429
- let response = await this.http.post(`/repos/${owner}/${repo}/labels`, data);
430
- return response.data;
431
- }
432
-
433
- // ─── Milestones ────────────────────────────────────────────────
434
-
435
- async listMilestones(
436
- owner: string,
437
- repo: string,
438
- params: {
439
- state?: string;
440
- sort?: string;
441
- direction?: string;
442
- perPage?: number;
443
- page?: number;
444
- } = {}
445
- ) {
446
- let response = await this.http.get(`/repos/${owner}/${repo}/milestones`, {
447
- params: { ...params, per_page: params.perPage }
448
- });
449
- return response.data;
450
- }
451
-
452
- // ─── Workflows / Actions ───────────────────────────────────────
453
-
454
- async listWorkflows(
455
- owner: string,
456
- repo: string,
457
- params: { perPage?: number; page?: number } = {}
458
- ) {
459
- let response = await this.http.get(`/repos/${owner}/${repo}/actions/workflows`, {
460
- params: { per_page: params.perPage, page: params.page }
461
- });
462
- return response.data;
463
- }
464
-
465
- async listWorkflowRuns(
466
- owner: string,
467
- repo: string,
468
- params: {
469
- workflowId?: number | string;
470
- branch?: string;
471
- event?: string;
472
- status?: string;
473
- perPage?: number;
474
- page?: number;
475
- } = {}
476
- ) {
477
- let url = params.workflowId
478
- ? `/repos/${owner}/${repo}/actions/workflows/${params.workflowId}/runs`
479
- : `/repos/${owner}/${repo}/actions/runs`;
480
-
481
- let { workflowId, ...queryParams } = params;
482
- let response = await this.http.get(url, {
483
- params: { ...queryParams, per_page: queryParams.perPage }
484
- });
485
- return response.data;
486
- }
487
-
488
- async getWorkflowRun(owner: string, repo: string, runId: number) {
489
- let response = await this.http.get(`/repos/${owner}/${repo}/actions/runs/${runId}`);
490
- return response.data;
491
- }
492
-
493
- async triggerWorkflowDispatch(
494
- owner: string,
495
- repo: string,
496
- workflowId: number | string,
497
- data: {
498
- ref: string;
499
- inputs?: Record<string, string>;
500
- }
501
- ) {
502
- await this.http.post(
503
- `/repos/${owner}/${repo}/actions/workflows/${workflowId}/dispatches`,
504
- data
505
- );
506
- }
507
-
508
- async cancelWorkflowRun(owner: string, repo: string, runId: number) {
509
- await this.http.post(`/repos/${owner}/${repo}/actions/runs/${runId}/cancel`);
510
- }
511
-
512
- async rerunWorkflow(owner: string, repo: string, runId: number) {
513
- await this.http.post(`/repos/${owner}/${repo}/actions/runs/${runId}/rerun`);
514
- }
515
-
516
- async listWorkflowRunJobs(
517
- owner: string,
518
- repo: string,
519
- runId: number,
520
- params: {
521
- filter?: string;
522
- perPage?: number;
523
- page?: number;
524
- } = {}
525
- ) {
526
- let response = await this.http.get(`/repos/${owner}/${repo}/actions/runs/${runId}/jobs`, {
527
- params: { ...params, per_page: params.perPage }
528
- });
529
- return response.data;
530
- }
531
-
532
- // ─── Releases ──────────────────────────────────────────────────
533
-
534
- async listReleases(
535
- owner: string,
536
- repo: string,
537
- params: { perPage?: number; page?: number } = {}
538
- ) {
539
- let response = await this.http.get(`/repos/${owner}/${repo}/releases`, {
540
- params: { per_page: params.perPage, page: params.page }
541
- });
542
- return response.data;
543
- }
544
-
545
- async getRelease(owner: string, repo: string, releaseId: number) {
546
- let response = await this.http.get(`/repos/${owner}/${repo}/releases/${releaseId}`);
547
- return response.data;
548
- }
549
-
550
- async getLatestRelease(owner: string, repo: string) {
551
- let response = await this.http.get(`/repos/${owner}/${repo}/releases/latest`);
552
- return response.data;
553
- }
554
-
555
- async createRelease(
556
- owner: string,
557
- repo: string,
558
- data: {
559
- tagName: string;
560
- targetCommitish?: string;
561
- name?: string;
562
- body?: string;
563
- draft?: boolean;
564
- prerelease?: boolean;
565
- generateReleaseNotes?: boolean;
566
- }
567
- ) {
568
- let body: Record<string, any> = {
569
- tag_name: data.tagName,
570
- name: data.name,
571
- body: data.body,
572
- draft: data.draft,
573
- prerelease: data.prerelease,
574
- generate_release_notes: data.generateReleaseNotes
575
- };
576
- if (data.targetCommitish) body.target_commitish = data.targetCommitish;
577
-
578
- let response = await this.http.post(`/repos/${owner}/${repo}/releases`, body);
579
- return response.data;
580
- }
581
-
582
- // ─── Search ────────────────────────────────────────────────────
583
-
584
- async searchRepositories(
585
- query: string,
586
- params: {
587
- sort?: string;
588
- order?: string;
589
- perPage?: number;
590
- page?: number;
591
- } = {}
592
- ) {
593
- let response = await this.http.get('/search/repositories', {
594
- params: { q: query, ...params, per_page: params.perPage }
595
- });
596
- return response.data;
597
- }
598
-
599
- async searchCode(
600
- query: string,
601
- params: {
602
- sort?: string;
603
- order?: string;
604
- perPage?: number;
605
- page?: number;
606
- } = {}
607
- ) {
608
- let response = await this.http.get('/search/code', {
609
- params: { q: query, ...params, per_page: params.perPage }
610
- });
611
- return response.data;
612
- }
613
-
614
- async searchIssues(
615
- query: string,
616
- params: {
617
- sort?: string;
618
- order?: string;
619
- perPage?: number;
620
- page?: number;
621
- } = {}
622
- ) {
623
- let response = await this.http.get('/search/issues', {
624
- params: { q: query, ...params, per_page: params.perPage }
625
- });
626
- return response.data;
627
- }
628
-
629
- async searchUsers(
630
- query: string,
631
- params: {
632
- sort?: string;
633
- order?: string;
634
- perPage?: number;
635
- page?: number;
636
- } = {}
637
- ) {
638
- let response = await this.http.get('/search/users', {
639
- params: { q: query, ...params, per_page: params.perPage }
640
- });
641
- return response.data;
642
- }
643
-
644
- // ─── Users ─────────────────────────────────────────────────────
645
-
646
- async getAuthenticatedUser() {
647
- let response = await this.http.get('/user');
648
- return response.data;
649
- }
650
-
651
- async getUser(username: string) {
652
- let response = await this.http.get(`/users/${username}`);
653
- return response.data;
654
- }
655
-
656
- // ─── Organizations ────────────────────────────────────────────
657
-
658
- async listUserOrgs(params: { perPage?: number; page?: number } = {}) {
659
- let response = await this.http.get('/user/orgs', {
660
- params: { per_page: params.perPage, page: params.page }
661
- });
662
- return response.data;
663
- }
664
-
665
- async getOrg(org: string) {
666
- let response = await this.http.get(`/orgs/${org}`);
667
- return response.data;
668
- }
669
-
670
- async listOrgMembers(
671
- org: string,
672
- params: { role?: string; perPage?: number; page?: number } = {}
673
- ) {
674
- let response = await this.http.get(`/orgs/${org}/members`, {
675
- params: { ...params, per_page: params.perPage }
676
- });
677
- return response.data;
678
- }
679
-
680
- async listOrgRepos(
681
- org: string,
682
- params: {
683
- type?: string;
684
- sort?: string;
685
- direction?: string;
686
- perPage?: number;
687
- page?: number;
688
- } = {}
689
- ) {
690
- let response = await this.http.get(`/orgs/${org}/repos`, {
691
- params: { ...params, per_page: params.perPage }
692
- });
693
- return response.data;
694
- }
695
-
696
- // ─── Teams ─────────────────────────────────────────────────────
697
-
698
- async listOrgTeams(org: string, params: { perPage?: number; page?: number } = {}) {
699
- let response = await this.http.get(`/orgs/${org}/teams`, {
700
- params: { per_page: params.perPage, page: params.page }
701
- });
702
- return response.data;
703
- }
704
-
705
- // ─── Commits ───────────────────────────────────────────────────
706
-
707
- async listCommits(
708
- owner: string,
709
- repo: string,
710
- params: {
711
- sha?: string;
712
- path?: string;
713
- author?: string;
714
- since?: string;
715
- until?: string;
716
- perPage?: number;
717
- page?: number;
718
- } = {}
719
- ) {
720
- let response = await this.http.get(`/repos/${owner}/${repo}/commits`, {
721
- params: { ...params, per_page: params.perPage }
722
- });
723
- return response.data;
724
- }
725
-
726
- async getCommit(owner: string, repo: string, ref: string) {
727
- let response = await this.http.get(`/repos/${owner}/${repo}/commits/${ref}`);
728
- return response.data;
729
- }
730
-
731
- // ─── Collaborators ────────────────────────────────────────────
732
-
733
- async listCollaborators(
734
- owner: string,
735
- repo: string,
736
- params: { perPage?: number; page?: number } = {}
737
- ) {
738
- let response = await this.http.get(`/repos/${owner}/${repo}/collaborators`, {
739
- params: { per_page: params.perPage, page: params.page }
740
- });
741
- return response.data;
742
- }
743
-
744
- async addCollaborator(owner: string, repo: string, username: string, permission?: string) {
745
- let response = await this.http.put(`/repos/${owner}/${repo}/collaborators/${username}`, {
746
- permission
747
- });
748
- return response.data;
749
- }
750
-
751
- async removeCollaborator(owner: string, repo: string, username: string) {
752
- await this.http.delete(`/repos/${owner}/${repo}/collaborators/${username}`);
753
- }
754
-
755
- // ─── Webhooks ──────────────────────────────────────────────────
756
-
757
- async createWebhook(
758
- owner: string,
759
- repo: string,
760
- data: {
761
- url: string;
762
- contentType?: string;
763
- secret?: string;
764
- events?: string[];
765
- active?: boolean;
766
- }
767
- ) {
768
- let response = await this.http.post(`/repos/${owner}/${repo}/hooks`, {
769
- name: 'web',
770
- active: data.active ?? true,
771
- events: data.events ?? ['push'],
772
- config: {
773
- url: data.url,
774
- content_type: data.contentType ?? 'json',
775
- secret: data.secret
776
- }
777
- });
778
- return response.data;
779
- }
780
-
781
- async deleteWebhook(owner: string, repo: string, hookId: number) {
782
- await this.http.delete(`/repos/${owner}/${repo}/hooks/${hookId}`);
783
- }
784
-
785
- async listWebhooks(
786
- owner: string,
787
- repo: string,
788
- params: { perPage?: number; page?: number } = {}
789
- ) {
790
- let response = await this.http.get(`/repos/${owner}/${repo}/hooks`, {
791
- params: { per_page: params.perPage, page: params.page }
792
- });
793
- return response.data;
794
- }
795
-
796
- // ─── Gists ─────────────────────────────────────────────────────
797
-
798
- async listGists(params: { since?: string; perPage?: number; page?: number } = {}) {
799
- let response = await this.http.get('/gists', {
800
- params: { ...params, per_page: params.perPage }
801
- });
802
- return response.data;
803
- }
804
-
805
- async getGist(gistId: string) {
806
- let response = await this.http.get(`/gists/${gistId}`);
807
- return response.data;
808
- }
809
-
810
- async createGist(data: {
811
- description?: string;
812
- public?: boolean;
813
- files: Record<string, { content: string }>;
814
- }) {
815
- let response = await this.http.post('/gists', data);
816
- return response.data;
817
- }
818
-
819
- async updateGist(
820
- gistId: string,
821
- data: {
822
- description?: string;
823
- files?: Record<string, { content?: string; filename?: string } | null>;
824
- }
825
- ) {
826
- let response = await this.http.patch(`/gists/${gistId}`, data);
827
- return response.data;
828
- }
829
-
830
- async deleteGist(gistId: string) {
831
- await this.http.delete(`/gists/${gistId}`);
832
- }
833
-
834
- // ─── Check Runs / Statuses ─────────────────────────────────────
835
-
836
- async listCheckRunsForRef(
837
- owner: string,
838
- repo: string,
839
- ref: string,
840
- params: {
841
- perPage?: number;
842
- page?: number;
843
- } = {}
844
- ) {
845
- let response = await this.http.get(`/repos/${owner}/${repo}/commits/${ref}/check-runs`, {
846
- params: { per_page: params.perPage, page: params.page }
847
- });
848
- return response.data;
849
- }
850
-
851
- async createCommitStatus(
852
- owner: string,
853
- repo: string,
854
- sha: string,
855
- data: {
856
- state: string;
857
- targetUrl?: string;
858
- description?: string;
859
- context?: string;
860
- }
861
- ) {
862
- let body: Record<string, any> = {
863
- state: data.state,
864
- description: data.description,
865
- context: data.context
866
- };
867
- if (data.targetUrl) body.target_url = data.targetUrl;
868
-
869
- let response = await this.http.post(`/repos/${owner}/${repo}/statuses/${sha}`, body);
870
- return response.data;
871
- }
872
-
873
- async getCombinedStatus(owner: string, repo: string, ref: string) {
874
- let response = await this.http.get(`/repos/${owner}/${repo}/commits/${ref}/status`);
875
- return response.data;
876
- }
877
-
878
- // ─── Deployments ───────────────────────────────────────────────
879
-
880
- async listDeployments(
881
- owner: string,
882
- repo: string,
883
- params: {
884
- environment?: string;
885
- sha?: string;
886
- ref?: string;
887
- perPage?: number;
888
- page?: number;
889
- } = {}
890
- ) {
891
- let response = await this.http.get(`/repos/${owner}/${repo}/deployments`, {
892
- params: { ...params, per_page: params.perPage }
893
- });
894
- return response.data;
895
- }
896
-
897
- async createDeployment(
898
- owner: string,
899
- repo: string,
900
- data: {
901
- ref: string;
902
- environment?: string;
903
- description?: string;
904
- autoMerge?: boolean;
905
- requiredContexts?: string[];
906
- }
907
- ) {
908
- let body: Record<string, any> = {
909
- ref: data.ref,
910
- environment: data.environment,
911
- description: data.description,
912
- auto_merge: data.autoMerge,
913
- required_contexts: data.requiredContexts
914
- };
915
-
916
- let response = await this.http.post(`/repos/${owner}/${repo}/deployments`, body);
917
- return response.data;
918
- }
919
-
920
- async createDeploymentStatus(
921
- owner: string,
922
- repo: string,
923
- deploymentId: number,
924
- data: {
925
- state: string;
926
- targetUrl?: string;
927
- description?: string;
928
- environment?: string;
929
- environmentUrl?: string;
930
- }
931
- ) {
932
- let body: Record<string, any> = {
933
- state: data.state,
934
- description: data.description,
935
- environment: data.environment
936
- };
937
- if (data.targetUrl) body.target_url = data.targetUrl;
938
- if (data.environmentUrl) body.environment_url = data.environmentUrl;
939
-
940
- let response = await this.http.post(
941
- `/repos/${owner}/${repo}/deployments/${deploymentId}/statuses`,
942
- body
943
- );
944
- return response.data;
945
- }
946
-
947
- // ─── Tags ──────────────────────────────────────────────────────
948
-
949
- async listTags(
950
- owner: string,
951
- repo: string,
952
- params: { perPage?: number; page?: number } = {}
953
- ) {
954
- let response = await this.http.get(`/repos/${owner}/${repo}/tags`, {
955
- params: { per_page: params.perPage, page: params.page }
956
- });
957
- return response.data;
958
- }
959
-
960
- // ─── Forks ─────────────────────────────────────────────────────
961
-
962
- async createFork(
963
- owner: string,
964
- repo: string,
965
- data: { organization?: string; name?: string } = {}
966
- ) {
967
- let response = await this.http.post(`/repos/${owner}/${repo}/forks`, data);
968
- return response.data;
969
- }
970
-
971
- // ─── Stars ─────────────────────────────────────────────────────
972
-
973
- async listStargazers(
974
- owner: string,
975
- repo: string,
976
- params: { perPage?: number; page?: number } = {}
977
- ) {
978
- let response = await this.http.get(`/repos/${owner}/${repo}/stargazers`, {
979
- params: { per_page: params.perPage, page: params.page }
980
- });
981
- return response.data;
982
- }
983
-
984
- async starRepository(owner: string, repo: string) {
985
- await this.http.put(`/user/starred/${owner}/${repo}`);
986
- }
987
-
988
- async unstarRepository(owner: string, repo: string) {
989
- await this.http.delete(`/user/starred/${owner}/${repo}`);
990
- }
991
- }