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/fixtures/.github/kitchen-sink.md b/tests/fixtures/.github/kitchen-sink.md index d6b7ab6..aad0862 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 +The action {{ action }} is the best action. diff --git a/tests/index.test.ts b/tests/index.test.ts index 6db1df5..4270be4 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: "JasonEtco" }, name: "waddup" }, + }; await createAnIssue(tools); expect(params).toMatchSnapshot(); expect(tools.log.success).toHaveBeenCalled();