From 372735999f514f5d6580c0b4f0d0f342eb012c20 Mon Sep 17 00:00:00 2001 From: Jakob Guddas Date: Mon, 30 Oct 2023 21:31:25 +0100 Subject: [PATCH] fix: exclude renames from contributor generation (#1643) * fix: exclude renames from contributor generation * fix: exclude renames from contributor generation --- scripts/updateContributors.mjs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/scripts/updateContributors.mjs b/scripts/updateContributors.mjs index 6243503df..03b9f9571 100644 --- a/scripts/updateContributors.mjs +++ b/scripts/updateContributors.mjs @@ -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) {