Skip to content

Commit 5218616

Browse files
committed
Unrelated prettier-ing
1 parent a3271ce commit 5218616

File tree

9 files changed

+413
-369
lines changed

9 files changed

+413
-369
lines changed

Dockerfile

-16
This file was deleted.

codecov.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ coverage:
88
default:
99
threshold: 3
1010

11-
comment: false
11+
comment: false

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@
5050
"<rootDir>/tests/**/*.test.(ts|js)"
5151
]
5252
}
53-
}
53+
}

src/action.ts

+92-63
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,155 @@
1-
import * as core from '@actions/core'
2-
import { Toolkit } from 'actions-toolkit'
3-
import fm from 'front-matter'
4-
import nunjucks from 'nunjucks'
1+
import * as core from "@actions/core";
2+
import { Toolkit } from "actions-toolkit";
3+
import fm from "front-matter";
4+
import nunjucks from "nunjucks";
55
// @ts-expect-error
6-
import dateFilter from 'nunjucks-date-filter'
7-
import { ZodError } from 'zod'
8-
import { FrontMatterAttributes, frontmatterSchema, listToArray, setOutputs } from './helpers'
9-
10-
function logError(tools: Toolkit, template: string, action: 'creating' | 'updating' | 'parsing', err: any) {
6+
import dateFilter from "nunjucks-date-filter";
7+
import { ZodError } from "zod";
8+
import {
9+
FrontMatterAttributes,
10+
frontmatterSchema,
11+
listToArray,
12+
setOutputs,
13+
} from "./helpers";
14+
15+
function logError(
16+
tools: Toolkit,
17+
template: string,
18+
action: "creating" | "updating" | "parsing",
19+
err: any
20+
) {
1121
// Log the error message
12-
const errorMessage = `An error occurred while ${action} the issue. This might be caused by a malformed issue title, or a typo in the labels or assignees. Check ${template}!`
13-
tools.log.error(errorMessage)
14-
tools.log.error(err)
22+
const errorMessage = `An error occurred while ${action} the issue. This might be caused by a malformed issue title, or a typo in the labels or assignees. Check ${template}!`;
23+
tools.log.error(errorMessage);
24+
tools.log.error(err);
1525

1626
// The error might have more details
17-
if (err.errors) tools.log.error(err.errors)
27+
if (err.errors) tools.log.error(err.errors);
1828

1929
// Exit with a failing status
20-
core.setFailed(errorMessage + '\n\n' + err.message)
21-
return tools.exit.failure()
30+
core.setFailed(errorMessage + "\n\n" + err.message);
31+
return tools.exit.failure();
2232
}
2333

24-
export async function createAnIssue (tools: Toolkit) {
25-
const template = tools.inputs.filename || '.github/ISSUE_TEMPLATE.md'
26-
const assignees = tools.inputs.assignees
34+
export async function createAnIssue(tools: Toolkit) {
35+
const template = tools.inputs.filename || ".github/ISSUE_TEMPLATE.md";
36+
const assignees = tools.inputs.assignees;
2737

28-
let updateExisting: Boolean | null = null
38+
let updateExisting: Boolean | null = null;
2939
if (tools.inputs.update_existing) {
30-
if (tools.inputs.update_existing === 'true') {
31-
updateExisting = true
32-
} else if (tools.inputs.update_existing === 'false') {
33-
updateExisting = false
40+
if (tools.inputs.update_existing === "true") {
41+
updateExisting = true;
42+
} else if (tools.inputs.update_existing === "false") {
43+
updateExisting = false;
3444
} else {
35-
tools.exit.failure(`Invalid value update_existing=${tools.inputs.update_existing}, must be one of true or false`)
45+
tools.exit.failure(
46+
`Invalid value update_existing=${tools.inputs.update_existing}, must be one of true or false`
47+
);
3648
}
3749
}
3850

39-
const env = nunjucks.configure({ autoescape: false })
40-
env.addFilter('date', dateFilter)
51+
const env = nunjucks.configure({ autoescape: false });
52+
env.addFilter("date", dateFilter);
4153

4254
const templateVariables = {
4355
...tools.context,
4456
repo: tools.context.repo,
4557
env: process.env,
46-
date: Date.now()
47-
}
58+
date: Date.now(),
59+
};
4860

4961
// Get the file
50-
tools.log.debug('Reading from file', template)
51-
const file = await tools.readFile(template) as string
62+
tools.log.debug("Reading from file", template);
63+
const file = (await tools.readFile(template)) as string;
5264

5365
// Grab the front matter as JSON
54-
const { attributes: rawAttributes, body } = fm<FrontMatterAttributes>(file)
66+
const { attributes: rawAttributes, body } = fm<FrontMatterAttributes>(file);
5567

56-
let attributes: FrontMatterAttributes
68+
let attributes: FrontMatterAttributes;
5769
try {
58-
attributes = await frontmatterSchema.parseAsync(rawAttributes)
70+
attributes = await frontmatterSchema.parseAsync(rawAttributes);
5971
} catch (err) {
6072
if (err instanceof ZodError) {
61-
const formatted = err.format()
62-
return logError(tools, template, 'parsing', formatted)
73+
const formatted = err.format();
74+
return logError(tools, template, "parsing", formatted);
6375
}
64-
throw err
76+
throw err;
6577
}
6678

67-
tools.log(`Front matter for ${template} is`, attributes)
79+
tools.log(`Front matter for ${template} is`, attributes);
6880

6981
const templated = {
7082
body: env.renderString(body, templateVariables),
71-
title: env.renderString(attributes.title, templateVariables)
72-
}
73-
tools.log.debug('Templates compiled', templated)
83+
title: env.renderString(attributes.title, templateVariables),
84+
};
85+
tools.log.debug("Templates compiled", templated);
7486

7587
if (updateExisting !== null) {
76-
tools.log.info(`Fetching issues with title "${templated.title}"`)
88+
tools.log.info(`Fetching issues with title "${templated.title}"`);
7789

78-
let query = `is:issue repo:${process.env.GITHUB_REPOSITORY} in:title "${templated.title.replace(/['"]/g, "\\$&")}"`
90+
let query = `is:issue repo:${
91+
process.env.GITHUB_REPOSITORY
92+
} in:title "${templated.title.replace(/['"]/g, "\\$&")}"`;
7993

80-
const searchExistingType = tools.inputs.search_existing || 'open'
81-
const allowedStates = ['open', 'closed']
94+
const searchExistingType = tools.inputs.search_existing || "open";
95+
const allowedStates = ["open", "closed"];
8296
if (allowedStates.includes(searchExistingType)) {
83-
query += ` is:${searchExistingType}`
97+
query += ` is:${searchExistingType}`;
8498
}
8599

86-
const existingIssues = await tools.github.search.issuesAndPullRequests({ q: query })
87-
const existingIssue = existingIssues.data.items.find(issue => issue.title === templated.title)
100+
const existingIssues = await tools.github.search.issuesAndPullRequests({
101+
q: query,
102+
});
103+
const existingIssue = existingIssues.data.items.find(
104+
(issue) => issue.title === templated.title
105+
);
88106
if (existingIssue) {
89107
if (updateExisting === false) {
90-
tools.exit.success(`Existing issue ${existingIssue.title}#${existingIssue.number}: ${existingIssue.html_url} found but not updated`)
108+
tools.exit.success(
109+
`Existing issue ${existingIssue.title}#${existingIssue.number}: ${existingIssue.html_url} found but not updated`
110+
);
91111
} else {
92112
try {
93-
tools.log.info(`Updating existing issue ${existingIssue.title}#${existingIssue.number}: ${existingIssue.html_url}`)
113+
tools.log.info(
114+
`Updating existing issue ${existingIssue.title}#${existingIssue.number}: ${existingIssue.html_url}`
115+
);
94116
const issue = await tools.github.issues.update({
95117
...tools.context.repo,
96118
issue_number: existingIssue.number,
97-
body: templated.body
98-
})
99-
setOutputs(tools, issue.data)
100-
tools.exit.success(`Updated issue ${existingIssue.title}#${existingIssue.number}: ${existingIssue.html_url}`)
119+
body: templated.body,
120+
});
121+
setOutputs(tools, issue.data);
122+
tools.exit.success(
123+
`Updated issue ${existingIssue.title}#${existingIssue.number}: ${existingIssue.html_url}`
124+
);
101125
} catch (err: any) {
102-
return logError(tools, template, 'updating', err)
126+
return logError(tools, template, "updating", err);
103127
}
104128
}
105129
} else {
106-
tools.log.info('No existing issue found to update')
130+
tools.log.info("No existing issue found to update");
107131
}
108132
}
109133

