Tidy up ready for review
This commit is contained in:
parent
1020df5700
commit
92ffb08081
6 changed files with 92 additions and 106 deletions
57
lib/actions-util.js
generated
57
lib/actions-util.js
generated
|
|
@ -107,30 +107,20 @@ var MissingTriggers;
|
|||
MissingTriggers[MissingTriggers["Push"] = 1] = "Push";
|
||||
MissingTriggers[MissingTriggers["PullRequest"] = 2] = "PullRequest";
|
||||
})(MissingTriggers || (MissingTriggers = {}));
|
||||
exports.ErrCheckoutWrongHead = {
|
||||
message: `Git checkout HEAD^2 is no longer necessary. Please remove this line.`,
|
||||
code: "CheckoutWrongHead",
|
||||
};
|
||||
exports.ErrMismatchedBranches = {
|
||||
message: `Please make sure that every branch in on.pull_request is also in on.push so that CodeQL can establish a baseline.`,
|
||||
code: "MismatchedBranches",
|
||||
};
|
||||
exports.ErrMissingHooks = {
|
||||
message: `Please specify on.push and on.pull_request hooks.`,
|
||||
code: "MissingHooks",
|
||||
};
|
||||
exports.ErrMissingPushHook = {
|
||||
message: `Please specify an on.push hook so CodeQL can establish a baseline.`,
|
||||
code: "MissingPushHook",
|
||||
};
|
||||
exports.ErrMissingPullRequestHook = {
|
||||
message: `Please specify an on.pull_request hook so CodeQL is run against new pull requests.`,
|
||||
code: "MissingPullRequestHook",
|
||||
};
|
||||
exports.ErrPathsSpecified = {
|
||||
message: `Please do not specify paths at on.pull.`,
|
||||
code: "PathsSpecified",
|
||||
};
|
||||
function toCodedErrors(errors) {
|
||||
return Object.entries(errors).reduce((acc, [key, value]) => {
|
||||
acc[key] = { message: value, code: key };
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
exports.WorkflowErrors = toCodedErrors({
|
||||
MismatchedBranches: `Please make sure that every branch in on.pull_request is also in on.push so that CodeQL can establish a baseline.`,
|
||||
MissingHooks: `Please specify on.push and on.pull_request hooks.`,
|
||||
MissingPullRequestHook: `Please specify an on.pull_request hook so CodeQL is run against new pull requests.`,
|
||||
MissingPushHook: `Please specify an on.push hook so CodeQL can establish a baseline.`,
|
||||
PathsSpecified: `Please do not specify paths at on.pull.`,
|
||||
CheckoutWrongHead: `Git checkout HEAD^2 is no longer necessary. Please remove this line.`,
|
||||
});
|
||||
function validateWorkflow(doc) {
|
||||
var _a, _b, _c, _d;
|
||||
const errors = [];
|
||||
|
|
@ -138,7 +128,7 @@ function validateWorkflow(doc) {
|
|||
for (const job of Object.values(((_a = doc) === null || _a === void 0 ? void 0 : _a.jobs) || {})) {
|
||||
for (const step of ((_b = job) === null || _b === void 0 ? void 0 : _b.steps) || []) {
|
||||
if (((_c = step) === null || _c === void 0 ? void 0 : _c.run) === "git checkout HEAD^2") {
|
||||
errors.push(exports.ErrCheckoutWrongHead);
|
||||
errors.push(exports.WorkflowErrors.CheckoutWrongHead);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -177,7 +167,7 @@ function validateWorkflow(doc) {
|
|||
else {
|
||||
const paths = (_d = doc.on.push) === null || _d === void 0 ? void 0 : _d.paths;
|
||||
if (Array.isArray(paths) && paths.length > 0) {
|
||||
errors.push(exports.ErrPathsSpecified);
|
||||
errors.push(exports.WorkflowErrors.PathsSpecified);
|
||||
}
|
||||
}
|
||||
if (doc.on.push) {
|
||||
|
|
@ -186,23 +176,23 @@ function validateWorkflow(doc) {
|
|||
const pull_request = doc.on.pull_request.branches || [];
|
||||
const intersects = pull_request.filter((value) => !push.includes(value));
|
||||
if (intersects.length > 0) {
|
||||
errors.push(exports.ErrMismatchedBranches);
|
||||
errors.push(exports.WorkflowErrors.MismatchedBranches);
|
||||
}
|
||||
}
|
||||
else if (push.length > 0) {
|
||||
errors.push(exports.ErrMismatchedBranches);
|
||||
errors.push(exports.WorkflowErrors.MismatchedBranches);
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (missing) {
|
||||
case MissingTriggers.PullRequest | MissingTriggers.Push:
|
||||
errors.push(exports.ErrMissingHooks);
|
||||
errors.push(exports.WorkflowErrors.MissingHooks);
|
||||
break;
|
||||
case MissingTriggers.PullRequest:
|
||||
errors.push(exports.ErrMissingPullRequestHook);
|
||||
errors.push(exports.WorkflowErrors.MissingPullRequestHook);
|
||||
break;
|
||||
case MissingTriggers.Push:
|
||||
errors.push(exports.ErrMissingPushHook);
|
||||
errors.push(exports.WorkflowErrors.MissingPushHook);
|
||||
break;
|
||||
}
|
||||
return errors;
|
||||
|
|
@ -221,7 +211,10 @@ async function getWorkflowErrors() {
|
|||
}
|
||||
exports.getWorkflowErrors = getWorkflowErrors;
|
||||
function formatWorkflowErrors(errors) {
|
||||
return `${errors.length} issue${errors.length === 1 ? " was" : "s were"} detected with this workflow: ${errors.map((e) => e.message).join(", ")}`;
|
||||
const issuesWere = errors.length === 1 ? "issue was" : "issues were";
|
||||
return `${errors.length} ${issuesWere} detected with this workflow: ${errors
|
||||
.map((e) => e.message)
|
||||
.join(", ")}`;
|
||||
}
|
||||
exports.formatWorkflowErrors = formatWorkflowErrors;
|
||||
function formatWorkflowCause(errors) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue