Skip to content

Commit

Permalink
Merge pull request #1 from fieldsfarmer/kw/assignee
Browse files Browse the repository at this point in the history
  • Loading branch information
fieldsfarmer authored Jan 25, 2024
2 parents ee46187 + c36c17d commit 2da786c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
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",
"fieldsfarmer",
],
"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: "fieldsfarmer" }, name: "waddup" },
};
await createAnIssue(tools);
expect(params).toMatchSnapshot();
expect(tools.log.success).toHaveBeenCalled();
Expand Down

0 comments on commit 2da786c

Please sign in to comment.