screwdriver-api 8.0.144 → 8.0.146
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/package.json +1 -1
- package/plugins/events/create.js +35 -19
- package/plugins/webhooks/helper.js +59 -56
package/package.json
CHANGED
package/plugins/events/create.js
CHANGED
|
@@ -21,7 +21,7 @@ module.exports = () => ({
|
|
|
21
21
|
|
|
22
22
|
handler: async (request, h) => {
|
|
23
23
|
const { buildFactory, jobFactory, eventFactory, pipelineFactory, userFactory } = request.server.app;
|
|
24
|
-
const { buildId, causeMessage, creator, sha } = request.payload;
|
|
24
|
+
const { buildId, causeMessage, creator, sha, startAction } = request.payload;
|
|
25
25
|
const { scmContext, username, scope } = request.auth.credentials;
|
|
26
26
|
const { scm } = eventFactory;
|
|
27
27
|
const { isValidToken } = request.server.plugins.pipelines;
|
|
@@ -67,8 +67,17 @@ module.exports = () => ({
|
|
|
67
67
|
payload.sha = sha;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
// If you specify a parentEventId in the payload, the metadata will be inherited.
|
|
71
|
+
// Therefore, you should not specify a parentEventId in the payload except when using RESTART.
|
|
72
|
+
// Prevents metadata from transferring when Start from a specific event
|
|
70
73
|
if (parentEventId) {
|
|
71
|
-
|
|
74
|
+
// eslint-disable-next-line default-case
|
|
75
|
+
switch (startAction) {
|
|
76
|
+
case 'RESTART_FROM_EVENT':
|
|
77
|
+
case 'RESTART_FROM_BUILD': {
|
|
78
|
+
payload.parentEventId = parentEventId;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
72
81
|
}
|
|
73
82
|
|
|
74
83
|
if (parentBuildId) {
|
|
@@ -240,27 +249,11 @@ module.exports = () => ({
|
|
|
240
249
|
|
|
241
250
|
// If there is parentEvent, pass workflowGraph, meta and sha to payload
|
|
242
251
|
// Skip PR, for PR builds, we should always start from latest commit
|
|
243
|
-
if (
|
|
252
|
+
if (parentEventId) {
|
|
244
253
|
const parentEvent = await eventFactory.get(parentEventId);
|
|
245
|
-
let mergedParameters = payload.meta.parameters || {};
|
|
246
254
|
|
|
247
255
|
payload.baseBranch = parentEvent.baseBranch || null;
|
|
248
256
|
|
|
249
|
-
// Merge parameters if they exist in the parent event and not in the payload
|
|
250
|
-
if (!payload.meta.parameters && parentEvent.meta && parentEvent.meta.parameters) {
|
|
251
|
-
mergedParameters = parentEvent.meta.parameters;
|
|
252
|
-
}
|
|
253
|
-
delete payload.meta.parameters;
|
|
254
|
-
|
|
255
|
-
// Copy meta from parent event if payload.meta is empty except for the parameters
|
|
256
|
-
if (Object.keys(payload.meta).length === 0) {
|
|
257
|
-
payload.meta = { ...parentEvent.meta };
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (Object.keys(mergedParameters).length > 0) {
|
|
261
|
-
payload.meta.parameters = mergedParameters;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
257
|
if (!prNum) {
|
|
265
258
|
payload.workflowGraph = parentEvent.workflowGraph;
|
|
266
259
|
payload.sha = parentEvent.sha;
|
|
@@ -269,6 +262,29 @@ module.exports = () => ({
|
|
|
269
262
|
payload.configPipelineSha = parentEvent.configPipelineSha;
|
|
270
263
|
}
|
|
271
264
|
}
|
|
265
|
+
|
|
266
|
+
// eslint-disable-next-line default-case
|
|
267
|
+
switch (startAction) {
|
|
268
|
+
case 'RESTART_FROM_EVENT':
|
|
269
|
+
case 'RESTART_FROM_BUILD': {
|
|
270
|
+
let mergedParameters = payload.meta.parameters || {};
|
|
271
|
+
|
|
272
|
+
// Merge parameters if they exist in the parent event and not in the payload
|
|
273
|
+
if (!payload.meta.parameters && parentEvent.meta && parentEvent.meta.parameters) {
|
|
274
|
+
mergedParameters = parentEvent.meta.parameters;
|
|
275
|
+
}
|
|
276
|
+
delete payload.meta.parameters;
|
|
277
|
+
|
|
278
|
+
// Copy meta from parent event if payload.meta is empty except for the parameters
|
|
279
|
+
if (Object.keys(payload.meta).length === 0) {
|
|
280
|
+
payload.meta = { ...parentEvent.meta };
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (Object.keys(mergedParameters).length > 0) {
|
|
284
|
+
payload.meta.parameters = mergedParameters;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
272
288
|
}
|
|
273
289
|
|
|
274
290
|
const event = await createEvent(payload, request.server);
|
|
@@ -1413,77 +1413,80 @@ async function startHookEvent(request, h, webhookConfig) {
|
|
|
1413
1413
|
const { type, hookId, username, scmContext, ref, checkoutUrl, action, prNum } = webhookConfig;
|
|
1414
1414
|
|
|
1415
1415
|
parsedHookId = hookId;
|
|
1416
|
+
webhookConfig.requestCache = new Map();
|
|
1416
1417
|
|
|
1417
1418
|
try {
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
// if skip ci then don't return
|
|
1424
|
-
if (action !== 'tag' && action !== 'release' && ignoreUser && ignoreUser.length !== 0 && !skipMessage) {
|
|
1425
|
-
const commitAuthors =
|
|
1426
|
-
Array.isArray(webhookConfig.commitAuthors) && webhookConfig.commitAuthors.length !== 0
|
|
1427
|
-
? webhookConfig.commitAuthors
|
|
1428
|
-
: [username];
|
|
1429
|
-
const validCommitAuthors = commitAuthors.filter(author => !ignoreUser.includes(author));
|
|
1430
|
-
|
|
1431
|
-
if (!validCommitAuthors.length) {
|
|
1432
|
-
message = `Skipping because user ${username} is ignored`;
|
|
1433
|
-
request.log(['webhook', hookId], message);
|
|
1434
|
-
|
|
1435
|
-
return h.response({ message }).code(204);
|
|
1419
|
+
return scm.withRequestCache(webhookConfig.requestCache, async () => {
|
|
1420
|
+
// skipping checks
|
|
1421
|
+
if (/\[(skip ci|ci skip)\]/.test(webhookConfig.lastCommitMessage)) {
|
|
1422
|
+
skipMessage = 'Skipping due to the commit message: [skip ci]';
|
|
1436
1423
|
}
|
|
1437
|
-
}
|
|
1438
1424
|
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1425
|
+
// if skip ci then don't return
|
|
1426
|
+
if (action !== 'tag' && action !== 'release' && ignoreUser && ignoreUser.length !== 0 && !skipMessage) {
|
|
1427
|
+
const commitAuthors =
|
|
1428
|
+
Array.isArray(webhookConfig.commitAuthors) && webhookConfig.commitAuthors.length !== 0
|
|
1429
|
+
? webhookConfig.commitAuthors
|
|
1430
|
+
: [username];
|
|
1431
|
+
const validCommitAuthors = commitAuthors.filter(author => !ignoreUser.includes(author));
|
|
1446
1432
|
|
|
1447
|
-
|
|
1448
|
-
|
|
1433
|
+
if (!validCommitAuthors.length) {
|
|
1434
|
+
message = `Skipping because user ${username} is ignored`;
|
|
1435
|
+
request.log(['webhook', hookId], message);
|
|
1449
1436
|
|
|
1450
|
-
|
|
1451
|
-
|
|
1437
|
+
return h.response({ message }).code(204);
|
|
1438
|
+
}
|
|
1452
1439
|
}
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1440
|
+
|
|
1441
|
+
const token = await obtainScmToken({
|
|
1442
|
+
pluginOptions: webhookConfig.pluginOptions,
|
|
1443
|
+
userFactory,
|
|
1444
|
+
username,
|
|
1457
1445
|
scmContext,
|
|
1458
|
-
|
|
1459
|
-
prNum
|
|
1446
|
+
scm
|
|
1460
1447
|
});
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
scm,
|
|
1448
|
+
|
|
1449
|
+
if (action !== 'release' && action !== 'tag') {
|
|
1450
|
+
let scmUri;
|
|
1451
|
+
|
|
1452
|
+
if (type === 'pr') {
|
|
1453
|
+
scmUri = await scm.parseUrl({ checkoutUrl, token, scmContext });
|
|
1454
|
+
}
|
|
1455
|
+
webhookConfig.changedFiles = await scm.getChangedFiles({
|
|
1456
|
+
webhookConfig,
|
|
1457
|
+
type,
|
|
1467
1458
|
token,
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
scmContext
|
|
1459
|
+
scmContext,
|
|
1460
|
+
scmUri,
|
|
1461
|
+
prNum
|
|
1472
1462
|
});
|
|
1473
|
-
|
|
1474
|
-
|
|
1463
|
+
request.log(['webhook', hookId], `Changed files are ${webhookConfig.changedFiles}`);
|
|
1464
|
+
} else {
|
|
1465
|
+
// The payload has no sha when webhook event is tag or release, so we need to get it.
|
|
1466
|
+
try {
|
|
1467
|
+
webhookConfig.sha = await getCommitRefSha({
|
|
1468
|
+
scm,
|
|
1469
|
+
token,
|
|
1470
|
+
ref,
|
|
1471
|
+
refType: 'tags',
|
|
1472
|
+
checkoutUrl,
|
|
1473
|
+
scmContext
|
|
1474
|
+
});
|
|
1475
|
+
} catch (err) {
|
|
1476
|
+
request.log(['webhook', hookId, 'getCommitRefSha'], err);
|
|
1475
1477
|
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
+
// there is a possibility of scm.getCommitRefSha() is not implemented yet
|
|
1479
|
+
return h.response({ message }).code(204);
|
|
1480
|
+
}
|
|
1478
1481
|
}
|
|
1479
|
-
}
|
|
1480
1482
|
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1483
|
+
if (type === 'pr') {
|
|
1484
|
+
// disregard skip ci for pull request events
|
|
1485
|
+
return pullRequestEvent(webhookConfig.pluginOptions, request, h, webhookConfig, token);
|
|
1486
|
+
}
|
|
1485
1487
|
|
|
1486
|
-
|
|
1488
|
+
return pushEvent(request, h, webhookConfig, skipMessage, token);
|
|
1489
|
+
});
|
|
1487
1490
|
} catch (err) {
|
|
1488
1491
|
logger.error(`[${parsedHookId}]: ${err}`);
|
|
1489
1492
|
|