110134
// Create the new issue
111-
tools.log.info(`Creating new issue ${templated.title}`)
135+
tools.log.info(`Creating new issue ${templated.title}`);
112136
try {
113137
const issue = await tools.github.issues.create({
114138
...tools.context.repo,
115139
...templated,
116-
assignees: assignees ? listToArray(assignees) : listToArray(attributes.assignees),
140+
assignees: assignees
141+
? listToArray(assignees)
142+
: listToArray(attributes.assignees),
117143
labels: listToArray(attributes.labels),
118-
milestone: Number(tools.inputs.milestone || attributes.milestone) || undefined
119-
})
120-
121-
setOutputs(tools, issue.data)
122-
tools.log.success(`Created issue ${issue.data.title}#${issue.data.number}: ${issue.data.html_url}`)
144+
milestone:
145+
Number(tools.inputs.milestone || attributes.milestone) || undefined,
146+
});
147+
148+
setOutputs(tools, issue.data);
149+
tools.log.success(
150+
`Created issue ${issue.data.title}#${issue.data.number}: ${issue.data.html_url}`
151+
);
123152
} catch (err: any) {
124-
return logError(tools, template, 'creating', err)
153+
return logError(tools, template, "creating", err);
125154
}
126155
}

src/helpers.ts

+21-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
import { Toolkit } from 'actions-toolkit'
2-
import { z } from 'zod'
1+
import { Toolkit } from "actions-toolkit";
2+
import { z } from "zod";
33

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-
}).strict()
4+
export const frontmatterSchema = z
5+
.object({
6+
title: z.string(),
7+
assignees: z.union([z.array(z.string()), z.string()]).optional(),
8+
labels: z.union([z.array(z.string()), z.string()]).optional(),
9+
milestone: z.union([z.string(), z.number()]).optional(),
10+
})
11+
.strict();
1012

