Contributors plugin: Display contributors per contribution category (#443)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//Setup
|
||||
export default async function({login, q, imports, data, rest, graphql, queries, account}, {enabled = false} = {}) {
|
||||
export default async function({login, q, imports, data, rest, graphql, queries, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
@@ -7,7 +7,7 @@ export default async function({login, q, imports, data, rest, graphql, queries,
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
let {head, base, ignored, contributions} = imports.metadata.plugins.contributors.inputs({data, account, q})
|
||||
let {head, base, ignored, contributions, sections, categories} = imports.metadata.plugins.contributors.inputs({data, account, q})
|
||||
const repo = {owner:data.repo.owner.login, repo:data.repo.name}
|
||||
|
||||
//Retrieve head and base commits
|
||||
@@ -67,8 +67,57 @@ export default async function({login, q, imports, data, rest, graphql, queries,
|
||||
for (const contributor of Object.values(contributors))
|
||||
contributor.pr = [...new Set(contributor.pr)]
|
||||
|
||||
//Contributions categories
|
||||
const types = Object.fromEntries([...new Set(Object.keys(categories))].map(type => [type, new Set()]))
|
||||
if ((sections.includes("categories"))&&(extras)) {
|
||||
//Temporary directory
|
||||
const repository = `${repo.owner}/${repo.repo}`
|
||||
const path = imports.paths.join(imports.os.tmpdir(), `${repository.replace(/[^\w]/g, "_")}`)
|
||||
console.debug(`metrics/compute/${login}/plugins > contributors > cloning ${repository} to temp dir ${path}`)
|
||||
|
||||
try {
|
||||
//Git clone into temporary directory
|
||||
await imports.fs.rm(path, {recursive:true, force:true})
|
||||
await imports.fs.mkdir(path, {recursive:true})
|
||||
const git = await imports.git(path)
|
||||
await git.clone(`https://github.com/${repository}`, ".").status()
|
||||
|
||||
//Analyze contributors' contributions
|
||||
for (const contributor in contributors) {
|
||||
//Load edited files by contributor
|
||||
const files = []
|
||||
await imports.spawn("git", ["--no-pager", "log", `--author="${contributor}"`, "--regexp-ignore-case", "--no-merges", "--name-only", '--pretty=format:""'], {cwd:path}, {
|
||||
stdout(line) {
|
||||
if (line.trim().length)
|
||||
files.push(line)
|
||||
}
|
||||
})
|
||||
//Search for contributions type in specified categories
|
||||
filesloop: for (const file of files) {
|
||||
for (const [category, globs] of Object.entries(categories)) {
|
||||
for (const glob of [globs].flat(Infinity)) {
|
||||
if (imports.minimatch(file, glob, {nocase:true})) {
|
||||
types[category].add(contributor)
|
||||
continue filesloop
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.debug(error)
|
||||
console.debug(`metrics/compute/${login}/plugins > contributors > an error occured while processing ${repository}`)
|
||||
}
|
||||
finally {
|
||||
//Cleaning
|
||||
console.debug(`metrics/compute/${login}/plugins > contributors > cleaning temp dir ${path}`)
|
||||
await imports.fs.rm(path, {recursive:true, force:true})
|
||||
}
|
||||
}
|
||||
|
||||
//Results
|
||||
return {head, base, ref, list:contributors, contributions}
|
||||
return {head, base, ref, list:contributors, categories:types, contributions, sections}
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user