-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckTemplate.ts
executable file
·29 lines (25 loc) · 1.1 KB
/
checkTemplate.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { danger, markdown } from "danger"
import { Issues } from "github-webhook-event-types"
// Support checking if the issue has the same content as the issue template.
export default async (issueWebhook: Issues) => {
const issue = issueWebhook.issue
const repo = issueWebhook.repository
// Grab, the issue template, it returns an empty string if a 404, so we can
// do a check for existence
const template = await danger.github.utils.fileContents(".github/ISSUE_TEMPLATE.md", repo.full_name)
// Whitespace between code on disk vs text which comes from GitHub is different.
// This took far too long to figure.
if (template && template.replace(/\s+/g, "") === issue.body.replace(/\s+/g, "")) {
markdown(
`Hi there, thanks for the issue, but it seem that this issue is just the default template. Please create a new issue with the template filled out.`
)
// Let's just close it.
await danger.github.api.issues.update({
...danger.github.thisPR,
number: issue.number,
state: "closed",
})
} else {
console.log("The message did not match the template.")
}
}