diff --git a/src/index.ts b/src/index.ts index df7fa05..8c6229e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ -import { getInput, setOutput, warning, setFailed } from '@actions/core'; +import { getInput, setOutput, warning, setFailed, debug } from '@actions/core'; + import { validateIssueTitleAndBody } from './validate'; import { getOctokit, context } from '@actions/github'; @@ -13,7 +14,18 @@ export async function run() { const issueType = getInput('issue-type') || 'issue'; const issueNumber = context.issue.number; const isAutoClose = getInput('auto-close') || 'false'; - isAutoClose === 'true' ? true : false; + + debug( + `inputs: ${JSON.stringify({ + title, + titleRegexFlags, + body, + bodyRegexFlags, + issueType, + issueNumber, + isAutoClose, + })}`, + ); let titleRegex: RegExp | string | null; let bodyRegex: RegExp | string | null; @@ -27,7 +39,18 @@ export async function run() { } else { bodyRegex = body; } - const result = await validateIssueTitleAndBody(issueType, issueNumber, titleRegex, bodyRegex); + + debug(`regex: ${JSON.stringify({ titleRegex, bodyRegex })}`); + + const result = await validateIssueTitleAndBody( + issueType, + issueNumber, + titleRegex, + bodyRegex, + ); + + debug(`result: ${result}`); + if (result === true) { setOutput('result', 'true'); } else { @@ -38,7 +61,7 @@ export async function run() { owner: context.repo.owner, repo: context.repo.repo, issue_number: issueNumber, - body: `Issue #${issueNumber} is not valid: Reason: ${result}: auto closing issue...`, + body: `Issue #${issueNumber} is not valid: ${result}`, }); // Close issue @@ -48,8 +71,9 @@ export async function run() { issue_number: issueNumber, state: 'closed', }); + } else { + warning(`Issue #${issueNumber} is not valid. Reason: ${result}`); } - setOutput('result', 'false'); } /* eslint @typescript-eslint/no-explicit-any: 0, @typescript-eslint/no-unsafe-argument: 0, @typescript-eslint/no-unsafe-member-access: 0, @typescript-eslint/no-floating-promises: 0 */ } catch (error: any) {