Skip to content

Commit b5872ea

Browse files
committed
Implement
1 parent b35e247 commit b5872ea

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/action.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import fm from 'front-matter'
44
import nunjucks from 'nunjucks'
55
// @ts-ignore
66
import dateFilter from 'nunjucks-date-filter'
7-
import { FrontMatterAttributes, listToArray, setOutputs } from './helpers'
7+
import { FrontMatterAttributes, frontmatterSchema, listToArray, setOutputs } from './helpers'
88

99
function logError(tools: Toolkit, template: string, action: 'creating' | 'updating', err: any) {
1010
// Log the error message
@@ -50,7 +50,8 @@ export async function createAnIssue (tools: Toolkit) {
5050
const file = await tools.readFile(template) as string
5151

5252
// Grab the front matter as JSON
53-
const { attributes, body } = fm<FrontMatterAttributes>(file)
53+
const { attributes: rawAttributes, body } = fm<FrontMatterAttributes>(file)
54+
const attributes = await frontmatterSchema.parseAsync(rawAttributes)
5455
tools.log(`Front matter for ${template} is`, attributes)
5556

5657
const templated = {

src/helpers.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { Toolkit } from 'actions-toolkit'
2+
import { z } from 'zod'
23

3-
export interface FrontMatterAttributes {
4-
title: string
5-
assignees?: string[] | string
6-
labels?: string[] | string
7-
milestone?: string | number
8-
}
4+
export const frontmatterSchema = z.object({
5+
title: z.string(),
6+
assignees: z.union([z.array(z.string()), z.string()]).optional(),
7+
labels: z.union([z.array(z.string()), z.string()]).optional(),
8+
milestone: z.union([z.string(), z.number()]).optional()
9+
})
10+
11+
export type FrontMatterAttributes = z.infer<typeof frontmatterSchema>
912

1013
export function setOutputs (tools: Toolkit, issue: { number: number, html_url: string }) {
1114
tools.outputs.number = String(issue.number)

0 commit comments

Comments
 (0)