@qawolf/ci-sdk 0.23.1 → 1.0.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.
- package/README.md +10 -199
- package/dist/index.cjs +628 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{index.d.mts → index.d.cts} +1 -210
- package/dist/index.d.ts +1 -210
- package/dist/index.js +48 -1041
- package/dist/index.js.map +1 -1
- package/package.json +21 -21
- package/dist/index.mjs +0 -1610
- package/dist/index.mjs.map +0 -1
package/dist/index.mjs
DELETED
|
@@ -1,1610 +0,0 @@
|
|
|
1
|
-
import slugify from 'slugify';
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
-
|
|
6
|
-
// src/lib/other.ts
|
|
7
|
-
function sleep(ms) {
|
|
8
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
9
|
-
}
|
|
10
|
-
__name(sleep, "sleep");
|
|
11
|
-
function pluralize(count) {
|
|
12
|
-
return count === 1 ? "" : "s";
|
|
13
|
-
}
|
|
14
|
-
__name(pluralize, "pluralize");
|
|
15
|
-
function getBackoffMs(attemptNumber, minWaitMs = 1e3, maxWaitMs = 1e4) {
|
|
16
|
-
return Math.min(maxWaitMs, minWaitMs * 1.2 ** attemptNumber);
|
|
17
|
-
}
|
|
18
|
-
__name(getBackoffMs, "getBackoffMs");
|
|
19
|
-
var buildFetchWithTimeout = /* @__PURE__ */ __name((fetch, timeout) => async (...args) => fetch(args[0], {
|
|
20
|
-
...args[1],
|
|
21
|
-
signal: AbortSignal.timeout(timeout)
|
|
22
|
-
}), "buildFetchWithTimeout");
|
|
23
|
-
|
|
24
|
-
// src/lib/sdk/defaults/fetch.ts
|
|
25
|
-
var defaultFetch = globalThis.fetch;
|
|
26
|
-
|
|
27
|
-
// src/lib/sdk/defaults/log.ts
|
|
28
|
-
var defaultLogDriver = {
|
|
29
|
-
error(message, error) {
|
|
30
|
-
console.error(message, error);
|
|
31
|
-
},
|
|
32
|
-
info(message) {
|
|
33
|
-
console.log(message);
|
|
34
|
-
},
|
|
35
|
-
warn(message) {
|
|
36
|
-
console.warn(message);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// src/lib/sdk/defaults/serviceBase.ts
|
|
41
|
-
var defaultServiceBase = "https://app.qawolf.com/";
|
|
42
|
-
|
|
43
|
-
// package.json
|
|
44
|
-
var version = "0.23.1";
|
|
45
|
-
|
|
46
|
-
// src/lib/sdk/defaults/userAgent.ts
|
|
47
|
-
var defaultUserAgent = `ci-sdk/${version}`;
|
|
48
|
-
|
|
49
|
-
// src/lib/api/log.ts
|
|
50
|
-
async function logFetchError({ log, methodName, response }) {
|
|
51
|
-
if (response.ok) return;
|
|
52
|
-
const { eventId, failureMessage } = await (async () => {
|
|
53
|
-
try {
|
|
54
|
-
const body = await response.json().catch(() => response.text());
|
|
55
|
-
if (typeof body === "object" && body !== null) {
|
|
56
|
-
return {
|
|
57
|
-
eventId: body.eventId,
|
|
58
|
-
failureMessage: body.failureMessage
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
eventId: void 0,
|
|
63
|
-
failureMessage: body
|
|
64
|
-
};
|
|
65
|
-
} catch {
|
|
66
|
-
return {
|
|
67
|
-
eventId: undefined,
|
|
68
|
-
failureMessage: undefined
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
})();
|
|
72
|
-
const eventIdSuffix = eventId ? ` (Event ID: ${eventId})` : "";
|
|
73
|
-
const messageSuffix = failureMessage ? `: ${failureMessage}` : "";
|
|
74
|
-
const statusText = response.status >= 500 ? "Server Error" : response.statusText || "Unknown Error";
|
|
75
|
-
log.error(`\u274C [${methodName}] ${response.status} ${statusText}${eventIdSuffix}${messageSuffix}`);
|
|
76
|
-
}
|
|
77
|
-
__name(logFetchError, "logFetchError");
|
|
78
|
-
|
|
79
|
-
// src/lib/sdk/domain/attemptDeploy/index.ts
|
|
80
|
-
async function attemptNotifyDeploy(deps, apiConfig, config) {
|
|
81
|
-
const { fetch: localFetch, log } = deps;
|
|
82
|
-
try {
|
|
83
|
-
const response = await localFetch(new URL("/api/webhooks/deploy_success", apiConfig.serviceBase), {
|
|
84
|
-
body: JSON.stringify({
|
|
85
|
-
branch: config.branch,
|
|
86
|
-
commit_url: config.commitUrl,
|
|
87
|
-
deduplication_key: config.deduplicationKey,
|
|
88
|
-
deployment_type: config.deploymentType,
|
|
89
|
-
deployment_url: config.deploymentUrl,
|
|
90
|
-
hosting_service: config.hostingService,
|
|
91
|
-
merge_request_number: config.hostingService === "GitLab" ? config.mergeRequestNumber : void 0,
|
|
92
|
-
pull_request_number: config.hostingService === "GitHub" ? config.pullRequestNumber : void 0,
|
|
93
|
-
repository: config.repository,
|
|
94
|
-
sha: config.sha,
|
|
95
|
-
variables: config.variables
|
|
96
|
-
}),
|
|
97
|
-
headers: {
|
|
98
|
-
Authorization: `Bearer ${apiConfig.apiKey}`,
|
|
99
|
-
"Content-Type": "application/json",
|
|
100
|
-
"User-Agent": apiConfig.userAgent
|
|
101
|
-
},
|
|
102
|
-
method: "POST"
|
|
103
|
-
});
|
|
104
|
-
if (!response.ok) return handleErrorResponse(response, log);
|
|
105
|
-
const data = await response.json();
|
|
106
|
-
return handleSuccessResponse(data, log);
|
|
107
|
-
} catch (error) {
|
|
108
|
-
log.error(`\u{1F6AB} Network error from deploy_success, aborting.`);
|
|
109
|
-
return {
|
|
110
|
-
abortReason: "network-error",
|
|
111
|
-
httpStatus: undefined,
|
|
112
|
-
outcome: "aborted"
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
__name(attemptNotifyDeploy, "attemptNotifyDeploy");
|
|
117
|
-
async function handleErrorResponse(response, log) {
|
|
118
|
-
const status = response.status;
|
|
119
|
-
let abortReason;
|
|
120
|
-
if (status === undefined) abortReason = "network-error";
|
|
121
|
-
else if (status === 401) abortReason = "401-unauthorized";
|
|
122
|
-
else if (status === 403) abortReason = "403-forbidden";
|
|
123
|
-
else if (status >= 500) abortReason = "5XX-server-error";
|
|
124
|
-
else abortReason = "4XX-client-error";
|
|
125
|
-
await logFetchError({
|
|
126
|
-
log,
|
|
127
|
-
methodName: "attemptNotifyDeploy",
|
|
128
|
-
response
|
|
129
|
-
});
|
|
130
|
-
return {
|
|
131
|
-
abortReason,
|
|
132
|
-
httpStatus: status,
|
|
133
|
-
outcome: "aborted"
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
__name(handleErrorResponse, "handleErrorResponse");
|
|
137
|
-
async function handleSuccessResponse(data, log) {
|
|
138
|
-
const { environment, results } = data;
|
|
139
|
-
const isPreviewDeployment = environment && !environment.isStatic;
|
|
140
|
-
if (environment) {
|
|
141
|
-
const logPrefix = environment.isStatic ? "Static environment" : "Preview environment";
|
|
142
|
-
log.info(`${logPrefix}: ${environment.alias} (id: ${environment.id})`);
|
|
143
|
-
}
|
|
144
|
-
if (results.length === 0) {
|
|
145
|
-
if (isPreviewDeployment) {
|
|
146
|
-
log.info(`\u2705 Deployment notification was successful. No run was created for this deployment.`);
|
|
147
|
-
return {
|
|
148
|
-
environmentId: environment.id,
|
|
149
|
-
outcome: "success",
|
|
150
|
-
runId: undefined
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
log.error(`\u{1F6AB} No trigger matched the request. Please contact support.`);
|
|
154
|
-
return {
|
|
155
|
-
failReason: "no-matched-trigger",
|
|
156
|
-
outcome: "failed"
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
if (!environment) {
|
|
160
|
-
log.error(`\u{1F6AB} No environment matched the request. Please contact support.`);
|
|
161
|
-
return {
|
|
162
|
-
failReason: "no-environment",
|
|
163
|
-
outcome: "failed"
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
const failedTrigger = results.find((t) => "failure_reason" in t);
|
|
167
|
-
if (failedTrigger) {
|
|
168
|
-
log.error(`\u{1F6AB} Run could not be created. Reason: "${failedTrigger.failure_reason}". Please contact support.`);
|
|
169
|
-
return {
|
|
170
|
-
failReason: "run-could-not-be-created",
|
|
171
|
-
outcome: "failed"
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
const duplicateSuite = results.find((t) => "duplicate_suite_id" in t);
|
|
175
|
-
if (duplicateSuite) {
|
|
176
|
-
log.info(`\u2705 Deployment notification was successful. Previous run ID: ${duplicateSuite.duplicate_suite_id} already exists for this deployment.`);
|
|
177
|
-
return {
|
|
178
|
-
environmentId: environment.id,
|
|
179
|
-
outcome: "success",
|
|
180
|
-
runId: duplicateSuite.duplicate_suite_id
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
const successfulTrigger = results.find((t) => "created_suite_id" in t);
|
|
184
|
-
if (!successfulTrigger) {
|
|
185
|
-
log.error(`\u{1F6AB} No trigger matched the request. Please contact support.`);
|
|
186
|
-
return {
|
|
187
|
-
failReason: "no-matched-trigger",
|
|
188
|
-
outcome: "failed"
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
log.info(`\u2705 Deployment notification was successful. Run created with ID: ${successfulTrigger.created_suite_id}`);
|
|
192
|
-
return {
|
|
193
|
-
environmentId: environment.id,
|
|
194
|
-
outcome: "success",
|
|
195
|
-
runId: successfulTrigger.created_suite_id
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
__name(handleSuccessResponse, "handleSuccessResponse");
|
|
199
|
-
|
|
200
|
-
// src/lib/api/generate-signed-url-for-run-inputs-executables.ts
|
|
201
|
-
async function callGenerateSignedUrlForRunInputsExecutablesStorage({ apiKey, serviceBase, userAgent }, { destinationFilePath }, { fetch: localFetch, log }) {
|
|
202
|
-
try {
|
|
203
|
-
const response = await localFetch(new URL(`${serviceBase}/api/v0/run-inputs-executables-signed-urls?file=${encodeURIComponent(destinationFilePath)}`), {
|
|
204
|
-
headers: {
|
|
205
|
-
Authorization: `Bearer ${apiKey}`,
|
|
206
|
-
"Content-Type": "application/json",
|
|
207
|
-
"User-Agent": userAgent
|
|
208
|
-
},
|
|
209
|
-
method: "GET"
|
|
210
|
-
});
|
|
211
|
-
if (response.status === 200) {
|
|
212
|
-
const json = await response.json();
|
|
213
|
-
return {
|
|
214
|
-
fileLocation: json.fileLocation,
|
|
215
|
-
httpStatus: response.status,
|
|
216
|
-
playgroundFileLocation: json.playgroundFileLocation,
|
|
217
|
-
signedUrl: json.signedUrl,
|
|
218
|
-
success: true
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
await logFetchError({
|
|
222
|
-
log,
|
|
223
|
-
methodName: "callGenerateSignedUrlForRunInputsExecutablesStorage",
|
|
224
|
-
response
|
|
225
|
-
});
|
|
226
|
-
return {
|
|
227
|
-
errorMessage: await response.text(),
|
|
228
|
-
httpStatus: response.status,
|
|
229
|
-
success: false
|
|
230
|
-
};
|
|
231
|
-
} catch (e) {
|
|
232
|
-
return {
|
|
233
|
-
errorMessage: "Network error, aborting request to generate signed URL",
|
|
234
|
-
httpStatus: 0,
|
|
235
|
-
success: false
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
__name(callGenerateSignedUrlForRunInputsExecutablesStorage, "callGenerateSignedUrlForRunInputsExecutablesStorage");
|
|
240
|
-
|
|
241
|
-
// src/lib/sdk/domain/generateSignedUrls/generate-signed-url-for-run-inputs-executables.ts
|
|
242
|
-
async function generateSignedUrlForRunInputsExecutablesStorage(deps, apiConfig, config) {
|
|
243
|
-
const { log } = deps;
|
|
244
|
-
if (!config.destinationFilePath) {
|
|
245
|
-
log.error(`\u{1F6AB} destinationFilePath is a required config parameter`);
|
|
246
|
-
return {
|
|
247
|
-
abortReason: "sdk-argument-validation-failed",
|
|
248
|
-
success: false
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
const responseState = await callGenerateSignedUrlForRunInputsExecutablesStorage(apiConfig, config, deps);
|
|
252
|
-
if (!responseState.success) {
|
|
253
|
-
let abortReason = "XXX-other-http-code";
|
|
254
|
-
if (responseState.httpStatus >= 500) {
|
|
255
|
-
abortReason = "5XX-server-error";
|
|
256
|
-
log.error(`\u{1F6AB} Unrecoverable error (status ${responseState.httpStatus}) when generating signed upload url: aborting.`);
|
|
257
|
-
} else {
|
|
258
|
-
if (responseState.httpStatus === 400) abortReason = "400-invalid-request";
|
|
259
|
-
else if (responseState.httpStatus === 401) abortReason = "401-invalid-credentials";
|
|
260
|
-
else if (responseState.httpStatus === 403) abortReason = "403-forbidden";
|
|
261
|
-
else if (responseState.httpStatus === 0) abortReason = "client-network-error";
|
|
262
|
-
log.error(`\u{1F6AB} Unrecoverable error (status ${responseState.httpStatus}) when generating signed upload url: ${responseState.errorMessage ? `${responseState.errorMessage}.` : ""} aborting.`);
|
|
263
|
-
}
|
|
264
|
-
return {
|
|
265
|
-
abortReason,
|
|
266
|
-
httpStatus: responseState.httpStatus,
|
|
267
|
-
success: false
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
log.info(`\u2705 Generated Signed Upload URL: ${responseState.signedUrl}.`);
|
|
271
|
-
return {
|
|
272
|
-
fileLocation: responseState.fileLocation,
|
|
273
|
-
playgroundFileLocation: responseState.playgroundFileLocation,
|
|
274
|
-
success: true,
|
|
275
|
-
uploadUrl: responseState.signedUrl
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
__name(generateSignedUrlForRunInputsExecutablesStorage, "generateSignedUrlForRunInputsExecutablesStorage");
|
|
279
|
-
|
|
280
|
-
// src/lib/api/generate-signed-url-for-team-storage.ts
|
|
281
|
-
async function callGenerateSignedUrlForTempTeamStorage({ apiKey, serviceBase, userAgent }, { destinationFilePath }, { fetch: localFetch, log }) {
|
|
282
|
-
try {
|
|
283
|
-
const response = await localFetch(new URL(`${serviceBase}/api/v0/team-storage-signed-url?file=${destinationFilePath}`), {
|
|
284
|
-
headers: {
|
|
285
|
-
Authorization: `Bearer ${apiKey}`,
|
|
286
|
-
"Content-Type": "application/json",
|
|
287
|
-
"User-Agent": userAgent
|
|
288
|
-
},
|
|
289
|
-
method: "GET"
|
|
290
|
-
});
|
|
291
|
-
if (response.status === 200) {
|
|
292
|
-
const json = await response.json();
|
|
293
|
-
return {
|
|
294
|
-
fileLocation: json.fileLocation,
|
|
295
|
-
httpStatus: response.status,
|
|
296
|
-
playgroundFileLocation: json.playgroundFileLocation,
|
|
297
|
-
signedUrl: json.signedUrl,
|
|
298
|
-
success: true
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
await logFetchError({
|
|
302
|
-
log,
|
|
303
|
-
methodName: "callGenerateSignedUrlForTempTeamStorage",
|
|
304
|
-
response
|
|
305
|
-
});
|
|
306
|
-
return {
|
|
307
|
-
errorMessage: await response.text(),
|
|
308
|
-
httpStatus: response.status,
|
|
309
|
-
success: false
|
|
310
|
-
};
|
|
311
|
-
} catch (e) {
|
|
312
|
-
return {
|
|
313
|
-
errorMessage: "Network error, aborting request to generate signed URL",
|
|
314
|
-
httpStatus: 0,
|
|
315
|
-
success: false
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
__name(callGenerateSignedUrlForTempTeamStorage, "callGenerateSignedUrlForTempTeamStorage");
|
|
320
|
-
|
|
321
|
-
// src/lib/sdk/domain/generateSignedUrls/generate-signed-url-for-team-storage.ts
|
|
322
|
-
async function generateSignedUrlForTempTeamStorage(deps, apiConfig, config) {
|
|
323
|
-
const { log } = deps;
|
|
324
|
-
if (!config.destinationFilePath) {
|
|
325
|
-
log.error(`\u{1F6AB} destinationFilePath is a required config parameter`);
|
|
326
|
-
return {
|
|
327
|
-
abortReason: "sdk-argument-validation-failed",
|
|
328
|
-
success: false
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
const responseState = await callGenerateSignedUrlForTempTeamStorage(apiConfig, config, deps);
|
|
332
|
-
if (!responseState.success) {
|
|
333
|
-
let abortReason = "XXX-other-http-code";
|
|
334
|
-
if (responseState.httpStatus >= 500) {
|
|
335
|
-
abortReason = "5XX-server-error";
|
|
336
|
-
log.error(`\u{1F6AB} Unrecoverable error (status ${responseState.httpStatus}) when generating signed upload url: aborting.`);
|
|
337
|
-
} else {
|
|
338
|
-
if (responseState.httpStatus === 400) abortReason = "400-invalid-request";
|
|
339
|
-
else if (responseState.httpStatus === 401) abortReason = "401-invalid-credentials";
|
|
340
|
-
else if (responseState.httpStatus === 403) abortReason = "403-forbidden";
|
|
341
|
-
else if (responseState.httpStatus === 0) abortReason = "client-network-error";
|
|
342
|
-
log.error(`\u{1F6AB} Unrecoverable error (status ${responseState.httpStatus}) when generating signed upload url: ${responseState.errorMessage ? `${responseState.errorMessage}.` : ""} aborting.`);
|
|
343
|
-
}
|
|
344
|
-
return {
|
|
345
|
-
abortReason,
|
|
346
|
-
httpStatus: responseState.httpStatus,
|
|
347
|
-
success: false
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
log.info(`\u2705 Generated Signed Upload URL: ${responseState.signedUrl}.`);
|
|
351
|
-
return {
|
|
352
|
-
fileLocation: responseState.fileLocation,
|
|
353
|
-
playgroundFileLocation: responseState.playgroundFileLocation,
|
|
354
|
-
success: true,
|
|
355
|
-
uploadUrl: responseState.signedUrl
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
__name(generateSignedUrlForTempTeamStorage, "generateSignedUrlForTempTeamStorage");
|
|
359
|
-
|
|
360
|
-
// src/lib/sdk/domain/legacy_previewTesting/constants.ts
|
|
361
|
-
var qawolfBaseUrl = "https://app.qawolf.com";
|
|
362
|
-
var qawolfGraphQLEndpoint = `${qawolfBaseUrl}/api/graphql`;
|
|
363
|
-
var previewDeploymentType = "qawolf-preview";
|
|
364
|
-
|
|
365
|
-
// src/lib/sdk/domain/legacy_previewTesting/createEnvironmentVariables.ts
|
|
366
|
-
async function createEnvironmentVariables(deps, apiConfig, { environmentId, variables }) {
|
|
367
|
-
const environmentVariableRequests = Object.keys(variables).map(async (key) => {
|
|
368
|
-
const value = variables[key];
|
|
369
|
-
return deps.fetch(qawolfGraphQLEndpoint, {
|
|
370
|
-
body: JSON.stringify({
|
|
371
|
-
query: `
|
|
372
|
-
mutation UpsertEnvironmentVariable($environmentId: ID!, $value: String!, $name: String) {
|
|
373
|
-
upsertEnvironmentVariable(environmentId: $environmentId, value: $value, name: $name) {
|
|
374
|
-
id
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
`,
|
|
378
|
-
variables: {
|
|
379
|
-
environmentId,
|
|
380
|
-
name: key,
|
|
381
|
-
value
|
|
382
|
-
}
|
|
383
|
-
}),
|
|
384
|
-
headers: {
|
|
385
|
-
Authorization: `Bearer ${apiConfig.apiKey}`,
|
|
386
|
-
"Content-Type": "application/json"
|
|
387
|
-
},
|
|
388
|
-
method: "post"
|
|
389
|
-
});
|
|
390
|
-
});
|
|
391
|
-
await Promise.all(environmentVariableRequests);
|
|
392
|
-
}
|
|
393
|
-
__name(createEnvironmentVariables, "createEnvironmentVariables");
|
|
394
|
-
|
|
395
|
-
// src/lib/sdk/domain/legacy_previewTesting/findOrCreateEnvironment.ts
|
|
396
|
-
async function findOrCreateEnvironment(deps, apiConfig, { baseEnvironmentId, branch, pr, qaWolfTeamId }) {
|
|
397
|
-
const retrievalResponse = await deps.fetch(qawolfGraphQLEndpoint, {
|
|
398
|
-
body: JSON.stringify({
|
|
399
|
-
query: `
|
|
400
|
-
query Environments($where: EnvironmentWhereInput) {
|
|
401
|
-
environments(where: $where) {
|
|
402
|
-
id
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
`,
|
|
406
|
-
variables: {
|
|
407
|
-
where: {
|
|
408
|
-
deletedAt: {
|
|
409
|
-
equals: null
|
|
410
|
-
},
|
|
411
|
-
name: {
|
|
412
|
-
equals: pr ? `[PR] #${pr.number} - ${pr.title}` : `[Preview] ${branch}`
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
}),
|
|
417
|
-
headers: {
|
|
418
|
-
Authorization: `Bearer ${apiConfig.apiKey}`,
|
|
419
|
-
"Content-Type": "application/json"
|
|
420
|
-
},
|
|
421
|
-
method: "post"
|
|
422
|
-
});
|
|
423
|
-
const jsonResponse = await retrievalResponse.json();
|
|
424
|
-
if (jsonResponse.data.environments[0]) {
|
|
425
|
-
const environmentId = jsonResponse.data.environments[0].id;
|
|
426
|
-
deps.log.info(`Environment already exists with ID: ${environmentId}`);
|
|
427
|
-
return environmentId;
|
|
428
|
-
}
|
|
429
|
-
const creationResponse = await deps.fetch(qawolfGraphQLEndpoint, {
|
|
430
|
-
body: JSON.stringify({
|
|
431
|
-
operationName: "createEnvironment",
|
|
432
|
-
query: `
|
|
433
|
-
mutation createEnvironment($name: String!, $teamId: String!) {
|
|
434
|
-
createEnvironment(name: $name, teamId: $teamId) {
|
|
435
|
-
id
|
|
436
|
-
branchId
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
`,
|
|
440
|
-
variables: {
|
|
441
|
-
name: pr ? `[PR] #${pr.number} - ${pr.title}` : `[Preview] ${branch}`,
|
|
442
|
-
teamId: qaWolfTeamId
|
|
443
|
-
}
|
|
444
|
-
}),
|
|
445
|
-
headers: {
|
|
446
|
-
Authorization: `Bearer ${apiConfig.apiKey}`,
|
|
447
|
-
"Content-Type": "application/json"
|
|
448
|
-
},
|
|
449
|
-
method: "post"
|
|
450
|
-
});
|
|
451
|
-
const createionResponseJson = await creationResponse.json();
|
|
452
|
-
deps.log.info(`Environment response: ${JSON.stringify(createionResponseJson)}`);
|
|
453
|
-
if (!createionResponseJson.data.createEnvironment.id) throw Error("Environment ID not found in response");
|
|
454
|
-
const multiBranchResponse = await deps.fetch(qawolfGraphQLEndpoint, {
|
|
455
|
-
body: JSON.stringify({
|
|
456
|
-
query: `
|
|
457
|
-
query teamBranches($teamId: String!) {
|
|
458
|
-
teamBranches: activeTeamBranches(teamId: $teamId) {
|
|
459
|
-
id
|
|
460
|
-
environments{
|
|
461
|
-
id
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
`,
|
|
466
|
-
variables: {
|
|
467
|
-
teamId: qaWolfTeamId
|
|
468
|
-
}
|
|
469
|
-
}),
|
|
470
|
-
headers: {
|
|
471
|
-
Authorization: `Bearer ${apiConfig.apiKey}`,
|
|
472
|
-
"Content-Type": "application/json"
|
|
473
|
-
},
|
|
474
|
-
method: "post"
|
|
475
|
-
});
|
|
476
|
-
const multiBranchResponseJson = await multiBranchResponse.json();
|
|
477
|
-
const hasMultipleBranches = multiBranchResponseJson.data.teamBranches.length > 1;
|
|
478
|
-
if (!hasMultipleBranches) return createionResponseJson.data.createEnvironment.id;
|
|
479
|
-
const sourceEnvironmentResponse = await deps.fetch(qawolfGraphQLEndpoint, {
|
|
480
|
-
body: JSON.stringify({
|
|
481
|
-
query: `
|
|
482
|
-
query EnvironmentWithBranch($where: EnvironmentWhereUniqueInput!) {
|
|
483
|
-
environment(where: $where) {
|
|
484
|
-
id
|
|
485
|
-
branchId
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
`,
|
|
489
|
-
variables: {
|
|
490
|
-
where: {
|
|
491
|
-
id: baseEnvironmentId
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
}),
|
|
495
|
-
headers: {
|
|
496
|
-
Authorization: `Bearer ${apiConfig.apiKey}`,
|
|
497
|
-
"Content-Type": "application/json"
|
|
498
|
-
},
|
|
499
|
-
method: "post"
|
|
500
|
-
});
|
|
501
|
-
const sourceEnvironmentJson = await sourceEnvironmentResponse.json();
|
|
502
|
-
const baseBranchId = sourceEnvironmentJson.data.environment.branchId;
|
|
503
|
-
const targetBranchId = createionResponseJson.data.createEnvironment.branchId;
|
|
504
|
-
if (!baseBranchId) throw Error("Base branch ID not found in response");
|
|
505
|
-
deps.log.info(`Promoting workflows from branch ${baseBranchId} to ${targetBranchId}`);
|
|
506
|
-
const promotionResponse = await deps.fetch(qawolfGraphQLEndpoint, {
|
|
507
|
-
body: JSON.stringify({
|
|
508
|
-
query: `
|
|
509
|
-
mutation PromoteWorkflowsToBranch(
|
|
510
|
-
$sourceTeamBranchId: String!
|
|
511
|
-
$targetTeamBranchId: String!
|
|
512
|
-
) {
|
|
513
|
-
promoteWorkflowsToBranch(
|
|
514
|
-
mergeStrategy: overwrite
|
|
515
|
-
sourceTeamBranchId: $sourceTeamBranchId
|
|
516
|
-
targetTeamBranchId: $targetTeamBranchId
|
|
517
|
-
)
|
|
518
|
-
}
|
|
519
|
-
`,
|
|
520
|
-
variables: {
|
|
521
|
-
sourceTeamBranchId: baseBranchId,
|
|
522
|
-
targetTeamBranchId: targetBranchId
|
|
523
|
-
}
|
|
524
|
-
}),
|
|
525
|
-
headers: {
|
|
526
|
-
Authorization: `Bearer ${apiConfig.apiKey}`,
|
|
527
|
-
"Content-Type": "application/json"
|
|
528
|
-
},
|
|
529
|
-
method: "post"
|
|
530
|
-
});
|
|
531
|
-
const promotionResponseJson = await promotionResponse.json();
|
|
532
|
-
if (!promotionResponseJson) throw Error("Promotion failed");
|
|
533
|
-
return createionResponseJson.data.createEnvironment.id;
|
|
534
|
-
}
|
|
535
|
-
__name(findOrCreateEnvironment, "findOrCreateEnvironment");
|
|
536
|
-
|
|
537
|
-
// src/lib/sdk/domain/legacy_previewTesting/findOrCreateTrigger.ts
|
|
538
|
-
async function findOrCreateTrigger(deps, apiConfig, args) {
|
|
539
|
-
const { branch, environmentId, pr, qaWolfTeamId, repositoryId, tags } = args;
|
|
540
|
-
const triggerName = `Deployments of ${pr ? `PR #${pr.number} - ${pr.title}` : `branch ${branch}`}`;
|
|
541
|
-
const retrievalResponse = await deps.fetch(qawolfGraphQLEndpoint, {
|
|
542
|
-
body: JSON.stringify({
|
|
543
|
-
query: `query getTriggersForBranch($where: TriggerWhereInput) {
|
|
544
|
-
triggers(where: $where) {
|
|
545
|
-
environment_id
|
|
546
|
-
id
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
`,
|
|
550
|
-
variables: {
|
|
551
|
-
where: {
|
|
552
|
-
environment_id: {
|
|
553
|
-
equals: environmentId
|
|
554
|
-
},
|
|
555
|
-
name: {
|
|
556
|
-
equals: triggerName
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
}),
|
|
561
|
-
headers: {
|
|
562
|
-
Authorization: `Bearer ${apiConfig.apiKey}`,
|
|
563
|
-
"Content-Type": "application/json"
|
|
564
|
-
},
|
|
565
|
-
method: "post"
|
|
566
|
-
});
|
|
567
|
-
const retrievalResponseJson = await retrievalResponse.json();
|
|
568
|
-
if (retrievalResponseJson.data.triggers[0]) {
|
|
569
|
-
const triggerId2 = retrievalResponseJson.data.triggers[0].id;
|
|
570
|
-
const environmentId2 = retrievalResponseJson.data.triggers[0].environment_id;
|
|
571
|
-
deps.log.info(`Trigger with name ${triggerName} already exists with id ${triggerId2} in environment ${environmentId2}`);
|
|
572
|
-
return triggerId2;
|
|
573
|
-
}
|
|
574
|
-
const creationResponse = await deps.fetch(qawolfGraphQLEndpoint, {
|
|
575
|
-
body: JSON.stringify({
|
|
576
|
-
operationName: "createTrigger",
|
|
577
|
-
query: `
|
|
578
|
-
mutation createTrigger(
|
|
579
|
-
$codeHostingServiceRepositoryId: ID!,
|
|
580
|
-
$deploymentBranches: String!,
|
|
581
|
-
$deploymentEnvironment: String!,
|
|
582
|
-
$deploymentProvider: String!,
|
|
583
|
-
$environmentId: ID!,
|
|
584
|
-
$name: String!,
|
|
585
|
-
$teamId: ID!,
|
|
586
|
-
$tag_ids: [ID!]
|
|
587
|
-
) {
|
|
588
|
-
createTrigger(
|
|
589
|
-
codeHostingServiceRepositoryId: $codeHostingServiceRepositoryId,
|
|
590
|
-
deployment_branches: $deploymentBranches,
|
|
591
|
-
deployment_environment: $deploymentEnvironment,
|
|
592
|
-
deployment_provider: $deploymentProvider,
|
|
593
|
-
environment_id: $environmentId,
|
|
594
|
-
name: $name,
|
|
595
|
-
team_id: $teamId,
|
|
596
|
-
tag_ids: $tag_ids
|
|
597
|
-
) {
|
|
598
|
-
id
|
|
599
|
-
__typename
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
`,
|
|
603
|
-
variables: {
|
|
604
|
-
codeHostingServiceRepositoryId: repositoryId,
|
|
605
|
-
deploymentBranches: branch,
|
|
606
|
-
deploymentEnvironment: previewDeploymentType,
|
|
607
|
-
deploymentProvider: "generic",
|
|
608
|
-
environmentId,
|
|
609
|
-
name: triggerName,
|
|
610
|
-
tag_ids: tags?.map((tag) => tag.id),
|
|
611
|
-
teamId: qaWolfTeamId
|
|
612
|
-
}
|
|
613
|
-
}),
|
|
614
|
-
headers: {
|
|
615
|
-
Authorization: `Bearer ${apiConfig.apiKey}`,
|
|
616
|
-
"Content-Type": "application/json"
|
|
617
|
-
},
|
|
618
|
-
method: "post"
|
|
619
|
-
});
|
|
620
|
-
const creationResponseJson = await creationResponse.json();
|
|
621
|
-
deps.log.info(`Trigger response: ${JSON.stringify(creationResponseJson)}`);
|
|
622
|
-
const triggerId = creationResponseJson.data?.createTrigger?.id;
|
|
623
|
-
if (!triggerId) throw Error("Trigger ID not found in response");
|
|
624
|
-
deps.log.info(`Trigger created with ID: ${triggerId}`);
|
|
625
|
-
return triggerId;
|
|
626
|
-
}
|
|
627
|
-
__name(findOrCreateTrigger, "findOrCreateTrigger");
|
|
628
|
-
|
|
629
|
-
// src/lib/sdk/domain/legacy_previewTesting/findRepositoryIdByName.ts
|
|
630
|
-
async function findRepositoryIdByName(deps, apiConfig, { headRepoFullName }) {
|
|
631
|
-
const response = await deps.fetch(qawolfGraphQLEndpoint, {
|
|
632
|
-
body: JSON.stringify({
|
|
633
|
-
query: `
|
|
634
|
-
query codeHostingServiceRepositories($where: CodeHostingServiceRepositoryWhereInput) {
|
|
635
|
-
codeHostingServiceRepositories(where: $where) {
|
|
636
|
-
id
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
`,
|
|
640
|
-
variables: {
|
|
641
|
-
where: {
|
|
642
|
-
externalFullName: {
|
|
643
|
-
equals: headRepoFullName
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
}),
|
|
648
|
-
headers: {
|
|
649
|
-
Authorization: `Bearer ${apiConfig.apiKey}`,
|
|
650
|
-
"Content-Type": "application/json"
|
|
651
|
-
},
|
|
652
|
-
method: "post"
|
|
653
|
-
});
|
|
654
|
-
const responseJson = await response.json();
|
|
655
|
-
deps.log.info(`Repository response: ${JSON.stringify(responseJson)}`);
|
|
656
|
-
const repositories = responseJson.data.codeHostingServiceRepositories;
|
|
657
|
-
if (!repositories[0]) return;
|
|
658
|
-
return repositories[0].id;
|
|
659
|
-
}
|
|
660
|
-
__name(findRepositoryIdByName, "findRepositoryIdByName");
|
|
661
|
-
|
|
662
|
-
// src/lib/sdk/domain/legacy_previewTesting/getEnvironmentVariablesFromEnvironment.ts
|
|
663
|
-
async function getEnvironmentVariablesFromEnvironment(deps, apiConfig, { environmentId }) {
|
|
664
|
-
const retrievalResponse = await deps.fetch(qawolfGraphQLEndpoint, {
|
|
665
|
-
body: JSON.stringify({
|
|
666
|
-
query: `
|
|
667
|
-
query EnvironmentVariables($where: EnvironmentWhereUniqueInput!) {
|
|
668
|
-
environment(where: $where) {
|
|
669
|
-
id
|
|
670
|
-
variablesJSON
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
`,
|
|
674
|
-
variables: {
|
|
675
|
-
where: {
|
|
676
|
-
id: environmentId
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
}),
|
|
680
|
-
headers: {
|
|
681
|
-
Authorization: `Bearer ${apiConfig.apiKey}`,
|
|
682
|
-
"Content-Type": "application/json"
|
|
683
|
-
},
|
|
684
|
-
method: "post"
|
|
685
|
-
});
|
|
686
|
-
const retrievalResponseJson = await retrievalResponse.json();
|
|
687
|
-
if (!retrievalResponseJson.data.environment) {
|
|
688
|
-
throw Error(`Environment not found with ID: ${environmentId}. Please check the environment ID is correct.`);
|
|
689
|
-
}
|
|
690
|
-
return JSON.parse(retrievalResponseJson.data.environment.variablesJSON);
|
|
691
|
-
}
|
|
692
|
-
__name(getEnvironmentVariablesFromEnvironment, "getEnvironmentVariablesFromEnvironment");
|
|
693
|
-
|
|
694
|
-
// src/lib/sdk/domain/legacy_previewTesting/getTagsFromEnvironment.ts
|
|
695
|
-
async function getTagsFromGenericTriggerInEnvironment(deps, apiConfig, { environmentId }) {
|
|
696
|
-
const retrievalResponse = await deps.fetch(qawolfGraphQLEndpoint, {
|
|
697
|
-
body: JSON.stringify({
|
|
698
|
-
query: `
|
|
699
|
-
query GenericTriggerTagsFromEnvironment($where: EnvironmentWhereUniqueInput!) {
|
|
700
|
-
environment(where: $where) {
|
|
701
|
-
id
|
|
702
|
-
triggers(where: {deployment_provider: {equals: "generic"}}) {
|
|
703
|
-
id
|
|
704
|
-
tags {
|
|
705
|
-
id
|
|
706
|
-
name
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
`,
|
|
712
|
-
variables: {
|
|
713
|
-
where: {
|
|
714
|
-
id: environmentId
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
}),
|
|
718
|
-
headers: {
|
|
719
|
-
Authorization: `Bearer ${apiConfig.apiKey}`,
|
|
720
|
-
"Content-Type": "application/json"
|
|
721
|
-
},
|
|
722
|
-
method: "post"
|
|
723
|
-
});
|
|
724
|
-
const retrievalResponseJson = await retrievalResponse.json();
|
|
725
|
-
if (!retrievalResponseJson.data.environment) {
|
|
726
|
-
throw Error(`Environment not found with ID: ${environmentId}. Please check the environment ID is correct.`);
|
|
727
|
-
}
|
|
728
|
-
return retrievalResponseJson.data.environment.triggers[0]?.tags?.map((tag) => tag);
|
|
729
|
-
}
|
|
730
|
-
__name(getTagsFromGenericTriggerInEnvironment, "getTagsFromGenericTriggerInEnvironment");
|
|
731
|
-
|
|
732
|
-
// src/lib/sdk/domain/legacy_previewTesting/createEnvironmentAction.ts
|
|
733
|
-
var createEnvironmentAction = /* @__PURE__ */ __name(async (deps, apiConfig, { baseEnvironmentId, branch, deploymentUrl, headRepoFullName, pr, qaWolfTeamId, variables }) => {
|
|
734
|
-
deps.log.info("Creating environment for pull request...");
|
|
735
|
-
const environmentId = await findOrCreateEnvironment(deps, apiConfig, {
|
|
736
|
-
baseEnvironmentId,
|
|
737
|
-
branch,
|
|
738
|
-
pr,
|
|
739
|
-
qaWolfTeamId
|
|
740
|
-
});
|
|
741
|
-
deps.log.info(`Environment created with ID: ${environmentId}`);
|
|
742
|
-
const baseEnvironmentVariablesJSON = baseEnvironmentId ? await getEnvironmentVariablesFromEnvironment(deps, apiConfig, {
|
|
743
|
-
environmentId: baseEnvironmentId
|
|
744
|
-
}) : {};
|
|
745
|
-
if (typeof baseEnvironmentVariablesJSON !== "object") {
|
|
746
|
-
deps.log.error("baseEnvironmentVariablesJSON is not an object");
|
|
747
|
-
throw Error("baseEnvironmentVariablesJSON is not an object");
|
|
748
|
-
}
|
|
749
|
-
const combinedEnvironmentVariables = {
|
|
750
|
-
...baseEnvironmentVariablesJSON,
|
|
751
|
-
...variables,
|
|
752
|
-
...deploymentUrl ? {
|
|
753
|
-
URL: deploymentUrl
|
|
754
|
-
} : {}
|
|
755
|
-
};
|
|
756
|
-
deps.log.info("Creating environment variables...");
|
|
757
|
-
await createEnvironmentVariables(deps, apiConfig, {
|
|
758
|
-
environmentId,
|
|
759
|
-
variables: combinedEnvironmentVariables
|
|
760
|
-
});
|
|
761
|
-
deps.log.info(`Environment variables created for environment ID: ${environmentId}`);
|
|
762
|
-
deps.log.info("Retrieving repository ID...");
|
|
763
|
-
const repositoryId = await findRepositoryIdByName(deps, apiConfig, {
|
|
764
|
-
headRepoFullName
|
|
765
|
-
});
|
|
766
|
-
deps.log.info(repositoryId ? `Repository ID retrieved: ${repositoryId}` : "Repository not integrated with QA Wolf, enable it in the settings page to get PR comments and checks.");
|
|
767
|
-
const tags = baseEnvironmentId ? await getTagsFromGenericTriggerInEnvironment(deps, apiConfig, {
|
|
768
|
-
environmentId: baseEnvironmentId
|
|
769
|
-
}) : undefined;
|
|
770
|
-
deps.log.info(`Tags retrieved: ${tags?.map((tag) => tag.name).join(", ")}`);
|
|
771
|
-
deps.log.info("Creating trigger for deployment...");
|
|
772
|
-
await findOrCreateTrigger(deps, apiConfig, {
|
|
773
|
-
branch,
|
|
774
|
-
environmentId,
|
|
775
|
-
pr,
|
|
776
|
-
qaWolfTeamId,
|
|
777
|
-
repositoryId,
|
|
778
|
-
tags
|
|
779
|
-
});
|
|
780
|
-
}, "createEnvironmentAction");
|
|
781
|
-
|
|
782
|
-
// src/lib/sdk/domain/legacy_previewTesting/deleteEnvironment.ts
|
|
783
|
-
async function deleteEnvironment(deps, apiConfig, { environmentId }) {
|
|
784
|
-
await deps.fetch(qawolfGraphQLEndpoint, {
|
|
785
|
-
body: JSON.stringify({
|
|
786
|
-
query: `
|
|
787
|
-
mutation deleteEnvironment($environmentId: ID!) {
|
|
788
|
-
deleteEnvironment(environment_id: $environmentId) {
|
|
789
|
-
id
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
`,
|
|
793
|
-
variables: {
|
|
794
|
-
environmentId
|
|
795
|
-
}
|
|
796
|
-
}),
|
|
797
|
-
headers: {
|
|
798
|
-
Authorization: `Bearer ${apiConfig.apiKey}`,
|
|
799
|
-
"Content-Type": "application/json"
|
|
800
|
-
},
|
|
801
|
-
method: "post"
|
|
802
|
-
});
|
|
803
|
-
deps.log.info(`Environment deleted with ID: ${environmentId}`);
|
|
804
|
-
}
|
|
805
|
-
__name(deleteEnvironment, "deleteEnvironment");
|
|
806
|
-
|
|
807
|
-
// src/lib/sdk/domain/legacy_previewTesting/getEnvironmentIdForBranch.ts
|
|
808
|
-
async function getEnvironmentIdForBranch(deps, apiConfig, branch) {
|
|
809
|
-
const response = await deps.fetch(qawolfGraphQLEndpoint, {
|
|
810
|
-
body: JSON.stringify({
|
|
811
|
-
query: `
|
|
812
|
-
query getTriggersForBranch($where: TriggerWhereInput) {
|
|
813
|
-
triggers(where: $where) {
|
|
814
|
-
id
|
|
815
|
-
environment_id
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
`,
|
|
819
|
-
variables: {
|
|
820
|
-
where: {
|
|
821
|
-
deployment_branches: {
|
|
822
|
-
contains: branch
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
}),
|
|
827
|
-
headers: {
|
|
828
|
-
Authorization: `Bearer ${apiConfig.apiKey}`,
|
|
829
|
-
"Content-Type": "application/json"
|
|
830
|
-
},
|
|
831
|
-
method: "post"
|
|
832
|
-
});
|
|
833
|
-
const responseJson = await response.json();
|
|
834
|
-
deps.log.info(`Trigger response: ${JSON.stringify(responseJson)}`);
|
|
835
|
-
const triggers = responseJson.data.triggers;
|
|
836
|
-
if (!triggers || !triggers[0]) throw Error(`No environment found for branch: ${branch}`);
|
|
837
|
-
return triggers[0].environment_id;
|
|
838
|
-
}
|
|
839
|
-
__name(getEnvironmentIdForBranch, "getEnvironmentIdForBranch");
|
|
840
|
-
|
|
841
|
-
// src/lib/sdk/domain/legacy_previewTesting/deleteEnvironmentAction.ts
|
|
842
|
-
var deleteEnvironmentAction = /* @__PURE__ */ __name(async (deps, apiConfig, { branch }) => {
|
|
843
|
-
deps.log.info("Retrieving environment ID for deletion...");
|
|
844
|
-
const environmentId = await getEnvironmentIdForBranch(deps, apiConfig, branch);
|
|
845
|
-
deps.log.info(`Deleting environment with ID: ${environmentId}`);
|
|
846
|
-
await deleteEnvironment(deps, apiConfig, {
|
|
847
|
-
environmentId
|
|
848
|
-
});
|
|
849
|
-
}, "deleteEnvironmentAction");
|
|
850
|
-
|
|
851
|
-
// src/lib/sdk/domain/legacy_previewTesting/index.ts
|
|
852
|
-
async function testPreview(deps, apiConfig, config) {
|
|
853
|
-
await createEnvironmentAction(deps, apiConfig, {
|
|
854
|
-
baseEnvironmentId: config.baseEnvironmentId,
|
|
855
|
-
branch: config.branch,
|
|
856
|
-
deploymentUrl: config.deploymentUrl,
|
|
857
|
-
headRepoFullName: config.repoFullName,
|
|
858
|
-
pr: config.pr,
|
|
859
|
-
qaWolfTeamId: config.qaWolfTeamId,
|
|
860
|
-
variables: config.variables
|
|
861
|
-
});
|
|
862
|
-
return attemptNotifyDeploy(deps, apiConfig, {
|
|
863
|
-
branch: config.branch,
|
|
864
|
-
commitUrl: config.commitUrl,
|
|
865
|
-
deploymentType: previewDeploymentType,
|
|
866
|
-
deploymentUrl: config.deploymentUrl,
|
|
867
|
-
sha: config.sha,
|
|
868
|
-
variables: config.variables
|
|
869
|
-
});
|
|
870
|
-
}
|
|
871
|
-
__name(testPreview, "testPreview");
|
|
872
|
-
async function removeEnvironment(deps, apiConfig, config) {
|
|
873
|
-
await deleteEnvironmentAction(deps, apiConfig, config);
|
|
874
|
-
}
|
|
875
|
-
__name(removeEnvironment, "removeEnvironment");
|
|
876
|
-
|
|
877
|
-
// src/lib/api/ci-greenlight.ts
|
|
878
|
-
async function fetchCiGreenlightStatus({ apiKey, serviceBase, userAgent }, { runId }, { fetch: localFetch, log }) {
|
|
879
|
-
try {
|
|
880
|
-
const resp = await localFetch(new URL(`/api/v0/ci-greenlight/${encodeURIComponent(runId)}`, serviceBase), {
|
|
881
|
-
headers: {
|
|
882
|
-
Authorization: `Bearer ${apiKey}`,
|
|
883
|
-
"User-Agent": userAgent
|
|
884
|
-
}
|
|
885
|
-
});
|
|
886
|
-
if (resp.ok) {
|
|
887
|
-
const greenlightStatus = await resp.json();
|
|
888
|
-
return {
|
|
889
|
-
greenlightStatus,
|
|
890
|
-
httpStatus: resp.status,
|
|
891
|
-
ok: true
|
|
892
|
-
};
|
|
893
|
-
}
|
|
894
|
-
await logFetchError({
|
|
895
|
-
log,
|
|
896
|
-
methodName: "fetchCiGreenlightStatus",
|
|
897
|
-
response: resp
|
|
898
|
-
});
|
|
899
|
-
if (resp.status === 404) {
|
|
900
|
-
return {
|
|
901
|
-
canRetry: true,
|
|
902
|
-
errorType: "not-found",
|
|
903
|
-
httpStatus: resp.status,
|
|
904
|
-
ok: false
|
|
905
|
-
};
|
|
906
|
-
}
|
|
907
|
-
if (resp.status >= 500) {
|
|
908
|
-
return {
|
|
909
|
-
canRetry: true,
|
|
910
|
-
errorType: "server",
|
|
911
|
-
httpStatus: resp.status,
|
|
912
|
-
ok: false
|
|
913
|
-
};
|
|
914
|
-
}
|
|
915
|
-
return {
|
|
916
|
-
canRetry: false,
|
|
917
|
-
errorType: "client",
|
|
918
|
-
httpStatus: resp.status,
|
|
919
|
-
ok: false
|
|
920
|
-
};
|
|
921
|
-
} catch (e) {
|
|
922
|
-
return {
|
|
923
|
-
canRetry: true,
|
|
924
|
-
errorType: "network",
|
|
925
|
-
httpStatus: 0,
|
|
926
|
-
ok: false
|
|
927
|
-
};
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
__name(fetchCiGreenlightStatus, "fetchCiGreenlightStatus");
|
|
931
|
-
|
|
932
|
-
// src/lib/sdk/domain/poll-ci-greenlight.ts
|
|
933
|
-
var safeDefaults = {
|
|
934
|
-
abortOnSuperseded: false,
|
|
935
|
-
maxRetries: 10,
|
|
936
|
-
pollTimeout: 120 * 60 * 1e3,
|
|
937
|
-
retryInterval: 10 * 1e3,
|
|
938
|
-
runInProgressInterval: 30 * 1e3,
|
|
939
|
-
runUnderReviewInterval: 60 * 1e3
|
|
940
|
-
};
|
|
941
|
-
async function pollCiGreenlightStatus(deps, apiConfig, { onRunStageChanged = /* @__PURE__ */ __name(() => undefined, "onRunStageChanged"), runId, ...pollConfig }) {
|
|
942
|
-
let retries = 0;
|
|
943
|
-
const { log } = deps;
|
|
944
|
-
const { abortOnSuperseded = safeDefaults.abortOnSuperseded, maxRetries = safeDefaults.maxRetries, pollTimeout = safeDefaults.pollTimeout, retryInterval = safeDefaults.retryInterval, runInProgressInterval = safeDefaults.runInProgressInterval, runUnderReviewInterval = safeDefaults.runUnderReviewInterval } = pollConfig;
|
|
945
|
-
let currentStatus = undefined;
|
|
946
|
-
const startedAt = Date.now();
|
|
947
|
-
let hasTimedOut = false;
|
|
948
|
-
while (!(hasTimedOut = Date.now() - startedAt > pollTimeout)) {
|
|
949
|
-
const responseState = await fetchCiGreenlightStatus(apiConfig, {
|
|
950
|
-
runId
|
|
951
|
-
}, deps);
|
|
952
|
-
if (!responseState.ok && !responseState.canRetry) {
|
|
953
|
-
log.error(`\u{1F6AB} Unrecoverable error (status ${responseState.httpStatus}) from CI greenlight, aborting.`);
|
|
954
|
-
return {
|
|
955
|
-
abortReason: "4XX-client-error",
|
|
956
|
-
httpStatus: responseState.httpStatus,
|
|
957
|
-
outcome: "aborted"
|
|
958
|
-
};
|
|
959
|
-
}
|
|
960
|
-
if (!responseState.ok) {
|
|
961
|
-
retries += 1;
|
|
962
|
-
if (retries > maxRetries) {
|
|
963
|
-
log.error(`\u{1F6AB} Unrecoverable error${responseState.httpStatus ? ` (status ${responseState.httpStatus})` : ""} from CI greenlight, aborting after ${maxRetries} attempts.`);
|
|
964
|
-
if (responseState.errorType === "network") {
|
|
965
|
-
return {
|
|
966
|
-
abortReason: "network-error",
|
|
967
|
-
httpStatus: undefined,
|
|
968
|
-
outcome: "aborted"
|
|
969
|
-
};
|
|
970
|
-
}
|
|
971
|
-
let abortReason = "XXX-other-http-code";
|
|
972
|
-
if (responseState.errorType === "not-found") abortReason = "404-run-not-found";
|
|
973
|
-
else if (responseState.errorType === "server") abortReason = "5XX-server-error";
|
|
974
|
-
else ;
|
|
975
|
-
return {
|
|
976
|
-
abortReason,
|
|
977
|
-
httpStatus: responseState.httpStatus,
|
|
978
|
-
outcome: "aborted"
|
|
979
|
-
};
|
|
980
|
-
}
|
|
981
|
-
const { errorType, httpStatus } = responseState;
|
|
982
|
-
const retryLabel = `${httpStatus ? ` (status ${httpStatus})` : ""}, will try again... (${retries}/${maxRetries})`;
|
|
983
|
-
if (errorType === "network") log.warn(`\u274C Network error${retryLabel}`);
|
|
984
|
-
else if (errorType === "not-found") log.info(`\u23F3 Run not found${retryLabel}`);
|
|
985
|
-
else if (errorType === "server") log.warn(`\u274C Server error${retryLabel}`);
|
|
986
|
-
await sleep(retryInterval);
|
|
987
|
-
continue;
|
|
988
|
-
}
|
|
989
|
-
retries = 0;
|
|
990
|
-
const { greenlightStatus } = responseState;
|
|
991
|
-
const previousStatus = currentStatus;
|
|
992
|
-
currentStatus = greenlightStatus;
|
|
993
|
-
if (!previousStatus || previousStatus.runStage !== greenlightStatus.runStage) {
|
|
994
|
-
try {
|
|
995
|
-
await onRunStageChanged(greenlightStatus, previousStatus);
|
|
996
|
-
} catch (e) {
|
|
997
|
-
log.error(`Error in onRunStageChanged callback`, e);
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
const urlInfo = `See ${greenlightStatus.relevantRunUrl}`;
|
|
1001
|
-
const { greenlight, relevantRunId, relevantRunUrl, relevantRunWithBugsUrl, rootRunId, rootRunUrl, runStage } = greenlightStatus;
|
|
1002
|
-
if (rootRunId !== relevantRunId) {
|
|
1003
|
-
const supersedingDetails = `
|
|
1004
|
-
- Root: ${rootRunUrl}
|
|
1005
|
-
- Superseding: ${relevantRunUrl}`;
|
|
1006
|
-
if (abortOnSuperseded) {
|
|
1007
|
-
log.warn(`\u274C Aborting due to superseded run (option 'abortOnSuperseded' is enabled).${supersedingDetails}`);
|
|
1008
|
-
return {
|
|
1009
|
-
abortReason: "superseded-run",
|
|
1010
|
-
httpStatus: undefined,
|
|
1011
|
-
outcome: "aborted"
|
|
1012
|
-
};
|
|
1013
|
-
}
|
|
1014
|
-
log.info(`Root run was superseded:${supersedingDetails}`);
|
|
1015
|
-
}
|
|
1016
|
-
if (runStage === "completed") {
|
|
1017
|
-
const { blockingBugsCount, blockingBugUrls = [], nonBlockingBugsCount, nonBlockingBugUrls = [] } = greenlightStatus;
|
|
1018
|
-
const blockingBugList = blockingBugUrls.map((url) => `
|
|
1019
|
-
\u2022 ${url}`).join("");
|
|
1020
|
-
const nonBlockingBugList = nonBlockingBugUrls.map((url) => `
|
|
1021
|
-
\u2022 ${url}`).join("");
|
|
1022
|
-
const bugsListInText = `${blockingBugUrls.length > 0 ? `
|
|
1023
|
-
BLOCKING BUGS:${blockingBugList}` : ""}${nonBlockingBugUrls.length > 0 ? `
|
|
1024
|
-
NON BLOCKING BUGS:${nonBlockingBugList}` : ""}`;
|
|
1025
|
-
if (greenlight) {
|
|
1026
|
-
log.info(`\u2705 Run passed and no blocking bugs found${nonBlockingBugsCount > 0 ? ` and ${nonBlockingBugsCount} non-blocking bug${pluralize(nonBlockingBugsCount)} found` : ""}.
|
|
1027
|
-
${urlInfo}`);
|
|
1028
|
-
return {
|
|
1029
|
-
greenlightStatus,
|
|
1030
|
-
outcome: "success"
|
|
1031
|
-
};
|
|
1032
|
-
} else {
|
|
1033
|
-
log.warn(`\u274C Run failed and ${blockingBugsCount} blocking bug${pluralize(blockingBugsCount)} found${nonBlockingBugsCount ? ` and ${nonBlockingBugsCount} non-blocking bug${pluralize(nonBlockingBugsCount)}` : ""}.
|
|
1034
|
-
See ${relevantRunWithBugsUrl}
|
|
1035
|
-
You may review the priority of certain bugs to mark these non-blocking and retry the job.
|
|
1036
|
-
` + bugsListInText);
|
|
1037
|
-
return {
|
|
1038
|
-
greenlightStatus,
|
|
1039
|
-
outcome: "failed"
|
|
1040
|
-
};
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
if (runStage === "canceled") {
|
|
1044
|
-
log.info(`\u{1F6AB} Run was canceled. Aborting... Please contact support.
|
|
1045
|
-
${urlInfo}`);
|
|
1046
|
-
return {
|
|
1047
|
-
abortReason: "run-canceled",
|
|
1048
|
-
httpStatus: undefined,
|
|
1049
|
-
outcome: "aborted"
|
|
1050
|
-
};
|
|
1051
|
-
}
|
|
1052
|
-
if (hasTimedOut) {
|
|
1053
|
-
log.warn(`\u274C Poll timed out after ${pollTimeout / 1e3}s. Aborting...`);
|
|
1054
|
-
return {
|
|
1055
|
-
abortReason: "poll-timed-out",
|
|
1056
|
-
httpStatus: undefined,
|
|
1057
|
-
outcome: "aborted"
|
|
1058
|
-
};
|
|
1059
|
-
}
|
|
1060
|
-
if (runStage === "initializing") {
|
|
1061
|
-
log.info(`\u23F3 Run is in progress... ${urlInfo}`);
|
|
1062
|
-
await sleep(runInProgressInterval);
|
|
1063
|
-
} else if (runStage === "underReview") {
|
|
1064
|
-
log.info(`\u{1F575}\uFE0F Run is under review... ${urlInfo}`);
|
|
1065
|
-
await sleep(runUnderReviewInterval);
|
|
1066
|
-
} else throw Error(`Unexpected run stage: ${runStage}`);
|
|
1067
|
-
}
|
|
1068
|
-
log.warn(`\u274C Poll timed out after ${pollTimeout / 1e3}s. Aborting...`);
|
|
1069
|
-
return {
|
|
1070
|
-
abortReason: "poll-timed-out",
|
|
1071
|
-
httpStatus: undefined,
|
|
1072
|
-
outcome: "aborted"
|
|
1073
|
-
};
|
|
1074
|
-
}
|
|
1075
|
-
__name(pollCiGreenlightStatus, "pollCiGreenlightStatus");
|
|
1076
|
-
|
|
1077
|
-
// src/lib/api/graphql.ts
|
|
1078
|
-
var GraphQLBadResponseError = class GraphQLBadResponseError2 extends Error {
|
|
1079
|
-
static {
|
|
1080
|
-
__name(this, "GraphQLBadResponseError");
|
|
1081
|
-
}
|
|
1082
|
-
constructor(message) {
|
|
1083
|
-
super(message);
|
|
1084
|
-
this.name = "GraphQLBadResponseError";
|
|
1085
|
-
}
|
|
1086
|
-
};
|
|
1087
|
-
function mapErrorCodeToAbortReason({ errorCode, log }) {
|
|
1088
|
-
switch (errorCode) {
|
|
1089
|
-
case "BAD_USER_INPUT":
|
|
1090
|
-
return "invalid-input";
|
|
1091
|
-
case "FORBIDDEN":
|
|
1092
|
-
return "forbidden";
|
|
1093
|
-
case "INTERNAL":
|
|
1094
|
-
return "server-error";
|
|
1095
|
-
case "UNAUTHENTICATED":
|
|
1096
|
-
return "unauthenticated";
|
|
1097
|
-
default:
|
|
1098
|
-
log.error(`Unknown error code. ${errorCode}`);
|
|
1099
|
-
return "server-error";
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
__name(mapErrorCodeToAbortReason, "mapErrorCodeToAbortReason");
|
|
1103
|
-
async function qawolfGraphql({ apiConfig: { apiKey, serviceBase, userAgent }, deps: { fetch: localFetch, log }, name, query: queryGql, variables }) {
|
|
1104
|
-
try {
|
|
1105
|
-
const response = await localFetch(new URL(`/api/graphql`, serviceBase), {
|
|
1106
|
-
body: JSON.stringify({
|
|
1107
|
-
query: queryGql,
|
|
1108
|
-
variables
|
|
1109
|
-
}),
|
|
1110
|
-
headers: {
|
|
1111
|
-
Authorization: `Bearer ${apiKey}`,
|
|
1112
|
-
"Content-Type": "application/json",
|
|
1113
|
-
"User-Agent": userAgent
|
|
1114
|
-
},
|
|
1115
|
-
method: "post"
|
|
1116
|
-
});
|
|
1117
|
-
let rawBody;
|
|
1118
|
-
try {
|
|
1119
|
-
rawBody = await response.json();
|
|
1120
|
-
} catch (e) {
|
|
1121
|
-
throw new GraphQLBadResponseError(`[GraphQL] Unexpected response schema. Not valid JSON body.`);
|
|
1122
|
-
}
|
|
1123
|
-
if ("errors" in rawBody) {
|
|
1124
|
-
for (const error of rawBody.errors) log.warn(`\u274C [GraphQL] error: ${error.message}`);
|
|
1125
|
-
const firstError = rawBody.errors[0];
|
|
1126
|
-
const eventId = firstError?.extensions?.eventId;
|
|
1127
|
-
const errorCode = firstError?.extensions?.code;
|
|
1128
|
-
return {
|
|
1129
|
-
abortReason: mapErrorCodeToAbortReason({
|
|
1130
|
-
errorCode,
|
|
1131
|
-
log
|
|
1132
|
-
}),
|
|
1133
|
-
eventId,
|
|
1134
|
-
isGqlError: true
|
|
1135
|
-
};
|
|
1136
|
-
}
|
|
1137
|
-
if (!("data" in rawBody)) {
|
|
1138
|
-
throw new GraphQLBadResponseError(`[GraphQL] Unexpected response schema. Missing 'data' in response body. This is a bug.`);
|
|
1139
|
-
}
|
|
1140
|
-
if (!(name in rawBody.data)) {
|
|
1141
|
-
throw new GraphQLBadResponseError(`[GraphQL] Unexpected response schema. Missing 'data.${name}' in response body. This is a bug.`);
|
|
1142
|
-
}
|
|
1143
|
-
return {
|
|
1144
|
-
isGqlError: false,
|
|
1145
|
-
responseBody: rawBody.data[name]
|
|
1146
|
-
};
|
|
1147
|
-
} catch (e) {
|
|
1148
|
-
if (e instanceof GraphQLBadResponseError) throw e;
|
|
1149
|
-
log.error(`\u274C [GraphQL] network error: ${e instanceof Error ? e.message : e}`);
|
|
1150
|
-
return {
|
|
1151
|
-
abortReason: "network-error",
|
|
1152
|
-
isGqlError: true
|
|
1153
|
-
};
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
__name(qawolfGraphql, "qawolfGraphql");
|
|
1157
|
-
function logGraphQLError({ log, methodName, payload }) {
|
|
1158
|
-
const eventIdSuffix = payload.eventId ? ` (Event ID: ${payload.eventId})` : "";
|
|
1159
|
-
switch (payload.abortReason) {
|
|
1160
|
-
case "forbidden":
|
|
1161
|
-
log.error(`\u274C [${methodName}] Forbidden. Aborting${eventIdSuffix}`);
|
|
1162
|
-
break;
|
|
1163
|
-
case "invalid-input":
|
|
1164
|
-
log.error(`\u274C [${methodName}] Bad GraphQL input. This is a bug. Aborting${eventIdSuffix}`);
|
|
1165
|
-
break;
|
|
1166
|
-
case "network-error":
|
|
1167
|
-
log.error(`\u274C [${methodName}] Network error. Aborting${eventIdSuffix}`);
|
|
1168
|
-
break;
|
|
1169
|
-
case "server-error":
|
|
1170
|
-
log.error(`\u274C [${methodName}] Server error. Aborting${eventIdSuffix}`);
|
|
1171
|
-
break;
|
|
1172
|
-
case "unauthenticated":
|
|
1173
|
-
log.error(`\u274C [${methodName}] Unauthenticated. Aborting${eventIdSuffix}`);
|
|
1174
|
-
break;
|
|
1175
|
-
default:
|
|
1176
|
-
payload.abortReason;
|
|
1177
|
-
log.error(`\u274C [${methodName}] Unknown error. ${payload.abortReason} This is a bug${eventIdSuffix}`);
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1180
|
-
__name(logGraphQLError, "logGraphQLError");
|
|
1181
|
-
|
|
1182
|
-
// src/lib/api/notify-vcs-branch-merge-canceled-mutation.ts
|
|
1183
|
-
var mutationName = "notifyVCSBranchMergeCanceled";
|
|
1184
|
-
var mutationGql = `
|
|
1185
|
-
mutation NotifyVCSBranchMergeCanceled($headEnvironmentAlias: String!) {
|
|
1186
|
-
${mutationName}(headEnvironmentAlias: $headEnvironmentAlias) {
|
|
1187
|
-
outcome
|
|
1188
|
-
failureCode
|
|
1189
|
-
failureDetails
|
|
1190
|
-
}
|
|
1191
|
-
}`;
|
|
1192
|
-
async function callNotifyVCSBranchMergeCanceledMutation(deps, apiConfig, { headEnvironmentAlias }) {
|
|
1193
|
-
return qawolfGraphql({
|
|
1194
|
-
apiConfig,
|
|
1195
|
-
deps,
|
|
1196
|
-
name: mutationName,
|
|
1197
|
-
query: mutationGql,
|
|
1198
|
-
variables: {
|
|
1199
|
-
headEnvironmentAlias
|
|
1200
|
-
}
|
|
1201
|
-
});
|
|
1202
|
-
}
|
|
1203
|
-
__name(callNotifyVCSBranchMergeCanceledMutation, "callNotifyVCSBranchMergeCanceledMutation");
|
|
1204
|
-
|
|
1205
|
-
// src/lib/sdk/domain/vcsBranchTesting/lib/domain-failure.ts
|
|
1206
|
-
function domainFailureToAbortResult({ log, methodName, result }) {
|
|
1207
|
-
switch (result.failureCode) {
|
|
1208
|
-
case "base-environment-not-found":
|
|
1209
|
-
log.error(`\u274C [${methodName}] Base environment not found. Aborting.`);
|
|
1210
|
-
return {
|
|
1211
|
-
abortReason: result.failureCode,
|
|
1212
|
-
outcome: "aborted"
|
|
1213
|
-
};
|
|
1214
|
-
case "base-trigger-not-found":
|
|
1215
|
-
log.error(`\u274C [${methodName}] Base trigger not found. A QA Wolf representative should set this up for you. Aborting.`);
|
|
1216
|
-
return {
|
|
1217
|
-
abortReason: result.failureCode,
|
|
1218
|
-
outcome: "aborted"
|
|
1219
|
-
};
|
|
1220
|
-
case "head-environment-not-found":
|
|
1221
|
-
log.error(`\u274C [${methodName}] Head environment not found. Aborting.`);
|
|
1222
|
-
return {
|
|
1223
|
-
abortReason: result.failureCode,
|
|
1224
|
-
outcome: "aborted"
|
|
1225
|
-
};
|
|
1226
|
-
case "head-trigger-not-found":
|
|
1227
|
-
log.error(`\u274C [${methodName}] Head trigger not found. Aborting.`);
|
|
1228
|
-
return {
|
|
1229
|
-
abortReason: result.failureCode,
|
|
1230
|
-
outcome: "aborted"
|
|
1231
|
-
};
|
|
1232
|
-
case "invalid-input":
|
|
1233
|
-
log.error(`\u274C [${methodName}] Invalid input: ${result.failureDetails} Aborting.`);
|
|
1234
|
-
return {
|
|
1235
|
-
abortReason: result.failureCode,
|
|
1236
|
-
outcome: "aborted"
|
|
1237
|
-
};
|
|
1238
|
-
case "non-ephemeral-head-environment-violation":
|
|
1239
|
-
log.error(`\u274C [${methodName}] Non-ephemeral head environment violation. Aborting.`);
|
|
1240
|
-
return {
|
|
1241
|
-
abortReason: result.failureCode,
|
|
1242
|
-
outcome: "aborted"
|
|
1243
|
-
};
|
|
1244
|
-
case "repository-not-found":
|
|
1245
|
-
log.error(`\u274C [${methodName}] Repository not found: ${result.failureDetails} Aborting.`);
|
|
1246
|
-
return {
|
|
1247
|
-
abortReason: result.failureCode,
|
|
1248
|
-
outcome: "aborted"
|
|
1249
|
-
};
|
|
1250
|
-
case "run-creation-failed":
|
|
1251
|
-
log.error(`\u274C [${methodName}] Run creation failed: ${result.failureDetails}. Aborting.`);
|
|
1252
|
-
return {
|
|
1253
|
-
abortReason: result.failureCode,
|
|
1254
|
-
outcome: "aborted"
|
|
1255
|
-
};
|
|
1256
|
-
default:
|
|
1257
|
-
result.failureCode;
|
|
1258
|
-
throw Error(`[${methodName}] Unreachable code detected. This is a bug. ${result.failureCode}`);
|
|
1259
|
-
}
|
|
1260
|
-
}
|
|
1261
|
-
__name(domainFailureToAbortResult, "domainFailureToAbortResult");
|
|
1262
|
-
|
|
1263
|
-
// src/lib/sdk/domain/vcsBranchTesting/lib/retry.ts
|
|
1264
|
-
async function retryWithExponentialBackoff({ log, maxRetries, methodName, retriableAbortReasons, runOnce }) {
|
|
1265
|
-
let attemptNumber = 0;
|
|
1266
|
-
let result;
|
|
1267
|
-
do {
|
|
1268
|
-
attemptNumber++;
|
|
1269
|
-
log.info(`\u{1F501} [${methodName}] Attempt ${attemptNumber}/${maxRetries + 1}.`);
|
|
1270
|
-
result = await runOnce();
|
|
1271
|
-
if (result.outcome === "success" || !retriableAbortReasons.includes(result.abortReason)) return result;
|
|
1272
|
-
if (attemptNumber >= maxRetries + 1) return result;
|
|
1273
|
-
const backoffMs = getBackoffMs(attemptNumber);
|
|
1274
|
-
const secondsApproximation = (backoffMs / 1e3).toFixed(1);
|
|
1275
|
-
log.warn(`\u23F3 [${methodName}] Retrying in ${secondsApproximation} seconds.`);
|
|
1276
|
-
await sleep(backoffMs);
|
|
1277
|
-
} while (true);
|
|
1278
|
-
}
|
|
1279
|
-
__name(retryWithExponentialBackoff, "retryWithExponentialBackoff");
|
|
1280
|
-
|
|
1281
|
-
// src/lib/sdk/domain/vcsBranchTesting/notify-vcs-branch-merge-canceled.ts
|
|
1282
|
-
async function runNotifyVCSMergeCanceledOnce(deps, apiConfig, input) {
|
|
1283
|
-
const log = deps.log;
|
|
1284
|
-
const { headEnvironmentAlias } = input;
|
|
1285
|
-
const resp = await callNotifyVCSBranchMergeCanceledMutation(deps, apiConfig, {
|
|
1286
|
-
headEnvironmentAlias
|
|
1287
|
-
});
|
|
1288
|
-
if (resp.isGqlError) {
|
|
1289
|
-
logGraphQLError({
|
|
1290
|
-
log,
|
|
1291
|
-
methodName: "notifyVCSBranchMergeCanceled",
|
|
1292
|
-
payload: resp
|
|
1293
|
-
});
|
|
1294
|
-
return {
|
|
1295
|
-
abortReason: resp.abortReason,
|
|
1296
|
-
eventId: resp.eventId,
|
|
1297
|
-
outcome: "aborted"
|
|
1298
|
-
};
|
|
1299
|
-
}
|
|
1300
|
-
const result = resp.responseBody;
|
|
1301
|
-
if (result.outcome === "success") {
|
|
1302
|
-
log.info(`\u2705 [notifyVCSBranchMergeCanceled] Successfully notified the CI system that the merge was canceled.`);
|
|
1303
|
-
return {
|
|
1304
|
-
outcome: "success"
|
|
1305
|
-
};
|
|
1306
|
-
}
|
|
1307
|
-
result.outcome;
|
|
1308
|
-
return domainFailureToAbortResult({
|
|
1309
|
-
log,
|
|
1310
|
-
methodName: "notifyVCSBranchMergeCanceled",
|
|
1311
|
-
result
|
|
1312
|
-
});
|
|
1313
|
-
}
|
|
1314
|
-
__name(runNotifyVCSMergeCanceledOnce, "runNotifyVCSMergeCanceledOnce");
|
|
1315
|
-
async function notifyVCSBranchMergeCanceled(deps, apiConfig, input) {
|
|
1316
|
-
const { maxRetries = 10 } = input;
|
|
1317
|
-
return retryWithExponentialBackoff({
|
|
1318
|
-
log: deps.log,
|
|
1319
|
-
maxRetries,
|
|
1320
|
-
methodName: "notifyVCSBranchMergeCanceled",
|
|
1321
|
-
retriableAbortReasons: [
|
|
1322
|
-
"network-error",
|
|
1323
|
-
"server-error"
|
|
1324
|
-
],
|
|
1325
|
-
runOnce: /* @__PURE__ */ __name(() => runNotifyVCSMergeCanceledOnce(deps, apiConfig, input), "runOnce")
|
|
1326
|
-
});
|
|
1327
|
-
}
|
|
1328
|
-
__name(notifyVCSBranchMergeCanceled, "notifyVCSBranchMergeCanceled");
|
|
1329
|
-
|
|
1330
|
-
// src/lib/api/notify-vcs-branch-merge-completed-mutation.ts
|
|
1331
|
-
var mutationName2 = "notifyVCSBranchMergeCompleted";
|
|
1332
|
-
var mutationGql2 = `
|
|
1333
|
-
mutation NotifyVCSBranchMergeCompleted($baseEnvironmentAlias: String, $headEnvironmentAlias: String!) {
|
|
1334
|
-
${mutationName2}(baseEnvironmentAlias: $baseEnvironmentAlias, headEnvironmentAlias: $headEnvironmentAlias) {
|
|
1335
|
-
outcome
|
|
1336
|
-
failureCode
|
|
1337
|
-
failureDetails
|
|
1338
|
-
}
|
|
1339
|
-
}`;
|
|
1340
|
-
async function callNotifyVCSBranchMergeCompletedMutation(deps, apiConfig, { baseEnvironmentAlias, headEnvironmentAlias }) {
|
|
1341
|
-
return qawolfGraphql({
|
|
1342
|
-
apiConfig,
|
|
1343
|
-
deps,
|
|
1344
|
-
name: mutationName2,
|
|
1345
|
-
query: mutationGql2,
|
|
1346
|
-
variables: {
|
|
1347
|
-
baseEnvironmentAlias: baseEnvironmentAlias ?? null,
|
|
1348
|
-
headEnvironmentAlias
|
|
1349
|
-
}
|
|
1350
|
-
});
|
|
1351
|
-
}
|
|
1352
|
-
__name(callNotifyVCSBranchMergeCompletedMutation, "callNotifyVCSBranchMergeCompletedMutation");
|
|
1353
|
-
|
|
1354
|
-
// src/lib/sdk/domain/vcsBranchTesting/notify-vcs-branch-merge-completed.ts
|
|
1355
|
-
async function runNotifyVCSBranchMergeCompletedOnce(deps, apiConfig, input) {
|
|
1356
|
-
const log = deps.log;
|
|
1357
|
-
const { baseEnvironmentsMapping, baseVcsBranch: vcsBaseBranch } = input;
|
|
1358
|
-
const baseEnvironmentAlias = baseEnvironmentsMapping?.find((mapping) => mapping.vcsBranch === vcsBaseBranch)?.environmentAlias;
|
|
1359
|
-
if (baseEnvironmentAlias === undefined) {
|
|
1360
|
-
log.info(`\u2139\uFE0F [notifyVCSBranchMergeCompleted] Could not find a base environment for VCS branch '${vcsBaseBranch}'. Fall back to use the default base environment`);
|
|
1361
|
-
}
|
|
1362
|
-
const resp = await callNotifyVCSBranchMergeCompletedMutation(deps, apiConfig, {
|
|
1363
|
-
baseEnvironmentAlias,
|
|
1364
|
-
headEnvironmentAlias: input.headEnvironmentAlias
|
|
1365
|
-
});
|
|
1366
|
-
if (resp.isGqlError) {
|
|
1367
|
-
logGraphQLError({
|
|
1368
|
-
log,
|
|
1369
|
-
methodName: "notifyVCSBranchMergeCompleted",
|
|
1370
|
-
payload: resp
|
|
1371
|
-
});
|
|
1372
|
-
return {
|
|
1373
|
-
abortReason: resp.abortReason,
|
|
1374
|
-
eventId: resp.eventId,
|
|
1375
|
-
outcome: "aborted"
|
|
1376
|
-
};
|
|
1377
|
-
}
|
|
1378
|
-
const result = resp.responseBody;
|
|
1379
|
-
if (result.outcome === "success") {
|
|
1380
|
-
log.info(`\u2705 [notifyVCSBranchMergeCompleted] Successfully notified the CI system that the merge was completed.`);
|
|
1381
|
-
return {
|
|
1382
|
-
outcome: "success"
|
|
1383
|
-
};
|
|
1384
|
-
}
|
|
1385
|
-
result.outcome;
|
|
1386
|
-
return domainFailureToAbortResult({
|
|
1387
|
-
log,
|
|
1388
|
-
methodName: "notifyVCSBranchMergeCompleted",
|
|
1389
|
-
result
|
|
1390
|
-
});
|
|
1391
|
-
}
|
|
1392
|
-
__name(runNotifyVCSBranchMergeCompletedOnce, "runNotifyVCSBranchMergeCompletedOnce");
|
|
1393
|
-
async function notifyVCSBranchMergeCompleted(deps, apiConfig, input) {
|
|
1394
|
-
const { maxRetries = 10 } = input;
|
|
1395
|
-
return retryWithExponentialBackoff({
|
|
1396
|
-
log: deps.log,
|
|
1397
|
-
maxRetries,
|
|
1398
|
-
methodName: "notifyVCSBranchMergeCompleted",
|
|
1399
|
-
retriableAbortReasons: [
|
|
1400
|
-
"network-error",
|
|
1401
|
-
"server-error"
|
|
1402
|
-
],
|
|
1403
|
-
runOnce: /* @__PURE__ */ __name(() => runNotifyVCSBranchMergeCompletedOnce(deps, apiConfig, input), "runOnce")
|
|
1404
|
-
});
|
|
1405
|
-
}
|
|
1406
|
-
__name(notifyVCSBranchMergeCompleted, "notifyVCSBranchMergeCompleted");
|
|
1407
|
-
|
|
1408
|
-
// src/lib/api/notify-vcs-branch-build-deployed-mutation.ts
|
|
1409
|
-
var mutationName3 = "notifyVCSBranchBuildDeployed";
|
|
1410
|
-
var mutationGql3 = `
|
|
1411
|
-
mutation NotifyVCSBranchBuildDeployed(
|
|
1412
|
-
$headVcsCommitId: String!,
|
|
1413
|
-
$baseVcsBranch: String,
|
|
1414
|
-
$headEnvironmentVariablesJson: String!,
|
|
1415
|
-
$baseEnvironmentAlias: String,
|
|
1416
|
-
$headEnvironmentAlias: String!,
|
|
1417
|
-
$concurrencyLimit: Int,
|
|
1418
|
-
$headEnvironmentName: String,
|
|
1419
|
-
$headVcsBranch: String,
|
|
1420
|
-
$headVcsCommitUrl: String,
|
|
1421
|
-
$pullOrMergeRequestNumber: Int
|
|
1422
|
-
) {
|
|
1423
|
-
${mutationName3}(
|
|
1424
|
-
headVcsCommitId: $headVcsCommitId,
|
|
1425
|
-
baseVcsBranch: $baseVcsBranch,
|
|
1426
|
-
headEnvironmentVariablesJson: $headEnvironmentVariablesJson,
|
|
1427
|
-
baseEnvironmentAlias: $baseEnvironmentAlias,
|
|
1428
|
-
headEnvironmentAlias: $headEnvironmentAlias,
|
|
1429
|
-
concurrencyLimit: $concurrencyLimit,
|
|
1430
|
-
headEnvironmentName: $headEnvironmentName,
|
|
1431
|
-
headVcsBranch: $headVcsBranch,
|
|
1432
|
-
headVcsCommitUrl: $headVcsCommitUrl,
|
|
1433
|
-
pullOrMergeRequestNumber: $pullOrMergeRequestNumber
|
|
1434
|
-
) {
|
|
1435
|
-
outcome
|
|
1436
|
-
codeHostingServiceInstallationPlatform
|
|
1437
|
-
failureCode
|
|
1438
|
-
failureDetails
|
|
1439
|
-
runId
|
|
1440
|
-
}
|
|
1441
|
-
}`;
|
|
1442
|
-
async function callNotifyVCSBranchBuildDeployedMutation(deps, apiConfig, { baseEnvironmentAlias, baseVcsBranch, concurrencyLimit, headEnvironmentAlias, headEnvironmentName, headEnvironmentVariables, headVcsBranch, headVcsCommitId, headVcsCommitUrl, pullOrMergeRequestNumber }) {
|
|
1443
|
-
return qawolfGraphql({
|
|
1444
|
-
apiConfig,
|
|
1445
|
-
deps,
|
|
1446
|
-
name: mutationName3,
|
|
1447
|
-
query: mutationGql3,
|
|
1448
|
-
variables: {
|
|
1449
|
-
baseEnvironmentAlias: baseEnvironmentAlias ?? null,
|
|
1450
|
-
baseVcsBranch: baseVcsBranch ?? null,
|
|
1451
|
-
concurrencyLimit: concurrencyLimit ?? null,
|
|
1452
|
-
headEnvironmentAlias,
|
|
1453
|
-
headEnvironmentName,
|
|
1454
|
-
headEnvironmentVariablesJson: JSON.stringify(headEnvironmentVariables),
|
|
1455
|
-
headVcsBranch: headVcsBranch ?? null,
|
|
1456
|
-
headVcsCommitId,
|
|
1457
|
-
headVcsCommitUrl: headVcsCommitUrl ?? null,
|
|
1458
|
-
pullOrMergeRequestNumber: pullOrMergeRequestNumber ?? null
|
|
1459
|
-
}
|
|
1460
|
-
});
|
|
1461
|
-
}
|
|
1462
|
-
__name(callNotifyVCSBranchBuildDeployedMutation, "callNotifyVCSBranchBuildDeployedMutation");
|
|
1463
|
-
|
|
1464
|
-
// src/lib/sdk/domain/vcsBranchTesting/notifyVCSBranchBuildDeployed/index.ts
|
|
1465
|
-
async function runNotifyVCSBranchBuildDeployedOnce(deps, apiConfig, input) {
|
|
1466
|
-
const { baseEnvironmentsMapping, baseVcsBranch, concurrencyLimit, headEnvironmentAlias, headEnvironmentName, headEnvironmentVariables, headVcsBranch, headVcsCommitId, headVcsCommitUrl, pullOrMergeRequestNumber } = input;
|
|
1467
|
-
const log = deps.log;
|
|
1468
|
-
const baseEnvironmentAlias = baseEnvironmentsMapping?.find((mapping) => mapping.vcsBranch === baseVcsBranch)?.environmentAlias;
|
|
1469
|
-
let finalConcurrencyLimit = concurrencyLimit;
|
|
1470
|
-
if (typeof concurrencyLimit === "number") {
|
|
1471
|
-
if (concurrencyLimit === Infinity) finalConcurrencyLimit = 0;
|
|
1472
|
-
else if (Number.isNaN(concurrencyLimit) || !Number.isInteger(concurrencyLimit)) {
|
|
1473
|
-
log.error(`\u274C [notifyVCSBranchBuildDeployed] Invalid concurrency limit '${concurrencyLimit}'. Must be a positive integer.`);
|
|
1474
|
-
return {
|
|
1475
|
-
abortReason: "invalid-input",
|
|
1476
|
-
outcome: "aborted"
|
|
1477
|
-
};
|
|
1478
|
-
}
|
|
1479
|
-
if (concurrencyLimit < 0) {
|
|
1480
|
-
log.error(`\u274C [notifyVCSBranchBuildDeployed] Invalid concurrency limit '${concurrencyLimit}'. Must be a positive integer.`);
|
|
1481
|
-
return {
|
|
1482
|
-
abortReason: "invalid-input",
|
|
1483
|
-
outcome: "aborted"
|
|
1484
|
-
};
|
|
1485
|
-
}
|
|
1486
|
-
}
|
|
1487
|
-
const resp = await callNotifyVCSBranchBuildDeployedMutation(deps, apiConfig, {
|
|
1488
|
-
baseEnvironmentAlias,
|
|
1489
|
-
baseVcsBranch,
|
|
1490
|
-
concurrencyLimit: finalConcurrencyLimit,
|
|
1491
|
-
headEnvironmentAlias,
|
|
1492
|
-
headEnvironmentName,
|
|
1493
|
-
headEnvironmentVariables,
|
|
1494
|
-
headVcsBranch,
|
|
1495
|
-
headVcsCommitId,
|
|
1496
|
-
headVcsCommitUrl,
|
|
1497
|
-
pullOrMergeRequestNumber
|
|
1498
|
-
});
|
|
1499
|
-
if (resp.isGqlError) {
|
|
1500
|
-
logGraphQLError({
|
|
1501
|
-
log,
|
|
1502
|
-
methodName: "notifyVCSBranchBuildDeployed",
|
|
1503
|
-
payload: resp
|
|
1504
|
-
});
|
|
1505
|
-
return {
|
|
1506
|
-
abortReason: resp.abortReason,
|
|
1507
|
-
eventId: resp.eventId,
|
|
1508
|
-
outcome: "aborted"
|
|
1509
|
-
};
|
|
1510
|
-
}
|
|
1511
|
-
const result = resp.responseBody;
|
|
1512
|
-
if (result.outcome === "success") {
|
|
1513
|
-
const codeHostingInfo = result.codeHostingServiceInstallationPlatform == null ? "" : `, and code hosting service integration '${result.codeHostingServiceInstallationPlatform}'.`;
|
|
1514
|
-
log.info(`\u2705 [notifyVCSBranchBuildDeployed] Success. Run was deployed with ID: '${result.runId}'${codeHostingInfo}`);
|
|
1515
|
-
return {
|
|
1516
|
-
codeHostingServiceInstallationType: result.codeHostingServiceInstallationPlatform ?? undefined,
|
|
1517
|
-
outcome: "success",
|
|
1518
|
-
runId: result.runId
|
|
1519
|
-
};
|
|
1520
|
-
}
|
|
1521
|
-
result.outcome;
|
|
1522
|
-
return domainFailureToAbortResult({
|
|
1523
|
-
log,
|
|
1524
|
-
methodName: "notifyVCSBranchBuildDeployed",
|
|
1525
|
-
result
|
|
1526
|
-
});
|
|
1527
|
-
}
|
|
1528
|
-
__name(runNotifyVCSBranchBuildDeployedOnce, "runNotifyVCSBranchBuildDeployedOnce");
|
|
1529
|
-
async function notifyVCSBranchBuildDeployed(deps, apiConfig, input) {
|
|
1530
|
-
const { maxRetries = 10 } = input;
|
|
1531
|
-
return retryWithExponentialBackoff({
|
|
1532
|
-
log: deps.log,
|
|
1533
|
-
maxRetries,
|
|
1534
|
-
methodName: "notifyVCSBranchBuildDeployed",
|
|
1535
|
-
retriableAbortReasons: [
|
|
1536
|
-
"network-error",
|
|
1537
|
-
"server-error",
|
|
1538
|
-
"run-creation-failed"
|
|
1539
|
-
],
|
|
1540
|
-
runOnce: /* @__PURE__ */ __name(() => runNotifyVCSBranchBuildDeployedOnce(deps, apiConfig, input), "runOnce")
|
|
1541
|
-
});
|
|
1542
|
-
}
|
|
1543
|
-
__name(notifyVCSBranchBuildDeployed, "notifyVCSBranchBuildDeployed");
|
|
1544
|
-
function pullRequestDetailsToEnvironmentAlias({ codeHostingServiceOrganization, codeHostingServiceRepositoryName, pullRequestIdentifier }) {
|
|
1545
|
-
return arbitraryStringToEnvironmentAlias(`${codeHostingServiceOrganization}-${codeHostingServiceRepositoryName}-pr-${pullRequestIdentifier}`);
|
|
1546
|
-
}
|
|
1547
|
-
__name(pullRequestDetailsToEnvironmentAlias, "pullRequestDetailsToEnvironmentAlias");
|
|
1548
|
-
function arbitraryStringToEnvironmentAlias(arbitraryString) {
|
|
1549
|
-
return slugify(arbitraryString, {
|
|
1550
|
-
lower: true
|
|
1551
|
-
});
|
|
1552
|
-
}
|
|
1553
|
-
__name(arbitraryStringToEnvironmentAlias, "arbitraryStringToEnvironmentAlias");
|
|
1554
|
-
|
|
1555
|
-
// src/lib/sdk/domain/vcsBranchTesting/index.ts
|
|
1556
|
-
function makeVCSBranchTestingSDK({ apiKey, serviceBase = defaultServiceBase, userAgent = defaultUserAgent }, { fetch = defaultFetch, log = defaultLogDriver } = {}) {
|
|
1557
|
-
const deps = {
|
|
1558
|
-
fetch,
|
|
1559
|
-
log
|
|
1560
|
-
};
|
|
1561
|
-
const apiConfig = {
|
|
1562
|
-
apiKey,
|
|
1563
|
-
serviceBase,
|
|
1564
|
-
userAgent
|
|
1565
|
-
};
|
|
1566
|
-
return {
|
|
1567
|
-
notifyVCSBranchBuildDeployed: notifyVCSBranchBuildDeployed.bind(null, deps, apiConfig),
|
|
1568
|
-
notifyVCSBranchMergeCanceled: notifyVCSBranchMergeCanceled.bind(null, deps, apiConfig),
|
|
1569
|
-
notifyVCSBranchMergeCompleted: notifyVCSBranchMergeCompleted.bind(null, deps, apiConfig)
|
|
1570
|
-
};
|
|
1571
|
-
}
|
|
1572
|
-
__name(makeVCSBranchTestingSDK, "makeVCSBranchTestingSDK");
|
|
1573
|
-
|
|
1574
|
-
// src/lib/sdk/index.ts
|
|
1575
|
-
function makeQaWolfSdk({ apiKey, serviceBase = defaultServiceBase, userAgent = defaultUserAgent }, { fetch = defaultFetch, log = defaultLogDriver } = {}) {
|
|
1576
|
-
if (typeof fetch !== "function") {
|
|
1577
|
-
throw Error(`QA Wolf CI-SDK requires fetch to be defined. Make sure you are using NodeJS 18+, OR pass a fetch polyfill to the makeQaWolfSdk function.
|
|
1578
|
-
We recommend 'undici' package for that purpose. See the Requirement section of our README for more guidance.`);
|
|
1579
|
-
}
|
|
1580
|
-
const deps = {
|
|
1581
|
-
// Versions of fetch may have different default timeouts. For consistency, we explicitly set it to 60 seconds here.
|
|
1582
|
-
fetch: buildFetchWithTimeout(fetch, 6e4),
|
|
1583
|
-
log
|
|
1584
|
-
};
|
|
1585
|
-
const apiConfig = {
|
|
1586
|
-
apiKey,
|
|
1587
|
-
serviceBase,
|
|
1588
|
-
userAgent
|
|
1589
|
-
};
|
|
1590
|
-
return {
|
|
1591
|
-
attemptNotifyDeploy: attemptNotifyDeploy.bind(null, deps, apiConfig),
|
|
1592
|
-
/**
|
|
1593
|
-
* @deprecated Use `experimental_vcsBranchTesting` instead.
|
|
1594
|
-
*/
|
|
1595
|
-
experimental_removeEnvironment: removeEnvironment.bind(null, deps, apiConfig),
|
|
1596
|
-
/**
|
|
1597
|
-
* @deprecated Use `experimental_vcsBranchTesting` instead.
|
|
1598
|
-
*/
|
|
1599
|
-
experimental_testPreview: testPreview.bind(null, deps, apiConfig),
|
|
1600
|
-
experimental_vcsBranchTesting: makeVCSBranchTestingSDK(apiConfig, deps),
|
|
1601
|
-
generateSignedUrlForRunInputsExecutablesStorage: generateSignedUrlForRunInputsExecutablesStorage.bind(null, deps, apiConfig),
|
|
1602
|
-
generateSignedUrlForTempTeamStorage: generateSignedUrlForTempTeamStorage.bind(null, deps, apiConfig),
|
|
1603
|
-
pollCiGreenlightStatus: pollCiGreenlightStatus.bind(null, deps, apiConfig)
|
|
1604
|
-
};
|
|
1605
|
-
}
|
|
1606
|
-
__name(makeQaWolfSdk, "makeQaWolfSdk");
|
|
1607
|
-
|
|
1608
|
-
export { arbitraryStringToEnvironmentAlias, makeQaWolfSdk, makeVCSBranchTestingSDK, pullRequestDetailsToEnvironmentAlias };
|
|
1609
|
-
//# sourceMappingURL=index.mjs.map
|
|
1610
|
-
//# sourceMappingURL=index.mjs.map
|