Skip to content

Commit

Permalink
Selecting a branch to scan
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfratello committed May 2, 2024
1 parent 53043f6 commit f11ee1b
Show file tree
Hide file tree
Showing 7 changed files with 2,327 additions and 1,231 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
coverage
.yarn
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ You can then use the options of the command to fine tune the results.
- `--json file.json` Output the raw data to a json file. (used in conjunction with `--verbose` will output raw data per file as well)
- `--max-contributors 10` Allows to customize the number of active contributors displayed in the table (default: 10)
- `--max-lost-contributors 10` Allows to customize the number of lost contributors displayed in the list (default: 10)
- `--branch` The branch of repository to scan (default: master)


A more advanced example :
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
],
"type": "module",
"main": "./src/index.js",
"bin": {
"absorption": "./src/bin.js"
},
"bin": "./src/bin.js",
"engines": {
"node": ">=18.0.0"
},
Expand Down
24 changes: 17 additions & 7 deletions src/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,17 @@ yargs(hideBin(process.argv))
const weights = argv.weights ? await loadFile(argv.weights) : {};
const withMedia = argv.withMedia;
const withLockfiles = argv.withLockfiles;
const branch = argv.branch;

const getWeight = prepareWeights(weights, withMedia, withLockfiles);

await listFiles(repository, (filename, hash) => {
console.log(` ${filename} ${getWeight(filename)}`);
});
await listFiles(
repository,
(filename, hash) => {
console.log(` ${filename} ${getWeight(filename)}`);
},
branch
);
}
)
.command(
Expand All @@ -178,15 +183,15 @@ yargs(hideBin(process.argv))
const verbose = argv.verbose;
const maxContributors = argv.maxContributors;
const maxLostContributors = argv.maxLostContributors;
const branch = argv.branch;

const result = await calculate(
contributors,
prepareWeights(weights, withMedia, withLockfiles),
threshold,
repository,
verbose,
maxContributors,
maxLostContributors
branch
);

if (argv.json) {
Expand All @@ -207,14 +212,14 @@ yargs(hideBin(process.argv))

renderTitle("Fresh/Fading knowledge");
if (result.knowledge.fresh.length) {
renderFresh(result, argv.maxContributors);
renderFresh(result, maxContributors);
} else {
console.log("It seems this repository has no fresh knowledge.");
}

renderTitle("Lost knowledge");
if (result.knowledge.lost.length) {
renderLost(result, argv.maxLostContributors);
renderLost(result, maxLostContributors);
} else {
console.log(
"It seems this repository has no lost knowledge, congratulations !"
Expand Down Expand Up @@ -263,6 +268,11 @@ yargs(hideBin(process.argv))
type: "boolean",
default: false
})
.option("branch", {
describe: "The branch to scan",
type: "string",
default: "master"
})
.option("verbose", {
type: "boolean",
default: false
Expand Down
44 changes: 24 additions & 20 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ export default async function main(
threshold,
repository,
verbose,
maxContributors,
maxLostContributors
branch
) {
let queueMaxSize = 0;
const queue = new Queue({ concurrency: maxProcess });
Expand Down Expand Up @@ -222,30 +221,35 @@ export default async function main(
}
}

await listFiles(execa, repository, (filename, hash) => {
const weight = getWeight(filename);
await listFiles(
execa,
repository,
(filename, hash) => {
const weight = getWeight(filename);

if (weight === 0) {
if (verbose) {
console.log("Ignoring file", filename);
if (weight === 0) {
if (verbose) {
console.log("Ignoring file", filename);
}

return;
}

return;
}
const cacheKey = `${repositoryCacheKey}:${hash}:${filename}:v2`;
queue.add(async () => {
const newData = await cacheInstance.wrap(cacheKey, () =>
getBlame(execa, repository, filename, branch)
);

const cacheKey = `${repositoryCacheKey}:${hash}:${filename}:v2`;
queue.add(async () => {
const newData = await cacheInstance.wrap(cacheKey, () =>
getBlame(execa, repository, filename)
);
fileData[filename] = newData;

fileData[filename] = newData;
const balanced = rebalance(newData, weight);

const balanced = rebalance(newData, weight);

appendBlame(data, balanced);
});
});
appendBlame(data, balanced);
});
},
branch
);

await queue.onIdle();
progress.stop();
Expand Down
Loading

0 comments on commit f11ee1b

Please sign in to comment.