fix: exclude renames from contributor generation (#1643)

* fix: exclude renames from contributor generation

* fix: exclude renames from contributor generation
This commit is contained in:
Jakob Guddas
2023-10-30 21:31:25 +01:00
committed by GitHub
parent f3a33346dd
commit 372735999f
+14 -1
View File
@@ -9,6 +9,8 @@ const FETCH_DEPTH = process.env.FETCH_DEPTH || 1000;
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
const git = simpleGit();
const cache = new Map();
const getUserName = pMemoize(
@@ -26,8 +28,19 @@ const getUserName = pMemoize(
{ cacheKey: ([commit]) => commit.author_email, cache }
);
// Check that a commit changes more than just the icon name
const isCommitRelevant = async (hash, file) => {
const summary = await git.diffSummary(['--diff-filter=AM', `${hash}~1`, hash]);
return summary.files.some(({ file: name }) => name === file);
};
const getContributors = async (file, includeCoAuthors) => {
const { all: commits } = await simpleGit().log([`HEAD~${FETCH_DEPTH}..`, '--', file]);
const { all } = await git.log([`HEAD~${FETCH_DEPTH}..`, '--', file]);
const commits = file.endsWith('.svg')
? (
await Promise.all(all.map((commit) => isCommitRelevant(commit.hash, file) && commit))
).filter(Boolean)
: all;
const emails = new Map();
for (let i = commits.length - 1; i >= 0; i -= 1) {