Skip to content

Commit

Permalink
Add contributor-count axiom
Browse files Browse the repository at this point in the history
Adds axiom to enable rules only on projects with a certain amount of
contributors. Uses node-gitlog library to get the contributor count of the
repository. Some simple tests are also included.

See issue #169

Signed-off-by: Yann Jorelle <yann.jorelle@nokia.com>
  • Loading branch information
Yann Jorelle committed Aug 12, 2020
1 parent 1a66d77 commit a890f8a
Show file tree
Hide file tree
Showing 6 changed files with 691 additions and 608 deletions.
17 changes: 17 additions & 0 deletions axioms/contributor-count.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const gitlog = require('gitlog').default

module.exports = function (fileSystem) {
const commits = gitlog({
repo: fileSystem.targetDir,
all: true,
number: 10000 // Fetch the last 10000 commits
})
if (!commits) {
return 0
}
// Get commit authors and filter unique values
const contributors = commits
.map((commit) => commit.authorName.toLowerCase())
.filter((value, index, self) => self.indexOf(value) === index)
return contributors.length
}
20 changes: 20 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ module.exports.lint = function lint (targetDir, filterPaths = [], ruleset = null
// Execute axiom
const axiomFunction = require(path.join(__dirname, 'axioms', axiomId))
targets = targets.concat(axiomName + '=*')
// Handle contributor-count axiom
if (axiomId === 'contributor-count') {
const contributorAxioms = Object.keys(ruleset.rules).filter((rule) =>
rule.includes('contributor')
)
// Evaluate each contributor axiom
contributorAxioms.forEach((axiom) => {
const operator = axiom.match(/<|>|=/g)[0]
const num = Number(axiom.match(/[0-9]+/g)[0])
const evaluate = {
'<': (a, b) => a < b,
'>': (a, b) => a > b,
'=': (a, b) => a === b
}
if (evaluate[operator](axiomFunction(fileSystem), num)) {
targets = targets.concat(axiomName + operator + num)
}
})
return
}
targets = targets.concat(axiomFunction(fileSystem).map(axiomOutput => axiomName + '=' + axiomOutput))
})
}
Expand Down
Loading

0 comments on commit a890f8a

Please sign in to comment.