Send short codes that do not need URL encoding for better splunk tracing

This commit is contained in:
Simon Engledew 2020-11-24 12:43:08 +00:00
parent 6df1fc5e38
commit 2ac22e8935
No known key found for this signature in database
GPG key ID: 84302E7B02FE8BCE
10 changed files with 215 additions and 72 deletions

90
lib/actions-util.js generated
View file

@ -103,16 +103,34 @@ function isObject(o) {
}
var MissingTriggers;
(function (MissingTriggers) {
MissingTriggers[MissingTriggers["NONE"] = 0] = "NONE";
MissingTriggers[MissingTriggers["PUSH"] = 1] = "PUSH";
MissingTriggers[MissingTriggers["PULL_REQUEST"] = 2] = "PULL_REQUEST";
MissingTriggers[MissingTriggers["None"] = 0] = "None";
MissingTriggers[MissingTriggers["Push"] = 1] = "Push";
MissingTriggers[MissingTriggers["PullRequest"] = 2] = "PullRequest";
})(MissingTriggers || (MissingTriggers = {}));
exports.ErrCheckoutWrongHead = `Git checkout HEAD^2 is no longer necessary. Please remove this line.`;
exports.ErrMismatchedBranches = `Please make sure that every branch in on.pull_request is also in on.push so that CodeQL can establish a baseline.`;
exports.ErrMissingHooks = `Please specify on.push and on.pull_request hooks.`;
exports.ErrMissingPushHook = `Please specify an on.push hook so CodeQL can establish a baseline.`;
exports.ErrMissingPullRequestHook = `Please specify an on.pull_request hook so CodeQL is run against new pull requests.`;
exports.ErrPathsSpecified = `Please do not specify paths at on.pull.`;
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 validateWorkflow(doc) {
var _a, _b, _c, _d;
const errors = [];
@ -124,37 +142,37 @@ function validateWorkflow(doc) {
}
}
}
let missing = MissingTriggers.NONE;
let missing = MissingTriggers.None;
if (doc.on === undefined) {
missing = MissingTriggers.PUSH | MissingTriggers.PULL_REQUEST;
missing = MissingTriggers.Push | MissingTriggers.PullRequest;
}
else if (typeof doc.on === "string") {
switch (doc.on) {
case "push":
missing = MissingTriggers.PULL_REQUEST;
missing = MissingTriggers.PullRequest;
break;
case "pull_request":
missing = MissingTriggers.PUSH;
missing = MissingTriggers.Push;
break;
default:
missing = MissingTriggers.PUSH | MissingTriggers.PULL_REQUEST;
missing = MissingTriggers.Push | MissingTriggers.PullRequest;
break;
}
}
else if (Array.isArray(doc.on)) {
if (!doc.on.includes("push")) {
missing = missing | MissingTriggers.PUSH;
missing = missing | MissingTriggers.Push;
}
if (!doc.on.includes("pull_request")) {
missing = missing | MissingTriggers.PULL_REQUEST;
missing = missing | MissingTriggers.PullRequest;
}
}
else if (isObject(doc.on)) {
if (!Object.prototype.hasOwnProperty.call(doc.on, "pull_request")) {
missing = missing | MissingTriggers.PULL_REQUEST;
missing = missing | MissingTriggers.PullRequest;
}
if (!Object.prototype.hasOwnProperty.call(doc.on, "push")) {
missing = missing | MissingTriggers.PUSH;
missing = missing | MissingTriggers.Push;
}
else {
const paths = (_d = doc.on.push) === null || _d === void 0 ? void 0 : _d.paths;
@ -162,30 +180,35 @@ function validateWorkflow(doc) {
errors.push(exports.ErrPathsSpecified);
}
}
if (doc.on.push && doc.on.pull_request) {
if (doc.on.push) {
const push = doc.on.push.branches || [];
const pull_request = doc.on.pull_request.branches || [];
const intersects = pull_request.filter((value) => !push.includes(value));
if (intersects.length > 0) {
if (doc.on.pull_request) {
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);
}
}
else if (push.length > 0) {
errors.push(exports.ErrMismatchedBranches);
}
}
}
switch (missing) {
case MissingTriggers.PULL_REQUEST | MissingTriggers.PUSH:
case MissingTriggers.PullRequest | MissingTriggers.Push:
errors.push(exports.ErrMissingHooks);
break;
case MissingTriggers.PULL_REQUEST:
case MissingTriggers.PullRequest:
errors.push(exports.ErrMissingPullRequestHook);
break;
case MissingTriggers.PUSH:
case MissingTriggers.Push:
errors.push(exports.ErrMissingPushHook);
break;
}
return errors;
}
exports.validateWorkflow = validateWorkflow;
async function getWorkflowError() {
async function getWorkflowErrors() {
const workflow = await getWorkflow();
if (workflow === undefined) {
return undefined;
@ -194,9 +217,20 @@ async function getWorkflowError() {
if (workflowErrors.length === 0) {
return undefined;
}
return `${workflowErrors.length} issue${workflowErrors.length === 1 ? " was" : "s were"} detected with this workflow: ${workflowErrors.join(", ")}`;
return workflowErrors;
}
exports.getWorkflowError = getWorkflowError;
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(", ")}`;
}
exports.formatWorkflowErrors = formatWorkflowErrors;
function formatWorkflowCause(errors) {
if (errors === undefined) {
return undefined;
}
return errors.map((e) => e.code).join(",");
}
exports.formatWorkflowCause = formatWorkflowCause;
async function getWorkflow() {
const relativePath = await getWorkflowPath();
const absolutePath = path.join(getRequiredEnvParam("GITHUB_WORKSPACE"), relativePath);