@gitkraken/core-gitlens 0.65.0 → 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 +6 -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/integrationService.js +1 -2
- package/dist/plus/integrations/integrationService.js.map +1 -1
- package/dist/plus/integrations/manager.d.ts +1 -4
- package/dist/plus/integrations/models/gitlabMergeRequestWrites.d.ts +3 -9
- 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/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 -2
- package/dist/plus/integrations/providers/gitlab/mergeRequestWrites.js +93 -73
- package/dist/plus/integrations/providers/gitlab/mergeRequestWrites.js.map +1 -1
- package/dist/plus/integrations/providers/gitlab/writeTransport.d.ts +7 -1
- package/dist/plus/integrations/providers/gitlab/writeTransport.js +21 -2
- package/dist/plus/integrations/providers/gitlab/writeTransport.js.map +1 -1
- package/dist/utils/env/node/exec.js +2 -2
- package/docs/integrations.md +34 -13
- package/package.json +1 -1
|
@@ -1206,10 +1206,7 @@ export interface IntegrationManager {
|
|
|
1206
1206
|
getGitLabMergeRequestCreateOptions(options: GitLabMergeRequestCreateOptions): Promise<GitLabMergeRequestCreateOptionsResult>;
|
|
1207
1207
|
getGitLabMergeRequestWriteOptions(options: GitLabMergeRequestWriteAddress): Promise<GitLabMergeRequestWriteOptionsResult>;
|
|
1208
1208
|
resolveGitLabMergeRequestWriteTarget(options: GitLabMergeRequestWriteTargetOptions): Promise<GitLabMergeRequestWriteTargetResult>;
|
|
1209
|
-
/**
|
|
1210
|
-
* Creates, edits, closes, reopens or merges a GitLab.com merge request. A merge lands directly or joins the
|
|
1211
|
-
* project's merge train, as `expectedExecution` pins; `applied: 'maybe'` is never retried by Core.
|
|
1212
|
-
*/
|
|
1209
|
+
/** KEEP: `expectedExecution: 'train'` is GitLab.com-only. Reconcile `applied: 'maybe'` before another write. */
|
|
1213
1210
|
writeGitLabMergeRequest(options: GitLabMergeRequestWriteOptions): Promise<GitLabMergeRequestWriteResult>;
|
|
1214
1211
|
deleteGitLabMergeRequest(options: GitLabMergeRequestDeleteOptions): Promise<GitLabMergeRequestWriteResult>;
|
|
1215
1212
|
getIssueTrackerCreateOptions(options: IssueTrackerCreateOptions): Promise<IssueTrackerCreateOptionsResult>;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { GitLabIssueWriteFailure, GitLabIssueWriteScope } from "./gitlabIssueWrites.js";
|
|
1
|
+
import { GitLabIssueWriteContext, GitLabIssueWriteFailure, GitLabIssueWriteScope } from "./gitlabIssueWrites.js";
|
|
3
2
|
//#region ../plus/integrations/src/models/gitlabMergeRequestWrites.d.ts
|
|
4
|
-
export type GitLabMergeRequestWriteScope =
|
|
5
|
-
providerId: GitCloudHostIntegrationId.GitLab;
|
|
6
|
-
}>;
|
|
3
|
+
export type GitLabMergeRequestWriteScope = GitLabIssueWriteScope;
|
|
7
4
|
/** SEE: https://docs.gitlab.com/api/projects/ (`merge_method`); the project owns it and a merge cannot choose another. */
|
|
8
5
|
export type GitLabMergeMethod = 'merge' | 'rebase_merge' | 'ff';
|
|
9
6
|
export type GitLabMergeExecution = 'merge' | 'train';
|
|
@@ -131,10 +128,7 @@ export type GitLabMergeRequestWriteField = {
|
|
|
131
128
|
id: 'title' | 'description';
|
|
132
129
|
required: boolean;
|
|
133
130
|
};
|
|
134
|
-
export type GitLabMergeRequestWriteContext =
|
|
135
|
-
accountId: string;
|
|
136
|
-
project: GitLabMergeRequestProject;
|
|
137
|
-
};
|
|
131
|
+
export type GitLabMergeRequestWriteContext = GitLabIssueWriteContext;
|
|
138
132
|
export type GitLabMergeRequestCreateOptionsResult = GitLabMergeRequestWriteFailure | (GitLabMergeRequestWriteContext & {
|
|
139
133
|
ok: true;
|
|
140
134
|
/** The target project itself unless the options named a fork. */
|
|
@@ -7,9 +7,9 @@ import { trace } from "../../../../utils/decorators/log.js";
|
|
|
7
7
|
import { PromiseCache } from "../../../../utils/promiseCache.js";
|
|
8
8
|
import __decorate from "../../../../_virtual/@oxc-project+runtime/helpers/esm/decorate.js";
|
|
9
9
|
import { AuthenticationError, RequestClientError, RequestNotFoundError, RequestRateLimitError, getDeferredRequestFailure, reportRequestFailure } from "../../../../git/errors.js";
|
|
10
|
+
import { sha256, uuid } from "../../../../utils/crypto.js";
|
|
10
11
|
import { maybeStopWatch } from "../../../../utils/stopwatch.js";
|
|
11
12
|
import { base64 } from "../../../../utils/base64.js";
|
|
12
|
-
import { sha256, uuid } from "../../../../utils/crypto.js";
|
|
13
13
|
import { effectiveIssueSort } from "../../../../git/utils/issue.utils.js";
|
|
14
14
|
import { ProviderFetchError, isRateLimitResponse, toRateLimitError } from "../../errors.js";
|
|
15
15
|
import { CommitReadRefusedError, isCommitReadRefusal, isNotFoundResponse, throwProviderError } from "../providerErrors.js";
|
|
@@ -2,9 +2,9 @@ import { chunk } from "../../../utils/array.js";
|
|
|
2
2
|
import { isCancellationError } from "../../../utils/cancellation.js";
|
|
3
3
|
import { batch, mapBounded, mapSettledBounded } from "../../../utils/promise.js";
|
|
4
4
|
import { AuthenticationError, RequestNotFoundError } from "../../../git/errors.js";
|
|
5
|
+
import { uuid } from "../../../utils/crypto.js";
|
|
5
6
|
import { parseGitRemoteUrl } from "../../../git/utils/remote.utils.js";
|
|
6
7
|
import { getGitHubNoReplyAddressParts } from "../../../git/remotes/github.js";
|
|
7
|
-
import { uuid } from "../../../utils/crypto.js";
|
|
8
8
|
import "../../../git/models/pullRequest.js";
|
|
9
9
|
import { countGitHubStackMergedLayers, decodeGitHubCheckRunId, fromGitHubCheckContextState, fromGitHubIssueOrPullRequestState, fromGitHubMergeQueueEntryState, fromGitHubMergeQueueRemoval, fromGitHubPullRequestMergeableState, fromGitHubPullRequestReviewDecision, fromGitHubPullRequestStatusCheckRollupState, toGitHubCheckRunId } from "../../git-github/models.js";
|
|
10
10
|
import { IntegrationReadUnavailableError } from "../errors.js";
|
|
@@ -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,16 +15,15 @@ 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;
|
|
21
22
|
private readMergeRequest;
|
|
22
|
-
private getContext;
|
|
23
23
|
private getWriteRefusal;
|
|
24
24
|
private getCapabilities;
|
|
25
25
|
private getMergeCapability;
|
|
26
26
|
private findOpenMergeRequest;
|
|
27
|
-
private readBranchTip;
|
|
28
27
|
private mergeRequestPath;
|
|
29
28
|
}
|
|
30
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"
|
|
@@ -440,22 +473,22 @@ var GitLabMergeRequestWriter = class {
|
|
|
440
473
|
capability = allowed(into && from);
|
|
441
474
|
}
|
|
442
475
|
return {
|
|
443
|
-
context: this.
|
|
476
|
+
context: this.transport.context(account, target.project),
|
|
444
477
|
sourceProject: source.project,
|
|
445
478
|
defaultBranch: target.raw.default_branch || void 0,
|
|
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
|
-
const context = this.
|
|
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,15 +498,10 @@ 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
|
}
|
|
472
|
-
getContext(account, project) {
|
|
473
|
-
const context = this.transport.context(account, project);
|
|
474
|
-
if (context.providerId !== "gitlab") throw new GitLabWriteError("unsupported");
|
|
475
|
-
return context;
|
|
476
|
-
}
|
|
477
505
|
getWriteRefusal(account, project) {
|
|
478
506
|
if (!account.canWrite) return {
|
|
479
507
|
allowed: false,
|
|
@@ -484,7 +512,7 @@ var GitLabMergeRequestWriter = class {
|
|
|
484
512
|
reason: "provider-policy"
|
|
485
513
|
};
|
|
486
514
|
}
|
|
487
|
-
async getCapabilities(account, target, raw, mergeRequest) {
|
|
515
|
+
async getCapabilities(account, target, raw, mergeRequest, checkRefs) {
|
|
488
516
|
const mergeStatus = mergeStatusOf(raw);
|
|
489
517
|
const unavailable = this.getWriteRefusal(account, target.raw);
|
|
490
518
|
if (unavailable != null) return {
|
|
@@ -494,29 +522,31 @@ var GitLabMergeRequestWriter = class {
|
|
|
494
522
|
delete: unavailable,
|
|
495
523
|
merge: unavailableMerge(unavailable.reason, mergeStatus)
|
|
496
524
|
};
|
|
497
|
-
const { project } = await this.transport.
|
|
498
|
-
path: target.project.fullPath,
|
|
499
|
-
iid: mergeRequest.iid
|
|
500
|
-
}, { project: target.project });
|
|
525
|
+
const { project } = await readMergeRequestPermissions(this.transport, target.project, mergeRequest.iid, checkRefs && mergeRequest.state === "opened");
|
|
501
526
|
const permissions = project?.mergeRequest;
|
|
502
527
|
if (permissions?.id !== `${mergeRequestGidPrefix}${mergeRequest.id}`) throw new GitLabWriteError("conflict");
|
|
503
528
|
const { updateMergeRequest, canMerge } = permissions.userPermissions ?? {};
|
|
504
529
|
const { autoMergeEnabled, availableAutoMergeStrategies: strategies, squashOnMerge, squashReadOnly } = permissions;
|
|
505
530
|
const accessLevel = project?.maxAccessLevel?.integerValue;
|
|
506
|
-
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");
|
|
507
532
|
const { state } = mergeRequest;
|
|
508
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";
|
|
509
536
|
return {
|
|
510
537
|
edit: transition(update, state === "opened" || state === "closed"),
|
|
511
538
|
close: transition(update, state === "opened"),
|
|
512
539
|
reopen: transition(update, state === "closed"),
|
|
513
|
-
delete:
|
|
514
|
-
|
|
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, {
|
|
515
545
|
canMerge,
|
|
516
546
|
autoMergeEnabled,
|
|
517
547
|
strategies: strategies ?? [],
|
|
518
|
-
squash
|
|
519
|
-
})
|
|
548
|
+
squash
|
|
549
|
+
}) : unavailableMerge(changed, mergeStatus)
|
|
520
550
|
};
|
|
521
551
|
}
|
|
522
552
|
getMergeCapability(project, raw, mergeRequest, policy) {
|
|
@@ -528,10 +558,12 @@ var GitLabMergeRequestWriter = class {
|
|
|
528
558
|
if (policy.autoMergeEnabled) return unavailableMerge("policy-blocked", mergeStatus, "auto-merge");
|
|
529
559
|
if (mergeRequest.sourceSha == null) return unavailableMerge("policy-blocked", mergeStatus, "checking");
|
|
530
560
|
if (mergeRequest.targetSha == null) return blockedMerge(mergeStatus, "other");
|
|
531
|
-
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");
|
|
532
562
|
if (hasTrain) {
|
|
563
|
+
if (this.transport.selfManaged) return unavailableMerge("unsupported", mergeStatus, "merge-train");
|
|
533
564
|
if (!policy.strategies.includes("merge_train")) return blockedMerge(mergeStatus, "merge-train");
|
|
534
565
|
} else if (mergeStatus !== "mergeable") return blockedMerge(mergeStatus, "other");
|
|
566
|
+
if (policy.squash == null) return unavailableMerge("unsupported", mergeStatus);
|
|
535
567
|
return {
|
|
536
568
|
kind: "available",
|
|
537
569
|
execution: hasTrain ? "train" : "merge",
|
|
@@ -540,29 +572,17 @@ var GitLabMergeRequestWriter = class {
|
|
|
540
572
|
removesSourceBranch: raw.should_remove_source_branch === true || raw.force_remove_source_branch === true
|
|
541
573
|
};
|
|
542
574
|
}
|
|
543
|
-
async findOpenMergeRequest(
|
|
575
|
+
async findOpenMergeRequest(context, sourceProject, sourceBranch, targetBranch) {
|
|
544
576
|
const query = new URLSearchParams({
|
|
545
577
|
state: "opened",
|
|
546
578
|
source_branch: sourceBranch,
|
|
547
579
|
target_branch: targetBranch,
|
|
548
580
|
per_page: "100"
|
|
549
581
|
});
|
|
550
|
-
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()}`);
|
|
551
583
|
if (!Array.isArray(found)) throw new GitLabWriteError("unknown");
|
|
552
584
|
const existing = found.find((raw) => restId(raw?.source_project_id) === sourceProject.id && raw.source_branch === sourceBranch && raw.target_branch === targetBranch && raw.state === "opened");
|
|
553
|
-
return existing && mergeRequestReceipt(existing,
|
|
554
|
-
}
|
|
555
|
-
async readBranchTip(project, branch) {
|
|
556
|
-
let raw;
|
|
557
|
-
try {
|
|
558
|
-
raw = await this.transport.read(`/api/v4/projects/${project.id}/repository/branches/${encodeURIComponent(branch)}`);
|
|
559
|
-
} catch (ex) {
|
|
560
|
-
if (ex instanceof GitLabWriteError && ex.reason === "not-found") return void 0;
|
|
561
|
-
throw ex;
|
|
562
|
-
}
|
|
563
|
-
const sha = raw?.commit?.id;
|
|
564
|
-
if (raw?.name !== branch || !isSha(sha)) throw new GitLabWriteError("unknown");
|
|
565
|
-
return sha;
|
|
585
|
+
return existing && mergeRequestReceipt(existing, context);
|
|
566
586
|
}
|
|
567
587
|
mergeRequestPath(project, mergeRequest) {
|
|
568
588
|
return `/api/v4/projects/${project.id}/merge_requests/${mergeRequest.iid}`;
|