Skip to content

Add interpolation support to labels and assignees #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
10 changes: 8 additions & 2 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Toolkit } from "actions-toolkit";
import nunjucks from "nunjucks";
import { z } from "zod";

export const frontmatterSchema = z
Expand All @@ -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));
}
1 change: 1 addition & 0 deletions tests/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"JasonEtco",
],
"milestone": 2,
"title": "DO EVERYTHING",
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/.github/kitchen-sink.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ assignees:
- JasonEtco
labels:
- bugs
- "{{ repo.owner }}"
milestone: 2
---
The action {{ action }} is the best action.
3 changes: 3 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down