Handle the case where branches may be strings, including "*"

This commit is contained in:
Simon Engledew 2020-12-01 10:42:21 +00:00
parent c6dbd5a9bf
commit ac1c081de8
No known key found for this signature in database
GPG key ID: 84302E7B02FE8BCE
6 changed files with 66 additions and 13 deletions

22
lib/actions-util.js generated
View file

@ -101,6 +101,18 @@ exports.getCommitOid = async function () {
function isObject(o) {
return o !== null && typeof o === "object";
}
function branchesToArray(branches) {
if (typeof branches === 'string') {
if (branches === "*") {
return "*";
}
return [branches];
}
if (!branches || branches.length === 0) {
return "*";
}
return branches;
}
var MissingTriggers;
(function (MissingTriggers) {
MissingTriggers[MissingTriggers["None"] = 0] = "None";
@ -123,7 +135,7 @@ exports.WorkflowErrors = toCodedErrors({
CheckoutWrongHead: `git checkout HEAD^2 is no longer necessary. Please remove this step as Code Scanning recommends analyzing the merge commit for best results.`,
});
function validateWorkflow(doc) {
var _a, _b, _c, _d, _e;
var _a, _b, _c, _d, _e, _f, _g;
const errors = [];
// .jobs[key].steps[].run
for (const job of Object.values(((_a = doc) === null || _a === void 0 ? void 0 : _a.jobs) || {})) {
@ -183,10 +195,10 @@ function validateWorkflow(doc) {
errors.push(exports.WorkflowErrors.PathsIgnoreSpecified);
}
}
if (doc.on.push) {
const push = doc.on.push.branches || [];
if (doc.on.pull_request) {
const pull_request = doc.on.pull_request.branches || [];
const push = branchesToArray((_f = doc.on.push) === null || _f === void 0 ? void 0 : _f.branches);
if (push !== "*") {
const pull_request = branchesToArray((_g = doc.on.pull_request) === null || _g === void 0 ? void 0 : _g.branches);
if (pull_request !== "*") {
const difference = pull_request.filter((value) => !push.includes(value));
if (difference.length > 0) {
// there are branches in pull_request that may not have a baseline