Skip to content

Commit c36c17d

Browse files
author
Kaiwei Wang
committed
1 parent ee46187 commit c36c17d

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

src/action.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,12 @@ export async function createAnIssue(tools: Toolkit) {
134134
// Create the new issue
135135
tools.log.info(`Creating new issue ${templated.title}`);
136136
try {
137+
const templateAssignees = assignees ? assignees : attributes.assignees;
137138
const issue = await tools.github.issues.create({
138139
...tools.context.repo,
139140
...templated,
140-
assignees: assignees
141-
? listToArray(assignees)
142-
: listToArray(attributes.assignees),
143-
labels: listToArray(attributes.labels),
141+
assignees: templateAssignees ? listToArray(templateAssignees, env, templateVariables) : [],
142+
labels: attributes.labels ? listToArray(attributes.labels, env, templateVariables) : [],
144143
milestone:
145144
Number(tools.inputs.milestone || attributes.milestone) || undefined,
146145
});

src/helpers.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Toolkit } from "actions-toolkit";
2+
import nunjucks from "nunjucks";
23
import { z } from "zod";
34

45
export const frontmatterSchema = z
@@ -22,7 +23,12 @@ export function setOutputs(
2223
tools.outputs.url = issue.html_url;
2324
}
2425

25-
export function listToArray(list?: string[] | string) {
26+
export function listToArray(
27+
list: string[] | string,
28+
env: nunjucks.Environment,
29+
context: object
30+
) {
2631
if (!list) return [];
27-
return Array.isArray(list) ? list : list.split(", ");
32+
const array = Array.isArray(list) ? list : list.split(", ");
33+
return array.map((item) => env.renderString(item, context));
2834
}

tests/__snapshots__/index.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ exports[`create-an-issue creates a new issue with assignees, labels and a milest
123123
"body": "The action create-an-issue is the best action.",
124124
"labels": [
125125
"bugs",
126+
"fieldsfarmer",
126127
],
127128
"milestone": 2,
128129
"title": "DO EVERYTHING",

tests/fixtures/.github/kitchen-sink.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ assignees:
44
- JasonEtco
55
labels:
66
- bugs
7+
- "{{ repo.owner}}"
78
milestone: 2
89
---
910
The action {{ action }} is the best action.

tests/index.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ describe("create-an-issue", () => {
9191

9292
it("creates a new issue with assignees, labels and a milestone", async () => {
9393
process.env.INPUT_FILENAME = ".github/kitchen-sink.md";
94+
tools.context.payload = {
95+
repository: { owner: { login: "fieldsfarmer" }, name: "waddup" },
96+
};
9497
await createAnIssue(tools);
9598
expect(params).toMatchSnapshot();
9699
expect(tools.log.success).toHaveBeenCalled();

0 commit comments

Comments
 (0)