@gitkraken/core-gitlens 0.50.0 → 0.51.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +15 -1
  2. package/dist/git-cli/providers/config.js +2 -2
  3. package/dist/git-cli/providers/pausedOperations.js +2 -2
  4. package/dist/git-cli/providers/pausedOperations.js.map +1 -1
  5. package/dist/git-cli/providers/staging.js +1 -1
  6. package/dist/ipc/discovery.js +1 -1
  7. package/dist/plus/agents/providers/claudeCodeTranscript.js +6 -6
  8. package/dist/plus/agents/providers/claudeCodeTranscript.js.map +1 -1
  9. package/dist/plus/ai/providers/openAICompatibleProviderBase.js +1 -1
  10. package/dist/plus/integrations/index.d.ts +2 -1
  11. package/dist/plus/integrations/index.js.map +1 -1
  12. package/dist/plus/integrations/integrationService.d.ts +5 -0
  13. package/dist/plus/integrations/integrationService.js +40 -0
  14. package/dist/plus/integrations/integrationService.js.map +1 -1
  15. package/dist/plus/integrations/manager.d.ts +4 -0
  16. package/dist/plus/integrations/models/azurePullRequestWrites.d.ts +93 -0
  17. package/dist/plus/integrations/models/azurePullRequestWrites.js +0 -0
  18. package/dist/plus/integrations/providers/azure/azure.js +1 -1
  19. package/dist/plus/integrations/providers/azure/models.d.ts +1 -1
  20. package/dist/plus/integrations/providers/azure/models.js.map +1 -1
  21. package/dist/plus/integrations/providers/azure/writeIdentity.d.ts +17 -0
  22. package/dist/plus/integrations/providers/azure/writeIdentity.js +33 -0
  23. package/dist/plus/integrations/providers/azure/writeIdentity.js.map +1 -0
  24. package/dist/plus/integrations/providers/azureDevOps.d.ts +4 -0
  25. package/dist/plus/integrations/providers/azureDevOps.js +14 -3
  26. package/dist/plus/integrations/providers/azureDevOps.js.map +1 -1
  27. package/dist/plus/integrations/providers/azurePullRequestWriteErrors.d.ts +11 -0
  28. package/dist/plus/integrations/providers/azurePullRequestWriteErrors.js +72 -0
  29. package/dist/plus/integrations/providers/azurePullRequestWriteErrors.js.map +1 -0
  30. package/dist/plus/integrations/providers/azurePullRequestWrites.d.ts +36 -0
  31. package/dist/plus/integrations/providers/azurePullRequestWrites.js +443 -0
  32. package/dist/plus/integrations/providers/azurePullRequestWrites.js.map +1 -0
  33. package/dist/plus/integrations/providers/azureWorkItemWriteErrors.d.ts +0 -3
  34. package/dist/plus/integrations/providers/azureWorkItemWriteErrors.js +3 -12
  35. package/dist/plus/integrations/providers/azureWorkItemWriteErrors.js.map +1 -1
  36. package/dist/plus/integrations/providers/azureWorkItemWrites.js +24 -35
  37. package/dist/plus/integrations/providers/azureWorkItemWrites.js.map +1 -1
  38. package/dist/plus/integrations/providers/providersApi.d.ts +3 -11
  39. package/dist/plus/integrations/providers/providersApi.js +10 -12
  40. package/dist/plus/integrations/providers/providersApi.js.map +1 -1
  41. package/dist/utils/env/node/exec.js +2 -2
  42. package/docs/integrations.md +53 -0
  43. package/package.json +1 -1
