mudlet/dangerfile.js
Vadim Peretokin 5111509577
Infrastructure: trial new guideline - no TODOs as they dont actually add value (#6446)
<!-- Keep the title short & concise so anyone non-technical can
understand it,
     the title appears in PTB changelogs -->
#### Brief overview of PR changes/additions
Trial a new project guideline for the codebase - no TODOs in the code.

#### Motivation for adding to Mudlet
We've added 100+ TODOs to the codebase over the 10+ years of Mudlet and
have barely resolved any of them. They just don't add any value by
sitting around, and nobody historically has taken an interest in going
through and resolving them.
#### Other info (issues closed, discussion etc)
Let's revisit on 1 Jan 2023 if this guideline still makes sense and we'd
like to keep it.
2022-11-27 22:41:08 +01:00

39 lines
1.6 KiB
JavaScript

const {danger, fail, message, warn} = require('danger');
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) {
// no-op
} 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 => {
diff.added.split("\n").forEach(function(item) {
if (item.includes("TODO:")) {
fail(`Source file ${filename} includes a TODO! Can you make the change right away? If no, better not to create a TODO - they just tend to hang around and never get fixed.`)
}
})
})
})
// 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`)
}