From c36c17d79ee5ecf00cd3a08b94989ce7d81b0baf Mon Sep 17 00:00:00 2001 From: Kaiwei Wang Date: Thu, 25 Jan 2024 15:25:46 -0800 Subject: [PATCH] Patch https://github.com/JasonEtco/create-an-issue/pull/166 --- src/action.ts | 7 +++---- src/helpers.ts | 10 ++++++++-- tests/__snapshots__/index.test.ts.snap | 1 + tests/fixtures/.github/kitchen-sink.md | 1 + tests/index.test.ts | 3 +++ 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/action.ts b/src/action.ts index 1319df9..c63a871 100644 --- a/src/action.ts +++ b/src/action.ts @@ -134,13 +134,12 @@ export async function createAnIssue(tools: Toolkit) { // Create the new issue tools.log.info(`Creating new issue ${templated.title}`); try { + const templateAssignees = assignees ? assignees : attributes.assignees; const issue = await tools.github.issues.create({ ...tools.context.repo, ...templated, - assignees: assignees - ? listToArray(assignees) - : listToArray(attributes.assignees), - labels: listToArray(attributes.labels), + assignees: templateAssignees ? listToArray(templateAssignees, env, templateVariables) : [], + labels: attributes.labels ? listToArray(attributes.labels, env, templateVariables) : [], milestone: Number(tools.inputs.milestone || attributes.milestone) || undefined, }); diff --git a/src/helpers.ts b/src/helpers.ts index 3e503f5..270fcff 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -1,4 +1,5 @@ import { Toolkit } from "actions-toolkit"; +import nunjucks from "nunjucks"; import { z } from "zod"; export const frontmatterSchema = z @@ -22,7 +23,12 @@ export function setOutputs( tools.outputs.url = issue.html_url; } -export function listToArray(list?: string[] | string) { +export function listToArray( + list: string[] | string, + env: nunjucks.Environment, + context: object +) { if (!list) return []; - return Array.isArray(list) ? list : list.split(", "); + const array = Array.isArray(list) ? list : list.split(", "); + return array.map((item) => env.renderString(item, context)); } diff --git a/tests/__snapshots__/index.test.ts.snap b/tests/__snapshots__/index.test.ts.snap index 0523e74..6c3cccd 100644 --- a/tests/__snapshots__/index.test.ts.snap +++ b/tests/__snapshots__/index.test.ts.snap @@ -123,6 +123,7 @@ exports[`create-an-issue creates a new issue with assignees, labels and a milest "body": "The action create-an-issue is the best action.", "labels": [ "bugs", + "fieldsfarmer", ], "milestone": 2, "title": "DO EVERYTHING", diff --git a/tests/fixtures/.github/kitchen-sink.md b/tests/fixtures/.github/kitchen-sink.md index d6b7ab6..c527872 100644 --- a/tests/fixtures/.github/kitchen-sink.md +++ b/tests/fixtures/.github/kitchen-sink.md @@ -4,6 +4,7 @@ assignees: - JasonEtco labels: - bugs + - "{{ repo.owner}}" milestone: 2 --- The action {{ action }} is the best action. \ No newline at end of file diff --git a/tests/index.test.ts b/tests/index.test.ts index 6db1df5..5dda308 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -91,6 +91,9 @@ describe("create-an-issue", () => { it("creates a new issue with assignees, labels and a milestone", async () => { process.env.INPUT_FILENAME = ".github/kitchen-sink.md"; + tools.context.payload = { + repository: { owner: { login: "fieldsfarmer" }, name: "waddup" }, + }; await createAnIssue(tools); expect(params).toMatchSnapshot(); expect(tools.log.success).toHaveBeenCalled();