@@ -0,0 +1,11 @@
1
+ import { AzurePullRequestWriteFailure } from "../models/azurePullRequestWrites.js";
2
+ //#region ../plus/integrations/src/providers/azurePullRequestWriteErrors.d.ts
3
+ export declare class AzurePullRequestWriteError extends Error {
4
+ readonly reason: AzurePullRequestWriteFailure['reason'];
5
+ constructor(reason: AzurePullRequestWriteFailure['reason']);
6
+ }
7
+ export declare function toAzurePullRequestWriteFailure(ex: unknown, dispatched?: {
8
+ complete: boolean;
9
+ }): AzurePullRequestWriteFailure;
10
+ //#endregion
11
+ //# sourceMappingURL=azurePullRequestWriteErrors.d.ts.map
@@ -0,0 +1,72 @@
1
+ import { AnonymousResponseError, UnexpectedHtmlResponseError, getProviderResponseBodyMessage } from "./providerErrors.js";
2
+ //#region ../plus/integrations/src/providers/azurePullRequestWriteErrors.ts
3
+ var AzurePullRequestWriteError = class extends Error {
4
+ reason;
5
+ constructor(reason) {
6
+ super(reason);
7
+ this.reason = reason;
8
+ }
9
+ };
10
+ function toAzurePullRequestWriteFailure(ex, dispatched) {
11
+ if (ex instanceof AzurePullRequestWriteError) return {
12
+ ok: false,
13
+ reason: ex.reason
14
+ };
15
+ const response = ex?.response;
16
+ const status = response?.status;
17
+ const ambiguous = dispatched == null ? "unknown" : "outcome-unknown";
18
+ if (UnexpectedHtmlResponseError.is(ex) || AnonymousResponseError.is(ex)) return {
19
+ ok: false,
20
+ reason: dispatched == null ? "no-connection" : ambiguous
21
+ };
22
+ const body = response?.body;
23
+ const type = body?.typeKey;
24
+ const message = getProviderResponseBodyMessage(body) ?? "";
25
+ if (status === 400 || status === 403 || status === 409 || status === 422) {
26
+ if (dispatched?.complete && (/(?:branch policies|policy requirements|required reviewers?|required approvals?) (?:have not been|are not|are still not) (?:met|satisfied|approved)|TF402455\b/i.test(message) || typeof type === "string" && /^(?:Git)?PullRequest.*Policy.*Exception$/.test(type))) return {
27
+ ok: false,
28
+ reason: "policy-blocked"
29
+ };
30
+ if (dispatched?.complete && /\bsource branch (?:has changed|was updated)\b/i.test(message)) return {
31
+ ok: false,
32
+ reason: "source-changed"
33
+ };
34
+ if (type === "GitPullRequestExistsException" || /\bTF401179\b/.test(message)) return {
35
+ ok: false,
36
+ reason: "conflict"
37
+ };
38
+ }
39
+ let reason;
40
+ switch (status) {
41
+ case 400:
42
+ case 413:
43
+ case 422:
44
+ reason = "invalid-input";
45
+ break;
46
+ case 401:
47
+ reason = dispatched == null ? "no-connection" : "forbidden";
48
+ break;
49
+ case 403:
50
+ reason = "forbidden";
51
+ break;
52
+ case 404:
53
+ reason = "not-found";
54
+ break;
55
+ case 409:
56
+ case 412:
57
+ reason = "conflict";
58
+ break;
59
+ case 429:
60
+ reason = "rate-limit";
61
+ break;
62
+ default: reason = ambiguous;
63
+ }
64
+ return {
65
+ ok: false,
66
+ reason
67
+ };
68
+ }
69
+ //#endregion
70
+ export { AzurePullRequestWriteError, toAzurePullRequestWriteFailure };
71
+
72
+ //# sourceMappingURL=azurePullRequestWriteErrors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"azurePullRequestWriteErrors.js","names":[],"sources":["../../../../../plus/integrations/src/providers/azurePullRequestWriteErrors.ts"],"sourcesContent":["import type { AzurePullRequestWriteFailure } from '../models/azurePullRequestWrites.js';\nimport {\n\tAnonymousResponseError,\n\tgetProviderResponseBodyMessage,\n\tUnexpectedHtmlResponseError,\n} from './providerErrors.js';\n\nexport class AzurePullRequestWriteError extends Error {\n\tconstructor(readonly reason: AzurePullRequestWriteFailure['reason']) {\n\t\tsuper(reason);\n\t}\n}\n\nexport function toAzurePullRequestWriteFailure(\n\tex: unknown,\n\tdispatched?: { complete: boolean },\n): AzurePullRequestWriteFailure {\n\tif (ex instanceof AzurePullRequestWriteError) return { ok: false, reason: ex.reason };\n\n\tconst response = (ex as { response?: { status?: number; body?: unknown } } | undefined)?.response;\n\tconst status = response?.status;\n\tconst ambiguous = dispatched == null ? 'unknown' : 'outcome-unknown';\n\tif (UnexpectedHtmlResponseError.is(ex) || AnonymousResponseError.is(ex)) {\n\t\treturn { ok: false, reason: dispatched == null ? 'no-connection' : ambiguous };\n\t}\n\n\tconst body = response?.body;\n\tconst type = (body as { typeKey?: unknown } | undefined)?.typeKey;\n\tconst message = getProviderResponseBodyMessage(body) ?? '';\n\tif (status === 400 || status === 403 || status === 409 || status === 422) {\n\t\tif (\n\t\t\tdispatched?.complete &&\n\t\t\t(/(?:branch policies|policy requirements|required reviewers?|required approvals?) (?:have not been|are not|are still not) (?:met|satisfied|approved)|TF402455\\b/i.test(\n\t\t\t\tmessage,\n\t\t\t) ||\n\t\t\t\t(typeof type === 'string' && /^(?:Git)?PullRequest.*Policy.*Exception$/.test(type)))\n\t\t) {\n\t\t\treturn { ok: false, reason: 'policy-blocked' };\n\t\t}\n\n\t\tif (dispatched?.complete && /\\bsource branch (?:has changed|was updated)\\b/i.test(message)) {\n\t\t\treturn { ok: false, reason: 'source-changed' };\n\t\t}\n\n\t\tif (type === 'GitPullRequestExistsException' || /\\bTF401179\\b/.test(message)) {\n\t\t\treturn { ok: false, reason: 'conflict' };\n\t\t}\n\t}\n\n\tlet reason: AzurePullRequestWriteFailure['reason'];\n\tswitch (status) {\n\t\tcase 400:\n\t\tcase 413:\n\t\tcase 422:\n\t\t\treason = 'invalid-input';\n\t\t\tbreak;\n\t\tcase 401:\n\t\t\treason = dispatched == null ? 'no-connection' : 'forbidden';\n\t\t\tbreak;\n\t\tcase 403:\n\t\t\treason = 'forbidden';\n\t\t\tbreak;\n\t\tcase 404:\n\t\t\treason = 'not-found';\n\t\t\tbreak;\n\t\tcase 409:\n\t\tcase 412:\n\t\t\treason = 'conflict';\n\t\t\tbreak;\n\t\tcase 429:\n\t\t\treason = 'rate-limit';\n\t\t\tbreak;\n\t\tdefault:\n\t\t\treason = ambiguous;\n\t}\n\n\treturn { ok: false, reason: reason };\n}\n"],"mappings":";;AAOA,IAAa,6BAAb,cAAgD,MAAM;CAChC;CAArB,YAAY,QAAyD;EACpE,MAAM,MAAM;EADQ,KAAA,SAAA;CAErB;AACD;AAEA,SAAgB,+BACf,IACA,YAC+B;CAC/B,IAAI,cAAc,4BAA4B,OAAO;EAAE,IAAI;EAAO,QAAQ,GAAG;CAAO;CAEpF,MAAM,WAAY,IAAuE;CACzF,MAAM,SAAS,UAAU;CACzB,MAAM,YAAY,cAAc,OAAO,YAAY;CACnD,IAAI,4BAA4B,GAAG,EAAE,KAAK,uBAAuB,GAAG,EAAE,GACrE,OAAO;EAAE,IAAI;EAAO,QAAQ,cAAc,OAAO,kBAAkB;CAAU;CAG9E,MAAM,OAAO,UAAU;CACvB,MAAM,OAAQ,MAA4C;CAC1D,MAAM,UAAU,+BAA+B,IAAI,KAAK;CACxD,IAAI,WAAW,OAAO,WAAW,OAAO,WAAW,OAAO,WAAW,KAAK;EACzE,IACC,YAAY,aACX,iKAAiK,KACjK,OACD,KACE,OAAO,SAAS,YAAY,2CAA2C,KAAK,IAAI,IAElF,OAAO;GAAE,IAAI;GAAO,QAAQ;EAAiB;EAG9C,IAAI,YAAY,YAAY,iDAAiD,KAAK,OAAO,GACxF,OAAO;GAAE,IAAI;GAAO,QAAQ;EAAiB;EAG9C,IAAI,SAAS,mCAAmC,eAAe,KAAK,OAAO,GAC1E,OAAO;GAAE,IAAI;GAAO,QAAQ;EAAW;CAEzC;CAEA,IAAI;CACJ,QAAQ,QAAR;EACC,KAAK;EACL,KAAK;EACL,KAAK;GACJ,SAAS;GACT;EACD,KAAK;GACJ,SAAS,cAAc,OAAO,kBAAkB;GAChD;EACD,KAAK;GACJ,SAAS;GACT;EACD,KAAK;GACJ,SAAS;GACT;EACD,KAAK;EACL,KAAK;GACJ,SAAS;GACT;EACD,KAAK;GACJ,SAAS;GACT;EACD,SACC,SAAS;CACX;CAEA,OAAO;EAAE,IAAI;EAAe;CAAO;AACpC"}
@@ -0,0 +1,36 @@
1
+ import { AzurePullRequestCreateCapabilityOptions, AzurePullRequestCreateCapabilityResult, AzurePullRequestWriteOptions, AzurePullRequestWriteResult, AzurePullRequestWriteTargetResult } from "../models/azurePullRequestWrites.js";
2
+ import { ProviderRequestFunction } from "./models.js";
3
+ //#region ../plus/integrations/src/providers/azurePullRequestWrites.d.ts
4
+ export declare function isAzurePullRequestScope(options: AzurePullRequestCreateCapabilityOptions): boolean;
5
+ export declare function isAzurePullRequestWrite(options: AzurePullRequestWriteOptions): boolean;
6
+ export declare class AzurePullRequestWriter {
7
+ private readonly request;
8
+ private readonly headers;
9
+ private readonly accountId;
10
+ private readonly repository;
11
+ private readonly isSessionCurrent;
12
+ static connect(request: ProviderRequestFunction, credential: {
13
+ accessToken: string;
14
+ accountsAuthorization: string;
15
+ gitAuthorization: string;
16
+ }, options: AzurePullRequestCreateCapabilityOptions, isSessionCurrent: () => Promise<boolean>): Promise<AzurePullRequestWriter>;
17
+ private readonly gitApiUrl;
18
+ private readonly repoUrl;
19
+ private constructor();
20
+ getCreateCapability(): AzurePullRequestCreateCapabilityResult;
21
+ resolveTarget(number: number): Promise<AzurePullRequestWriteTargetResult>;
22
+ write(options: AzurePullRequestWriteOptions): Promise<AzurePullRequestWriteResult>;
23
+ private complete;
24
+ private getCompletionTarget;
25
+ private readCompletionRefs;
26
+ private getAllowedStrategies;
27
+ private readRef;
28
+ private readPages;
29
+ private readPullRequest;
30
+ private pullRequestUrl;
31
+ private toPullRequestSnapshot;
32
+ private save;
33
+ private getReceipt;
34
+ }
35
+ //#endregion
36
+ //# sourceMappingURL=azurePullRequestWrites.d.ts.map
@@ -0,0 +1,443 @@
1
+ import { encodeAzurePathSegment, getAzurePullRequestWebUrl } from "./azure/models.js";
2
+ import { AzurePullRequestWriteError, toAzurePullRequestWriteFailure } from "./azurePullRequestWriteErrors.js";
3
+ import { getAzureWriteOrganizations, getAzureWriteProfile, isAzureGuid, isAzureIdentifier, isAzurePositiveInt, sameAzureIdentifier } from "./azure/writeIdentity.js";
4
+ //#region ../plus/integrations/src/providers/azurePullRequestWrites.ts
5
+ const azureBaseUrl = "https://dev.azure.com";
6
+ const branchRefPrefix = "refs/heads/";
7
+ const mergeStrategyPolicyId = "fa4e907d-c16b-4a4c-9dfa-4916e5d171ab";
8
+ const strategySettings = {
9
+ noFastForward: "allowNoFastForward",
10
+ squash: "allowSquash",
11
+ rebase: "allowRebase",
12
+ rebaseMerge: "allowRebaseMerge"
13
+ };
14
+ const mergeStrategies = [
15
+ "noFastForward",
16
+ "squash",
17
+ "rebase",
18
+ "rebaseMerge"
19
+ ];
20
+ function isPathSegment(value) {
21
+ return isAzureIdentifier(value) && value !== "." && value !== ".." && !value.includes("/") && !value.includes("\\");
22
+ }
23
+ function isBranchRef(ref) {
24
+ return typeof ref === "string" && ref.startsWith(branchRefPrefix) && ref.length > 11 && ![...ref].some((character) => character <= " " || "~^:?*[\\".includes(character)) && !ref.includes("..") && !ref.includes("@{") && !ref.endsWith(".") && ref.split("/").every((part) => part.length > 0 && !part.startsWith(".") && !part.endsWith(".lock"));
25
+ }
26
+ function isCommitId(sha) {
27
+ return typeof sha === "string" && /^(?!0{40}$)[0-9a-f]{40}$/i.test(sha);
28
+ }
29
+ function isAzurePullRequestScope(options) {
30
+ return isAzureIdentifier(options.connectionId) && typeof options.organization === "string" && /^[a-z0-9][a-z0-9-]*$/i.test(options.organization) && isPathSegment(options.project) && isPathSegment(options.repository) && (options.expectedAccountId === void 0 || isAzureIdentifier(options.expectedAccountId));
31
+ }
32
+ function isTitle(title) {
33
+ return typeof title === "string" && title.trim().length > 0;
34
+ }
35
+ function isDescription(description) {
36
+ return description === void 0 || typeof description === "string" && description.length <= 4e3;
37
+ }
38
+ function isAzurePullRequestWrite(options) {
39
+ if (!isAzureGuid(options.projectId) || !isAzureGuid(options.repositoryId) || !isAzureIdentifier(options.expectedAccountId)) return false;
40
+ if (options.action === "create") return isBranchRef(options.sourceRef) && isBranchRef(options.targetRef) && options.sourceRef !== options.targetRef && isTitle(options.title) && isDescription(options.description);
41
+ if (!isAzurePositiveInt(options.number)) return false;
42
+ switch (options.action) {
43
+ case "edit": return (options.title !== void 0 || options.description !== void 0) && (options.title === void 0 || isTitle(options.title)) && isDescription(options.description);
44
+ case "abandon":
45
+ case "reactivate": return true;
46
+ case "complete": return mergeStrategies.includes(options.strategy) && isBranchRef(options.expectedSourceRef) && isBranchRef(options.expectedTargetRef) && options.expectedSourceRef !== options.expectedTargetRef && isCommitId(options.expectedSourceSha) && isCommitId(options.expectedTargetSha);
47
+ default: return false;
48
+ }
49
+ }
50
+ function allowsStrategy(policy, strategy) {
51
+ const settings = policy.settings;
52
+ if (settings == null) return false;
53
+ if (mergeStrategies.some((type) => settings[strategySettings[type]] != null)) return settings[strategySettings[strategy]] === true;
54
+ return strategy === "squash" && settings.useSquashMerge === true || strategy === "noFastForward" && settings.useSquashMerge === false;
55
+ }
56
+ function getCompletionRefFailure(options, pullRequest) {
57
+ if (pullRequest.sourceRef !== options.expectedSourceRef || !sameAzureIdentifier(pullRequest.sourceSha, options.expectedSourceSha)) return "source-changed";
58
+ if (pullRequest.targetRef !== options.expectedTargetRef) return "target-changed";
59
+ }
60
+ function getCompletionStateFailure(raw) {
61
+ if (raw.forkSource != null) return "unsupported";
62
+ if (raw.isDraft) return "policy-blocked";
63
+ if (raw.status !== "active" || raw.mergeStatus === "queued") return "conflict";
64
+ }
65
+ function getMergePreviewFailure(raw, targetSha) {
66
+ if (raw.mergeStatus !== "conflicts" && raw.mergeStatus !== "failure") return void 0;
67
+ const previewTargetSha = raw.lastMergeTargetCommit?.commitId;
68
+ if (!isCommitId(previewTargetSha)) return "unknown";
69
+ if (!sameAzureIdentifier(previewTargetSha, targetSha)) return void 0;
70
+ return raw.mergeStatus === "conflicts" ? "conflict" : "unknown";
71
+ }
72
+ function getReportedMergeFailure(mergeStatus) {
73
+ switch (mergeStatus) {
74
+ case "rejectedByPolicy": return "policy-blocked";
75
+ case "conflicts": return "conflict";
76
+ case "failure": return "unknown";
77
+ default: return;
78
+ }
79
+ }
80
+ var AzurePullRequestWriter = class AzurePullRequestWriter {
81
+ request;
82
+ headers;
83
+ accountId;
84
+ repository;
85
+ isSessionCurrent;
86
+ static async connect(request, credential, options, isSessionCurrent) {
87
+ const { body: profile } = await getAzureWriteProfile(request, credential.accessToken);
88
+ const accountId = profile?.id;
89
+ if (!isAzureIdentifier(accountId) || options.expectedAccountId !== void 0 && !sameAzureIdentifier(accountId, options.expectedAccountId)) throw new AzurePullRequestWriteError("no-connection");
90
+ const { body: accounts } = await getAzureWriteOrganizations(request, credential.accountsAuthorization, accountId);
91
+ if (!Array.isArray(accounts?.value)) throw new AzurePullRequestWriteError("unknown");
92
+ const organization = accounts.value.find((account) => sameAzureIdentifier(account?.accountName, options.organization))?.accountName;
93
+ if (organization == null) throw new AzurePullRequestWriteError("not-found");
94
+ const headers = { Authorization: credential.gitAuthorization };
95
+ const { body: repo } = await request({
96
+ url: `${azureBaseUrl}/${organization}/${encodeAzurePathSegment(options.project)}/_apis/git/repositories/${encodeAzurePathSegment(options.repository)}?api-version=7.1`,
97
+ headers,
98
+ redirect: "error"
99
+ });
100
+ if (!isAzureGuid(repo?.id) || !isAzureGuid(repo.project?.id) || !isPathSegment(repo.name) || !isPathSegment(repo.project.name) || !sameAzureIdentifier(isAzureGuid(options.repository) ? repo.id : repo.name, options.repository) || !sameAzureIdentifier(isAzureGuid(options.project) ? repo.project.id : repo.project.name, options.project)) throw new AzurePullRequestWriteError("not-found");
101
+ if (repo.isDisabled || repo.isInMaintenance) throw new AzurePullRequestWriteError("unsupported");
102
+ return new AzurePullRequestWriter(request, headers, accountId, {
103
+ organization,
104
+ projectId: repo.project.id,
105
+ projectName: repo.project.name,
106
+ repositoryId: repo.id,
107
+ repositoryName: repo.name
108
+ }, isSessionCurrent);
109
+ }
110
+ gitApiUrl;
111
+ repoUrl;
112
+ constructor(request, headers, accountId, repository, isSessionCurrent) {
113
+ this.request = request;
114
+ this.headers = headers;
115
+ this.accountId = accountId;
116
+ this.repository = repository;
117
+ this.isSessionCurrent = isSessionCurrent;
118
+ this.gitApiUrl = `${azureBaseUrl}/${repository.organization}/${repository.projectId}/_apis/git`;
119
+ this.repoUrl = `${this.gitApiUrl}/repositories/${repository.repositoryId}`;
120
+ }
121
+ getCreateCapability() {
122
+ return {
123
+ ok: true,
124
+ accountId: this.accountId,
125
+ repository: this.repository
126
+ };
127
+ }
128
+ async resolveTarget(number) {
129
+ if (!isAzurePositiveInt(number)) return {
130
+ ok: false,
131
+ reason: "invalid-input"
132
+ };
133
+ const { raw, pullRequest } = await this.readPullRequest(number);
134
+ const state = raw.status;
135
+ const { capability, targetSha } = await this.getCompletionTarget(raw, pullRequest);
136
+ return {
137
+ ok: true,
138
+ accountId: this.accountId,
139
+ pullRequest: targetSha === void 0 ? pullRequest : {
140
+ ...pullRequest,
141
+ targetSha
142
+ },
143
+ capabilities: {
144
+ edit: state === "active" || state === "abandoned",
145
+ abandon: state === "active",
146
+ reactivate: state === "abandoned",
147
+ complete: capability
148
+ }
149
+ };
150
+ }
151
+ async write(options) {
152
+ if (options.action === "create") return this.save(options, {
153
+ sourceRefName: options.sourceRef,
154
+ targetRefName: options.targetRef,
155
+ title: options.title,
156
+ description: options.description
157
+ });
158
+ const current = await this.readPullRequest(options.number);
159
+ const state = current.raw.status;
160
+ switch (options.action) {
161
+ case "edit":
162
+ if (state === "completed") return {
163
+ ok: false,
164
+ reason: "conflict"
165
+ };
166
+ return this.save(options, {
167
+ title: options.title,
168
+ description: options.description
169
+ });
170
+ case "abandon":
171
+ if (state !== "active") return {
172
+ ok: false,
173
+ reason: "conflict"
174
+ };
175
+ return this.save(options, { status: "abandoned" });
176
+ case "reactivate":
177
+ if (state !== "abandoned") return {
178
+ ok: false,
179
+ reason: "conflict"
180
+ };
181
+ return this.save(options, { status: "active" });
182
+ case "complete": return this.complete(options, current.raw, current.pullRequest);
183
+ }
184
+ }
185
+ async complete(options, raw, pullRequest) {
186
+ const failure = getCompletionRefFailure(options, pullRequest) ?? getCompletionStateFailure(raw);
187
+ if (failure != null) return {
188
+ ok: false,
189
+ reason: failure
190
+ };
191
+ if (!(await this.getAllowedStrategies(options.expectedTargetRef)).includes(options.strategy)) return {
192
+ ok: false,
193
+ reason: "policy-blocked"
194
+ };
195
+ const [source, target] = await this.readCompletionRefs(pullRequest);
196
+ if (!sameAzureIdentifier(source, options.expectedSourceSha)) return {
197
+ ok: false,
198
+ reason: "source-changed"
199
+ };
200
+ if (!sameAzureIdentifier(target, options.expectedTargetSha)) return {
201
+ ok: false,
202
+ reason: "target-changed"
203
+ };
204
+ const latest = await this.readPullRequest(options.number);
205
+ const latestFailure = getCompletionRefFailure(options, latest.pullRequest) ?? getCompletionStateFailure(latest.raw);
206
+ if (latestFailure != null) return {
207
+ ok: false,
208
+ reason: latestFailure
209
+ };
210
+ const latestTarget = await this.readRef(options.expectedTargetRef);
211
+ if (!sameAzureIdentifier(latestTarget, options.expectedTargetSha)) return {
212
+ ok: false,
213
+ reason: "target-changed"
214
+ };
215
+ const previewFailure = getMergePreviewFailure(latest.raw, options.expectedTargetSha);
216
+ if (previewFailure != null) return {
217
+ ok: false,
218
+ reason: previewFailure
219
+ };
220
+ return this.save(options, {
221
+ status: "completed",
222
+ completionOptions: {
223
+ mergeStrategy: options.strategy,
224
+ bypassPolicy: false
225
+ },
226
+ lastMergeSourceCommit: { commitId: options.expectedSourceSha }
227
+ });
228
+ }
229
+ async getCompletionTarget(raw, pullRequest) {
230
+ const stateFailure = getCompletionStateFailure(raw);
231
+ if (stateFailure != null) return { capability: {
232
+ kind: "unavailable",
233
+ reason: stateFailure
234
+ } };
235
+ if (!pullRequest.sourceSha) return { capability: {
236
+ kind: "unavailable",
237
+ reason: "unknown"
238
+ } };
239
+ try {
240
+ const strategies = await this.getAllowedStrategies(pullRequest.targetRef);
241
+ if (!strategies.length) return { capability: {
242
+ kind: "unavailable",
243
+ reason: "policy-blocked"
244
+ } };
245
+ const [source, targetSha] = await this.readCompletionRefs(pullRequest);
246
+ if (!sameAzureIdentifier(source, pullRequest.sourceSha)) return {
247
+ capability: {
248
+ kind: "unavailable",
249
+ reason: "source-changed"
250
+ },
251
+ targetSha
252
+ };
253
+ if (targetSha === void 0) return { capability: {
254
+ kind: "unavailable",
255
+ reason: "target-changed"
256
+ } };
257
+ const previewFailure = getMergePreviewFailure(raw, targetSha);
258
+ return {
259
+ capability: previewFailure === void 0 ? {
260
+ kind: "available",
261
+ strategies
262
+ } : {
263
+ kind: "unavailable",
264
+ reason: previewFailure
265
+ },
266
+ targetSha
267
+ };
268
+ } catch (ex) {
269
+ return { capability: {
270
+ kind: "unavailable",
271
+ reason: toAzurePullRequestWriteFailure(ex).reason
272
+ } };
273
+ }
274
+ }
275
+ readCompletionRefs(pullRequest) {
276
+ return Promise.all([this.readRef(pullRequest.sourceRef), this.readRef(pullRequest.targetRef)]);
277
+ }
278
+ async getAllowedStrategies(ref) {
279
+ const query = new URLSearchParams({
280
+ "api-version": "7.1",
281
+ repositoryId: this.repository.repositoryId,
282
+ refName: ref,
283
+ policyType: mergeStrategyPolicyId
284
+ });
285
+ let strategies = mergeStrategies.slice();
286
+ for await (const policies of this.readPages(`${this.gitApiUrl}/policy/configurations`, query)) for (const policy of policies) if (policy.isEnabled === true && policy.isDeleted !== true && policy.isBlocking === true) strategies = strategies.filter((strategy) => allowsStrategy(policy, strategy));
287
+ return strategies;
288
+ }
289
+ async readRef(ref) {
290
+ const query = new URLSearchParams({
291
+ "api-version": "7.1",
292
+ filter: ref.slice(5)
293
+ });
294
+ for await (const refs of this.readPages(`${this.repoUrl}/refs`, query)) {
295
+ const match = refs.find((row) => row.name === ref);
296
+ if (match != null) return isCommitId(match.objectId) ? match.objectId : void 0;
297
+ }
298
+ }
299
+ async *readPages(url, query) {
300
+ const seen = /* @__PURE__ */ new Set();
301
+ while (true) {
302
+ const { body, headers } = await this.request({
303
+ url: `${url}?${query.toString()}`,
304
+ headers: this.headers,
305
+ redirect: "error"
306
+ });
307
+ if (!Array.isArray(body?.value)) throw new AzurePullRequestWriteError("unknown");
308
+ yield body.value;
309
+ const next = headers["x-ms-continuationtoken"];
310
+ if (!next) return;
311
+ if (seen.has(next)) throw new AzurePullRequestWriteError("unknown");
312
+ seen.add(next);
313
+ query.set("continuationToken", next);
314
+ }
315
+ }
316
+ async readPullRequest(number) {
317
+ const { body: raw } = await this.request({
318
+ url: this.pullRequestUrl(number),
319
+ headers: this.headers,
320
+ redirect: "error"
321
+ });
322
+ const snapshot = this.toPullRequestSnapshot(raw, number);
323
+ const { state } = snapshot;
324
+ if (state === void 0) throw new AzurePullRequestWriteError(getReportedMergeFailure(raw.mergeStatus) ?? "unknown");
325
+ return {
326
+ raw,
327
+ pullRequest: {
328
+ ...snapshot,
329
+ state
330
+ }
331
+ };
332
+ }
333
+ pullRequestUrl(number) {
334
+ return `${this.repoUrl}/pullrequests${number === void 0 ? "" : `/${number}`}?api-version=7.1`;
335
+ }
336
+ toPullRequestSnapshot(raw, number) {
337
+ if (!sameAzureIdentifier(raw?.repository?.id, this.repository.repositoryId) || !sameAzureIdentifier(raw.repository.project?.id, this.repository.projectId) || number !== void 0 && raw.pullRequestId !== number) throw new AzurePullRequestWriteError("not-found");
338
+ if (!isAzurePositiveInt(raw.pullRequestId) || raw.status !== "active" && raw.status !== "abandoned" && raw.status !== "completed" || typeof raw.title !== "string" || raw.description != null && typeof raw.description !== "string" || !isBranchRef(raw.sourceRefName) || !isBranchRef(raw.targetRefName)) throw new AzurePullRequestWriteError("unknown");
339
+ const sourceSha = raw.lastMergeSourceCommit?.commitId;
340
+ const targetSha = raw.lastMergeTargetCommit?.commitId;
341
+ let state = raw.status;
342
+ if (state === "completed" && raw.mergeStatus !== "succeeded") state = raw.mergeStatus === "queued" ? "active" : void 0;
343
+ return {
344
+ repository: this.repository,
345
+ number: raw.pullRequestId,
346
+ url: getAzurePullRequestWebUrl({
347
+ pullRequestId: raw.pullRequestId,
348
+ repository: {
349
+ ...raw.repository,
350
+ name: this.repository.repositoryName,
351
+ project: {
352
+ id: this.repository.projectId,
353
+ name: this.repository.projectName
354
+ }
355
+ }
356
+ }, azureBaseUrl, this.repository.organization),
357
+ title: raw.title,
358
+ description: raw.description ?? "",
359
+ state,
360
+ sourceRef: raw.sourceRefName,
361
+ targetRef: raw.targetRefName,
362
+ sourceSha: isCommitId(sourceSha) ? sourceSha : void 0,
363
+ targetSha: isCommitId(targetSha) ? targetSha : void 0
364
+ };
365
+ }
366
+ async save(options, body) {
367
+ if (!await this.isSessionCurrent()) return {
368
+ ok: false,
369
+ reason: "no-connection"
370
+ };
371
+ const create = options.action === "create";
372
+ const number = create ? void 0 : options.number;
373
+ let raw;
374
+ try {
375
+ ({body: raw} = await this.request({
376
+ url: this.pullRequestUrl(number),
377
+ method: create ? "POST" : "PATCH",
378
+ headers: {
379
+ ...this.headers,
380
+ "Content-Type": "application/json"
381
+ },
382
+ body: JSON.stringify(body),
383
+ redirect: "error"
384
+ }));
385
+ } catch (ex) {
386
+ return toAzurePullRequestWriteFailure(ex, { complete: options.action === "complete" });
387
+ }
388
+ let snapshot;
389
+ try {
390
+ snapshot = this.toPullRequestSnapshot(raw, number);
391
+ } catch {
392
+ return {
393
+ ok: false,
394
+ reason: "outcome-unknown"
395
+ };
396
+ }
397
+ return this.getReceipt(options, raw, snapshot);
398
+ }
399
+ getReceipt(options, raw, snapshot) {
400
+ const { state, sourceRef, targetRef } = snapshot;
401
+ let status;
402
+ switch (options.action) {
403
+ case "create":
404
+ if (state === "active" && sourceRef === options.sourceRef && targetRef === options.targetRef) status = "created";
405
+ break;
406
+ case "edit":
407
+ if ((options.title === void 0 || snapshot.title === options.title) && (options.description === void 0 || snapshot.description === options.description)) status = "updated";
408
+ break;
409
+ case "abandon":
410
+ if (state === "abandoned") status = "abandoned";
411
+ break;
412
+ case "reactivate":
413
+ if (state === "active") status = "reactivated";
414
+ break;
415
+ case "complete": {
416
+ if (sourceRef !== options.expectedSourceRef || targetRef !== options.expectedTargetRef) break;
417
+ const failure = getReportedMergeFailure(raw.mergeStatus);
418
+ if (failure != null) return {
419
+ ok: false,
420
+ reason: failure
421
+ };
422
+ if (state === "active" && raw.mergeStatus === "queued") status = "pending";
423
+ else if (state === "completed") status = "completed";
424
+ break;
425
+ }
426
+ }
427
+ return status === void 0 || state === void 0 ? {
428
+ ok: false,
429
+ reason: "outcome-unknown"
430
+ } : {
431
+ ok: true,
432
+ status,
433
+ pullRequest: {
434
+ ...snapshot,
435
+ state
436
+ }
437
+ };
438
+ }
439
+ };
440
+ //#endregion
441
+ export { AzurePullRequestWriter, isAzurePullRequestScope, isAzurePullRequestWrite };
442
+
443
+ //# sourceMappingURL=azurePullRequestWrites.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"azurePullRequestWrites.js","names":[],"sources":["../../../../../plus/integrations/src/providers/azurePullRequestWrites.ts"],"sourcesContent":["import type {\n\tAzurePullRequestCreateCapabilityOptions,\n\tAzurePullRequestCreateCapabilityResult,\n\tAzurePullRequestMergeStrategy,\n\tAzurePullRequestRepository,\n\tAzurePullRequestWriteFailure,\n\tAzurePullRequestWriteOptions,\n\tAzurePullRequestWriteResult,\n\tAzurePullRequestWriteTargetResult,\n\tAzureWrittenPullRequest,\n} from '../models/azurePullRequestWrites.js';\nimport type { AzurePullRequest, AzureRepository } from './azure/models.js';\nimport { encodeAzurePathSegment, getAzurePullRequestWebUrl } from './azure/models.js';\nimport {\n\tgetAzureWriteOrganizations,\n\tgetAzureWriteProfile,\n\tisAzureGuid,\n\tisAzureIdentifier,\n\tisAzurePositiveInt,\n\tsameAzureIdentifier,\n} from './azure/writeIdentity.js';\nimport { AzurePullRequestWriteError, toAzurePullRequestWriteFailure } from './azurePullRequestWriteErrors.js';\nimport type { ProviderRequestFunction } from './models.js';\n\nconst azureBaseUrl = 'https://dev.azure.com';\nconst branchRefPrefix = 'refs/heads/';\nconst mergeStrategyPolicyId = 'fa4e907d-c16b-4a4c-9dfa-4916e5d171ab';\nconst strategySettings = {\n\tnoFastForward: 'allowNoFastForward',\n\tsquash: 'allowSquash',\n\trebase: 'allowRebase',\n\trebaseMerge: 'allowRebaseMerge',\n} as const;\nconst mergeStrategies: AzurePullRequestMergeStrategy[] = ['noFastForward', 'squash', 'rebase', 'rebaseMerge'];\n\ntype MergePolicy = {\n\tisEnabled?: boolean;\n\tisDeleted?: boolean;\n\tisBlocking?: boolean;\n\tsettings?: Partial<Record<(typeof strategySettings)[AzurePullRequestMergeStrategy] | 'useSquashMerge', boolean>>;\n};\n\ntype CompletionCapability = Extract<AzurePullRequestWriteTargetResult, { ok: true }>['capabilities']['complete'];\ntype CompletionOptions = Extract<AzurePullRequestWriteOptions, { action: 'complete' }>;\ntype FailureReason = AzurePullRequestWriteFailure['reason'];\ntype PullRequestSnapshot = Omit<AzureWrittenPullRequest, 'state'> & {\n\tstate: AzureWrittenPullRequest['state'] | undefined;\n};\ntype WriteStatus = Extract<AzurePullRequestWriteResult, { ok: true }>['status'];\n\nfunction isPathSegment(value: unknown): value is string {\n\treturn isAzureIdentifier(value) && value !== '.' && value !== '..' && !value.includes('/') && !value.includes('\\\\');\n}\n\nfunction isBranchRef(ref: unknown): ref is string {\n\treturn (\n\t\ttypeof ref === 'string' &&\n\t\tref.startsWith(branchRefPrefix) &&\n\t\tref.length > branchRefPrefix.length &&\n\t\t![...ref].some(character => character <= ' ' || '~^:?*[\\\\\\x7f'.includes(character)) &&\n\t\t!ref.includes('..') &&\n\t\t!ref.includes('@{') &&\n\t\t!ref.endsWith('.') &&\n\t\tref.split('/').every(part => part.length > 0 && !part.startsWith('.') && !part.endsWith('.lock'))\n\t);\n}\n\nfunction isCommitId(sha: unknown): sha is string {\n\treturn typeof sha === 'string' && /^(?!0{40}$)[0-9a-f]{40}$/i.test(sha);\n}\n\nexport function isAzurePullRequestScope(options: AzurePullRequestCreateCapabilityOptions): boolean {\n\treturn (\n\t\tisAzureIdentifier(options.connectionId) &&\n\t\ttypeof options.organization === 'string' &&\n\t\t/^[a-z0-9][a-z0-9-]*$/i.test(options.organization) &&\n\t\tisPathSegment(options.project) &&\n\t\tisPathSegment(options.repository) &&\n\t\t(options.expectedAccountId === undefined || isAzureIdentifier(options.expectedAccountId))\n\t);\n}\n\nfunction isTitle(title: unknown): title is string {\n\treturn typeof title === 'string' && title.trim().length > 0;\n}\n\nfunction isDescription(description: unknown): boolean {\n\treturn description === undefined || (typeof description === 'string' && description.length <= 4000);\n}\n\nexport function isAzurePullRequestWrite(options: AzurePullRequestWriteOptions): boolean {\n\tif (\n\t\t!isAzureGuid(options.projectId) ||\n\t\t!isAzureGuid(options.repositoryId) ||\n\t\t!isAzureIdentifier(options.expectedAccountId)\n\t) {\n\t\treturn false;\n\t}\n\n\tif (options.action === 'create') {\n\t\treturn (\n\t\t\tisBranchRef(options.sourceRef) &&\n\t\t\tisBranchRef(options.targetRef) &&\n\t\t\toptions.sourceRef !== options.targetRef &&\n\t\t\tisTitle(options.title) &&\n\t\t\tisDescription(options.description)\n\t\t);\n\t}\n\n\tif (!isAzurePositiveInt(options.number)) return false;\n\n\tswitch (options.action) {\n\t\tcase 'edit':\n\t\t\treturn (\n\t\t\t\t(options.title !== undefined || options.description !== undefined) &&\n\t\t\t\t(options.title === undefined || isTitle(options.title)) &&\n\t\t\t\tisDescription(options.description)\n\t\t\t);\n\t\tcase 'abandon':\n\t\tcase 'reactivate':\n\t\t\treturn true;\n\t\tcase 'complete':\n\t\t\treturn (\n\t\t\t\tmergeStrategies.includes(options.strategy) &&\n\t\t\t\tisBranchRef(options.expectedSourceRef) &&\n\t\t\t\tisBranchRef(options.expectedTargetRef) &&\n\t\t\t\toptions.expectedSourceRef !== options.expectedTargetRef &&\n\t\t\t\tisCommitId(options.expectedSourceSha) &&\n\t\t\t\tisCommitId(options.expectedTargetSha)\n\t\t\t);\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction allowsStrategy(policy: MergePolicy, strategy: AzurePullRequestMergeStrategy): boolean {\n\tconst settings = policy.settings;\n\tif (settings == null) return false;\n\tif (mergeStrategies.some(type => settings[strategySettings[type]] != null)) {\n\t\treturn settings[strategySettings[strategy]] === true;\n\t}\n\n\treturn (\n\t\t(strategy === 'squash' && settings.useSquashMerge === true) ||\n\t\t(strategy === 'noFastForward' && settings.useSquashMerge === false)\n\t);\n}\n\nfunction getCompletionRefFailure(\n\toptions: CompletionOptions,\n\tpullRequest: AzureWrittenPullRequest,\n): FailureReason | undefined {\n\tif (\n\t\tpullRequest.sourceRef !== options.expectedSourceRef ||\n\t\t!sameAzureIdentifier(pullRequest.sourceSha, options.expectedSourceSha)\n\t) {\n\t\treturn 'source-changed';\n\t}\n\tif (pullRequest.targetRef !== options.expectedTargetRef) return 'target-changed';\n\n\treturn undefined;\n}\n\nfunction getCompletionStateFailure(raw: AzurePullRequest): FailureReason | undefined {\n\tif (raw.forkSource != null) return 'unsupported';\n\tif (raw.isDraft) return 'policy-blocked';\n\tif (raw.status !== 'active' || raw.mergeStatus === 'queued') return 'conflict';\n\n\treturn undefined;\n}\n\nfunction getMergePreviewFailure(raw: AzurePullRequest, targetSha: string): FailureReason | undefined {\n\tif (raw.mergeStatus !== 'conflicts' && raw.mergeStatus !== 'failure') return undefined;\n\n\tconst previewTargetSha = raw.lastMergeTargetCommit?.commitId;\n\tif (!isCommitId(previewTargetSha)) return 'unknown';\n\tif (!sameAzureIdentifier(previewTargetSha, targetSha)) return undefined;\n\n\treturn raw.mergeStatus === 'conflicts' ? 'conflict' : 'unknown';\n}\n\nfunction getReportedMergeFailure(mergeStatus: AzurePullRequest['mergeStatus']): FailureReason | undefined {\n\tswitch (mergeStatus) {\n\t\tcase 'rejectedByPolicy':\n\t\t\treturn 'policy-blocked';\n\t\tcase 'conflicts':\n\t\t\treturn 'conflict';\n\t\tcase 'failure':\n\t\t\treturn 'unknown';\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\nexport class AzurePullRequestWriter {\n\tstatic async connect(\n\t\trequest: ProviderRequestFunction,\n\t\tcredential: { accessToken: string; accountsAuthorization: string; gitAuthorization: string },\n\t\toptions: AzurePullRequestCreateCapabilityOptions,\n\t\tisSessionCurrent: () => Promise<boolean>,\n\t): Promise<AzurePullRequestWriter> {\n\t\tconst { body: profile } = await getAzureWriteProfile(request, credential.accessToken);\n\t\tconst accountId = profile?.id;\n\t\tif (\n\t\t\t!isAzureIdentifier(accountId) ||\n\t\t\t(options.expectedAccountId !== undefined && !sameAzureIdentifier(accountId, options.expectedAccountId))\n\t\t) {\n\t\t\tthrow new AzurePullRequestWriteError('no-connection');\n\t\t}\n\n\t\tconst { body: accounts } = await getAzureWriteOrganizations(\n\t\t\trequest,\n\t\t\tcredential.accountsAuthorization,\n\t\t\taccountId,\n\t\t);\n\t\tif (!Array.isArray(accounts?.value)) throw new AzurePullRequestWriteError('unknown');\n\n\t\tconst organization = accounts.value.find(account =>\n\t\t\tsameAzureIdentifier(account?.accountName, options.organization),\n\t\t)?.accountName;\n\t\tif (organization == null) throw new AzurePullRequestWriteError('not-found');\n\n\t\tconst headers = { Authorization: credential.gitAuthorization };\n\t\tconst { body: repo } = await request<AzureRepository>({\n\t\t\turl: `${azureBaseUrl}/${organization}/${encodeAzurePathSegment(options.project)}/_apis/git/repositories/${encodeAzurePathSegment(options.repository)}?api-version=7.1`,\n\t\t\theaders: headers,\n\t\t\tredirect: 'error',\n\t\t});\n\t\tif (\n\t\t\t!isAzureGuid(repo?.id) ||\n\t\t\t!isAzureGuid(repo.project?.id) ||\n\t\t\t!isPathSegment(repo.name) ||\n\t\t\t!isPathSegment(repo.project.name) ||\n\t\t\t!sameAzureIdentifier(isAzureGuid(options.repository) ? repo.id : repo.name, options.repository) ||\n\t\t\t!sameAzureIdentifier(isAzureGuid(options.project) ? repo.project.id : repo.project.name, options.project)\n\t\t) {\n\t\t\tthrow new AzurePullRequestWriteError('not-found');\n\t\t}\n\t\tif (repo.isDisabled || repo.isInMaintenance) throw new AzurePullRequestWriteError('unsupported');\n\n\t\treturn new AzurePullRequestWriter(\n\t\t\trequest,\n\t\t\theaders,\n\t\t\taccountId,\n\t\t\t{\n\t\t\t\torganization: organization,\n\t\t\t\tprojectId: repo.project.id,\n\t\t\t\tprojectName: repo.project.name,\n\t\t\t\trepositoryId: repo.id,\n\t\t\t\trepositoryName: repo.name,\n\t\t\t},\n\t\t\tisSessionCurrent,\n\t\t);\n\t}\n\n\tprivate readonly gitApiUrl: string;\n\tprivate readonly repoUrl: string;\n\n\tprivate constructor(\n\t\tprivate readonly request: ProviderRequestFunction,\n\t\tprivate readonly headers: { Authorization: string },\n\t\tprivate readonly accountId: string,\n\t\tprivate readonly repository: AzurePullRequestRepository,\n\t\tprivate readonly isSessionCurrent: () => Promise<boolean>,\n\t) {\n\t\tthis.gitApiUrl = `${azureBaseUrl}/${repository.organization}/${repository.projectId}/_apis/git`;\n\t\tthis.repoUrl = `${this.gitApiUrl}/repositories/${repository.repositoryId}`;\n\t}\n\n\tgetCreateCapability(): AzurePullRequestCreateCapabilityResult {\n\t\treturn { ok: true, accountId: this.accountId, repository: this.repository };\n\t}\n\n\tasync resolveTarget(number: number): Promise<AzurePullRequestWriteTargetResult> {\n\t\tif (!isAzurePositiveInt(number)) return { ok: false, reason: 'invalid-input' };\n\n\t\tconst { raw, pullRequest } = await this.readPullRequest(number);\n\t\tconst state = raw.status;\n\t\tconst { capability, targetSha } = await this.getCompletionTarget(raw, pullRequest);\n\t\treturn {\n\t\t\tok: true,\n\t\t\taccountId: this.accountId,\n\t\t\tpullRequest: targetSha === undefined ? pullRequest : { ...pullRequest, targetSha: targetSha },\n\t\t\tcapabilities: {\n\t\t\t\tedit: state === 'active' || state === 'abandoned',\n\t\t\t\tabandon: state === 'active',\n\t\t\t\treactivate: state === 'abandoned',\n\t\t\t\tcomplete: capability,\n\t\t\t},\n\t\t};\n\t}\n\n\tasync write(options: AzurePullRequestWriteOptions): Promise<AzurePullRequestWriteResult> {\n\t\tif (options.action === 'create') {\n\t\t\treturn this.save(options, {\n\t\t\t\tsourceRefName: options.sourceRef,\n\t\t\t\ttargetRefName: options.targetRef,\n\t\t\t\ttitle: options.title,\n\t\t\t\tdescription: options.description,\n\t\t\t});\n\t\t}\n\n\t\tconst current = await this.readPullRequest(options.number);\n\t\tconst state = current.raw.status;\n\t\tswitch (options.action) {\n\t\t\tcase 'edit':\n\t\t\t\tif (state === 'completed') return { ok: false, reason: 'conflict' };\n\n\t\t\t\treturn this.save(options, { title: options.title, description: options.description });\n\t\t\tcase 'abandon':\n\t\t\t\tif (state !== 'active') return { ok: false, reason: 'conflict' };\n\n\t\t\t\treturn this.save(options, { status: 'abandoned' });\n\t\t\tcase 'reactivate':\n\t\t\t\tif (state !== 'abandoned') return { ok: false, reason: 'conflict' };\n\n\t\t\t\treturn this.save(options, { status: 'active' });\n\t\t\tcase 'complete':\n\t\t\t\treturn this.complete(options, current.raw, current.pullRequest);\n\t\t}\n\t}\n\n\tprivate async complete(\n\t\toptions: CompletionOptions,\n\t\traw: AzurePullRequest,\n\t\tpullRequest: AzureWrittenPullRequest,\n\t): Promise<AzurePullRequestWriteResult> {\n\t\tconst failure = getCompletionRefFailure(options, pullRequest) ?? getCompletionStateFailure(raw);\n\t\tif (failure != null) return { ok: false, reason: failure };\n\n\t\tconst strategies = await this.getAllowedStrategies(options.expectedTargetRef);\n\t\tif (!strategies.includes(options.strategy)) return { ok: false, reason: 'policy-blocked' };\n\n\t\tconst [source, target] = await this.readCompletionRefs(pullRequest);\n\t\tif (!sameAzureIdentifier(source, options.expectedSourceSha)) return { ok: false, reason: 'source-changed' };\n\t\tif (!sameAzureIdentifier(target, options.expectedTargetSha)) return { ok: false, reason: 'target-changed' };\n\n\t\tconst latest = await this.readPullRequest(options.number);\n\t\tconst latestFailure =\n\t\t\tgetCompletionRefFailure(options, latest.pullRequest) ?? getCompletionStateFailure(latest.raw);\n\t\tif (latestFailure != null) return { ok: false, reason: latestFailure };\n\n\t\tconst latestTarget = await this.readRef(options.expectedTargetRef);\n\t\tif (!sameAzureIdentifier(latestTarget, options.expectedTargetSha)) {\n\t\t\treturn { ok: false, reason: 'target-changed' };\n\t\t}\n\n\t\tconst previewFailure = getMergePreviewFailure(latest.raw, options.expectedTargetSha);\n\t\tif (previewFailure != null) return { ok: false, reason: previewFailure };\n\n\t\treturn this.save(options, {\n\t\t\tstatus: 'completed',\n\t\t\tcompletionOptions: { mergeStrategy: options.strategy, bypassPolicy: false },\n\t\t\tlastMergeSourceCommit: { commitId: options.expectedSourceSha },\n\t\t});\n\t}\n\n\tprivate async getCompletionTarget(\n\t\traw: AzurePullRequest,\n\t\tpullRequest: AzureWrittenPullRequest,\n\t): Promise<{ capability: CompletionCapability; targetSha?: string }> {\n\t\tconst stateFailure = getCompletionStateFailure(raw);\n\t\tif (stateFailure != null) return { capability: { kind: 'unavailable', reason: stateFailure } };\n\t\tif (!pullRequest.sourceSha) return { capability: { kind: 'unavailable', reason: 'unknown' } };\n\n\t\ttry {\n\t\t\tconst strategies = await this.getAllowedStrategies(pullRequest.targetRef);\n\t\t\tif (!strategies.length) return { capability: { kind: 'unavailable', reason: 'policy-blocked' } };\n\n\t\t\tconst [source, targetSha] = await this.readCompletionRefs(pullRequest);\n\t\t\tif (!sameAzureIdentifier(source, pullRequest.sourceSha)) {\n\t\t\t\treturn { capability: { kind: 'unavailable', reason: 'source-changed' }, targetSha: targetSha };\n\t\t\t}\n\t\t\tif (targetSha === undefined) return { capability: { kind: 'unavailable', reason: 'target-changed' } };\n\n\t\t\tconst previewFailure = getMergePreviewFailure(raw, targetSha);\n\t\t\treturn {\n\t\t\t\tcapability:\n\t\t\t\t\tpreviewFailure === undefined\n\t\t\t\t\t\t? { kind: 'available', strategies: strategies }\n\t\t\t\t\t\t: { kind: 'unavailable', reason: previewFailure },\n\t\t\t\ttargetSha: targetSha,\n\t\t\t};\n\t\t} catch (ex) {\n\t\t\treturn { capability: { kind: 'unavailable', reason: toAzurePullRequestWriteFailure(ex).reason } };\n\t\t}\n\t}\n\n\tprivate readCompletionRefs(\n\t\tpullRequest: AzureWrittenPullRequest,\n\t): Promise<[string | undefined, string | undefined]> {\n\t\treturn Promise.all([this.readRef(pullRequest.sourceRef), this.readRef(pullRequest.targetRef)]);\n\t}\n\n\tprivate async getAllowedStrategies(ref: string): Promise<AzurePullRequestMergeStrategy[]> {\n\t\tconst query = new URLSearchParams({\n\t\t\t'api-version': '7.1',\n\t\t\trepositoryId: this.repository.repositoryId,\n\t\t\trefName: ref,\n\t\t\tpolicyType: mergeStrategyPolicyId,\n\t\t});\n\t\tlet strategies = mergeStrategies.slice();\n\t\tfor await (const policies of this.readPages<MergePolicy>(`${this.gitApiUrl}/policy/configurations`, query)) {\n\t\t\tfor (const policy of policies) {\n\t\t\t\tif (policy.isEnabled === true && policy.isDeleted !== true && policy.isBlocking === true) {\n\t\t\t\t\tstrategies = strategies.filter(strategy => allowsStrategy(policy, strategy));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn strategies;\n\t}\n\n\tprivate async readRef(ref: string): Promise<string | undefined> {\n\t\tconst query = new URLSearchParams({ 'api-version': '7.1', filter: ref.slice('refs/'.length) });\n\t\tfor await (const refs of this.readPages<{ name: string; objectId: string }>(`${this.repoUrl}/refs`, query)) {\n\t\t\tconst match = refs.find(row => row.name === ref);\n\t\t\tif (match != null) return isCommitId(match.objectId) ? match.objectId : undefined;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tprivate async *readPages<T>(url: string, query: URLSearchParams): AsyncGenerator<T[]> {\n\t\tconst seen = new Set<string>();\n\t\twhile (true) {\n\t\t\tconst { body, headers } = await this.request<{ value?: T[] }>({\n\t\t\t\turl: `${url}?${query.toString()}`,\n\t\t\t\theaders: this.headers,\n\t\t\t\tredirect: 'error',\n\t\t\t});\n\t\t\tif (!Array.isArray(body?.value)) throw new AzurePullRequestWriteError('unknown');\n\n\t\t\tyield body.value;\n\n\t\t\tconst next = headers['x-ms-continuationtoken'];\n\t\t\tif (!next) return;\n\t\t\tif (seen.has(next)) throw new AzurePullRequestWriteError('unknown');\n\n\t\t\tseen.add(next);\n\t\t\tquery.set('continuationToken', next);\n\t\t}\n\t}\n\n\tprivate async readPullRequest(\n\t\tnumber: number,\n\t): Promise<{ raw: AzurePullRequest; pullRequest: AzureWrittenPullRequest }> {\n\t\tconst { body: raw } = await this.request<AzurePullRequest>({\n\t\t\turl: this.pullRequestUrl(number),\n\t\t\theaders: this.headers,\n\t\t\tredirect: 'error',\n\t\t});\n\t\tconst snapshot = this.toPullRequestSnapshot(raw, number);\n\t\tconst { state } = snapshot;\n\t\tif (state === undefined) {\n\t\t\tthrow new AzurePullRequestWriteError(getReportedMergeFailure(raw.mergeStatus) ?? 'unknown');\n\t\t}\n\t\treturn { raw: raw, pullRequest: { ...snapshot, state: state } };\n\t}\n\n\tprivate pullRequestUrl(number?: number): string {\n\t\treturn `${this.repoUrl}/pullrequests${number === undefined ? '' : `/${number}`}?api-version=7.1`;\n\t}\n\n\tprivate toPullRequestSnapshot(raw: AzurePullRequest, number?: number): PullRequestSnapshot {\n\t\tif (\n\t\t\t!sameAzureIdentifier(raw?.repository?.id, this.repository.repositoryId) ||\n\t\t\t!sameAzureIdentifier(raw.repository.project?.id, this.repository.projectId) ||\n\t\t\t(number !== undefined && raw.pullRequestId !== number)\n\t\t) {\n\t\t\tthrow new AzurePullRequestWriteError('not-found');\n\t\t}\n\n\t\tif (\n\t\t\t!isAzurePositiveInt(raw.pullRequestId) ||\n\t\t\t(raw.status !== 'active' && raw.status !== 'abandoned' && raw.status !== 'completed') ||\n\t\t\ttypeof raw.title !== 'string' ||\n\t\t\t(raw.description != null && typeof raw.description !== 'string') ||\n\t\t\t!isBranchRef(raw.sourceRefName) ||\n\t\t\t!isBranchRef(raw.targetRefName)\n\t\t) {\n\t\t\tthrow new AzurePullRequestWriteError('unknown');\n\t\t}\n\n\t\tconst sourceSha = raw.lastMergeSourceCommit?.commitId;\n\t\tconst targetSha = raw.lastMergeTargetCommit?.commitId;\n\t\tlet state: PullRequestSnapshot['state'] = raw.status;\n\t\tif (state === 'completed' && raw.mergeStatus !== 'succeeded') {\n\t\t\tstate = raw.mergeStatus === 'queued' ? 'active' : undefined;\n\t\t}\n\t\treturn {\n\t\t\trepository: this.repository,\n\t\t\tnumber: raw.pullRequestId,\n\t\t\turl: getAzurePullRequestWebUrl(\n\t\t\t\t{\n\t\t\t\t\tpullRequestId: raw.pullRequestId,\n\t\t\t\t\trepository: {\n\t\t\t\t\t\t...raw.repository,\n\t\t\t\t\t\tname: this.repository.repositoryName,\n\t\t\t\t\t\tproject: { id: this.repository.projectId, name: this.repository.projectName },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tazureBaseUrl,\n\t\t\t\tthis.repository.organization,\n\t\t\t),\n\t\t\ttitle: raw.title,\n\t\t\tdescription: raw.description ?? '',\n\t\t\tstate: state,\n\t\t\tsourceRef: raw.sourceRefName,\n\t\t\ttargetRef: raw.targetRefName,\n\t\t\tsourceSha: isCommitId(sourceSha) ? sourceSha : undefined,\n\t\t\ttargetSha: isCommitId(targetSha) ? targetSha : undefined,\n\t\t};\n\t}\n\n\tprivate async save(options: AzurePullRequestWriteOptions, body: object): Promise<AzurePullRequestWriteResult> {\n\t\tif (!(await this.isSessionCurrent())) return { ok: false, reason: 'no-connection' };\n\n\t\tconst create = options.action === 'create';\n\t\tconst number = create ? undefined : options.number;\n\t\tlet raw: AzurePullRequest;\n\t\ttry {\n\t\t\t({ body: raw } = await this.request<AzurePullRequest>({\n\t\t\t\turl: this.pullRequestUrl(number),\n\t\t\t\tmethod: create ? 'POST' : 'PATCH',\n\t\t\t\theaders: { ...this.headers, 'Content-Type': 'application/json' },\n\t\t\t\tbody: JSON.stringify(body),\n\t\t\t\tredirect: 'error',\n\t\t\t}));\n\t\t} catch (ex) {\n\t\t\treturn toAzurePullRequestWriteFailure(ex, { complete: options.action === 'complete' });\n\t\t}\n\n\t\tlet snapshot: PullRequestSnapshot;\n\t\ttry {\n\t\t\tsnapshot = this.toPullRequestSnapshot(raw, number);\n\t\t} catch {\n\t\t\treturn { ok: false, reason: 'outcome-unknown' };\n\t\t}\n\n\t\treturn this.getReceipt(options, raw, snapshot);\n\t}\n\n\tprivate getReceipt(\n\t\toptions: AzurePullRequestWriteOptions,\n\t\traw: AzurePullRequest,\n\t\tsnapshot: PullRequestSnapshot,\n\t): AzurePullRequestWriteResult {\n\t\tconst { state, sourceRef, targetRef } = snapshot;\n\t\tlet status: WriteStatus | undefined;\n\t\tswitch (options.action) {\n\t\t\tcase 'create':\n\t\t\t\tif (state === 'active' && sourceRef === options.sourceRef && targetRef === options.targetRef) {\n\t\t\t\t\tstatus = 'created';\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'edit':\n\t\t\t\tif (\n\t\t\t\t\t(options.title === undefined || snapshot.title === options.title) &&\n\t\t\t\t\t(options.description === undefined || snapshot.description === options.description)\n\t\t\t\t) {\n\t\t\t\t\tstatus = 'updated';\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'abandon':\n\t\t\t\tif (state === 'abandoned') {\n\t\t\t\t\tstatus = 'abandoned';\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'reactivate':\n\t\t\t\tif (state === 'active') {\n\t\t\t\t\tstatus = 'reactivated';\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'complete': {\n\t\t\t\tif (sourceRef !== options.expectedSourceRef || targetRef !== options.expectedTargetRef) break;\n\n\t\t\t\tconst failure = getReportedMergeFailure(raw.mergeStatus);\n\t\t\t\tif (failure != null) return { ok: false, reason: failure };\n\n\t\t\t\tif (state === 'active' && raw.mergeStatus === 'queued') {\n\t\t\t\t\tstatus = 'pending';\n\t\t\t\t} else if (state === 'completed') {\n\t\t\t\t\tstatus = 'completed';\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\treturn status === undefined || state === undefined\n\t\t\t? { ok: false, reason: 'outcome-unknown' }\n\t\t\t: { ok: true, status: status, pullRequest: { ...snapshot, state: state } };\n\t}\n}\n"],"mappings":";;;;AAwBA,MAAM,eAAe;AACrB,MAAM,kBAAkB;AACxB,MAAM,wBAAwB;AAC9B,MAAM,mBAAmB;CACxB,eAAe;CACf,QAAQ;CACR,QAAQ;CACR,aAAa;AACd;AACA,MAAM,kBAAmD;CAAC;CAAiB;CAAU;CAAU;AAAa;AAiB5G,SAAS,cAAc,OAAiC;CACvD,OAAO,kBAAkB,KAAK,KAAK,UAAU,OAAO,UAAU,QAAQ,CAAC,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,SAAS,IAAI;AACnH;AAEA,SAAS,YAAY,KAA6B;CACjD,OACC,OAAO,QAAQ,YACf,IAAI,WAAW,eAAe,KAC9B,IAAI,SAAS,MACb,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,MAAK,cAAa,aAAa,OAAO,YAAe,SAAS,SAAS,CAAC,KAClF,CAAC,IAAI,SAAS,IAAI,KAClB,CAAC,IAAI,SAAS,IAAI,KAClB,CAAC,IAAI,SAAS,GAAG,KACjB,IAAI,MAAM,GAAG,CAAC,CAAC,OAAM,SAAQ,KAAK,SAAS,KAAK,CAAC,KAAK,WAAW,GAAG,KAAK,CAAC,KAAK,SAAS,OAAO,CAAC;AAElG;AAEA,SAAS,WAAW,KAA6B;CAChD,OAAO,OAAO,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AAQ,WAClF,SAAS;IAEV;GACD,KAAK;IACJ,KACE,QAAQ,UAAU,KAAA,KAAa,SAAS,UAAU,QAAQ,WAC1D,QAAQ,gBAAgB,KAAA,KAAa,SAAS,gBAAgB,QAAQ,cAEvE,SAAS;IAEV;GACD,KAAK;IACJ,IAAI,UAAU,aACb,SAAS;IAEV;GACD,KAAK;IACJ,IAAI,UAAU,UACb,SAAS;IAEV;GACD,KAAK,YAAY;IAChB,IAAI,cAAc,QAAQ,qBAAqB,cAAc,QAAQ,mBAAmB;IAExF,MAAM,UAAU,wBAAwB,IAAI,WAAW;IACvD,IAAI,WAAW,MAAM,OAAO;KAAE,IAAI;KAAO,QAAQ;IAAQ;IAEzD,IAAI,UAAU,YAAY,IAAI,gBAAgB,UAC7C,SAAS;SACH,IAAI,UAAU,aACpB,SAAS;IAEV;GACD;EACD;EAEA,OAAO,WAAW,KAAA,KAAa,UAAU,KAAA,IACtC;GAAE,IAAI;GAAO,QAAQ;EAAkB,IACvC;GAAE,IAAI;GAAc;GAAQ,aAAa;IAAE,GAAG;IAAiB;GAAM;EAAE;CAC3E;AACD"}
@@ -2,9 +2,6 @@ import { IssueTrackerWriteFailure } from "../models/issueTrackerWrites.js";
2
2
  import { WorkItemWriteField, WorkItemWriteScope } from "../models/workItemWrites.js";
3
3
  //#region ../plus/integrations/src/providers/azureWorkItemWriteErrors.d.ts
4
4
  export declare function isWorkItemWriteScope(options: WorkItemWriteScope): boolean;
5
- export declare function isGuid(value: unknown): value is string;
6
- export declare function isWorkItemIdentifier(value: unknown): value is string;
7
- export declare function isWorkItemNumber(value: unknown): value is number;
8
5
  export declare class WorkItemWriteError extends Error {
9
6
  readonly reason: IssueTrackerWriteFailure['reason'];
10
7
  readonly fieldErrors?: Readonly<Record<string, string>> | undefined;