Skip to content

Commit

Permalink
feat: add option for multiple labels
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol-Baranwal committed Nov 15, 2023
1 parent 1e6c47b commit 6964518
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: 'Handle the current issue if the author has existing open issues'
author: 'Anmol Baranwal <[email protected]>'
inputs:
label:
description: 'Label to add to the current issue.'
description: 'Add a label to the current issue. Use commas to separate if there are multiple labels.'
default: 'multiple issues'
required: false
issueNumber:
Expand Down
10 changes: 4 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const core = __importStar(__nccwpck_require__(2186));
const github = __importStar(__nccwpck_require__(5438));
async function HandleMultipleIssues() {
var _a;
console.log("Hello World!");
try {
const token = core.getInput("gh-token");
if (!token)
Expand All @@ -49,8 +48,7 @@ async function HandleMultipleIssues() {
const context = github.context;
core.notice("step 1.");
// Retrieve custom inputs
const label = core.getInput("label") || "multiple issues"; // Set default label
const labelInput = core.getInput("label");
const labels = core.getInput("label").split(",").map(label => label.trim());
const issueNumber = core.getInput("issueNumber") === "true" || false; // converts to boolean
const comment = core.getInput("comment");
const close = core.getInput("close") === "true" || false;
Expand Down Expand Up @@ -78,8 +76,8 @@ async function HandleMultipleIssues() {
.map((issueNumber) => `#${issueNumber}`)
.join(", ");
// Check if label is an array and add multiple labels if needed
if (Array.isArray(label)) {
for (const lbl of label) {
if (Array.isArray(labels)) {
for (const lbl of labels) {
await octokit.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
Expand All @@ -94,7 +92,7 @@ async function HandleMultipleIssues() {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumberToLabel,
labels: [label],
labels: [labels],
});
}
core.notice("Labels added to issue #" + issueNumberToLabel);
Expand Down
11 changes: 4 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import * as core from "@actions/core";
import * as github from "@actions/github";

async function HandleMultipleIssues() {
console.log("Hello World!");

try {
const token = core.getInput("gh-token");

Expand All @@ -23,8 +21,7 @@ async function HandleMultipleIssues() {
core.notice("step 1.");

// Retrieve custom inputs
const label = core.getInput("label") || "multiple issues"; // Set default label
const labelInput = core.getInput("label");
const labels = core.getInput("label").split(",").map(label => label.trim());
const issueNumber = core.getInput("issueNumber") === "true" || false; // converts to boolean
const comment = core.getInput("comment");
const close = core.getInput("close") === "true" || false;
Expand Down Expand Up @@ -62,8 +59,8 @@ async function HandleMultipleIssues() {
.join(", ");

// Check if label is an array and add multiple labels if needed
if (Array.isArray(label)) {
for (const lbl of label) {
if (Array.isArray(labels)) {
for (const lbl of labels) {
await octokit.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
Expand All @@ -77,7 +74,7 @@ async function HandleMultipleIssues() {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumberToLabel,
labels: [label],
labels: [labels],
});
}

Expand Down

0 comments on commit 6964518

Please sign in to comment.