11-
export type FrontMatterAttributes = z.infer<typeof frontmatterSchema>
13+
export type FrontMatterAttributes = z.infer<typeof frontmatterSchema>;
1214

13-
export function setOutputs (tools: Toolkit, issue: { number: number, html_url: string }) {
14-
tools.outputs.number = String(issue.number)
15-
tools.outputs.url = issue.html_url
15+
export function setOutputs(
16+
tools: Toolkit,
17+
issue: { number: number; html_url: string }
18+
) {
19+
tools.outputs.number = String(issue.number);
20+
tools.outputs.url = issue.html_url;
1621
}
1722

18-
export function listToArray (list?: string[] | string) {
19-
if (!list) return []
20-
return Array.isArray(list) ? list : list.split(', ')
21-
}
23+
export function listToArray(list?: string[] | string) {
24+
if (!list) return [];
25+
return Array.isArray(list) ? list : list.split(", ");
26+
}

src/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Toolkit } from 'actions-toolkit'
2-
import { createAnIssue } from './action'
1+
import { Toolkit } from "actions-toolkit";
2+
import { createAnIssue } from "./action";
33

44
Toolkit.run(createAnIssue, {
5-
secrets: ['GITHUB_TOKEN']
6-
})
5+
secrets: ["GITHUB_TOKEN"],
6+
});

tests/fixtures/event.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"repository": {
3-
"owner": { "login": "JasonEtco" },
3+
"owner": {
4+
"login": "JasonEtco"
5+
},
46
"name": "waddup"
57
}
6-
}
8+
}

0 commit comments

Comments
 (0)