From dd87c163d311405014293eb267504663ebbbad39 Mon Sep 17 00:00:00 2001 From: Anmol Baranwal Date: Sat, 11 Nov 2023 16:30:38 +0530 Subject: [PATCH] chore: add option for multiple labels --- .github/workflows/main.yml | 16 ---------------- src/index.ts | 14 ++++++-------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e8a192b..1e80ff3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,19 +15,3 @@ jobs: - uses: ./ with: gh-token: ${{ secrets.GITHUB_TOKEN }} - # - name: Setup Node.js - # uses: actions/setup-node@v2 - # with: - # node-version: 16 - - # - name: Install Dependencies - # run: npm install - - # - name: Compile TypeScript - # run: npx tsc - - # - name: Run Custom Action - # run: | - # node dist/index.js - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/src/index.ts b/src/index.ts index 14b33c2..30f336b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,14 +1,10 @@ import * as core from "@actions/core"; import * as github from "@actions/github"; -// const core = require("@actions/core"); -// const github = require("@actions/github"); - async function HandleMultipleIssues() { console.log("Hello World!"); try { - // const token = process.env.GITHUB_TOKEN; const token = core.getInput("gh-token"); if (!token) core.debug(token + ""); @@ -27,7 +23,9 @@ async function HandleMultipleIssues() { core.notice("step 1."); // Retrieve custom inputs - const label = core.getInput("label") || "up for grabs"; // Set default label + // const label = core.getInput("label") || "up for grabs"; // Set default label + const labelInput = core.getInput("label"); + const labels = labelInput ? JSON.parse(labelInput) : ["up for grabs"]; const issueNumber = core.getInput("issueNumber") === "true" || false; // converts to boolean const comment = core.getInput("comment"); const close = core.getInput("close") === "true" || false; @@ -65,8 +63,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) && labels.length > 0) { + for (const lbl of labels) { await octokit.rest.issues.addLabels({ owner: context.repo.owner, repo: context.repo.repo, @@ -80,7 +78,7 @@ async function HandleMultipleIssues() { owner: context.repo.owner, repo: context.repo.repo, issue_number: issueNumberToLabel, - labels: [label], + labels: [labels[0]], }); }