Skip to content

Commit

Permalink
Showing 9 changed files with 27 additions and 32 deletions.
16 changes: 6 additions & 10 deletions lib/actions-util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/actions-util.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/actions-util.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/actions-util.test.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/init-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/init-action.js.map
2 changes: 1 addition & 1 deletion src/actions-util.test.ts
@@ -228,5 +228,5 @@ test("formatWorkflowCause()", (t) => {
]);

t.deepEqual(message, "CheckoutWrongHead,PathsSpecified");
t.deepEqual(actionsutil.formatWorkflowCause(undefined), undefined);
t.deepEqual(actionsutil.formatWorkflowCause([]), undefined);
});
29 changes: 14 additions & 15 deletions src/actions-util.ts
@@ -115,6 +115,11 @@ interface WorkflowTrigger {
paths?: string[];
}

// on: {} then push/pull_request are undefined
// on:
// push:
// pull_request:
// then push/pull_request are null
interface WorkflowTriggers {
push?: WorkflowTrigger | null;
pull_request?: WorkflowTrigger | null;
@@ -125,7 +130,7 @@ interface Workflow {
on?: string | string[] | WorkflowTriggers;
}

function isObject(o): o is object {
function isObject(o: unknown): o is object {
return o !== null && typeof o === "object";
}

@@ -224,10 +229,10 @@ export function validateWorkflow(doc: Workflow): CodedError[] {

if (doc.on.pull_request) {
const pull_request = doc.on.pull_request.branches || [];
const intersects = pull_request.filter(
const difference = pull_request.filter(
(value) => !push.includes(value)
);
if (intersects.length > 0) {
if (difference.length > 0) {
// there are branches in pull_request that may not have a baseline
// because we are not building them on push
errors.push(WorkflowErrors.MismatchedBranches);
@@ -255,32 +260,26 @@ export function validateWorkflow(doc: Workflow): CodedError[] {
return errors;
}

export async function getWorkflowErrors(): Promise<CodedError[] | undefined> {
export async function getWorkflowErrors(): Promise<CodedError[]> {
const workflow = await getWorkflow();

if (workflow === undefined) {
return undefined;
}

const workflowErrors = validateWorkflow(workflow);

if (workflowErrors.length === 0) {
return undefined;
return [];
}

return workflowErrors;
return validateWorkflow(workflow);
}

export function formatWorkflowErrors(errors: CodedError[]): string {
const issuesWere = errors.length === 1 ? "issue was" : "issues were";

const errorsList = errors.map((e) => e.message).join(", ");
const errorsList = errors.map((e) => e.message).join(" ");

return `${errors.length} ${issuesWere} detected with this workflow: ${errorsList}`;
}

export function formatWorkflowCause(errors?: CodedError[]): undefined | string {
if (errors === undefined) {
export function formatWorkflowCause(errors: CodedError[]): undefined | string {
if (errors.length === 0) {
return undefined;
}
return errors.map((e) => e.code).join(",");
2 changes: 1 addition & 1 deletion src/init-action.ts
@@ -98,7 +98,7 @@ async function run() {

const workflowErrors = await actionsUtil.getWorkflowErrors();

if (workflowErrors !== undefined) {
if (workflowErrors.length > 0) {
core.warning(actionsUtil.formatWorkflowErrors(workflowErrors));
}

0 comments on commit be09fb3

Please sign in to comment.