1 Star 0 Fork 10

甜甜圈好甜/Mudlet

forked from Mudlet/Mudlet 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
dangerfile.js 2.24 KB
一键复制 编辑 原始数据 按行查看 历史
const {danger, fail, message, warn} = require('danger');
const ISSUE_REGEX = /https?:\/\/(?:www\.)?github\.com\/Mudlet\/Mudlet\/issues\/(\d+)/i
const ISSUE_URL = "https://github.com/Mudlet/Mudlet/issues"
const SOURCE_REGEX = /.*\.(cpp|c|h|lua)$/i
const TITLE_REGEX = /^(fix|improve|add|infra)/i
const touched_files = [...danger.git.created_files, ...danger.git.modified_files]
const sourcefiles = touched_files.filter(item => item.match(SOURCE_REGEX))
const pr_title = danger.github.pr.title
// Checks the title to make sure it matches expectations
const title_type = pr_title.match(TITLE_REGEX)
if (title_type) {
const type_to_readable = {
add: "Addition",
fix: "Fix",
improve: "Improvement",
infra: "Infrastructure"
}
message(`PR type: \`${type_to_readable[title_type[0].toLowerCase()]}\``, {icon: ":heavy_check_mark:", line: 1})
} else if(pr_title.match(/^\[?WIP\]?/i)) {
fail("PR is still a WIP, do not merge")
} else {
fail("PR title must start with `fix`, `improve`, `add` or `infra` for release notes purposes.")
}
// checks sourcefile changes to ensure any new TODO items also have a Mudlet issue
sourcefiles.forEach(function(filename) {
const additions = danger.git.diffForFile(filename)
additions.then(diff => {
const issues = []
diff.added.split("\n").forEach(function(item) {
if (item.includes("TODO:")) {
const has_issue = item.match(ISSUE_REGEX)
if (!has_issue) {
fail(`Source file ${filename} includes a TODO with no Mudlet issue link.\n New TODO items in source files must have an accompanying github issue`)
} else {
issues.push(has_issue[1])
}
}
})
if (issues.length > 0) {
message(`\`${filename}\` adds TODO issues: ${issues.map(iss => `[${iss}](${ISSUE_URL}/${iss})`).join(", ")}`,{icon: ":heavy_check_mark:"} )
}
})
})
// Warns if a PR touched more than 10 source files.
if (sourcefiles.length > 10) {
warn(`PR makes changes to ${sourcefiles.length} source files. Double check the scope hasn't gotten out of hand`)
}
// Warns if the title is perhaps a bit verbose
const title_wordcount = pr_title.split(" ").length
if (title_wordcount > 25) {
warn(`PR title is ${title_wordcount} words long, double check it will make a good changelog line`)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/doughnuts-are-so-sweet/Mudlet.git
git@gitee.com:doughnuts-are-so-sweet/Mudlet.git
doughnuts-are-so-sweet
Mudlet
Mudlet
development

搜索帮助