@forge-glance/sdk 0.1.1 → 0.2.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/dist/GitHubProvider.d.ts +14 -3
- package/dist/GitHubProvider.js +95 -2
- package/dist/GitLabProvider.d.ts +20 -3
- package/dist/GitLabProvider.js +185 -10
- package/dist/GitProvider.d.ts +64 -1
- package/dist/index.d.ts +14 -14
- package/dist/index.js +280 -12
- package/dist/providers.js +280 -12
- package/dist/types.d.ts +56 -1
- package/package.json +1 -1
- package/src/GitHubProvider.ts +424 -154
- package/src/GitLabProvider.ts +426 -88
- package/src/GitProvider.ts +113 -21
- package/src/index.ts +22 -15
- package/src/types.ts +59 -1
package/dist/GitHubProvider.d.ts
CHANGED
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
* Base URL: "https://api.github.com" for github.com; for GHES, the user
|
|
12
12
|
* provides the instance URL and we append "/api/v3".
|
|
13
13
|
*/
|
|
14
|
-
import type { GitProvider } from
|
|
15
|
-
import type { BranchProtectionRule, CreatePullRequestInput, MRDetail, PullRequest, UpdatePullRequestInput, UserRef } from
|
|
16
|
-
import { type ForgeLogger } from
|
|
14
|
+
import type { GitProvider } from './GitProvider.ts';
|
|
15
|
+
import type { BranchProtectionRule, CreatePullRequestInput, MergePullRequestInput, MRDetail, ProviderCapabilities, PullRequest, UpdatePullRequestInput, UserRef } from './types.ts';
|
|
16
|
+
import { type ForgeLogger } from './logger.ts';
|
|
17
17
|
export declare class GitHubProvider implements GitProvider {
|
|
18
18
|
readonly providerName: "github";
|
|
19
19
|
readonly baseURL: string;
|
|
@@ -29,6 +29,7 @@ export declare class GitHubProvider implements GitProvider {
|
|
|
29
29
|
constructor(baseURL: string, token: string, options?: {
|
|
30
30
|
logger?: ForgeLogger;
|
|
31
31
|
});
|
|
32
|
+
readonly capabilities: ProviderCapabilities;
|
|
32
33
|
validateToken(): Promise<UserRef>;
|
|
33
34
|
fetchPullRequests(): Promise<PullRequest[]>;
|
|
34
35
|
fetchSingleMR(projectPath: string, mrIid: number, _currentUserNumericId: number | null): Promise<PullRequest | null>;
|
|
@@ -39,6 +40,16 @@ export declare class GitHubProvider implements GitProvider {
|
|
|
39
40
|
createPullRequest(input: CreatePullRequestInput): Promise<PullRequest>;
|
|
40
41
|
updatePullRequest(projectPath: string, mrIid: number, input: UpdatePullRequestInput): Promise<PullRequest>;
|
|
41
42
|
restRequest(method: string, path: string, body?: unknown): Promise<Response>;
|
|
43
|
+
mergePullRequest(projectPath: string, mrIid: number, input?: MergePullRequestInput): Promise<PullRequest>;
|
|
44
|
+
approvePullRequest(projectPath: string, mrIid: number): Promise<void>;
|
|
45
|
+
unapprovePullRequest(_projectPath: string, _mrIid: number): Promise<void>;
|
|
46
|
+
rebasePullRequest(_projectPath: string, _mrIid: number): Promise<void>;
|
|
47
|
+
setAutoMerge(_projectPath: string, _mrIid: number): Promise<void>;
|
|
48
|
+
cancelAutoMerge(_projectPath: string, _mrIid: number): Promise<void>;
|
|
49
|
+
resolveDiscussion(_projectPath: string, _mrIid: number, _discussionId: string): Promise<void>;
|
|
50
|
+
unresolveDiscussion(_projectPath: string, _mrIid: number, _discussionId: string): Promise<void>;
|
|
51
|
+
retryPipeline(projectPath: string, pipelineId: number): Promise<void>;
|
|
52
|
+
requestReReview(projectPath: string, mrIid: number, reviewerUsernames?: string[]): Promise<void>;
|
|
42
53
|
private api;
|
|
43
54
|
/**
|
|
44
55
|
* Search for PRs using the GitHub search API.
|
package/dist/GitHubProvider.js
CHANGED
|
@@ -95,6 +95,16 @@ class GitHubProvider {
|
|
|
95
95
|
this.apiBase = `${this.baseURL}/api/v3`;
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
+
capabilities = {
|
|
99
|
+
canMerge: true,
|
|
100
|
+
canApprove: true,
|
|
101
|
+
canUnapprove: false,
|
|
102
|
+
canRebase: false,
|
|
103
|
+
canAutoMerge: false,
|
|
104
|
+
canResolveDiscussions: false,
|
|
105
|
+
canRetryPipeline: true,
|
|
106
|
+
canRequestReReview: true
|
|
107
|
+
};
|
|
98
108
|
async validateToken() {
|
|
99
109
|
const res = await this.api("GET", "/user");
|
|
100
110
|
if (!res.ok) {
|
|
@@ -136,7 +146,9 @@ class GitHubProvider {
|
|
|
136
146
|
]);
|
|
137
147
|
return this.toPullRequest(pr, prRoles, reviews, checkRuns);
|
|
138
148
|
}));
|
|
139
|
-
this.log.debug("GitHubProvider.fetchPullRequests", {
|
|
149
|
+
this.log.debug("GitHubProvider.fetchPullRequests", {
|
|
150
|
+
count: results.length
|
|
151
|
+
});
|
|
140
152
|
return results;
|
|
141
153
|
}
|
|
142
154
|
async fetchSingleMR(projectPath, mrIid, _currentUserNumericId) {
|
|
@@ -249,7 +261,11 @@ class GitHubProvider {
|
|
|
249
261
|
async fetchPullRequestByBranch(projectPath, sourceBranch) {
|
|
250
262
|
const res = await this.api("GET", `/repos/${projectPath}/pulls?head=${projectPath.split("/")[0]}:${encodeURIComponent(sourceBranch)}&state=open&per_page=1`);
|
|
251
263
|
if (!res.ok) {
|
|
252
|
-
this.log.warn("fetchPullRequestByBranch failed", {
|
|
264
|
+
this.log.warn("fetchPullRequestByBranch failed", {
|
|
265
|
+
projectPath,
|
|
266
|
+
sourceBranch,
|
|
267
|
+
status: res.status
|
|
268
|
+
});
|
|
253
269
|
return null;
|
|
254
270
|
}
|
|
255
271
|
const prs = await res.json();
|
|
@@ -333,6 +349,83 @@ class GitHubProvider {
|
|
|
333
349
|
async restRequest(method, path, body) {
|
|
334
350
|
return this.api(method, path, body);
|
|
335
351
|
}
|
|
352
|
+
async mergePullRequest(projectPath, mrIid, input) {
|
|
353
|
+
const body = {};
|
|
354
|
+
if (input?.commitMessage != null)
|
|
355
|
+
body.commit_title = input.commitMessage;
|
|
356
|
+
if (input?.squashCommitMessage != null)
|
|
357
|
+
body.commit_title = input.squashCommitMessage;
|
|
358
|
+
if (input?.shouldRemoveSourceBranch != null)
|
|
359
|
+
body.delete_branch = input.shouldRemoveSourceBranch;
|
|
360
|
+
if (input?.sha != null)
|
|
361
|
+
body.sha = input.sha;
|
|
362
|
+
if (input?.mergeMethod) {
|
|
363
|
+
body.merge_method = input.mergeMethod;
|
|
364
|
+
} else if (input?.squash) {
|
|
365
|
+
body.merge_method = "squash";
|
|
366
|
+
}
|
|
367
|
+
const res = await this.api("PUT", `/repos/${projectPath}/pulls/${mrIid}/merge`, body);
|
|
368
|
+
if (!res.ok) {
|
|
369
|
+
const text = await res.text();
|
|
370
|
+
throw new Error(`mergePullRequest failed: ${res.status} ${text}`);
|
|
371
|
+
}
|
|
372
|
+
const pr = await this.fetchSingleMR(projectPath, mrIid, null);
|
|
373
|
+
if (!pr)
|
|
374
|
+
throw new Error("Merged PR but failed to fetch it back");
|
|
375
|
+
return pr;
|
|
376
|
+
}
|
|
377
|
+
async approvePullRequest(projectPath, mrIid) {
|
|
378
|
+
const res = await this.api("POST", `/repos/${projectPath}/pulls/${mrIid}/reviews`, {
|
|
379
|
+
event: "APPROVE"
|
|
380
|
+
});
|
|
381
|
+
if (!res.ok) {
|
|
382
|
+
const text = await res.text().catch(() => "");
|
|
383
|
+
throw new Error(`approvePullRequest failed: ${res.status} ${res.statusText}${text ? ` — ${text}` : ""}`);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
async unapprovePullRequest(_projectPath, _mrIid) {
|
|
387
|
+
throw new Error("unapprovePullRequest is not supported by GitHub. " + "Check provider.capabilities.canUnapprove before calling.");
|
|
388
|
+
}
|
|
389
|
+
async rebasePullRequest(_projectPath, _mrIid) {
|
|
390
|
+
throw new Error("rebasePullRequest is not supported by GitHub. " + "Check provider.capabilities.canRebase before calling.");
|
|
391
|
+
}
|
|
392
|
+
async setAutoMerge(_projectPath, _mrIid) {
|
|
393
|
+
throw new Error("setAutoMerge is not supported by the GitHub REST API. " + "Check provider.capabilities.canAutoMerge before calling.");
|
|
394
|
+
}
|
|
395
|
+
async cancelAutoMerge(_projectPath, _mrIid) {
|
|
396
|
+
throw new Error("cancelAutoMerge is not supported by the GitHub REST API. " + "Check provider.capabilities.canAutoMerge before calling.");
|
|
397
|
+
}
|
|
398
|
+
async resolveDiscussion(_projectPath, _mrIid, _discussionId) {
|
|
399
|
+
throw new Error("resolveDiscussion is not supported by the GitHub REST API. " + "Check provider.capabilities.canResolveDiscussions before calling.");
|
|
400
|
+
}
|
|
401
|
+
async unresolveDiscussion(_projectPath, _mrIid, _discussionId) {
|
|
402
|
+
throw new Error("unresolveDiscussion is not supported by the GitHub REST API. " + "Check provider.capabilities.canResolveDiscussions before calling.");
|
|
403
|
+
}
|
|
404
|
+
async retryPipeline(projectPath, pipelineId) {
|
|
405
|
+
const res = await this.api("POST", `/repos/${projectPath}/actions/runs/${pipelineId}/rerun`);
|
|
406
|
+
if (!res.ok) {
|
|
407
|
+
const text = await res.text().catch(() => "");
|
|
408
|
+
throw new Error(`retryPipeline failed: ${res.status} ${res.statusText}${text ? ` — ${text}` : ""}`);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
async requestReReview(projectPath, mrIid, reviewerUsernames) {
|
|
412
|
+
if (!reviewerUsernames?.length) {
|
|
413
|
+
const prRes = await this.api("GET", `/repos/${projectPath}/pulls/${mrIid}`);
|
|
414
|
+
if (!prRes.ok) {
|
|
415
|
+
throw new Error(`requestReReview: failed to fetch PR: ${prRes.status}`);
|
|
416
|
+
}
|
|
417
|
+
const pr = await prRes.json();
|
|
418
|
+
reviewerUsernames = pr.requested_reviewers.map((r) => r.login);
|
|
419
|
+
if (!reviewerUsernames.length) {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
const res = await this.api("POST", `/repos/${projectPath}/pulls/${mrIid}/requested_reviewers`, { reviewers: reviewerUsernames });
|
|
424
|
+
if (!res.ok) {
|
|
425
|
+
const text = await res.text().catch(() => "");
|
|
426
|
+
throw new Error(`requestReReview failed: ${res.status} ${res.statusText}${text ? ` — ${text}` : ""}`);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
336
429
|
async api(method, path, body) {
|
|
337
430
|
const url = `${this.apiBase}${path}`;
|
|
338
431
|
const headers = {
|
package/dist/GitLabProvider.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { GitProvider } from
|
|
2
|
-
import type { BranchProtectionRule, CreatePullRequestInput, MRDetail, PullRequest, UpdatePullRequestInput, UserRef } from
|
|
3
|
-
import { type ForgeLogger } from
|
|
1
|
+
import type { GitProvider } from './GitProvider.ts';
|
|
2
|
+
import type { BranchProtectionRule, CreatePullRequestInput, MergePullRequestInput, MRDetail, ProviderCapabilities, PullRequest, UpdatePullRequestInput, UserRef } from './types.ts';
|
|
3
|
+
import { type ForgeLogger } from './logger.ts';
|
|
4
4
|
/**
|
|
5
5
|
* Strips the provider prefix from a scoped repositoryId and returns the
|
|
6
6
|
* numeric GitLab project ID needed for REST API calls.
|
|
@@ -17,6 +17,7 @@ export declare class GitLabProvider implements GitProvider {
|
|
|
17
17
|
constructor(baseURL: string, token: string, options?: {
|
|
18
18
|
logger?: ForgeLogger;
|
|
19
19
|
});
|
|
20
|
+
readonly capabilities: ProviderCapabilities;
|
|
20
21
|
validateToken(): Promise<UserRef>;
|
|
21
22
|
/**
|
|
22
23
|
* Fetch a single MR by project path and IID.
|
|
@@ -35,5 +36,21 @@ export declare class GitLabProvider implements GitProvider {
|
|
|
35
36
|
createPullRequest(input: CreatePullRequestInput): Promise<PullRequest>;
|
|
36
37
|
updatePullRequest(projectPath: string, mrIid: number, input: UpdatePullRequestInput): Promise<PullRequest>;
|
|
37
38
|
restRequest(method: string, path: string, body?: unknown): Promise<Response>;
|
|
39
|
+
mergePullRequest(projectPath: string, mrIid: number, input?: MergePullRequestInput): Promise<PullRequest>;
|
|
40
|
+
approvePullRequest(projectPath: string, mrIid: number): Promise<void>;
|
|
41
|
+
unapprovePullRequest(projectPath: string, mrIid: number): Promise<void>;
|
|
42
|
+
rebasePullRequest(projectPath: string, mrIid: number): Promise<void>;
|
|
43
|
+
setAutoMerge(projectPath: string, mrIid: number): Promise<void>;
|
|
44
|
+
cancelAutoMerge(projectPath: string, mrIid: number): Promise<void>;
|
|
45
|
+
resolveDiscussion(projectPath: string, mrIid: number, discussionId: string): Promise<void>;
|
|
46
|
+
unresolveDiscussion(projectPath: string, mrIid: number, discussionId: string): Promise<void>;
|
|
47
|
+
retryPipeline(projectPath: string, pipelineId: number): Promise<void>;
|
|
48
|
+
requestReReview(projectPath: string, mrIid: number, _reviewerUsernames?: string[]): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Retry `fetchSingleMR` with exponential backoff to handle REST→GraphQL
|
|
51
|
+
* eventual consistency. GitLab's GraphQL may not immediately reflect
|
|
52
|
+
* changes made via REST. 3 attempts: 0ms, 300ms, 600ms delay.
|
|
53
|
+
*/
|
|
54
|
+
private fetchSingleMRWithRetry;
|
|
38
55
|
private runQuery;
|
|
39
56
|
}
|
package/dist/GitLabProvider.js
CHANGED
|
@@ -236,8 +236,20 @@ class GitLabProvider {
|
|
|
236
236
|
this.baseURL = baseURL.replace(/\/$/, "");
|
|
237
237
|
this.token = token;
|
|
238
238
|
this.log = options.logger ?? noopLogger;
|
|
239
|
-
this.mrDetailFetcher = new MRDetailFetcher(this.baseURL, token, {
|
|
239
|
+
this.mrDetailFetcher = new MRDetailFetcher(this.baseURL, token, {
|
|
240
|
+
logger: this.log
|
|
241
|
+
});
|
|
240
242
|
}
|
|
243
|
+
capabilities = {
|
|
244
|
+
canMerge: true,
|
|
245
|
+
canApprove: true,
|
|
246
|
+
canUnapprove: true,
|
|
247
|
+
canRebase: true,
|
|
248
|
+
canAutoMerge: true,
|
|
249
|
+
canResolveDiscussions: true,
|
|
250
|
+
canRetryPipeline: true,
|
|
251
|
+
canRequestReReview: true
|
|
252
|
+
};
|
|
241
253
|
async validateToken() {
|
|
242
254
|
const url = `${this.baseURL}/api/v4/user`;
|
|
243
255
|
const res = await fetch(url, {
|
|
@@ -343,7 +355,11 @@ class GitLabProvider {
|
|
|
343
355
|
headers: { "PRIVATE-TOKEN": this.token }
|
|
344
356
|
});
|
|
345
357
|
if (!res.ok) {
|
|
346
|
-
this.log.warn("fetchPullRequestByBranch failed", {
|
|
358
|
+
this.log.warn("fetchPullRequestByBranch failed", {
|
|
359
|
+
projectPath,
|
|
360
|
+
sourceBranch,
|
|
361
|
+
status: res.status
|
|
362
|
+
});
|
|
347
363
|
return null;
|
|
348
364
|
}
|
|
349
365
|
const mrs = await res.json();
|
|
@@ -381,10 +397,7 @@ class GitLabProvider {
|
|
|
381
397
|
throw new Error(`createPullRequest failed: ${res.status} ${text}`);
|
|
382
398
|
}
|
|
383
399
|
const created = await res.json();
|
|
384
|
-
|
|
385
|
-
if (!pr)
|
|
386
|
-
throw new Error("Created MR but failed to fetch it back");
|
|
387
|
-
return pr;
|
|
400
|
+
return this.fetchSingleMRWithRetry(input.projectPath, created.iid, "Created MR but failed to fetch it back");
|
|
388
401
|
}
|
|
389
402
|
async updatePullRequest(projectPath, mrIid, input) {
|
|
390
403
|
const encoded = encodeURIComponent(projectPath);
|
|
@@ -417,10 +430,7 @@ class GitLabProvider {
|
|
|
417
430
|
const text = await res.text();
|
|
418
431
|
throw new Error(`updatePullRequest failed: ${res.status} ${text}`);
|
|
419
432
|
}
|
|
420
|
-
|
|
421
|
-
if (!pr)
|
|
422
|
-
throw new Error("Updated MR but failed to fetch it back");
|
|
423
|
-
return pr;
|
|
433
|
+
return this.fetchSingleMRWithRetry(projectPath, mrIid, "Updated MR but failed to fetch it back");
|
|
424
434
|
}
|
|
425
435
|
async restRequest(method, path, body) {
|
|
426
436
|
const url = `${this.baseURL}${path}`;
|
|
@@ -436,6 +446,171 @@ class GitLabProvider {
|
|
|
436
446
|
body: body !== undefined ? JSON.stringify(body) : undefined
|
|
437
447
|
});
|
|
438
448
|
}
|
|
449
|
+
async mergePullRequest(projectPath, mrIid, input) {
|
|
450
|
+
const encoded = encodeURIComponent(projectPath);
|
|
451
|
+
const body = {};
|
|
452
|
+
if (input?.commitMessage != null)
|
|
453
|
+
body.merge_commit_message = input.commitMessage;
|
|
454
|
+
if (input?.squashCommitMessage != null)
|
|
455
|
+
body.squash_commit_message = input.squashCommitMessage;
|
|
456
|
+
if (input?.squash != null)
|
|
457
|
+
body.squash = input.squash;
|
|
458
|
+
if (input?.shouldRemoveSourceBranch != null)
|
|
459
|
+
body.should_remove_source_branch = input.shouldRemoveSourceBranch;
|
|
460
|
+
if (input?.sha != null)
|
|
461
|
+
body.sha = input.sha;
|
|
462
|
+
if (input?.mergeMethod === "squash" && input?.squash == null)
|
|
463
|
+
body.squash = true;
|
|
464
|
+
const res = await fetch(`${this.baseURL}/api/v4/projects/${encoded}/merge_requests/${mrIid}/merge`, {
|
|
465
|
+
method: "PUT",
|
|
466
|
+
headers: {
|
|
467
|
+
"PRIVATE-TOKEN": this.token,
|
|
468
|
+
"Content-Type": "application/json"
|
|
469
|
+
},
|
|
470
|
+
body: JSON.stringify(body)
|
|
471
|
+
});
|
|
472
|
+
if (!res.ok) {
|
|
473
|
+
const text = await res.text();
|
|
474
|
+
throw new Error(`mergePullRequest failed: ${res.status} ${text}`);
|
|
475
|
+
}
|
|
476
|
+
return this.fetchSingleMRWithRetry(projectPath, mrIid, "Merged MR but failed to fetch it back");
|
|
477
|
+
}
|
|
478
|
+
async approvePullRequest(projectPath, mrIid) {
|
|
479
|
+
const encoded = encodeURIComponent(projectPath);
|
|
480
|
+
const res = await fetch(`${this.baseURL}/api/v4/projects/${encoded}/merge_requests/${mrIid}/approve`, {
|
|
481
|
+
method: "POST",
|
|
482
|
+
headers: { "PRIVATE-TOKEN": this.token }
|
|
483
|
+
});
|
|
484
|
+
if (!res.ok) {
|
|
485
|
+
const text = await res.text().catch(() => "");
|
|
486
|
+
throw new Error(`approvePullRequest failed: ${res.status} ${res.statusText}${text ? ` — ${text}` : ""}`);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
async unapprovePullRequest(projectPath, mrIid) {
|
|
490
|
+
const encoded = encodeURIComponent(projectPath);
|
|
491
|
+
const res = await fetch(`${this.baseURL}/api/v4/projects/${encoded}/merge_requests/${mrIid}/unapprove`, {
|
|
492
|
+
method: "POST",
|
|
493
|
+
headers: { "PRIVATE-TOKEN": this.token }
|
|
494
|
+
});
|
|
495
|
+
if (!res.ok) {
|
|
496
|
+
const text = await res.text().catch(() => "");
|
|
497
|
+
throw new Error(`unapprovePullRequest failed: ${res.status} ${res.statusText}${text ? ` — ${text}` : ""}`);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
async rebasePullRequest(projectPath, mrIid) {
|
|
501
|
+
const encoded = encodeURIComponent(projectPath);
|
|
502
|
+
const res = await fetch(`${this.baseURL}/api/v4/projects/${encoded}/merge_requests/${mrIid}/rebase`, {
|
|
503
|
+
method: "PUT",
|
|
504
|
+
headers: { "PRIVATE-TOKEN": this.token }
|
|
505
|
+
});
|
|
506
|
+
if (!res.ok) {
|
|
507
|
+
const text = await res.text().catch(() => "");
|
|
508
|
+
throw new Error(`rebasePullRequest failed: ${res.status} ${res.statusText}${text ? ` — ${text}` : ""}`);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
async setAutoMerge(projectPath, mrIid) {
|
|
512
|
+
const encoded = encodeURIComponent(projectPath);
|
|
513
|
+
const res = await fetch(`${this.baseURL}/api/v4/projects/${encoded}/merge_requests/${mrIid}/merge`, {
|
|
514
|
+
method: "PUT",
|
|
515
|
+
headers: {
|
|
516
|
+
"PRIVATE-TOKEN": this.token,
|
|
517
|
+
"Content-Type": "application/json"
|
|
518
|
+
},
|
|
519
|
+
body: JSON.stringify({ merge_when_pipeline_succeeds: true })
|
|
520
|
+
});
|
|
521
|
+
if (!res.ok) {
|
|
522
|
+
const text = await res.text().catch(() => "");
|
|
523
|
+
throw new Error(`setAutoMerge failed: ${res.status} ${res.statusText}${text ? ` — ${text}` : ""}`);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
async cancelAutoMerge(projectPath, mrIid) {
|
|
527
|
+
const encoded = encodeURIComponent(projectPath);
|
|
528
|
+
const res = await fetch(`${this.baseURL}/api/v4/projects/${encoded}/merge_requests/${mrIid}/cancel_merge_when_pipeline_succeeds`, {
|
|
529
|
+
method: "POST",
|
|
530
|
+
headers: { "PRIVATE-TOKEN": this.token }
|
|
531
|
+
});
|
|
532
|
+
if (!res.ok) {
|
|
533
|
+
const text = await res.text().catch(() => "");
|
|
534
|
+
throw new Error(`cancelAutoMerge failed: ${res.status} ${res.statusText}${text ? ` — ${text}` : ""}`);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
async resolveDiscussion(projectPath, mrIid, discussionId) {
|
|
538
|
+
const encoded = encodeURIComponent(projectPath);
|
|
539
|
+
const res = await fetch(`${this.baseURL}/api/v4/projects/${encoded}/merge_requests/${mrIid}/discussions/${discussionId}`, {
|
|
540
|
+
method: "PUT",
|
|
541
|
+
headers: {
|
|
542
|
+
"PRIVATE-TOKEN": this.token,
|
|
543
|
+
"Content-Type": "application/json"
|
|
544
|
+
},
|
|
545
|
+
body: JSON.stringify({ resolved: true })
|
|
546
|
+
});
|
|
547
|
+
if (!res.ok) {
|
|
548
|
+
const text = await res.text().catch(() => "");
|
|
549
|
+
throw new Error(`resolveDiscussion failed: ${res.status} ${res.statusText}${text ? ` — ${text}` : ""}`);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
async unresolveDiscussion(projectPath, mrIid, discussionId) {
|
|
553
|
+
const encoded = encodeURIComponent(projectPath);
|
|
554
|
+
const res = await fetch(`${this.baseURL}/api/v4/projects/${encoded}/merge_requests/${mrIid}/discussions/${discussionId}`, {
|
|
555
|
+
method: "PUT",
|
|
556
|
+
headers: {
|
|
557
|
+
"PRIVATE-TOKEN": this.token,
|
|
558
|
+
"Content-Type": "application/json"
|
|
559
|
+
},
|
|
560
|
+
body: JSON.stringify({ resolved: false })
|
|
561
|
+
});
|
|
562
|
+
if (!res.ok) {
|
|
563
|
+
const text = await res.text().catch(() => "");
|
|
564
|
+
throw new Error(`unresolveDiscussion failed: ${res.status} ${res.statusText}${text ? ` — ${text}` : ""}`);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
async retryPipeline(projectPath, pipelineId) {
|
|
568
|
+
const encoded = encodeURIComponent(projectPath);
|
|
569
|
+
const res = await fetch(`${this.baseURL}/api/v4/projects/${encoded}/pipelines/${pipelineId}/retry`, {
|
|
570
|
+
method: "POST",
|
|
571
|
+
headers: { "PRIVATE-TOKEN": this.token }
|
|
572
|
+
});
|
|
573
|
+
if (!res.ok) {
|
|
574
|
+
const text = await res.text().catch(() => "");
|
|
575
|
+
throw new Error(`retryPipeline failed: ${res.status} ${res.statusText}${text ? ` — ${text}` : ""}`);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
async requestReReview(projectPath, mrIid, _reviewerUsernames) {
|
|
579
|
+
const encoded = encodeURIComponent(projectPath);
|
|
580
|
+
const mrRes = await fetch(`${this.baseURL}/api/v4/projects/${encoded}/merge_requests/${mrIid}`, { headers: { "PRIVATE-TOKEN": this.token } });
|
|
581
|
+
if (!mrRes.ok) {
|
|
582
|
+
const text = await mrRes.text().catch(() => "");
|
|
583
|
+
throw new Error(`requestReReview: failed to fetch MR: ${mrRes.status}${text ? ` — ${text}` : ""}`);
|
|
584
|
+
}
|
|
585
|
+
const mr = await mrRes.json();
|
|
586
|
+
const reviewerIds = mr.reviewers?.map((r) => r.id) ?? [];
|
|
587
|
+
if (reviewerIds.length === 0) {
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
const res = await fetch(`${this.baseURL}/api/v4/projects/${encoded}/merge_requests/${mrIid}`, {
|
|
591
|
+
method: "PUT",
|
|
592
|
+
headers: {
|
|
593
|
+
"PRIVATE-TOKEN": this.token,
|
|
594
|
+
"Content-Type": "application/json"
|
|
595
|
+
},
|
|
596
|
+
body: JSON.stringify({ reviewer_ids: reviewerIds })
|
|
597
|
+
});
|
|
598
|
+
if (!res.ok) {
|
|
599
|
+
const text = await res.text().catch(() => "");
|
|
600
|
+
throw new Error(`requestReReview failed: ${res.status} ${res.statusText}${text ? ` — ${text}` : ""}`);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
async fetchSingleMRWithRetry(projectPath, mrIid, errorMessage) {
|
|
604
|
+
for (let attempt = 0;attempt < 3; attempt++) {
|
|
605
|
+
if (attempt > 0) {
|
|
606
|
+
await new Promise((r) => setTimeout(r, attempt * 300));
|
|
607
|
+
}
|
|
608
|
+
const pr = await this.fetchSingleMR(projectPath, mrIid, null);
|
|
609
|
+
if (pr)
|
|
610
|
+
return pr;
|
|
611
|
+
}
|
|
612
|
+
throw new Error(errorMessage);
|
|
613
|
+
}
|
|
439
614
|
async runQuery(query, variables) {
|
|
440
615
|
const url = `${this.baseURL}/api/graphql`;
|
|
441
616
|
const body = JSON.stringify({ query, variables: variables ?? {} });
|
package/dist/GitProvider.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BranchProtectionRule, CreatePullRequestInput, MRDetail, PullRequest, UpdatePullRequestInput, UserRef } from
|
|
1
|
+
import type { BranchProtectionRule, CreatePullRequestInput, MergePullRequestInput, MRDetail, ProviderCapabilities, PullRequest, UpdatePullRequestInput, UserRef } from './types.ts';
|
|
2
2
|
/**
|
|
3
3
|
* Provider-agnostic interface for a Git hosting service.
|
|
4
4
|
*
|
|
@@ -54,6 +54,69 @@ export interface GitProvider {
|
|
|
54
54
|
* Returns the MRDetail with discussions populated.
|
|
55
55
|
*/
|
|
56
56
|
fetchMRDiscussions(repositoryId: string, mrIid: number): Promise<MRDetail>;
|
|
57
|
+
/**
|
|
58
|
+
* Reports which mutation operations this provider supports.
|
|
59
|
+
* Callers should check these flags to conditionally show/hide UI
|
|
60
|
+
* affordances without knowing which provider they're talking to.
|
|
61
|
+
*/
|
|
62
|
+
readonly capabilities: ProviderCapabilities;
|
|
63
|
+
/**
|
|
64
|
+
* Merge (accept) a pull request / merge request.
|
|
65
|
+
* All input fields are optional — omitting them defers to the project's
|
|
66
|
+
* configured defaults (merge method, squash policy, delete-source-branch).
|
|
67
|
+
*/
|
|
68
|
+
mergePullRequest(projectPath: string, mrIid: number, input?: MergePullRequestInput): Promise<PullRequest>;
|
|
69
|
+
/**
|
|
70
|
+
* Approve a pull request / merge request.
|
|
71
|
+
* On GitLab: POST /merge_requests/:iid/approve
|
|
72
|
+
* On GitHub: POST /pulls/:number/reviews with event "APPROVE"
|
|
73
|
+
*/
|
|
74
|
+
approvePullRequest(projectPath: string, mrIid: number): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Revoke an existing approval.
|
|
77
|
+
* GitLab-only — GitHub does not support unapproving via API.
|
|
78
|
+
* Check `capabilities.canUnapprove` before calling.
|
|
79
|
+
*/
|
|
80
|
+
unapprovePullRequest(projectPath: string, mrIid: number): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Rebase the MR source branch onto the target branch.
|
|
83
|
+
* GitLab-only — GitHub does not have a native rebase API.
|
|
84
|
+
* Check `capabilities.canRebase` before calling.
|
|
85
|
+
*/
|
|
86
|
+
rebasePullRequest(projectPath: string, mrIid: number): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Enable auto-merge: the MR will be merged automatically when the
|
|
89
|
+
* pipeline succeeds and all approval rules are met.
|
|
90
|
+
* GitLab-only — check `capabilities.canAutoMerge` before calling.
|
|
91
|
+
*/
|
|
92
|
+
setAutoMerge(projectPath: string, mrIid: number): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* Cancel a previously enabled auto-merge.
|
|
95
|
+
* GitLab-only — check `capabilities.canAutoMerge` before calling.
|
|
96
|
+
*/
|
|
97
|
+
cancelAutoMerge(projectPath: string, mrIid: number): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Resolve a discussion thread on an MR.
|
|
100
|
+
* GitLab-only — check `capabilities.canResolveDiscussions` before calling.
|
|
101
|
+
*/
|
|
102
|
+
resolveDiscussion(projectPath: string, mrIid: number, discussionId: string): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Unresolve a previously resolved discussion thread.
|
|
105
|
+
* GitLab-only — check `capabilities.canResolveDiscussions` before calling.
|
|
106
|
+
*/
|
|
107
|
+
unresolveDiscussion(projectPath: string, mrIid: number, discussionId: string): Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* Retry a failed or canceled pipeline.
|
|
110
|
+
* On GitLab: POST /pipelines/:id/retry
|
|
111
|
+
* On GitHub: POST re-run for the workflow run.
|
|
112
|
+
*/
|
|
113
|
+
retryPipeline(projectPath: string, pipelineId: number): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Re-request review attention on an MR from its reviewers.
|
|
116
|
+
* If `reviewerUsernames` is provided, only those reviewers are pinged;
|
|
117
|
+
* otherwise all current reviewers are re-requested.
|
|
118
|
+
*/
|
|
119
|
+
requestReReview(projectPath: string, mrIid: number, reviewerUsernames?: string[]): Promise<void>;
|
|
57
120
|
/**
|
|
58
121
|
* Make an authenticated REST API request to the provider.
|
|
59
122
|
* Used for operations that don't have a typed method yet (job traces,
|
package/dist/index.d.ts
CHANGED
|
@@ -11,17 +11,17 @@
|
|
|
11
11
|
* const provider = new GitLabProvider('https://gitlab.com', token, { logger: console });
|
|
12
12
|
* const prs = await provider.fetchPullRequests();
|
|
13
13
|
*/
|
|
14
|
-
export type { PullRequest, PullRequestsSnapshot, CreatePullRequestInput, UpdatePullRequestInput, BranchProtectionRule, Pipeline, PipelineJob, UserRef, DiffStats, Discussion, Note, NoteAuthor, NotePosition, MRDetail, FeedEvent, FeedSnapshot, ServerNotification
|
|
15
|
-
export type { GitProvider } from
|
|
16
|
-
export { parseRepoId, repoIdProvider } from
|
|
17
|
-
export type { ForgeLogger } from
|
|
18
|
-
export { noopLogger } from
|
|
19
|
-
export { GitLabProvider, parseGitLabRepoId, MR_DASHBOARD_FRAGMENT } from
|
|
20
|
-
export { GitHubProvider } from
|
|
21
|
-
export { createProvider, SUPPORTED_PROVIDERS } from
|
|
22
|
-
export type { ProviderSlug } from
|
|
23
|
-
export { ActionCableClient } from
|
|
24
|
-
export type { ActionCableCallbacks } from
|
|
25
|
-
export { MRDetailFetcher } from
|
|
26
|
-
export { NoteMutator } from
|
|
27
|
-
export type { CreatedNote } from
|
|
14
|
+
export type { PullRequest, PullRequestsSnapshot, CreatePullRequestInput, UpdatePullRequestInput, MergePullRequestInput, MergeMethod, ProviderCapabilities, BranchProtectionRule, Pipeline, PipelineJob, UserRef, DiffStats, Discussion, Note, NoteAuthor, NotePosition, MRDetail, FeedEvent, FeedSnapshot, ServerNotification } from './types.ts';
|
|
15
|
+
export type { GitProvider } from './GitProvider.ts';
|
|
16
|
+
export { parseRepoId, repoIdProvider } from './GitProvider.ts';
|
|
17
|
+
export type { ForgeLogger } from './logger.ts';
|
|
18
|
+
export { noopLogger } from './logger.ts';
|
|
19
|
+
export { GitLabProvider, parseGitLabRepoId, MR_DASHBOARD_FRAGMENT } from './GitLabProvider.ts';
|
|
20
|
+
export { GitHubProvider } from './GitHubProvider.ts';
|
|
21
|
+
export { createProvider, SUPPORTED_PROVIDERS } from './providers.ts';
|
|
22
|
+
export type { ProviderSlug } from './providers.ts';
|
|
23
|
+
export { ActionCableClient } from './ActionCableClient.ts';
|
|
24
|
+
export type { ActionCableCallbacks } from './ActionCableClient.ts';
|
|
25
|
+
export { MRDetailFetcher } from './MRDetailFetcher.ts';
|
|
26
|
+
export { NoteMutator } from './NoteMutator.ts';
|
|
27
|
+
export type { CreatedNote } from './NoteMutator.ts';
|