@gitkraken/core-gitlens 0.64.1 → 0.66.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/git-cli/providers/config.js +2 -2
- package/dist/git-cli/providers/pausedOperations.js +2 -2
- package/dist/git-cli/providers/pausedOperations.js.map +1 -1
- package/dist/git-cli/providers/staging.js +1 -1
- package/dist/ipc/discovery.js +1 -1
- package/dist/plus/agents/providers/claudeCodeTranscript.js +6 -6
- package/dist/plus/agents/providers/claudeCodeTranscript.js.map +1 -1
- package/dist/plus/ai/providers/openAICompatibleProviderBase.js +1 -1
- package/dist/plus/integrations/extensionManager.js.map +1 -1
- package/dist/plus/integrations/index.js +5 -1
- package/dist/plus/integrations/index.js.map +1 -1
- package/dist/plus/integrations/integrationService.d.ts +8 -4
- package/dist/plus/integrations/integrationService.js +23 -23
- package/dist/plus/integrations/integrationService.js.map +1 -1
- package/dist/plus/integrations/manager.d.ts +1 -4
- package/dist/plus/integrations/models/gitlabIssueWrites.d.ts +12 -5
- package/dist/plus/integrations/models/gitlabIssueWrites.js.map +1 -1
- package/dist/plus/integrations/models/gitlabMergeRequestWrites.d.ts +2 -5
- package/dist/plus/integrations/providers/azure/azure.js +1 -1
- package/dist/plus/integrations/providers/github.js +1 -1
- package/dist/plus/integrations/providers/gitlab/issueDelete.d.ts +11 -0
- package/dist/plus/integrations/providers/gitlab/issueDelete.js +132 -0
- package/dist/plus/integrations/providers/gitlab/issueDelete.js.map +1 -0
- package/dist/plus/integrations/providers/gitlab/issueWrites.d.ts +2 -1
- package/dist/plus/integrations/providers/gitlab/issueWrites.js +77 -33
- package/dist/plus/integrations/providers/gitlab/issueWrites.js.map +1 -1
- package/dist/plus/integrations/providers/gitlab/mergeRequestPermissions.d.ts +36 -0
- package/dist/plus/integrations/providers/gitlab/mergeRequestPermissions.js +36 -0
- package/dist/plus/integrations/providers/gitlab/mergeRequestPermissions.js.map +1 -0
- package/dist/plus/integrations/providers/gitlab/mergeRequestWrites.d.ts +1 -1
- package/dist/plus/integrations/providers/gitlab/mergeRequestWrites.js +91 -66
- package/dist/plus/integrations/providers/gitlab/mergeRequestWrites.js.map +1 -1
- package/dist/plus/integrations/providers/gitlab/writeTransport.d.ts +18 -1
- package/dist/plus/integrations/providers/gitlab/writeTransport.js +70 -11
- package/dist/plus/integrations/providers/gitlab/writeTransport.js.map +1 -1
- package/dist/plus/integrations/providers/gitlab.d.ts +4 -9
- package/dist/plus/integrations/providers/gitlab.js +29 -29
- package/dist/plus/integrations/providers/gitlab.js.map +1 -1
- package/dist/utils/env/node/exec.js +2 -2
- package/docs/integrations.md +48 -17
- package/package.json +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { GitLabMergeRequestReceipt } from "../../models/gitlabMergeRequestWrites.js";
|
|
2
|
+
import { GitLabWriteProject, GitLabWriteTransport } from "./writeTransport.js";
|
|
3
|
+
//#region ../plus/integrations/src/providers/gitlab/mergeRequestPermissions.d.ts
|
|
4
|
+
type MergeRequestPermissionFields = {
|
|
5
|
+
id?: string;
|
|
6
|
+
autoMergeEnabled?: unknown;
|
|
7
|
+
availableAutoMergeStrategies?: unknown;
|
|
8
|
+
squashOnMerge?: unknown;
|
|
9
|
+
squashReadOnly?: unknown;
|
|
10
|
+
sourceProject?: {
|
|
11
|
+
id?: unknown;
|
|
12
|
+
} | null;
|
|
13
|
+
targetProject?: {
|
|
14
|
+
id?: unknown;
|
|
15
|
+
} | null;
|
|
16
|
+
sourceBranch?: unknown;
|
|
17
|
+
targetBranch?: unknown;
|
|
18
|
+
diffHeadSha?: unknown;
|
|
19
|
+
userPermissions?: {
|
|
20
|
+
updateMergeRequest?: unknown;
|
|
21
|
+
canMerge?: unknown;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
type MergeRequestPermissions = {
|
|
25
|
+
project?: {
|
|
26
|
+
id?: string;
|
|
27
|
+
maxAccessLevel?: {
|
|
28
|
+
integerValue?: unknown;
|
|
29
|
+
};
|
|
30
|
+
mergeRequest?: MergeRequestPermissionFields | null;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export declare function readMergeRequestPermissions(transport: GitLabWriteTransport, project: GitLabWriteProject, iid: string, checkRefs: boolean): Promise<MergeRequestPermissions>;
|
|
34
|
+
export declare function changedMergeRequestRef(permissions: MergeRequestPermissionFields, mergeRequest: GitLabMergeRequestReceipt): 'source-changed' | 'target-changed' | undefined;
|
|
35
|
+
//#endregion
|
|
36
|
+
//# sourceMappingURL=mergeRequestPermissions.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region ../plus/integrations/src/providers/gitlab/mergeRequestPermissions.ts
|
|
2
|
+
function permissionsQuery(fields) {
|
|
3
|
+
return `query MergeRequestWritePermissions($path: ID!, $iid: String!) {
|
|
4
|
+
project(fullPath: $path) {
|
|
5
|
+
id
|
|
6
|
+
maxAccessLevel { integerValue }
|
|
7
|
+
mergeRequest(iid: $iid) {
|
|
8
|
+
id
|
|
9
|
+
autoMergeEnabled
|
|
10
|
+
availableAutoMergeStrategies
|
|
11
|
+
squashOnMerge
|
|
12
|
+
${fields}
|
|
13
|
+
userPermissions { updateMergeRequest canMerge }
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}`;
|
|
17
|
+
}
|
|
18
|
+
function readMergeRequestPermissions(transport, project, iid, checkRefs) {
|
|
19
|
+
const refs = checkRefs ? "sourceProject { id } targetProject { id } sourceBranch targetBranch diffHeadSha" : "";
|
|
20
|
+
return transport.readGraphQL(permissionsQuery(`squashReadOnly ${refs}`), {
|
|
21
|
+
path: project.fullPath,
|
|
22
|
+
iid
|
|
23
|
+
}, { project }, transport.selfManaged ? {
|
|
24
|
+
query: permissionsQuery(refs),
|
|
25
|
+
typeName: "MergeRequest",
|
|
26
|
+
fieldName: "squashReadOnly"
|
|
27
|
+
} : void 0);
|
|
28
|
+
}
|
|
29
|
+
function changedMergeRequestRef(permissions, mergeRequest) {
|
|
30
|
+
if (mergeRequest.sourceProjectId == null || permissions.sourceProject?.id !== `gid://gitlab/Project/${mergeRequest.sourceProjectId}` || permissions.sourceBranch !== mergeRequest.sourceBranch || typeof permissions.diffHeadSha !== "string" || permissions.diffHeadSha.toLowerCase() !== mergeRequest.sourceSha?.toLowerCase()) return "source-changed";
|
|
31
|
+
return permissions.targetProject?.id !== `gid://gitlab/Project/${mergeRequest.targetProjectId}` || permissions.targetBranch !== mergeRequest.targetBranch ? "target-changed" : void 0;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { changedMergeRequestRef, readMergeRequestPermissions };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=mergeRequestPermissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mergeRequestPermissions.js","names":[],"sources":["../../../../../../plus/integrations/src/providers/gitlab/mergeRequestPermissions.ts"],"sourcesContent":["import type { GitLabMergeRequestReceipt } from '../../models/gitlabMergeRequestWrites.js';\nimport type { GitLabWriteProject, GitLabWriteTransport } from './writeTransport.js';\n\ntype MergeRequestPermissionFields = {\n\tid?: string;\n\tautoMergeEnabled?: unknown;\n\tavailableAutoMergeStrategies?: unknown;\n\tsquashOnMerge?: unknown;\n\tsquashReadOnly?: unknown;\n\tsourceProject?: { id?: unknown } | null;\n\ttargetProject?: { id?: unknown } | null;\n\tsourceBranch?: unknown;\n\ttargetBranch?: unknown;\n\tdiffHeadSha?: unknown;\n\tuserPermissions?: { updateMergeRequest?: unknown; canMerge?: unknown };\n};\n\ntype MergeRequestPermissions = {\n\tproject?: {\n\t\tid?: string;\n\t\tmaxAccessLevel?: { integerValue?: unknown };\n\t\tmergeRequest?: MergeRequestPermissionFields | null;\n\t};\n};\nfunction permissionsQuery(fields: string): string {\n\treturn `query MergeRequestWritePermissions($path: ID!, $iid: String!) {\n\tproject(fullPath: $path) {\n\t\tid\n\t\tmaxAccessLevel { integerValue }\n\t\tmergeRequest(iid: $iid) {\n\t\t\tid\n\t\t\tautoMergeEnabled\n\t\t\tavailableAutoMergeStrategies\n\t\t\tsquashOnMerge\n\t\t\t${fields}\n\t\t\tuserPermissions { updateMergeRequest canMerge }\n\t\t}\n\t}\n}`;\n}\n\nexport function readMergeRequestPermissions(\n\ttransport: GitLabWriteTransport,\n\tproject: GitLabWriteProject,\n\tiid: string,\n\tcheckRefs: boolean,\n): Promise<MergeRequestPermissions> {\n\tconst refs = checkRefs ? 'sourceProject { id } targetProject { id } sourceBranch targetBranch diffHeadSha' : '';\n\treturn transport.readGraphQL<MergeRequestPermissions>(\n\t\tpermissionsQuery(`squashReadOnly ${refs}`),\n\t\t{ path: project.fullPath, iid: iid },\n\t\t{ project: project },\n\t\ttransport.selfManaged\n\t\t\t? {\n\t\t\t\t\tquery: permissionsQuery(refs),\n\t\t\t\t\ttypeName: 'MergeRequest',\n\t\t\t\t\tfieldName: 'squashReadOnly',\n\t\t\t\t}\n\t\t\t: undefined,\n\t);\n}\n\nexport function changedMergeRequestRef(\n\tpermissions: MergeRequestPermissionFields,\n\tmergeRequest: GitLabMergeRequestReceipt,\n): 'source-changed' | 'target-changed' | undefined {\n\tif (\n\t\tmergeRequest.sourceProjectId == null ||\n\t\tpermissions.sourceProject?.id !== `gid://gitlab/Project/${mergeRequest.sourceProjectId}` ||\n\t\tpermissions.sourceBranch !== mergeRequest.sourceBranch ||\n\t\ttypeof permissions.diffHeadSha !== 'string' ||\n\t\tpermissions.diffHeadSha.toLowerCase() !== mergeRequest.sourceSha?.toLowerCase()\n\t) {\n\t\treturn 'source-changed';\n\t}\n\n\treturn permissions.targetProject?.id !== `gid://gitlab/Project/${mergeRequest.targetProjectId}` ||\n\t\tpermissions.targetBranch !== mergeRequest.targetBranch\n\t\t? 'target-changed'\n\t\t: undefined;\n}\n"],"mappings":";AAwBA,SAAS,iBAAiB,QAAwB;CACjD,OAAO;;;;;;;;;KASH,OAAO;;;;;AAKZ;AAEA,SAAgB,4BACf,WACA,SACA,KACA,WACmC;CACnC,MAAM,OAAO,YAAY,oFAAoF;CAC7G,OAAO,UAAU,YAChB,iBAAiB,kBAAkB,MAAM,GACzC;EAAE,MAAM,QAAQ;EAAe;CAAI,GACnC,EAAW,QAAQ,GACnB,UAAU,cACP;EACA,OAAO,iBAAiB,IAAI;EAC5B,UAAU;EACV,WAAW;CACZ,IACC,KAAA,CACJ;AACD;AAEA,SAAgB,uBACf,aACA,cACkD;CAClD,IACC,aAAa,mBAAmB,QAChC,YAAY,eAAe,OAAO,wBAAwB,aAAa,qBACvE,YAAY,iBAAiB,aAAa,gBAC1C,OAAO,YAAY,gBAAgB,YACnC,YAAY,YAAY,YAAY,MAAM,aAAa,WAAW,YAAY,GAE9E,OAAO;CAGR,OAAO,YAAY,eAAe,OAAO,wBAAwB,aAAa,qBAC7E,YAAY,iBAAiB,aAAa,eACxC,mBACA,KAAA;AACJ"}
|
|
@@ -15,6 +15,7 @@ export declare class GitLabMergeRequestWriter {
|
|
|
15
15
|
delete(input: GitLabMergeRequestDeleteOptions): Promise<GitLabMergeRequestWriteResult>;
|
|
16
16
|
private create;
|
|
17
17
|
private writeExisting;
|
|
18
|
+
private checkLiveMergeRefs;
|
|
18
19
|
private merge;
|
|
19
20
|
private toMergeRefusal;
|
|
20
21
|
private readCreateTarget;
|
|
@@ -23,7 +24,6 @@ export declare class GitLabMergeRequestWriter {
|
|
|
23
24
|
private getCapabilities;
|
|
24
25
|
private getMergeCapability;
|
|
25
26
|
private findOpenMergeRequest;
|
|
26
|
-
private readBranchTip;
|
|
27
27
|
private mergeRequestPath;
|
|
28
28
|
}
|
|
29
29
|
//#endregion
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { isGitLabDecimalId } from "../../models/gitlabIssueWrites.js";
|
|
2
2
|
import { isGitBranchName } from "../utils/writeInputs.js";
|
|
3
3
|
import { GitLabWriteError, gitLabWriteFailure, validateGitLabWriteFields } from "./writeErrors.js";
|
|
4
|
-
import { isGitLabProjectRef, isGitLabUrl, restId } from "./writeTransport.js";
|
|
4
|
+
import { gitLabWriteUrlKey, isGitLabProjectRef, isGitLabSha, isGitLabUrl, restId } from "./writeTransport.js";
|
|
5
|
+
import { changedMergeRequestRef, readMergeRequestPermissions } from "./mergeRequestPermissions.js";
|
|
5
6
|
import * as l10n from "@vscode/l10n";
|
|
6
7
|
//#region ../plus/integrations/src/providers/gitlab/mergeRequestWrites.ts
|
|
7
8
|
const mergeRequestGidPrefix = "gid://gitlab/MergeRequest/";
|
|
8
9
|
const ownerAccessLevel = 50;
|
|
9
|
-
const shaPattern = /^[\da-f]{40}(?:[\da-f]{24})?$/i;
|
|
10
10
|
const draftTitlePattern = /^\s*(?:\[draft\]|\(draft\)|draft:)/i;
|
|
11
11
|
const timestampPattern = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})(?:\.(\d{1,9}))?(Z|[+-]\d{2}:\d{2})$/;
|
|
12
12
|
const mergeStatusPattern = /^[a-z][a-z_]{0,63}$/;
|
|
@@ -56,23 +56,6 @@ const createPermissionsQuery = `query MergeRequestCreatePermissions($target: ID!
|
|
|
56
56
|
target: project(fullPath: $target) { id userPermissions { createMergeRequestIn } }
|
|
57
57
|
source: project(fullPath: $source) { id userPermissions { createMergeRequestFrom } }
|
|
58
58
|
}`;
|
|
59
|
-
const mergeRequestPermissionsQuery = `query MergeRequestWritePermissions($path: ID!, $iid: String!) {
|
|
60
|
-
project(fullPath: $path) {
|
|
61
|
-
id
|
|
62
|
-
maxAccessLevel { integerValue }
|
|
63
|
-
mergeRequest(iid: $iid) {
|
|
64
|
-
id
|
|
65
|
-
autoMergeEnabled
|
|
66
|
-
availableAutoMergeStrategies
|
|
67
|
-
squashOnMerge
|
|
68
|
-
squashReadOnly
|
|
69
|
-
userPermissions { updateMergeRequest canMerge }
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}`;
|
|
73
|
-
function isSha(value) {
|
|
74
|
-
return typeof value === "string" && shaPattern.test(value);
|
|
75
|
-
}
|
|
76
59
|
function sameSha(actual, expected) {
|
|
77
60
|
return actual?.toLowerCase() === expected.toLowerCase();
|
|
78
61
|
}
|
|
@@ -94,17 +77,25 @@ function mergeStatusOf(raw) {
|
|
|
94
77
|
function isApprovedMerge(mergeRequest, input) {
|
|
95
78
|
return mergeRequest.sourceProjectId === input.expectedSourceProjectId && mergeRequest.sourceBranch === input.expectedSourceBranch && mergeRequest.targetBranch === input.expectedTargetBranch && sameSha(mergeRequest.sourceSha, input.expectedSourceSha);
|
|
96
79
|
}
|
|
80
|
+
function reachedApprovedSquash(raw, input) {
|
|
81
|
+
return input.squash ? isGitLabSha(raw.squash_commit_sha) : raw.squash_commit_sha === null;
|
|
82
|
+
}
|
|
97
83
|
function isApprovedTrainCar(car, project, input) {
|
|
98
84
|
const queued = car?.merge_request;
|
|
99
85
|
return restId(queued?.id) === input.expectedMergeRequestId && restId(queued?.iid) === input.iid && restId(queued?.project_id) === project.id && queued?.state === "opened" && car?.target_branch === input.expectedTargetBranch;
|
|
100
86
|
}
|
|
101
|
-
function mergeRequestReceipt(raw,
|
|
87
|
+
function mergeRequestReceipt(raw, context, iid, expectedId) {
|
|
88
|
+
const { project } = context;
|
|
102
89
|
const id = restId(raw?.id);
|
|
103
90
|
const actualIid = restId(raw?.iid);
|
|
104
91
|
const targetProjectId = restId(raw?.target_project_id);
|
|
105
92
|
const state = raw?.state;
|
|
106
|
-
if (id == null || actualIid == null || targetProjectId == null || !isGitLabUrl(raw.web_url) || typeof raw.title !== "string" || raw.description !== null && typeof raw.description !== "string" || !states.includes(state) || typeof raw.draft !== "boolean" || typeof raw.source_branch !== "string" || typeof raw.target_branch !== "string" || raw.sha != null && !
|
|
93
|
+
if (id == null || actualIid == null || targetProjectId == null || typeof raw.web_url !== "string" || context.providerId === "gitlab" && !isGitLabUrl(raw.web_url) || typeof raw.title !== "string" || raw.description !== null && typeof raw.description !== "string" || !states.includes(state) || typeof raw.draft !== "boolean" || typeof raw.source_branch !== "string" || typeof raw.target_branch !== "string" || raw.sha != null && !isGitLabSha(raw.sha)) throw new GitLabWriteError("unknown");
|
|
107
94
|
if (targetProjectId !== project.id || restId(raw.project_id) !== project.id || iid != null && iid !== actualIid || expectedId != null && expectedId !== id) throw new GitLabWriteError("conflict");
|
|
95
|
+
if (context.providerId !== "gitlab") {
|
|
96
|
+
const projectUrl = gitLabWriteUrlKey(project.url);
|
|
97
|
+
if (projectUrl == null || gitLabWriteUrlKey(raw.web_url) !== `${projectUrl}/-/merge_requests/${actualIid}`) throw new GitLabWriteError("conflict");
|
|
98
|
+
}
|
|
108
99
|
const sourceProjectId = restId(raw.source_project_id);
|
|
109
100
|
return {
|
|
110
101
|
id,
|
|
@@ -128,6 +119,15 @@ function allowed(value) {
|
|
|
128
119
|
reason: "forbidden"
|
|
129
120
|
};
|
|
130
121
|
}
|
|
122
|
+
function selfManagedSquash(project, squashOnMerge) {
|
|
123
|
+
switch (project.squash_option) {
|
|
124
|
+
case "always": return squashOnMerge ? "required" : void 0;
|
|
125
|
+
case "never": return squashOnMerge ? void 0 : "unavailable";
|
|
126
|
+
case "default_on":
|
|
127
|
+
case "default_off": return squashOnMerge ? "required" : "optional";
|
|
128
|
+
default: return;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
131
|
function transition(permission, available) {
|
|
132
132
|
return permission.allowed && !available ? {
|
|
133
133
|
allowed: false,
|
|
@@ -153,7 +153,7 @@ function mergeFailure({ kind: _kind, ...refusal }, dispatched) {
|
|
|
153
153
|
};
|
|
154
154
|
}
|
|
155
155
|
function isValidMerge(input) {
|
|
156
|
-
return typeof input.squash === "boolean" && mergeExecutions.includes(input.expectedExecution) && isMergeMethod(input.expectedMergeMethod) && typeof input.expectedRemovesSourceBranch === "boolean" && isGitLabDecimalId(input.expectedSourceProjectId) && isGitBranchName(input.expectedSourceBranch) && isGitBranchName(input.expectedTargetBranch) &&
|
|
156
|
+
return typeof input.squash === "boolean" && mergeExecutions.includes(input.expectedExecution) && isMergeMethod(input.expectedMergeMethod) && typeof input.expectedRemovesSourceBranch === "boolean" && isGitLabDecimalId(input.expectedSourceProjectId) && isGitBranchName(input.expectedSourceBranch) && isGitBranchName(input.expectedTargetBranch) && isGitLabSha(input.expectedSourceSha) && isGitLabSha(input.expectedTargetSha);
|
|
157
157
|
}
|
|
158
158
|
function validateFields(action, title, description) {
|
|
159
159
|
return validateGitLabWriteFields(action, title, description, l10n.t("GitLab quick actions are unavailable in merge request descriptions."));
|
|
@@ -215,7 +215,7 @@ var GitLabMergeRequestWriter = class {
|
|
|
215
215
|
if (input.action === "create") return this.create(input);
|
|
216
216
|
const { action } = input;
|
|
217
217
|
if (action !== "edit" && action !== "close" && action !== "reopen" && action !== "merge") return gitLabWriteFailure("invalid-input");
|
|
218
|
-
if (!isGitLabDecimalId(input.expectedMergeRequestId)) return gitLabWriteFailure("invalid-input");
|
|
218
|
+
if (!isGitLabDecimalId(input.iid) || !isGitLabDecimalId(input.expectedMergeRequestId)) return gitLabWriteFailure("invalid-input");
|
|
219
219
|
return this.writeExisting(input);
|
|
220
220
|
}
|
|
221
221
|
async delete(input) {
|
|
@@ -235,7 +235,10 @@ var GitLabMergeRequestWriter = class {
|
|
|
235
235
|
ok: true,
|
|
236
236
|
status: "deleted",
|
|
237
237
|
mergeRequest
|
|
238
|
-
}),
|
|
238
|
+
}), this.transport.selfManaged ? (response) => response.status === 405 ? {
|
|
239
|
+
ok: false,
|
|
240
|
+
reason: "unsupported"
|
|
241
|
+
} : void 0 : void 0, { "If-Unmodified-Since": unmodifiedSince });
|
|
239
242
|
}
|
|
240
243
|
async create(input) {
|
|
241
244
|
const { title, description, sourceBranch, targetBranch, sourceProjectId, draft } = input;
|
|
@@ -250,9 +253,9 @@ var GitLabMergeRequestWriter = class {
|
|
|
250
253
|
if (moved != null) return moved;
|
|
251
254
|
if (!capability.allowed) return gitLabWriteFailure(capability.reason);
|
|
252
255
|
if (sourceProject.id === project.id && sourceBranch === targetBranch) return gitLabWriteFailure("invalid-input");
|
|
253
|
-
if (await this.readBranchTip(sourceProject, sourceBranch) == null) return gitLabWriteFailure("not-found", { sourceBranch: l10n.t("Branch '{0}' not found", sourceBranch) });
|
|
254
|
-
if (await this.readBranchTip(project, targetBranch) == null) return gitLabWriteFailure("not-found", { targetBranch: l10n.t("Branch '{0}' not found", targetBranch) });
|
|
255
|
-
const existing = await this.findOpenMergeRequest(
|
|
256
|
+
if (await this.transport.readBranchTip(sourceProject, sourceBranch) == null) return gitLabWriteFailure("not-found", { sourceBranch: l10n.t("Branch '{0}' not found", sourceBranch) });
|
|
257
|
+
if (await this.transport.readBranchTip(project, targetBranch) == null) return gitLabWriteFailure("not-found", { targetBranch: l10n.t("Branch '{0}' not found", targetBranch) });
|
|
258
|
+
const existing = await this.findOpenMergeRequest(context, sourceProject, sourceBranch, targetBranch);
|
|
256
259
|
if (existing != null) return {
|
|
257
260
|
...gitLabWriteFailure("conflict"),
|
|
258
261
|
mergeRequest: existing
|
|
@@ -264,7 +267,7 @@ var GitLabMergeRequestWriter = class {
|
|
|
264
267
|
title: draft === true && !marked ? `Draft: ${title}` : title,
|
|
265
268
|
description
|
|
266
269
|
}, 201, async (response) => {
|
|
267
|
-
const created = mergeRequestReceipt(await response.json(),
|
|
270
|
+
const created = mergeRequestReceipt(await response.json(), context);
|
|
268
271
|
return created.state === "opened" && created.sourceProjectId === sourceProject.id && created.sourceBranch === sourceBranch && created.targetBranch === targetBranch ? {
|
|
269
272
|
...context,
|
|
270
273
|
ok: true,
|
|
@@ -283,10 +286,15 @@ var GitLabMergeRequestWriter = class {
|
|
|
283
286
|
const invalid = validateFields(action, input.title, input.description);
|
|
284
287
|
if (invalid != null) return invalid;
|
|
285
288
|
} else if (action === "merge" && !isValidMerge(input)) return gitLabWriteFailure("invalid-input");
|
|
289
|
+
const selfManagedMerge = action === "merge" && this.transport.selfManaged ? input : void 0;
|
|
290
|
+
if (selfManagedMerge != null) {
|
|
291
|
+
const stale = await this.checkLiveMergeRefs(selfManagedMerge);
|
|
292
|
+
if (stale != null) return stale;
|
|
293
|
+
}
|
|
286
294
|
const read = await this.readMergeRequest({
|
|
287
295
|
...input,
|
|
288
296
|
project: input.projectId
|
|
289
|
-
});
|
|
297
|
+
}, selfManagedMerge?.expectedTargetSha);
|
|
290
298
|
const { context, mergeRequest, capabilities, lockVersion } = read;
|
|
291
299
|
const moved = movedProject(input, context.project);
|
|
292
300
|
if (moved != null) return moved;
|
|
@@ -306,7 +314,7 @@ var GitLabMergeRequestWriter = class {
|
|
|
306
314
|
}
|
|
307
315
|
const { project } = context;
|
|
308
316
|
return this.transport.mutate("PUT", this.mergeRequestPath(project, mergeRequest), fields, 200, async (response) => {
|
|
309
|
-
const updated = mergeRequestReceipt(await response.json(),
|
|
317
|
+
const updated = mergeRequestReceipt(await response.json(), context, mergeRequest.iid, mergeRequest.id);
|
|
310
318
|
if (action === "edit") return {
|
|
311
319
|
...context,
|
|
312
320
|
ok: true,
|
|
@@ -326,6 +334,25 @@ var GitLabMergeRequestWriter = class {
|
|
|
326
334
|
};
|
|
327
335
|
});
|
|
328
336
|
}
|
|
337
|
+
async checkLiveMergeRefs(input) {
|
|
338
|
+
const account = await this.transport.readAccount();
|
|
339
|
+
const target = await this.transport.readProject(input.projectId);
|
|
340
|
+
const moved = movedProject(input, target.project);
|
|
341
|
+
if (moved != null) return moved;
|
|
342
|
+
const unavailable = this.getWriteRefusal(account, target.raw);
|
|
343
|
+
if (unavailable != null) return gitLabWriteFailure(unavailable.reason);
|
|
344
|
+
const source = input.expectedSourceProjectId === target.project.id ? target.project : (await this.transport.readProject(input.expectedSourceProjectId)).project;
|
|
345
|
+
if (!sameSha(await this.transport.readBranchTip(source, input.expectedSourceBranch), input.expectedSourceSha)) return {
|
|
346
|
+
ok: false,
|
|
347
|
+
reason: "source-changed",
|
|
348
|
+
mutationDispatched: false
|
|
349
|
+
};
|
|
350
|
+
if (!sameSha(await this.transport.readBranchTip(target.project, input.expectedTargetBranch), input.expectedTargetSha)) return {
|
|
351
|
+
ok: false,
|
|
352
|
+
reason: "target-changed",
|
|
353
|
+
mutationDispatched: false
|
|
354
|
+
};
|
|
355
|
+
}
|
|
329
356
|
merge(input, { context, mergeRequest, capabilities }) {
|
|
330
357
|
const { merge } = capabilities;
|
|
331
358
|
if (merge.kind === "unavailable") return mergeFailure(merge, false);
|
|
@@ -365,9 +392,13 @@ var GitLabMergeRequestWriter = class {
|
|
|
365
392
|
};
|
|
366
393
|
}, refusal);
|
|
367
394
|
}
|
|
368
|
-
return this.transport.mutate("PUT", `${this.mergeRequestPath(project, mergeRequest)}/merge`,
|
|
369
|
-
|
|
370
|
-
|
|
395
|
+
return this.transport.mutate("PUT", `${this.mergeRequestPath(project, mergeRequest)}/merge`, this.transport.selfManaged ? {
|
|
396
|
+
...body,
|
|
397
|
+
should_remove_source_branch: input.expectedRemovesSourceBranch
|
|
398
|
+
} : body, 200, async (response) => {
|
|
399
|
+
const raw = await response.json();
|
|
400
|
+
const merged = mergeRequestReceipt(raw, context, mergeRequest.iid, mergeRequest.id);
|
|
401
|
+
return merged.state === "merged" && isApprovedMerge(merged, input) && (!this.transport.selfManaged || reachedApprovedSquash(raw, input)) ? {
|
|
371
402
|
...context,
|
|
372
403
|
ok: true,
|
|
373
404
|
status: "merged",
|
|
@@ -393,10 +424,12 @@ var GitLabMergeRequestWriter = class {
|
|
|
393
424
|
if (!refused && (execution === "train" || status !== 422)) return void 0;
|
|
394
425
|
let current;
|
|
395
426
|
let mergeStatus;
|
|
427
|
+
let matchedSquash = false;
|
|
396
428
|
try {
|
|
397
429
|
const raw = await this.transport.read(this.mergeRequestPath(context.project, input));
|
|
398
|
-
current = mergeRequestReceipt(raw, context
|
|
430
|
+
current = mergeRequestReceipt(raw, context, input.iid, input.expectedMergeRequestId);
|
|
399
431
|
mergeStatus = mergeStatusOf(raw);
|
|
432
|
+
matchedSquash = !this.transport.selfManaged || reachedApprovedSquash(raw, input);
|
|
400
433
|
} catch {
|
|
401
434
|
current = void 0;
|
|
402
435
|
}
|
|
@@ -406,13 +439,13 @@ var GitLabMergeRequestWriter = class {
|
|
|
406
439
|
reason: "unknown",
|
|
407
440
|
applied: "maybe"
|
|
408
441
|
};
|
|
409
|
-
if (current.state === "merged") return {
|
|
442
|
+
if (current.state === "merged" && matchedSquash) return {
|
|
410
443
|
...context,
|
|
411
444
|
ok: true,
|
|
412
445
|
status: "merged",
|
|
413
446
|
mergeRequest: current
|
|
414
447
|
};
|
|
415
|
-
if (current.state !== "opened") return {
|
|
448
|
+
if (current.state !== "opened" || this.transport.selfManaged && input.squash) return {
|
|
416
449
|
ok: false,
|
|
417
450
|
reason: "unknown",
|
|
418
451
|
applied: "maybe"
|
|
@@ -446,16 +479,16 @@ var GitLabMergeRequestWriter = class {
|
|
|
446
479
|
capability
|
|
447
480
|
};
|
|
448
481
|
}
|
|
449
|
-
async readMergeRequest(options) {
|
|
482
|
+
async readMergeRequest(options, checkedTargetSha) {
|
|
450
483
|
const { project, iid, expectedMergeRequestId } = options;
|
|
451
484
|
if (!isGitLabProjectRef(project) || !isGitLabDecimalId(iid) || expectedMergeRequestId !== void 0 && !isGitLabDecimalId(expectedMergeRequestId)) throw new GitLabWriteError("invalid-input");
|
|
452
485
|
const account = await this.transport.readAccount();
|
|
453
486
|
const target = await this.transport.readProject(project);
|
|
454
487
|
const context = this.transport.context(account, target.project);
|
|
455
488
|
const raw = await this.transport.read(this.mergeRequestPath(target.project, { iid }));
|
|
456
|
-
let mergeRequest = mergeRequestReceipt(raw,
|
|
489
|
+
let mergeRequest = mergeRequestReceipt(raw, context, iid, expectedMergeRequestId);
|
|
457
490
|
if (mergeRequest.state === "opened") {
|
|
458
|
-
const targetSha = await this.readBranchTip(target.project, mergeRequest.targetBranch);
|
|
491
|
+
const targetSha = checkedTargetSha ?? await this.transport.readBranchTip(target.project, mergeRequest.targetBranch);
|
|
459
492
|
if (targetSha != null) mergeRequest = {
|
|
460
493
|
...mergeRequest,
|
|
461
494
|
targetSha
|
|
@@ -465,7 +498,7 @@ var GitLabMergeRequestWriter = class {
|
|
|
465
498
|
return {
|
|
466
499
|
context,
|
|
467
500
|
mergeRequest,
|
|
468
|
-
capabilities: await this.getCapabilities(account, target, raw, mergeRequest),
|
|
501
|
+
capabilities: await this.getCapabilities(account, target, raw, mergeRequest, checkedTargetSha != null),
|
|
469
502
|
lockVersion: typeof lockVersion === "number" && Number.isSafeInteger(lockVersion) && lockVersion >= 0 ? lockVersion : void 0
|
|
470
503
|
};
|
|
471
504
|
}
|
|
@@ -479,7 +512,7 @@ var GitLabMergeRequestWriter = class {
|
|
|
479
512
|
reason: "provider-policy"
|
|
480
513
|
};
|
|
481
514
|
}
|
|
482
|
-
async getCapabilities(account, target, raw, mergeRequest) {
|
|
515
|
+
async getCapabilities(account, target, raw, mergeRequest, checkRefs) {
|
|
483
516
|
const mergeStatus = mergeStatusOf(raw);
|
|
484
517
|
const unavailable = this.getWriteRefusal(account, target.raw);
|
|
485
518
|
if (unavailable != null) return {
|
|
@@ -489,29 +522,31 @@ var GitLabMergeRequestWriter = class {
|
|
|
489
522
|
delete: unavailable,
|
|
490
523
|
merge: unavailableMerge(unavailable.reason, mergeStatus)
|
|
491
524
|
};
|
|
492
|
-
const { project } = await this.transport.
|
|
493
|
-
path: target.project.fullPath,
|
|
494
|
-
iid: mergeRequest.iid
|
|
495
|
-
}, { project: target.project });
|
|
525
|
+
const { project } = await readMergeRequestPermissions(this.transport, target.project, mergeRequest.iid, checkRefs && mergeRequest.state === "opened");
|
|
496
526
|
const permissions = project?.mergeRequest;
|
|
497
527
|
if (permissions?.id !== `${mergeRequestGidPrefix}${mergeRequest.id}`) throw new GitLabWriteError("conflict");
|
|
498
528
|
const { updateMergeRequest, canMerge } = permissions.userPermissions ?? {};
|
|
499
529
|
const { autoMergeEnabled, availableAutoMergeStrategies: strategies, squashOnMerge, squashReadOnly } = permissions;
|
|
500
530
|
const accessLevel = project?.maxAccessLevel?.integerValue;
|
|
501
|
-
if (typeof updateMergeRequest !== "boolean" || typeof canMerge !== "boolean" || typeof autoMergeEnabled !== "boolean" || typeof squashOnMerge !== "boolean" || typeof squashReadOnly !== "boolean" || typeof accessLevel !== "number" || strategies != null && !Array.isArray(strategies)) throw new GitLabWriteError("unknown");
|
|
531
|
+
if (typeof updateMergeRequest !== "boolean" || typeof canMerge !== "boolean" || typeof autoMergeEnabled !== "boolean" || typeof squashOnMerge !== "boolean" || typeof squashReadOnly !== "boolean" && !(this.transport.selfManaged && squashReadOnly === void 0) || typeof accessLevel !== "number" || strategies != null && !Array.isArray(strategies)) throw new GitLabWriteError("unknown");
|
|
502
532
|
const { state } = mergeRequest;
|
|
503
533
|
const update = allowed(updateMergeRequest);
|
|
534
|
+
const changed = checkRefs && state === "opened" ? changedMergeRequestRef(permissions, mergeRequest) : void 0;
|
|
535
|
+
const squash = squashReadOnly === void 0 ? selfManagedSquash(target.raw, squashOnMerge) : squashOnMerge ? "required" : squashReadOnly ? "unavailable" : "optional";
|
|
504
536
|
return {
|
|
505
537
|
edit: transition(update, state === "opened" || state === "closed"),
|
|
506
538
|
close: transition(update, state === "opened"),
|
|
507
539
|
reopen: transition(update, state === "closed"),
|
|
508
|
-
delete:
|
|
509
|
-
|
|
540
|
+
delete: this.transport.selfManaged && accessLevel >= ownerAccessLevel && deleteFence(mergeRequest.updatedAt) == null ? {
|
|
541
|
+
allowed: false,
|
|
542
|
+
reason: "unsupported"
|
|
543
|
+
} : allowed(accessLevel >= ownerAccessLevel),
|
|
544
|
+
merge: changed == null ? this.getMergeCapability(target.raw, raw, mergeRequest, {
|
|
510
545
|
canMerge,
|
|
511
546
|
autoMergeEnabled,
|
|
512
547
|
strategies: strategies ?? [],
|
|
513
|
-
squash
|
|
514
|
-
})
|
|
548
|
+
squash
|
|
549
|
+
}) : unavailableMerge(changed, mergeStatus)
|
|
515
550
|
};
|
|
516
551
|
}
|
|
517
552
|
getMergeCapability(project, raw, mergeRequest, policy) {
|
|
@@ -523,10 +558,12 @@ var GitLabMergeRequestWriter = class {
|
|
|
523
558
|
if (policy.autoMergeEnabled) return unavailableMerge("policy-blocked", mergeStatus, "auto-merge");
|
|
524
559
|
if (mergeRequest.sourceSha == null) return unavailableMerge("policy-blocked", mergeStatus, "checking");
|
|
525
560
|
if (mergeRequest.targetSha == null) return blockedMerge(mergeStatus, "other");
|
|
526
|
-
const hasTrain = project.merge_trains_enabled === true || policy.strategies.includes("merge_train") || policy.strategies.includes("add_to_merge_train_when_checks_pass");
|
|
561
|
+
const hasTrain = project.merge_trains_enabled === true || policy.strategies.includes("merge_train") || policy.strategies.includes("add_to_merge_train_when_checks_pass") || this.transport.selfManaged && policy.strategies.includes("add_to_merge_train_when_pipeline_succeeds");
|
|
527
562
|
if (hasTrain) {
|
|
563
|
+
if (this.transport.selfManaged) return unavailableMerge("unsupported", mergeStatus, "merge-train");
|
|
528
564
|
if (!policy.strategies.includes("merge_train")) return blockedMerge(mergeStatus, "merge-train");
|
|
529
565
|
} else if (mergeStatus !== "mergeable") return blockedMerge(mergeStatus, "other");
|
|
566
|
+
if (policy.squash == null) return unavailableMerge("unsupported", mergeStatus);
|
|
530
567
|
return {
|
|
531
568
|
kind: "available",
|
|
532
569
|
execution: hasTrain ? "train" : "merge",
|
|
@@ -535,29 +572,17 @@ var GitLabMergeRequestWriter = class {
|
|
|
535
572
|
removesSourceBranch: raw.should_remove_source_branch === true || raw.force_remove_source_branch === true
|
|
536
573
|
};
|
|
537
574
|
}
|
|
538
|
-
async findOpenMergeRequest(
|
|
575
|
+
async findOpenMergeRequest(context, sourceProject, sourceBranch, targetBranch) {
|
|
539
576
|
const query = new URLSearchParams({
|
|
540
577
|
state: "opened",
|
|
541
578
|
source_branch: sourceBranch,
|
|
542
579
|
target_branch: targetBranch,
|
|
543
580
|
per_page: "100"
|
|
544
581
|
});
|
|
545
|
-
const found = await this.transport.read(`/api/v4/projects/${project.id}/merge_requests?${query.toString()}`);
|
|
582
|
+
const found = await this.transport.read(`/api/v4/projects/${context.project.id}/merge_requests?${query.toString()}`);
|
|
546
583
|
if (!Array.isArray(found)) throw new GitLabWriteError("unknown");
|
|
547
584
|
const existing = found.find((raw) => restId(raw?.source_project_id) === sourceProject.id && raw.source_branch === sourceBranch && raw.target_branch === targetBranch && raw.state === "opened");
|
|
548
|
-
return existing && mergeRequestReceipt(existing,
|
|
549
|
-
}
|
|
550
|
-
async readBranchTip(project, branch) {
|
|
551
|
-
let raw;
|
|
552
|
-
try {
|
|
553
|
-
raw = await this.transport.read(`/api/v4/projects/${project.id}/repository/branches/${encodeURIComponent(branch)}`);
|
|
554
|
-
} catch (ex) {
|
|
555
|
-
if (ex instanceof GitLabWriteError && ex.reason === "not-found") return void 0;
|
|
556
|
-
throw ex;
|
|
557
|
-
}
|
|
558
|
-
const sha = raw?.commit?.id;
|
|
559
|
-
if (raw?.name !== branch || !isSha(sha)) throw new GitLabWriteError("unknown");
|
|
560
|
-
return sha;
|
|
585
|
+
return existing && mergeRequestReceipt(existing, context);
|
|
561
586
|
}
|
|
562
587
|
mergeRequestPath(project, mergeRequest) {
|
|
563
588
|
return `/api/v4/projects/${project.id}/merge_requests/${mergeRequest.iid}`;
|