Skip to content

Commit

Permalink
chore: update versoin (#31)
Browse files Browse the repository at this point in the history
* refactor: build with debug logging codes

* chore: update version
  • Loading branch information
shioyang authored Jan 7, 2023
1 parent 2c88bd3 commit 1b39415
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
steps:
- name: Check PR labels action step
id: check_pr_labels
uses: shioyang/[email protected].7
uses: shioyang/[email protected].8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
labels: '["enhancement"]'
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The result if given labels have be applied to the PR
## Example Usage

```
uses: shioyang/[email protected].7
uses: shioyang/[email protected].8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
labels: '["label-1", "label-2"]'
Expand All @@ -42,7 +42,7 @@ jobs:
steps:
- name: Check PR labels action step
id: check_pr_labels
uses: shioyang/[email protected].7
uses: shioyang/[email protected].8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
labels: '["enhancement"]'
Expand Down
8 changes: 7 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,38 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__nccwpck_require__(2186));
const github = __importStar(__nccwpck_require__(5438));
async function run() {
core.debug("Start");
const token = core.getInput("github-token", { required: true });
const octokit = github.getOctokit(token);
const labelNames = await getPullRequestLabelNames(octokit);
const labels = getInputLabels();
const result = labels.every((label) => labelNames.findIndex((value) => label === value) >= 0);
core.setOutput("result", result);
core.debug("End");
}
async function getPullRequestLabelNames(octokit) {
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() {
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}`);
});


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "check-pr-labels-on-push-action",
"version": "1.0.7",
"version": "1.0.8",
"main": "index.js",
"repository": "[email protected]:shioyang/check-pr-labels-on-push-action.git",
"author": "Tomohiro (Tomo) SHIOYA",
Expand Down

0 comments on commit 1b39415

Please sign in to comment.