-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdangerfile.ts
32 lines (28 loc) · 1.07 KB
/
dangerfile.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
30
31
32
import { danger, fail, warn } from "danger"
const title = danger.github.pr.title
const body = danger.github.pr.body
const checkTitle = () => {
const allowedPrefixList = ["chore", "docs", "feat", "fix", "perf", "refactor", "style", "test"]
const allowTitleRegex = new RegExp(`^(${allowedPrefixList.join("|")})(\\(([\\w$.* -]*)\\))?: (.+)(?:\\n|$)`, "g")
if (!allowTitleRegex.test(title)) {
fail(
`PRのタイトルが不正です: \`${title}\`\n次のいずれかのPrefixを使用してください: \n${allowedPrefixList
.map((prefix) => {
return `\`${prefix}: \``
})
.join(" ")}\n例: \`feat: ユーザーの削除機能を追加\``,
)
}
}
const checkCloseIssue = () => {
if (
!/\[bot\]$/.test(danger.github.pr.user.login) &&
!/(close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved)\s+(#\d+|https:\/\/github\.com\/[\w.-]+\/[\w.-]+\/issues\/\d+)/i.test(
body,
)
) {
warn("このPRが解決するIssueへのリンクを記載してください。\n例: `close #123`")
}
}
checkTitle()
checkCloseIssue()