Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: debug output #21

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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;
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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) {
Expand Down