-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
run knowledge gap analysis applying the filtering for ignored files
- Loading branch information
Showing
8 changed files
with
111 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.env | ||
node_modules | ||
.idea | ||
.idea | ||
.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { debug } from "codebase-stats-collector/dist/console/console.js"; | ||
import { SummaryDashboard } from "codebase-stats-collector/dist/dashboard/summary-dashboard.js"; | ||
import { GitRepository } from "codebase-stats-collector/dist/git-reader/git-repository.js"; | ||
import { ExpandedCommit } from "codebase-stats-collector/dist/interfaces.js"; | ||
import { getNumberOfContributorsPerFile } from "codebase-stats-collector/dist/stats/number-of-contributors-per-file.js"; | ||
import { Readable } from "stream"; | ||
|
||
import { log } from "../console.js"; | ||
|
||
function setupProgressStream(summaryDashboard: SummaryDashboard): Readable { | ||
let commitsCounter = 0; | ||
|
||
const commitsStream = new Readable({ | ||
objectMode: true, | ||
read() { | ||
// do nothing. | ||
}, | ||
}); | ||
commitsStream.on("data", (commit: ExpandedCommit) => { | ||
debug("Commit", commit); | ||
|
||
commitsCounter += 1; | ||
summaryDashboard.setCurrentProgress(commitsCounter, commit); | ||
}); | ||
commitsStream.on("error", (err) => { | ||
debug("error reading commits", { err }); | ||
}); | ||
commitsStream.on("end", () => { | ||
debug("done reading commits", {}); | ||
}); | ||
commitsStream.on("close", () => { | ||
debug("stream closed", {}); | ||
}); | ||
return commitsStream; | ||
} | ||
|
||
export async function collectKnowledgeGaps( | ||
dir: string, | ||
ignoreFiles: string | null, | ||
): Promise<void> { | ||
// initialize repo | ||
const repo = new GitRepository(dir); | ||
|
||
// initialize summary dashboard: | ||
const summaryDashboard = new SummaryDashboard([]); | ||
summaryDashboard.startProgress(); | ||
|
||
const commitsStream = setupProgressStream(summaryDashboard); | ||
|
||
// number of total commits: | ||
const commits = await repo.getListOfCommits(); | ||
summaryDashboard.setCommits(commits); | ||
|
||
const commitsWithChangedFiles = await repo.getListOfCommitsWithChangedFiles({ | ||
stream: commitsStream, | ||
}); | ||
const contributorsPerFile = getNumberOfContributorsPerFile( | ||
commitsWithChangedFiles, | ||
).filter((x) => x.isExistingFile); | ||
let knowledgeGaps = contributorsPerFile.sort((a, b) => { | ||
if (a.contributorsNames.length === b.contributorsNames.length) { | ||
return a.lastChange.getTime() - b.lastChange.getTime(); | ||
} | ||
return a.contributorsNames.length - b.contributorsNames.length; | ||
}); | ||
|
||
if (ignoreFiles) { | ||
knowledgeGaps = knowledgeGaps.filter((x) => !x.filePath.match(ignoreFiles)); | ||
} | ||
|
||
const topKnowledgeGaps = knowledgeGaps.slice(0, 50); | ||
|
||
log( | ||
"knowledge gaps (files with least number of contributors)", | ||
topKnowledgeGaps, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export function log(arg1: string, arg2: object | string | null) { | ||
if (arg2 === null) { | ||
// eslint-disable-next-line no-console | ||
console.log(arg1); | ||
return; | ||
} | ||
// eslint-disable-next-line no-console | ||
console.log(arg1, arg2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import { CommandLineInterface } from "./cli.js"; | ||
|
||
|
||
export function main() { | ||
new CommandLineInterface().run(); | ||
new CommandLineInterface().run(); | ||
} | ||
main(); | ||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters