Skip to content

Commit

Permalink
refactor: place codes for debug logging (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
shioyang authored Jan 7, 2023
1 parent 87ade5e commit 2c88bd3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import * as github from "@actions/github";
import { GitHub } from "@actions/github/lib/utils";

async function run() {
core.debug("Start");

const token = core.getInput("github-token", { required: true });
const octokit = github.getOctokit(token);

Expand All @@ -13,6 +15,8 @@ async function run() {
(label) => labelNames.findIndex((value) => label === value) >= 0
);
core.setOutput("result", result);

core.debug("End");
}

async function getPullRequestLabelNames(
Expand All @@ -21,24 +25,32 @@ async function getPullRequestLabelNames(
const owner = github.context.repo.owner;
const repo = github.context.repo.repo;
const commit_sha = github.context.sha;
core.debug(
`PR context - Owner: ${owner} Repo: ${repo} Commit_SHA: ${commit_sha}`
);

const response =
await octokit.rest.repos.listPullRequestsAssociatedWithCommit({
owner,
repo,
commit_sha,
});
core.debug(`Retrieved commit data: ${response.data}`);

const pr = response.data.length > 0 && response.data[0];
return pr ? pr.labels.map((label) => label.name || "") : [];
}

function getInputLabels(): string[] {
const raw = core.getInput("labels", { required: true });
core.debug(`Get input "labels": ${raw}`);

const json = JSON.parse(raw);
core.debug(`Parsed as JSON: ${json}`);

return Array.isArray(json) ? json : [];
}

run().catch((err) => {
core.setFailed(err.message);
core.setFailed(`Action failed with error: ${err.message}`);
});

0 comments on commit 2c88bd3

Please sign in to comment.