Skip to content

Commit

Permalink
Implement
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonEtco committed Dec 21, 2022
1 parent b35e247 commit b5872ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fm from 'front-matter'
import nunjucks from 'nunjucks'
// @ts-ignore
import dateFilter from 'nunjucks-date-filter'
import { FrontMatterAttributes, listToArray, setOutputs } from './helpers'
import { FrontMatterAttributes, frontmatterSchema, listToArray, setOutputs } from './helpers'

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

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

const templated = {
Expand Down
15 changes: 9 additions & 6 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Toolkit } from 'actions-toolkit'
import { z } from 'zod'

export interface FrontMatterAttributes {
title: string
assignees?: string[] | string
labels?: string[] | string
milestone?: string | number
}
export const frontmatterSchema = z.object({
title: z.string(),
assignees: z.union([z.array(z.string()), z.string()]).optional(),
labels: z.union([z.array(z.string()), z.string()]).optional(),
milestone: z.union([z.string(), z.number()]).optional()
})

export type FrontMatterAttributes = z.infer<typeof frontmatterSchema>

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

0 comments on commit b5872ea

Please sign in to comment.