screwdriver-api 8.0.145 → 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/webhooks/helper.js +59 -56
package/package.json
CHANGED
|
@@ -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
|
|