@paklo/core 0.7.3 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/azure/index.d.mts +930 -116
- package/dist/azure/index.mjs +412 -229
- package/dist/azure/index.mjs.map +1 -1
- package/dist/dependabot/index.d.mts +3 -3
- package/dist/dependabot/index.mjs +3 -4
- package/dist/{dependabot-_TVZhG0L.mjs → dependabot-rtPO9HdD.mjs} +21 -14
- package/dist/dependabot-rtPO9HdD.mjs.map +1 -0
- package/dist/github/index.d.mts +1 -1
- package/dist/github/index.mjs +1 -1
- package/dist/{index-BWftXTYB.d.mts → index-BfwWezjJ.d.mts} +1 -1
- package/dist/{index-vaaBSJ7v.d.mts → index-Byxjhvfz.d.mts} +67 -59
- package/dist/{job-DQiSYFHb.mjs → job-BxOZ-hqF.mjs} +2 -2
- package/dist/job-BxOZ-hqF.mjs.map +1 -0
- package/dist/{logger-BqvUa-Ue.mjs → logger-5PEqZVLr.mjs} +10 -3
- package/dist/{logger-BqvUa-Ue.mjs.map → logger-5PEqZVLr.mjs.map} +1 -1
- package/dist/logger.mjs +1 -1
- package/dist/usage.d.mts +1 -1
- package/dist/usage.mjs +1 -1
- package/package.json +6 -9
- package/dist/dependabot-_TVZhG0L.mjs.map +0 -1
- package/dist/http/index.d.mts +0 -121
- package/dist/http/index.mjs +0 -3
- package/dist/http-D2wwAKQ-.mjs +0 -241
- package/dist/http-D2wwAKQ-.mjs.map +0 -1
- package/dist/job-DQiSYFHb.mjs.map +0 -1
package/dist/azure/index.mjs
CHANGED
|
@@ -1,78 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import "
|
|
1
|
+
import { n as logger } from "../logger-5PEqZVLr.mjs";
|
|
2
|
+
import { F as parseDependabotConfig, M as POSSIBLE_CONFIG_FILE_PATHS, c as DependabotExistingGroupPRSchema, l as DependabotExistingPRSchema } from "../job-BxOZ-hqF.mjs";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import ky, { isHTTPError } from "ky";
|
|
5
5
|
import * as path from "node:path";
|
|
6
6
|
import { existsSync } from "node:fs";
|
|
7
7
|
import { readFile } from "node:fs/promises";
|
|
8
8
|
|
|
9
|
-
//#region src/azure/types.ts
|
|
10
|
-
let VersionControlChangeType = /* @__PURE__ */ function(VersionControlChangeType$1) {
|
|
11
|
-
VersionControlChangeType$1[VersionControlChangeType$1["None"] = 0] = "None";
|
|
12
|
-
VersionControlChangeType$1[VersionControlChangeType$1["Add"] = 1] = "Add";
|
|
13
|
-
VersionControlChangeType$1[VersionControlChangeType$1["Edit"] = 2] = "Edit";
|
|
14
|
-
VersionControlChangeType$1[VersionControlChangeType$1["Encoding"] = 4] = "Encoding";
|
|
15
|
-
VersionControlChangeType$1[VersionControlChangeType$1["Rename"] = 8] = "Rename";
|
|
16
|
-
VersionControlChangeType$1[VersionControlChangeType$1["Delete"] = 16] = "Delete";
|
|
17
|
-
VersionControlChangeType$1[VersionControlChangeType$1["Undelete"] = 32] = "Undelete";
|
|
18
|
-
VersionControlChangeType$1[VersionControlChangeType$1["Branch"] = 64] = "Branch";
|
|
19
|
-
VersionControlChangeType$1[VersionControlChangeType$1["Merge"] = 128] = "Merge";
|
|
20
|
-
VersionControlChangeType$1[VersionControlChangeType$1["Lock"] = 256] = "Lock";
|
|
21
|
-
VersionControlChangeType$1[VersionControlChangeType$1["Rollback"] = 512] = "Rollback";
|
|
22
|
-
VersionControlChangeType$1[VersionControlChangeType$1["SourceRename"] = 1024] = "SourceRename";
|
|
23
|
-
VersionControlChangeType$1[VersionControlChangeType$1["TargetRename"] = 2048] = "TargetRename";
|
|
24
|
-
VersionControlChangeType$1[VersionControlChangeType$1["Property"] = 4096] = "Property";
|
|
25
|
-
VersionControlChangeType$1[VersionControlChangeType$1["All"] = 8191] = "All";
|
|
26
|
-
return VersionControlChangeType$1;
|
|
27
|
-
}({});
|
|
28
|
-
let GitPullRequestMergeStrategy = /* @__PURE__ */ function(GitPullRequestMergeStrategy$1) {
|
|
29
|
-
GitPullRequestMergeStrategy$1[GitPullRequestMergeStrategy$1["NoFastForward"] = 1] = "NoFastForward";
|
|
30
|
-
GitPullRequestMergeStrategy$1[GitPullRequestMergeStrategy$1["Squash"] = 2] = "Squash";
|
|
31
|
-
GitPullRequestMergeStrategy$1[GitPullRequestMergeStrategy$1["Rebase"] = 3] = "Rebase";
|
|
32
|
-
GitPullRequestMergeStrategy$1[GitPullRequestMergeStrategy$1["RebaseMerge"] = 4] = "RebaseMerge";
|
|
33
|
-
return GitPullRequestMergeStrategy$1;
|
|
34
|
-
}({});
|
|
35
|
-
let CommentThreadStatus = /* @__PURE__ */ function(CommentThreadStatus$1) {
|
|
36
|
-
CommentThreadStatus$1[CommentThreadStatus$1["Unknown"] = 0] = "Unknown";
|
|
37
|
-
CommentThreadStatus$1[CommentThreadStatus$1["Active"] = 1] = "Active";
|
|
38
|
-
CommentThreadStatus$1[CommentThreadStatus$1["Fixed"] = 2] = "Fixed";
|
|
39
|
-
CommentThreadStatus$1[CommentThreadStatus$1["WontFix"] = 3] = "WontFix";
|
|
40
|
-
CommentThreadStatus$1[CommentThreadStatus$1["Closed"] = 4] = "Closed";
|
|
41
|
-
CommentThreadStatus$1[CommentThreadStatus$1["ByDesign"] = 5] = "ByDesign";
|
|
42
|
-
CommentThreadStatus$1[CommentThreadStatus$1["Pending"] = 6] = "Pending";
|
|
43
|
-
return CommentThreadStatus$1;
|
|
44
|
-
}({});
|
|
45
|
-
let CommentType = /* @__PURE__ */ function(CommentType$1) {
|
|
46
|
-
CommentType$1[CommentType$1["Unknown"] = 0] = "Unknown";
|
|
47
|
-
CommentType$1[CommentType$1["Text"] = 1] = "Text";
|
|
48
|
-
CommentType$1[CommentType$1["CodeChange"] = 2] = "CodeChange";
|
|
49
|
-
CommentType$1[CommentType$1["System"] = 3] = "System";
|
|
50
|
-
return CommentType$1;
|
|
51
|
-
}({});
|
|
52
|
-
let ItemContentType = /* @__PURE__ */ function(ItemContentType$1) {
|
|
53
|
-
ItemContentType$1[ItemContentType$1["RawText"] = 0] = "RawText";
|
|
54
|
-
ItemContentType$1[ItemContentType$1["Base64Encoded"] = 1] = "Base64Encoded";
|
|
55
|
-
return ItemContentType$1;
|
|
56
|
-
}({});
|
|
57
|
-
let PullRequestAsyncStatus = /* @__PURE__ */ function(PullRequestAsyncStatus$1) {
|
|
58
|
-
PullRequestAsyncStatus$1[PullRequestAsyncStatus$1["NotSet"] = 0] = "NotSet";
|
|
59
|
-
PullRequestAsyncStatus$1[PullRequestAsyncStatus$1["Queued"] = 1] = "Queued";
|
|
60
|
-
PullRequestAsyncStatus$1[PullRequestAsyncStatus$1["Conflicts"] = 2] = "Conflicts";
|
|
61
|
-
PullRequestAsyncStatus$1[PullRequestAsyncStatus$1["Succeeded"] = 3] = "Succeeded";
|
|
62
|
-
PullRequestAsyncStatus$1[PullRequestAsyncStatus$1["RejectedByPolicy"] = 4] = "RejectedByPolicy";
|
|
63
|
-
PullRequestAsyncStatus$1[PullRequestAsyncStatus$1["Failure"] = 5] = "Failure";
|
|
64
|
-
return PullRequestAsyncStatus$1;
|
|
65
|
-
}({});
|
|
66
|
-
let PullRequestStatus = /* @__PURE__ */ function(PullRequestStatus$1) {
|
|
67
|
-
PullRequestStatus$1[PullRequestStatus$1["NotSet"] = 0] = "NotSet";
|
|
68
|
-
PullRequestStatus$1[PullRequestStatus$1["Active"] = 1] = "Active";
|
|
69
|
-
PullRequestStatus$1[PullRequestStatus$1["Abandoned"] = 2] = "Abandoned";
|
|
70
|
-
PullRequestStatus$1[PullRequestStatus$1["Completed"] = 3] = "Completed";
|
|
71
|
-
PullRequestStatus$1[PullRequestStatus$1["All"] = 4] = "All";
|
|
72
|
-
return PullRequestStatus$1;
|
|
73
|
-
}({});
|
|
74
|
-
|
|
75
|
-
//#endregion
|
|
76
9
|
//#region src/azure/models.ts
|
|
77
10
|
/**
|
|
78
11
|
* Pull request property names used to store metadata about the pull request.
|
|
@@ -121,10 +54,10 @@ function areEqual(a, b) {
|
|
|
121
54
|
}
|
|
122
55
|
function getPullRequestChangedFilesForOutputData(data) {
|
|
123
56
|
return data["updated-dependency-files"].filter((file) => file.type === "file").map((file) => {
|
|
124
|
-
let changeType =
|
|
125
|
-
if (file.deleted === true || file.operation === "delete") changeType =
|
|
126
|
-
else if (file.operation === "update") changeType =
|
|
127
|
-
else changeType =
|
|
57
|
+
let changeType = "none";
|
|
58
|
+
if (file.deleted === true || file.operation === "delete") changeType = "delete";
|
|
59
|
+
else if (file.operation === "update") changeType = "edit";
|
|
60
|
+
else changeType = "add";
|
|
128
61
|
return {
|
|
129
62
|
changeType,
|
|
130
63
|
path: path.join(file.directory, file.name),
|
|
@@ -195,17 +128,18 @@ var AzureDevOpsWebApiClient = class AzureDevOpsWebApiClient {
|
|
|
195
128
|
identityApiUrl;
|
|
196
129
|
accessToken;
|
|
197
130
|
debug;
|
|
131
|
+
client;
|
|
198
132
|
authenticatedUserId;
|
|
199
133
|
resolvedUserIds;
|
|
200
134
|
static API_VERSION = "5.0";
|
|
201
135
|
static API_VERSION_PREVIEW = "5.0-preview";
|
|
202
136
|
constructor(url, accessToken, debug = false) {
|
|
203
|
-
|
|
204
|
-
this.
|
|
205
|
-
this.identityApiUrl = getIdentityApiUrl(organisationApiUrl).replace(/\/$/, "");
|
|
137
|
+
this.organisationApiUrl = url.value.toString().replace(/\/$/, "");
|
|
138
|
+
this.identityApiUrl = url["identity-api-url"].toString().replace(/\/$/, "");
|
|
206
139
|
this.accessToken = accessToken;
|
|
207
140
|
this.debug = debug;
|
|
208
141
|
this.resolvedUserIds = {};
|
|
142
|
+
this.client = this.createClient();
|
|
209
143
|
}
|
|
210
144
|
/**
|
|
211
145
|
* Get the identity of the authenticated user.
|
|
@@ -213,7 +147,7 @@ var AzureDevOpsWebApiClient = class AzureDevOpsWebApiClient {
|
|
|
213
147
|
*/
|
|
214
148
|
async getUserId() {
|
|
215
149
|
if (!this.authenticatedUserId) {
|
|
216
|
-
this.authenticatedUserId = (await this.
|
|
150
|
+
this.authenticatedUserId = (await this.client.get(this.makeUrl(`${this.organisationApiUrl}/_apis/connectiondata`, AzureDevOpsWebApiClient.API_VERSION_PREVIEW)).json())?.authenticatedUser?.id;
|
|
217
151
|
if (!this.authenticatedUserId) throw new Error("Failed to get authenticated user ID");
|
|
218
152
|
}
|
|
219
153
|
return this.authenticatedUserId;
|
|
@@ -227,13 +161,13 @@ var AzureDevOpsWebApiClient = class AzureDevOpsWebApiClient {
|
|
|
227
161
|
async resolveIdentityId(userNameEmailOrGroupName) {
|
|
228
162
|
if (this.resolvedUserIds[userNameEmailOrGroupName]) return this.resolvedUserIds[userNameEmailOrGroupName];
|
|
229
163
|
try {
|
|
230
|
-
const identities = await this.
|
|
164
|
+
const identities = await this.client.get(this.makeUrl(`${this.identityApiUrl}/_apis/identities`, {
|
|
231
165
|
searchFilter: "General",
|
|
232
166
|
filterValue: userNameEmailOrGroupName,
|
|
233
167
|
queryMembership: "None"
|
|
234
|
-
});
|
|
168
|
+
})).json();
|
|
235
169
|
if (!identities?.value || identities.value.length === 0) return;
|
|
236
|
-
this.resolvedUserIds[userNameEmailOrGroupName] = identities.value[0]
|
|
170
|
+
this.resolvedUserIds[userNameEmailOrGroupName] = identities.value[0].id;
|
|
237
171
|
return this.resolvedUserIds[userNameEmailOrGroupName];
|
|
238
172
|
} catch (e) {
|
|
239
173
|
logger.error(`Failed to resolve user id: ${e}`);
|
|
@@ -243,7 +177,7 @@ var AzureDevOpsWebApiClient = class AzureDevOpsWebApiClient {
|
|
|
243
177
|
}
|
|
244
178
|
async getProjects() {
|
|
245
179
|
try {
|
|
246
|
-
return await this.
|
|
180
|
+
return await this.client.get(this.makeUrl(`${this.organisationApiUrl}/_apis/projects`)).json();
|
|
247
181
|
} catch (e) {
|
|
248
182
|
logger.error(`Failed to get projects: ${e}`);
|
|
249
183
|
logger.debug(e);
|
|
@@ -252,7 +186,7 @@ var AzureDevOpsWebApiClient = class AzureDevOpsWebApiClient {
|
|
|
252
186
|
}
|
|
253
187
|
async getProject(idOrName) {
|
|
254
188
|
try {
|
|
255
|
-
return await this.
|
|
189
|
+
return await this.client.get(this.makeUrl(`${this.organisationApiUrl}/_apis/projects/${encodeURIComponent(idOrName)}`)).json();
|
|
256
190
|
} catch (e) {
|
|
257
191
|
logger.error(`Failed to get project: ${e}`);
|
|
258
192
|
logger.debug(e);
|
|
@@ -261,7 +195,7 @@ var AzureDevOpsWebApiClient = class AzureDevOpsWebApiClient {
|
|
|
261
195
|
}
|
|
262
196
|
async getRepositories(projectIdOrName) {
|
|
263
197
|
try {
|
|
264
|
-
return await this.
|
|
198
|
+
return await this.client.get(this.makeUrl(`${this.organisationApiUrl}/${encodeURIComponent(projectIdOrName)}/_apis/git/repositories`)).json();
|
|
265
199
|
} catch (e) {
|
|
266
200
|
logger.error(`Failed to get repositories: ${e}`);
|
|
267
201
|
logger.debug(e);
|
|
@@ -270,9 +204,9 @@ var AzureDevOpsWebApiClient = class AzureDevOpsWebApiClient {
|
|
|
270
204
|
}
|
|
271
205
|
async getRepository(projectIdOrName, repositoryIdOrName) {
|
|
272
206
|
try {
|
|
273
|
-
return await this.
|
|
207
|
+
return await this.client.get(this.makeUrl(`${this.organisationApiUrl}/${encodeURIComponent(projectIdOrName)}/_apis/git/repositories/${encodeURIComponent(repositoryIdOrName)}`)).json();
|
|
274
208
|
} catch (e) {
|
|
275
|
-
if (e
|
|
209
|
+
if (isHTTPError(e) && e.response.status === 404) return;
|
|
276
210
|
else {
|
|
277
211
|
logger.error(`Failed to get repository: ${e}`);
|
|
278
212
|
logger.debug(e);
|
|
@@ -282,13 +216,13 @@ var AzureDevOpsWebApiClient = class AzureDevOpsWebApiClient {
|
|
|
282
216
|
}
|
|
283
217
|
async getRepositoryItem(projectIdOrName, repositoryIdOrName, path$1, includeContent = true, latestProcessedChange = true) {
|
|
284
218
|
try {
|
|
285
|
-
return await this.
|
|
219
|
+
return await this.client.get(this.makeUrl(`${this.organisationApiUrl}/${encodeURIComponent(projectIdOrName)}/_apis/git/repositories/${encodeURIComponent(repositoryIdOrName)}/items`, {
|
|
286
220
|
path: path$1,
|
|
287
221
|
includeContent,
|
|
288
222
|
latestProcessedChange
|
|
289
|
-
});
|
|
223
|
+
})).json();
|
|
290
224
|
} catch (e) {
|
|
291
|
-
if (e
|
|
225
|
+
if (isHTTPError(e) && e.response.status === 404) return;
|
|
292
226
|
else {
|
|
293
227
|
logger.error(`Failed to get repository item: ${e}`);
|
|
294
228
|
logger.debug(e);
|
|
@@ -305,7 +239,7 @@ var AzureDevOpsWebApiClient = class AzureDevOpsWebApiClient {
|
|
|
305
239
|
*/
|
|
306
240
|
async getDefaultBranch(project, repository) {
|
|
307
241
|
try {
|
|
308
|
-
const repo = await this.
|
|
242
|
+
const repo = await this.client.get(this.makeUrl(`${this.organisationApiUrl}/${project}/_apis/git/repositories/${repository}`)).json();
|
|
309
243
|
if (!repo) throw new Error(`Repository '${project}/${repository}' not found`);
|
|
310
244
|
return normalizeBranchName(repo.defaultBranch);
|
|
311
245
|
} catch (e) {
|
|
@@ -323,7 +257,7 @@ var AzureDevOpsWebApiClient = class AzureDevOpsWebApiClient {
|
|
|
323
257
|
*/
|
|
324
258
|
async getBranchNames(project, repository) {
|
|
325
259
|
try {
|
|
326
|
-
const refs = await this.
|
|
260
|
+
const refs = await this.client.get(this.makeUrl(`${this.organisationApiUrl}/${project}/_apis/git/repositories/${repository}/refs`)).json();
|
|
327
261
|
if (!refs) throw new Error(`Repository '${project}/${repository}' not found`);
|
|
328
262
|
return refs.value?.map((r) => normalizeBranchName(r.name)) || [];
|
|
329
263
|
} catch (e) {
|
|
@@ -342,21 +276,19 @@ var AzureDevOpsWebApiClient = class AzureDevOpsWebApiClient {
|
|
|
342
276
|
*/
|
|
343
277
|
async getActivePullRequestProperties(project, repository, creator) {
|
|
344
278
|
try {
|
|
345
|
-
const pullRequests = await this.
|
|
279
|
+
const pullRequests = await this.client.get(this.makeUrl(`${this.organisationApiUrl}/${project}/_apis/git/repositories/${repository}/pullrequests`, {
|
|
346
280
|
"searchCriteria.creatorId": isGuid(creator) ? creator : await this.getUserId(),
|
|
347
281
|
"searchCriteria.status": "Active"
|
|
348
|
-
});
|
|
282
|
+
})).json();
|
|
349
283
|
if (!pullRequests?.value || pullRequests.value.length === 0) return [];
|
|
350
284
|
return await Promise.all(pullRequests.value.map(async (pr) => {
|
|
351
|
-
const properties = await this.
|
|
285
|
+
const properties = await this.client.get(this.makeUrl(`${this.organisationApiUrl}/${project}/_apis/git/repositories/${repository}/pullrequests/${pr.pullRequestId}/properties`)).json();
|
|
352
286
|
return {
|
|
353
287
|
id: pr.pullRequestId,
|
|
354
|
-
properties: Object.
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
};
|
|
359
|
-
}) || []
|
|
288
|
+
properties: Object.entries(properties?.value || {}).map(([key, val]) => ({
|
|
289
|
+
name: key,
|
|
290
|
+
value: val?.$value
|
|
291
|
+
}))
|
|
360
292
|
};
|
|
361
293
|
}));
|
|
362
294
|
} catch (e) {
|
|
@@ -383,7 +315,7 @@ var AzureDevOpsWebApiClient = class AzureDevOpsWebApiClient {
|
|
|
383
315
|
else logger.warn(`Unable to resolve assignee identity '${assignee}'`);
|
|
384
316
|
}
|
|
385
317
|
logger.info(` - Pushing ${pr.changes.length} file change(s) to branch '${pr.source.branch}'...`);
|
|
386
|
-
const push = await this.
|
|
318
|
+
const push = await this.client.post(this.makeUrl(`${this.organisationApiUrl}/${pr.project}/_apis/git/repositories/${pr.repository}/pushes`), { json: {
|
|
387
319
|
refUpdates: [{
|
|
388
320
|
name: `refs/heads/${pr.source.branch}`,
|
|
389
321
|
oldObjectId: pr.source.commit
|
|
@@ -391,22 +323,22 @@ var AzureDevOpsWebApiClient = class AzureDevOpsWebApiClient {
|
|
|
391
323
|
commits: [{
|
|
392
324
|
comment: pr.commitMessage,
|
|
393
325
|
author: pr.author,
|
|
394
|
-
changes: pr.changes.filter((change) => change.changeType !==
|
|
326
|
+
changes: pr.changes.filter((change) => change.changeType !== "none").map(({ changeType, ...change }) => {
|
|
395
327
|
return {
|
|
396
328
|
changeType,
|
|
397
329
|
item: { path: normalizeFilePath(change.path) },
|
|
398
|
-
newContent: changeType !==
|
|
330
|
+
newContent: changeType !== "delete" ? {
|
|
399
331
|
content: Buffer.from(change.content, change.encoding).toString("base64"),
|
|
400
|
-
contentType:
|
|
332
|
+
contentType: "base64encoded"
|
|
401
333
|
} : void 0
|
|
402
334
|
};
|
|
403
335
|
})
|
|
404
336
|
}]
|
|
405
|
-
});
|
|
337
|
+
} }).json();
|
|
406
338
|
if (!push?.commits?.length) throw new Error("Failed to push changes to source branch, no commits were created");
|
|
407
339
|
logger.info(` - Pushed commit: ${push.commits.map((c) => c.commitId).join(", ")}.`);
|
|
408
340
|
logger.info(` - Creating pull request to merge '${pr.source.branch}' into '${pr.target.branch}'...`);
|
|
409
|
-
const pullRequest = await this.
|
|
341
|
+
const pullRequest = await this.client.post(this.makeUrl(`${this.organisationApiUrl}/${pr.project}/_apis/git/repositories/${pr.repository}/pullrequests`), { json: {
|
|
410
342
|
sourceRefName: `refs/heads/${pr.source.branch}`,
|
|
411
343
|
targetRefName: `refs/heads/${pr.target.branch}`,
|
|
412
344
|
title: pr.title,
|
|
@@ -414,22 +346,25 @@ var AzureDevOpsWebApiClient = class AzureDevOpsWebApiClient {
|
|
|
414
346
|
reviewers,
|
|
415
347
|
workItemRefs: pr.workItems?.map((id) => ({ id })),
|
|
416
348
|
labels: pr.labels?.map((label) => ({ name: label }))
|
|
417
|
-
});
|
|
349
|
+
} }).json();
|
|
418
350
|
if (!pullRequest?.pullRequestId) throw new Error("Failed to create pull request, no pull request id was returned");
|
|
419
351
|
logger.info(` - Created pull request: #${pullRequest.pullRequestId}.`);
|
|
420
352
|
if (pr.properties && pr.properties.length > 0) {
|
|
421
353
|
logger.info(` - Adding dependency metadata to pull request properties...`);
|
|
422
|
-
if (!(await this.
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
354
|
+
if (!(await this.client.patch(this.makeUrl(`${this.organisationApiUrl}/${pr.project}/_apis/git/repositories/${pr.repository}/pullrequests/${pullRequest.pullRequestId}/properties`), {
|
|
355
|
+
json: pr.properties.map((property) => {
|
|
356
|
+
return {
|
|
357
|
+
op: "add",
|
|
358
|
+
path: `/${property.name}`,
|
|
359
|
+
value: property.value
|
|
360
|
+
};
|
|
361
|
+
}),
|
|
362
|
+
headers: { "Content-Type": "application/json-patch+json" }
|
|
363
|
+
}).json())?.count) throw new Error("Failed to add dependency metadata properties to pull request");
|
|
429
364
|
}
|
|
430
365
|
if (pr.autoComplete) {
|
|
431
366
|
logger.info(` - Updating auto-complete options...`);
|
|
432
|
-
const updatedPullRequest = await this.
|
|
367
|
+
const updatedPullRequest = await this.client.patch(this.makeUrl(`${this.organisationApiUrl}/${pr.project}/_apis/git/repositories/${pr.repository}/pullrequests/${pullRequest.pullRequestId}`), { json: {
|
|
433
368
|
autoCompleteSetBy: { id: userId },
|
|
434
369
|
completionOptions: {
|
|
435
370
|
autoCompleteIgnoreConfigIds: pr.autoComplete.ignorePolicyConfigIds,
|
|
@@ -438,7 +373,7 @@ var AzureDevOpsWebApiClient = class AzureDevOpsWebApiClient {
|
|
|
438
373
|
mergeStrategy: pr.autoComplete.mergeStrategy,
|
|
439
374
|
transitionWorkItems: false
|
|
440
375
|
}
|
|
441
|
-
});
|
|
376
|
+
} }).json();
|
|
442
377
|
if (!updatedPullRequest || updatedPullRequest.autoCompleteSetBy?.id !== userId) throw new Error("Failed to set auto-complete on pull request");
|
|
443
378
|
}
|
|
444
379
|
logger.info(` - Pull request was created successfully.`);
|
|
@@ -458,19 +393,19 @@ var AzureDevOpsWebApiClient = class AzureDevOpsWebApiClient {
|
|
|
458
393
|
async updatePullRequest(pr) {
|
|
459
394
|
logger.info(`Updating pull request #${pr.pullRequestId}...`);
|
|
460
395
|
try {
|
|
461
|
-
const pullRequest = await this.
|
|
396
|
+
const pullRequest = await this.client.get(this.makeUrl(`${this.organisationApiUrl}/${pr.project}/_apis/git/repositories/${pr.repository}/pullrequests/${pr.pullRequestId}`)).json();
|
|
462
397
|
if (!pullRequest) throw new Error(`Pull request #${pr.pullRequestId} not found`);
|
|
463
398
|
if (pr.skipIfDraft && pullRequest.isDraft) {
|
|
464
399
|
logger.info(` - Skipping update as pull request is currently marked as a draft.`);
|
|
465
400
|
return true;
|
|
466
401
|
}
|
|
467
402
|
if (pr.skipIfCommitsFromAuthorsOtherThan) {
|
|
468
|
-
if ((await this.
|
|
403
|
+
if ((await this.client.get(this.makeUrl(`${this.organisationApiUrl}/${pr.project}/_apis/git/repositories/${pr.repository}/pullrequests/${pr.pullRequestId}/commits`)).json())?.value?.some((c) => c.author?.email !== pr.skipIfCommitsFromAuthorsOtherThan)) {
|
|
469
404
|
logger.info(` - Skipping update as pull request has been modified by another user.`);
|
|
470
405
|
return true;
|
|
471
406
|
}
|
|
472
407
|
}
|
|
473
|
-
const stats = await this.
|
|
408
|
+
const stats = await this.client.get(this.makeUrl(`${this.organisationApiUrl}/${pr.project}/_apis/git/repositories/${pr.repository}/stats/branches`, { name: normalizeBranchName(pullRequest.sourceRefName) })).json();
|
|
474
409
|
if (stats?.behindCount === void 0) throw new Error(`Failed to get branch stats for '${pullRequest.sourceRefName}'`);
|
|
475
410
|
if (pr.skipIfNotBehindTargetBranch && stats.behindCount === 0) {
|
|
476
411
|
logger.info(` - Skipping update as source branch is not behind target branch.`);
|
|
@@ -480,33 +415,33 @@ var AzureDevOpsWebApiClient = class AzureDevOpsWebApiClient {
|
|
|
480
415
|
const targetBranchName = normalizeBranchName(pullRequest.targetRefName);
|
|
481
416
|
if (stats.behindCount > 0) {
|
|
482
417
|
logger.info(` - Rebasing '${targetBranchName}' into '${sourceBranchName}' (${stats.behindCount} commit(s) behind)...`);
|
|
483
|
-
if ((await this.
|
|
418
|
+
if ((await this.client.post(this.makeUrl(`${this.organisationApiUrl}/${pr.project}/_apis/git/repositories/${pr.repository}/refs`), { json: [{
|
|
484
419
|
name: pullRequest.sourceRefName,
|
|
485
420
|
oldObjectId: pullRequest.lastMergeSourceCommit.commitId,
|
|
486
421
|
newObjectId: pr.commit
|
|
487
|
-
}]))?.value?.[0]?.success !== true) throw new Error("Failed to rebase the target branch into the source branch");
|
|
422
|
+
}] }).json())?.value?.[0]?.success !== true) throw new Error("Failed to rebase the target branch into the source branch");
|
|
488
423
|
}
|
|
489
424
|
logger.info(` - Pushing ${pr.changes.length} file change(s) to branch '${pullRequest.sourceRefName}'...`);
|
|
490
|
-
const push = await this.
|
|
425
|
+
const push = await this.client.post(this.makeUrl(`${this.organisationApiUrl}/${pr.project}/_apis/git/repositories/${pr.repository}/pushes`), { json: {
|
|
491
426
|
refUpdates: [{
|
|
492
427
|
name: pullRequest.sourceRefName,
|
|
493
428
|
oldObjectId: pr.commit
|
|
494
429
|
}],
|
|
495
430
|
commits: [{
|
|
496
|
-
comment: pullRequest.mergeStatus ===
|
|
431
|
+
comment: pullRequest.mergeStatus === "conflicts" ? "Resolve merge conflicts" : `Rebase '${sourceBranchName}' onto '${targetBranchName}'`,
|
|
497
432
|
author: pr.author,
|
|
498
|
-
changes: pr.changes.filter((change) => change.changeType !==
|
|
433
|
+
changes: pr.changes.filter((change) => change.changeType !== "none").map(({ changeType, ...change }) => {
|
|
499
434
|
return {
|
|
500
435
|
changeType,
|
|
501
436
|
item: { path: normalizeFilePath(change.path) },
|
|
502
|
-
newContent: changeType !==
|
|
437
|
+
newContent: changeType !== "delete" ? {
|
|
503
438
|
content: Buffer.from(change.content, change.encoding).toString("base64"),
|
|
504
|
-
contentType:
|
|
439
|
+
contentType: "base64encoded"
|
|
505
440
|
} : void 0
|
|
506
441
|
};
|
|
507
442
|
})
|
|
508
443
|
}]
|
|
509
|
-
});
|
|
444
|
+
} }).json();
|
|
510
445
|
if (!push?.commits?.length) throw new Error("Failed to push changes to source branch, no commits were created");
|
|
511
446
|
logger.info(` - Pushed commit: ${push.commits.map((c) => c.commitId).join(", ")}.`);
|
|
512
447
|
logger.info(` - Pull request was updated successfully.`);
|
|
@@ -528,10 +463,10 @@ var AzureDevOpsWebApiClient = class AzureDevOpsWebApiClient {
|
|
|
528
463
|
try {
|
|
529
464
|
logger.info(` - Updating reviewer vote on pull request...`);
|
|
530
465
|
const userId = await this.getUserId();
|
|
531
|
-
if ((await this.
|
|
466
|
+
if ((await this.client.put(this.makeUrl(`${this.organisationApiUrl}/${pr.project}/_apis/git/repositories/${pr.repository}/pullrequests/${pr.pullRequestId}/reviewers/${userId}`, "7.1"), { json: {
|
|
532
467
|
vote: 10,
|
|
533
468
|
isReapprove: true
|
|
534
|
-
}
|
|
469
|
+
} }).json())?.vote !== 10) throw new Error("Failed to approve pull request, vote was not recorded");
|
|
535
470
|
logger.info(` - Pull request was approved successfully.`);
|
|
536
471
|
return true;
|
|
537
472
|
} catch (e) {
|
|
@@ -559,19 +494,19 @@ var AzureDevOpsWebApiClient = class AzureDevOpsWebApiClient {
|
|
|
559
494
|
})) throw new Error("Failed to add comment to pull request, thread was not created");
|
|
560
495
|
}
|
|
561
496
|
logger.info(` - Abandoning pull request...`);
|
|
562
|
-
const abandonedPullRequest = await this.
|
|
563
|
-
status:
|
|
497
|
+
const abandonedPullRequest = await this.client.patch(this.makeUrl(`${this.organisationApiUrl}/${pr.project}/_apis/git/repositories/${pr.repository}/pullrequests/${pr.pullRequestId}`), { json: {
|
|
498
|
+
status: "abandoned",
|
|
564
499
|
closedBy: { id: userId }
|
|
565
|
-
});
|
|
566
|
-
if (abandonedPullRequest?.status
|
|
500
|
+
} }).json();
|
|
501
|
+
if (abandonedPullRequest?.status !== "abandoned") throw new Error("Failed to abandon pull request, status was not updated");
|
|
567
502
|
if (pr.deleteSourceBranch) {
|
|
568
503
|
logger.info(` - Deleting source branch...`);
|
|
569
|
-
if ((await this.
|
|
504
|
+
if ((await this.client.post(this.makeUrl(`${this.organisationApiUrl}/${pr.project}/_apis/git/repositories/${pr.repository}/refs`), { json: [{
|
|
570
505
|
name: abandonedPullRequest.sourceRefName,
|
|
571
506
|
oldObjectId: abandonedPullRequest.lastMergeSourceCommit.commitId,
|
|
572
507
|
newObjectId: "0000000000000000000000000000000000000000",
|
|
573
508
|
isLocked: false
|
|
574
|
-
}]))?.value?.[0]?.success !== true) throw new Error("Failed to delete the source branch");
|
|
509
|
+
}] }).json())?.value?.[0]?.success !== true) throw new Error("Failed to delete the source branch");
|
|
575
510
|
}
|
|
576
511
|
logger.info(` - Pull request was abandoned successfully.`);
|
|
577
512
|
return true;
|
|
@@ -587,67 +522,50 @@ var AzureDevOpsWebApiClient = class AzureDevOpsWebApiClient {
|
|
|
587
522
|
*/
|
|
588
523
|
async addCommentThread(comment) {
|
|
589
524
|
const userId = comment.userId ?? await this.getUserId();
|
|
590
|
-
return (await this.
|
|
591
|
-
status:
|
|
525
|
+
return (await this.client.post(this.makeUrl(`${this.organisationApiUrl}/${comment.project}/_apis/git/repositories/${comment.repository}/pullrequests/${comment.pullRequestId}/threads`), { json: {
|
|
526
|
+
status: "closed",
|
|
592
527
|
comments: [{
|
|
593
528
|
author: { id: userId },
|
|
594
529
|
content: comment.content,
|
|
595
|
-
commentType:
|
|
530
|
+
commentType: "system"
|
|
596
531
|
}]
|
|
597
|
-
}))?.id;
|
|
598
|
-
}
|
|
599
|
-
async restApiGet(url, params, apiVersion = AzureDevOpsWebApiClient.API_VERSION) {
|
|
600
|
-
params ??= {};
|
|
601
|
-
const queryString = Object.keys(params).map((key) => `${key}=${params[key]}`).join("&");
|
|
602
|
-
const fullUrl = `${url}?api-version=${apiVersion}${queryString ? `&${queryString}` : ""}`;
|
|
603
|
-
return await sendRestApiRequestWithRetry("GET", fullUrl, void 0, async () => {
|
|
604
|
-
return await fetch(fullUrl, {
|
|
605
|
-
method: "GET",
|
|
606
|
-
headers: {
|
|
607
|
-
Accept: "application/json",
|
|
608
|
-
Authorization: `Basic ${Buffer.from(`:${this.accessToken}`).toString("base64")}`
|
|
609
|
-
}
|
|
610
|
-
});
|
|
611
|
-
}, this.debug);
|
|
612
|
-
}
|
|
613
|
-
async restApiPost(url, data, apiVersion = AzureDevOpsWebApiClient.API_VERSION) {
|
|
614
|
-
const fullUrl = `${url}?api-version=${apiVersion}`;
|
|
615
|
-
return await sendRestApiRequestWithRetry("POST", fullUrl, data, async () => {
|
|
616
|
-
return await fetch(fullUrl, {
|
|
617
|
-
method: "POST",
|
|
618
|
-
headers: {
|
|
619
|
-
"Content-Type": "application/json",
|
|
620
|
-
Authorization: `Basic ${Buffer.from(`:${this.accessToken}`).toString("base64")}`
|
|
621
|
-
},
|
|
622
|
-
body: JSON.stringify(data)
|
|
623
|
-
});
|
|
624
|
-
}, this.debug);
|
|
532
|
+
} }).json())?.id;
|
|
625
533
|
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
body: JSON.stringify(data)
|
|
636
|
-
});
|
|
637
|
-
}, this.debug);
|
|
534
|
+
makeUrl(url, params, apiVersion = AzureDevOpsWebApiClient.API_VERSION) {
|
|
535
|
+
if (typeof params === "string") {
|
|
536
|
+
apiVersion = params;
|
|
537
|
+
params = {};
|
|
538
|
+
}
|
|
539
|
+
return `${url}?${Object.entries({
|
|
540
|
+
"api-version": apiVersion,
|
|
541
|
+
...params
|
|
542
|
+
}).map(([key, value]) => `${key}=${value}`).join("&")}`;
|
|
638
543
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
544
|
+
createClient() {
|
|
545
|
+
return ky.create({
|
|
546
|
+
headers: {
|
|
547
|
+
Authorization: `Basic ${Buffer.from(`:${this.accessToken}`).toString("base64")}`,
|
|
548
|
+
Accept: "application/json"
|
|
549
|
+
},
|
|
550
|
+
hooks: {
|
|
551
|
+
beforeRequest: [async (request, options) => {
|
|
552
|
+
if (this.debug) logger.debug(`🌎 🠊 [${request.method}] ${request.url}`);
|
|
553
|
+
}],
|
|
554
|
+
afterResponse: [async (request, options, response) => {
|
|
555
|
+
if (this.debug) {
|
|
556
|
+
logger.debug(`🌎 🠈 [${response.status}] ${response.statusText}`);
|
|
557
|
+
if (request.body) logger.debug(`REQUEST: ${JSON.stringify(request.body)}`);
|
|
558
|
+
}
|
|
559
|
+
}],
|
|
560
|
+
beforeRetry: [async ({ request, options, error, retryCount }) => {
|
|
561
|
+
if (this.debug && isHTTPError(error)) logger.debug(`⏳ Retrying failed request with status code: ${error.response.status}`);
|
|
562
|
+
}]
|
|
563
|
+
},
|
|
564
|
+
retry: {
|
|
565
|
+
limit: 3,
|
|
566
|
+
delay: (attempt) => 3e3
|
|
567
|
+
}
|
|
568
|
+
});
|
|
651
569
|
}
|
|
652
570
|
};
|
|
653
571
|
function mergeCommitMessage(id, title, description) {
|
|
@@ -656,38 +574,6 @@ function mergeCommitMessage(id, title, description) {
|
|
|
656
574
|
function isGuid(guid) {
|
|
657
575
|
return /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(guid);
|
|
658
576
|
}
|
|
659
|
-
function getIdentityApiUrl(organisationApiUrl) {
|
|
660
|
-
const uri = new URL(organisationApiUrl);
|
|
661
|
-
const hostname = uri.hostname.toLowerCase();
|
|
662
|
-
if (hostname === "dev.azure.com" || hostname.endsWith(".visualstudio.com")) uri.host = "vssps.dev.azure.com";
|
|
663
|
-
return uri.toString();
|
|
664
|
-
}
|
|
665
|
-
async function sendRestApiRequestWithRetry(method, url, payload, requestAsync, isDebug = false, retryCount = 3, retryDelay = 3e3) {
|
|
666
|
-
let body;
|
|
667
|
-
try {
|
|
668
|
-
if (isDebug) logger.debug(`🌎 🠊 [${method}] ${url}`);
|
|
669
|
-
const response = await requestAsync();
|
|
670
|
-
body = await response.text();
|
|
671
|
-
const { status: statusCode, statusText: statusMessage } = response;
|
|
672
|
-
if (isDebug) logger.debug(`🌎 🠈 [${statusCode}] ${statusMessage}`);
|
|
673
|
-
if (statusCode < 200 || statusCode > 299) throw new HttpRequestError(`HTTP ${method} '${url}' failed: ${statusCode} ${statusMessage}`, statusCode);
|
|
674
|
-
return JSON.parse(body);
|
|
675
|
-
} catch (e) {
|
|
676
|
-
const err = e;
|
|
677
|
-
if (retryCount > 1 && isErrorTemporaryFailure(err)) {
|
|
678
|
-
logger.warn(err.message);
|
|
679
|
-
if (isDebug) logger.debug(`⏳ Retrying request in ${retryDelay}ms...`);
|
|
680
|
-
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
681
|
-
return sendRestApiRequestWithRetry(method, url, payload, requestAsync, isDebug, retryCount - 1, retryDelay);
|
|
682
|
-
}
|
|
683
|
-
if (isDebug) {
|
|
684
|
-
if (payload) logger.debug(`REQUEST: ${JSON.stringify(payload)}`);
|
|
685
|
-
if (body) logger.debug(`RESPONSE: ${body}`);
|
|
686
|
-
}
|
|
687
|
-
logger.trace(`THROW${e}`);
|
|
688
|
-
throw e;
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
577
|
|
|
692
578
|
//#endregion
|
|
693
579
|
//#region src/azure/config.ts
|
|
@@ -710,10 +596,17 @@ async function getDependabotConfig({ url, token, remote, rootDir = process.cwd()
|
|
|
710
596
|
logger.debug(`GET ${requestUrl}`);
|
|
711
597
|
try {
|
|
712
598
|
const authHeader = `Basic ${Buffer.from(`x-access-token:${token}`).toString("base64")}`;
|
|
713
|
-
const response = await
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
599
|
+
const response = await ky.get(requestUrl, {
|
|
600
|
+
headers: {
|
|
601
|
+
Authorization: authHeader,
|
|
602
|
+
Accept: "*/*"
|
|
603
|
+
},
|
|
604
|
+
throwHttpErrors: (status) => ![
|
|
605
|
+
401,
|
|
606
|
+
403,
|
|
607
|
+
404
|
|
608
|
+
].includes(status)
|
|
609
|
+
});
|
|
717
610
|
if (response.ok) {
|
|
718
611
|
logger.debug(`Found configuration file at '${requestUrl}'`);
|
|
719
612
|
configContents = await response.text();
|
|
@@ -747,6 +640,294 @@ async function getDependabotConfig({ url, token, remote, rootDir = process.cwd()
|
|
|
747
640
|
});
|
|
748
641
|
}
|
|
749
642
|
|
|
643
|
+
//#endregion
|
|
644
|
+
//#region src/azure/types.ts
|
|
645
|
+
const AzdoVersionControlChangeTypeSchema = z.enum([
|
|
646
|
+
"none",
|
|
647
|
+
"add",
|
|
648
|
+
"edit",
|
|
649
|
+
"encoding",
|
|
650
|
+
"rename",
|
|
651
|
+
"delete",
|
|
652
|
+
"undelete",
|
|
653
|
+
"branch",
|
|
654
|
+
"merge",
|
|
655
|
+
"lock",
|
|
656
|
+
"rollback",
|
|
657
|
+
"sourceRename",
|
|
658
|
+
"targetRename",
|
|
659
|
+
"property",
|
|
660
|
+
"all"
|
|
661
|
+
]);
|
|
662
|
+
const AZDO_PULL_REQUEST_MERGE_STRATEGIES = [
|
|
663
|
+
"noFastForward",
|
|
664
|
+
"squash",
|
|
665
|
+
"rebase",
|
|
666
|
+
"rebaseMerge"
|
|
667
|
+
];
|
|
668
|
+
const AzdoPullRequestMergeStrategySchema = z.enum(AZDO_PULL_REQUEST_MERGE_STRATEGIES);
|
|
669
|
+
const AzdoCommentThreadStatusSchema = z.enum([
|
|
670
|
+
"unknown",
|
|
671
|
+
"active",
|
|
672
|
+
"fixed",
|
|
673
|
+
"wontFix",
|
|
674
|
+
"closed",
|
|
675
|
+
"byDesign",
|
|
676
|
+
"pending"
|
|
677
|
+
]);
|
|
678
|
+
const AzdoCommentTypeSchema = z.enum([
|
|
679
|
+
"unknown",
|
|
680
|
+
"text",
|
|
681
|
+
"codeChange",
|
|
682
|
+
"system"
|
|
683
|
+
]);
|
|
684
|
+
const AzdoPullRequestAsyncStatusSchema = z.enum([
|
|
685
|
+
"notSet",
|
|
686
|
+
"queued",
|
|
687
|
+
"conflicts",
|
|
688
|
+
"succeeded",
|
|
689
|
+
"rejectedByPolicy",
|
|
690
|
+
"failure"
|
|
691
|
+
]);
|
|
692
|
+
const AzdoPullRequestStatusSchema = z.enum([
|
|
693
|
+
"notSet",
|
|
694
|
+
"active",
|
|
695
|
+
"abandoned",
|
|
696
|
+
"completed",
|
|
697
|
+
"all"
|
|
698
|
+
]);
|
|
699
|
+
const AzdoProjectSchema = z.object({
|
|
700
|
+
id: z.string(),
|
|
701
|
+
name: z.string(),
|
|
702
|
+
description: z.string().optional(),
|
|
703
|
+
url: z.string(),
|
|
704
|
+
state: z.enum([
|
|
705
|
+
"deleting",
|
|
706
|
+
"new",
|
|
707
|
+
"wellFormed",
|
|
708
|
+
"createPending",
|
|
709
|
+
"all",
|
|
710
|
+
"unchanged",
|
|
711
|
+
"deleted"
|
|
712
|
+
]),
|
|
713
|
+
_links: z.object({
|
|
714
|
+
self: z.object({ href: z.string() }),
|
|
715
|
+
collection: z.object({ href: z.string() }),
|
|
716
|
+
web: z.object({ href: z.string() })
|
|
717
|
+
}).optional()
|
|
718
|
+
});
|
|
719
|
+
const AzdoRepositorySchema = z.object({
|
|
720
|
+
id: z.string(),
|
|
721
|
+
name: z.string(),
|
|
722
|
+
defaultBranch: z.string().optional(),
|
|
723
|
+
project: AzdoProjectSchema,
|
|
724
|
+
isDisabled: z.boolean().optional(),
|
|
725
|
+
isFork: z.boolean().optional(),
|
|
726
|
+
url: z.string(),
|
|
727
|
+
remoteUrl: z.string(),
|
|
728
|
+
webUrl: z.string()
|
|
729
|
+
});
|
|
730
|
+
const AzdoIdentitySchema = z.object({
|
|
731
|
+
id: z.string(),
|
|
732
|
+
displayName: z.string(),
|
|
733
|
+
url: z.string()
|
|
734
|
+
});
|
|
735
|
+
const AzdoIdentityRefSchema = z.object({
|
|
736
|
+
id: z.string().optional(),
|
|
737
|
+
displayName: z.string().optional(),
|
|
738
|
+
url: z.string().optional()
|
|
739
|
+
});
|
|
740
|
+
const AzdoConnectionDataSchema = z.object({
|
|
741
|
+
authenticatedUser: AzdoIdentitySchema,
|
|
742
|
+
authorizedUser: AzdoIdentitySchema
|
|
743
|
+
});
|
|
744
|
+
const AzdoGitUserDateSchema = z.object({
|
|
745
|
+
name: z.string(),
|
|
746
|
+
email: z.string(),
|
|
747
|
+
date: z.string().optional()
|
|
748
|
+
});
|
|
749
|
+
const AzdoGitRefSchema = z.object({
|
|
750
|
+
name: z.string(),
|
|
751
|
+
objectId: z.string(),
|
|
752
|
+
isLocked: z.boolean().optional()
|
|
753
|
+
});
|
|
754
|
+
const AzdoGitRefUpdateResultSchema = AzdoGitRefSchema.extend({
|
|
755
|
+
oldObjectId: z.string(),
|
|
756
|
+
newObjectId: z.string(),
|
|
757
|
+
success: z.boolean(),
|
|
758
|
+
customMessage: z.string().optional()
|
|
759
|
+
});
|
|
760
|
+
const AzdoGitChangeSchema = z.object({
|
|
761
|
+
changeType: AzdoVersionControlChangeTypeSchema,
|
|
762
|
+
newContent: z.object({
|
|
763
|
+
content: z.string(),
|
|
764
|
+
contentType: z.enum(["rawtext", "base64encoded"])
|
|
765
|
+
}).optional()
|
|
766
|
+
});
|
|
767
|
+
const AzdoGitCommitRefSchema = z.object({
|
|
768
|
+
commitId: z.string().optional(),
|
|
769
|
+
author: AzdoGitUserDateSchema.optional(),
|
|
770
|
+
committer: AzdoGitUserDateSchema.optional(),
|
|
771
|
+
changes: AzdoGitChangeSchema.array()
|
|
772
|
+
});
|
|
773
|
+
const AzdoGitPushSchema = z.object({
|
|
774
|
+
commits: AzdoGitCommitRefSchema.array(),
|
|
775
|
+
refUpdates: AzdoGitRefSchema.array()
|
|
776
|
+
});
|
|
777
|
+
const AzdoGitPushCreateSchema = z.object({
|
|
778
|
+
refUpdates: z.object({
|
|
779
|
+
name: z.string(),
|
|
780
|
+
oldObjectId: z.string(),
|
|
781
|
+
newObjectId: z.string().optional()
|
|
782
|
+
}).array(),
|
|
783
|
+
commits: z.object({
|
|
784
|
+
comment: z.string(),
|
|
785
|
+
author: AzdoGitUserDateSchema.optional(),
|
|
786
|
+
changes: AzdoGitChangeSchema.extend({ item: z.object({ path: z.string() }) }).array()
|
|
787
|
+
}).array()
|
|
788
|
+
});
|
|
789
|
+
const AzdoGitBranchStatsSchema = z.object({
|
|
790
|
+
aheadCount: z.number(),
|
|
791
|
+
behindCount: z.number()
|
|
792
|
+
});
|
|
793
|
+
const AzdoRepositoryItemSchema = z.object({
|
|
794
|
+
latestProcessedChange: AzdoGitCommitRefSchema.optional(),
|
|
795
|
+
content: z.string().optional()
|
|
796
|
+
});
|
|
797
|
+
const AzdoPullRequestSchema = z.object({
|
|
798
|
+
pullRequestId: z.number(),
|
|
799
|
+
status: AzdoPullRequestStatusSchema,
|
|
800
|
+
isDraft: z.boolean(),
|
|
801
|
+
sourceRefName: z.string(),
|
|
802
|
+
targetRefName: z.string(),
|
|
803
|
+
lastMergeCommit: AzdoGitCommitRefSchema,
|
|
804
|
+
lastMergeSourceCommit: AzdoGitCommitRefSchema,
|
|
805
|
+
mergeStatus: AzdoPullRequestAsyncStatusSchema,
|
|
806
|
+
autoCompleteSetBy: AzdoIdentityRefSchema.optional(),
|
|
807
|
+
closedBy: AzdoIdentityRefSchema.optional()
|
|
808
|
+
});
|
|
809
|
+
const AdoPropertiesSchema = z.record(z.string(), z.object({
|
|
810
|
+
$type: z.string(),
|
|
811
|
+
$value: z.string()
|
|
812
|
+
}));
|
|
813
|
+
const AzdoIdentityRefWithVoteSchema = z.object({
|
|
814
|
+
id: z.string().optional(),
|
|
815
|
+
displayName: z.string().optional(),
|
|
816
|
+
vote: z.number().optional(),
|
|
817
|
+
hasDeclined: z.boolean().optional(),
|
|
818
|
+
isFlagged: z.boolean().optional(),
|
|
819
|
+
isRequired: z.boolean().optional()
|
|
820
|
+
});
|
|
821
|
+
const AzdoPullRequestCommentSchema = z.object({
|
|
822
|
+
id: z.number(),
|
|
823
|
+
parentCommentId: z.number().nullable(),
|
|
824
|
+
content: z.string(),
|
|
825
|
+
commentType: AzdoCommentTypeSchema,
|
|
826
|
+
publishedDate: z.string(),
|
|
827
|
+
author: AzdoIdentityRefSchema.optional()
|
|
828
|
+
});
|
|
829
|
+
const AzdoPullRequestCommentThreadSchema = z.object({
|
|
830
|
+
id: z.number(),
|
|
831
|
+
comments: AzdoPullRequestCommentSchema.array(),
|
|
832
|
+
status: AzdoCommentThreadStatusSchema
|
|
833
|
+
});
|
|
834
|
+
const AzdoSubscriptionSchema = z.object({
|
|
835
|
+
id: z.string().optional(),
|
|
836
|
+
status: z.enum([
|
|
837
|
+
"enabled",
|
|
838
|
+
"onProbation",
|
|
839
|
+
"disabledByUser",
|
|
840
|
+
"disabledBySystem",
|
|
841
|
+
"disabledByInactiveIdentity"
|
|
842
|
+
]),
|
|
843
|
+
publisherId: z.string(),
|
|
844
|
+
publisherInputs: z.record(z.string(), z.string()),
|
|
845
|
+
consumerId: z.string().optional(),
|
|
846
|
+
consumerActionId: z.string().optional(),
|
|
847
|
+
consumerInputs: z.record(z.string(), z.string()),
|
|
848
|
+
eventType: z.string(),
|
|
849
|
+
resourceVersion: z.string(),
|
|
850
|
+
eventDescription: z.string().optional(),
|
|
851
|
+
actionDescription: z.string().optional()
|
|
852
|
+
});
|
|
853
|
+
const AzdoSubscriptionsQueryResponseSchema = z.object({ results: AzdoSubscriptionSchema.array() });
|
|
854
|
+
const AzdoSubscriptionsQueryInputFilterSchema = z.object({ conditions: z.object({
|
|
855
|
+
caseSensitive: z.boolean().optional(),
|
|
856
|
+
inputId: z.string().optional(),
|
|
857
|
+
inputValue: z.string().optional(),
|
|
858
|
+
operator: z.enum(["equals", "notEquals"])
|
|
859
|
+
}).array().optional() });
|
|
860
|
+
const AzdoSubscriptionsQuerySchema = z.object({
|
|
861
|
+
consumerActionId: z.string().optional(),
|
|
862
|
+
consumerId: z.string().optional(),
|
|
863
|
+
consumerInputFilters: AzdoSubscriptionsQueryInputFilterSchema.array().optional(),
|
|
864
|
+
eventType: z.string().optional(),
|
|
865
|
+
publisherId: z.string().optional(),
|
|
866
|
+
publisherInputFilters: AzdoSubscriptionsQueryInputFilterSchema.array().optional(),
|
|
867
|
+
subscriberId: z.string().optional()
|
|
868
|
+
});
|
|
869
|
+
const AzdoEventTypeSchema = z.enum([
|
|
870
|
+
"git.push",
|
|
871
|
+
"git.pullrequest.updated",
|
|
872
|
+
"git.pullrequest.merged",
|
|
873
|
+
"ms.vss-code.git-pullrequest-comment-event"
|
|
874
|
+
]);
|
|
875
|
+
const AzdoEventRepositorySchema = z.object({
|
|
876
|
+
id: z.string(),
|
|
877
|
+
name: z.string(),
|
|
878
|
+
project: z.object({
|
|
879
|
+
id: z.string(),
|
|
880
|
+
name: z.string(),
|
|
881
|
+
url: z.string()
|
|
882
|
+
}),
|
|
883
|
+
defaultBranch: z.string().optional(),
|
|
884
|
+
remoteUrl: z.string()
|
|
885
|
+
});
|
|
886
|
+
const AzdoEventPullRequestResourceSchema = z.object({
|
|
887
|
+
repository: AzdoEventRepositorySchema,
|
|
888
|
+
pullRequestId: z.number(),
|
|
889
|
+
status: AzdoPullRequestStatusSchema,
|
|
890
|
+
title: z.string(),
|
|
891
|
+
sourceRefName: z.string(),
|
|
892
|
+
targetRefName: z.string(),
|
|
893
|
+
mergeStatus: AzdoPullRequestAsyncStatusSchema,
|
|
894
|
+
mergeId: z.string(),
|
|
895
|
+
url: z.string()
|
|
896
|
+
});
|
|
897
|
+
const AzdoEventPullRequestCommentEventResourceSchema = z.object({
|
|
898
|
+
pullRequest: AzdoEventPullRequestResourceSchema,
|
|
899
|
+
comment: AzdoPullRequestCommentSchema
|
|
900
|
+
});
|
|
901
|
+
const AzdoEventCodePushResourceSchema = z.object({
|
|
902
|
+
repository: AzdoEventRepositorySchema,
|
|
903
|
+
refUpdates: z.object({
|
|
904
|
+
name: z.string(),
|
|
905
|
+
oldObjectId: z.string().nullish(),
|
|
906
|
+
newObjectId: z.string().nullish()
|
|
907
|
+
}).array()
|
|
908
|
+
});
|
|
909
|
+
const AzdoEventSchema = z.object({
|
|
910
|
+
subscriptionId: z.string(),
|
|
911
|
+
notificationId: z.number()
|
|
912
|
+
}).and(z.discriminatedUnion("eventType", [
|
|
913
|
+
z.object({
|
|
914
|
+
eventType: z.literal("git.push"),
|
|
915
|
+
resource: AzdoEventCodePushResourceSchema
|
|
916
|
+
}),
|
|
917
|
+
z.object({
|
|
918
|
+
eventType: z.literal("git.pullrequest.updated"),
|
|
919
|
+
resource: AzdoEventPullRequestResourceSchema
|
|
920
|
+
}),
|
|
921
|
+
z.object({
|
|
922
|
+
eventType: z.literal("git.pullrequest.merged"),
|
|
923
|
+
resource: AzdoEventPullRequestResourceSchema
|
|
924
|
+
}),
|
|
925
|
+
z.object({
|
|
926
|
+
eventType: z.literal("ms.vss-code.git-pullrequest-comment-event"),
|
|
927
|
+
resource: AzdoEventPullRequestCommentEventResourceSchema
|
|
928
|
+
})
|
|
929
|
+
]));
|
|
930
|
+
|
|
750
931
|
//#endregion
|
|
751
932
|
//#region src/azure/url-parts.ts
|
|
752
933
|
function extractOrganizationUrl({ organisationUrl }) {
|
|
@@ -757,12 +938,14 @@ function extractOrganizationUrl({ organisationUrl }) {
|
|
|
757
938
|
const organisation = extractOrganisation(organisationUrl);
|
|
758
939
|
const virtualDirectory = extractVirtualDirectory(value);
|
|
759
940
|
const apiEndpoint = `${protocol}://${hostname}${value.port ? `:${value.port}` : ""}/${virtualDirectory ? `${virtualDirectory}/` : ""}`;
|
|
941
|
+
const identityApiUrl = hostname === "dev.azure.com" || hostname.endsWith(".visualstudio.com") ? new URL(`https://vssps.dev.azure.com/${organisation}/`) : value;
|
|
760
942
|
return {
|
|
761
943
|
value,
|
|
762
944
|
hostname,
|
|
763
945
|
"api-endpoint": apiEndpoint,
|
|
764
946
|
organisation,
|
|
765
|
-
"virtual-directory": virtualDirectory
|
|
947
|
+
"virtual-directory": virtualDirectory,
|
|
948
|
+
"identity-api-url": identityApiUrl
|
|
766
949
|
};
|
|
767
950
|
}
|
|
768
951
|
function extractProjectUrl({ organisationUrl, project }) {
|
|
@@ -818,5 +1001,5 @@ function extractVirtualDirectory(organisationUrl) {
|
|
|
818
1001
|
}
|
|
819
1002
|
|
|
820
1003
|
//#endregion
|
|
821
|
-
export { ANONYMOUS_USER_ID,
|
|
1004
|
+
export { ANONYMOUS_USER_ID, AZDO_PULL_REQUEST_MERGE_STRATEGIES, AdoPropertiesSchema, AzdoCommentThreadStatusSchema, AzdoCommentTypeSchema, AzdoConnectionDataSchema, AzdoEventCodePushResourceSchema, AzdoEventPullRequestCommentEventResourceSchema, AzdoEventPullRequestResourceSchema, AzdoEventRepositorySchema, AzdoEventSchema, AzdoEventTypeSchema, AzdoGitBranchStatsSchema, AzdoGitChangeSchema, AzdoGitCommitRefSchema, AzdoGitPushCreateSchema, AzdoGitPushSchema, AzdoGitRefSchema, AzdoGitRefUpdateResultSchema, AzdoGitUserDateSchema, AzdoIdentityRefSchema, AzdoIdentityRefWithVoteSchema, AzdoIdentitySchema, AzdoProjectSchema, AzdoPullRequestAsyncStatusSchema, AzdoPullRequestCommentSchema, AzdoPullRequestCommentThreadSchema, AzdoPullRequestMergeStrategySchema, AzdoPullRequestSchema, AzdoPullRequestStatusSchema, AzdoRepositoryItemSchema, AzdoRepositorySchema, AzdoSubscriptionSchema, AzdoSubscriptionsQueryInputFilterSchema, AzdoSubscriptionsQueryResponseSchema, AzdoSubscriptionsQuerySchema, AzdoVersionControlChangeTypeSchema, AzureDevOpsWebApiClient, DEVOPS_PR_PROPERTY_DEPENDABOT_DEPENDENCIES, DEVOPS_PR_PROPERTY_DEPENDABOT_PACKAGE_MANAGER, DEVOPS_PR_PROPERTY_MICROSOFT_GIT_SOURCE_REF_NAME, DependenciesPrPropertySchema, buildPullRequestProperties, extractOrganizationUrl, extractProjectUrl, extractRepositoryUrl, getDependabotConfig, getPullRequestChangedFilesForOutputData, getPullRequestCloseReasonForOutputData, getPullRequestDependenciesPropertyValueForOutputData, getPullRequestDescription, getPullRequestForDependencyNames, normalizeBranchName, normalizeFilePath, parsePullRequestProperties };
|
|
822
1005
|
//# sourceMappingURL=index.mjs.map
|