From d631111610f9d7fc1fea8144877db3ef6236d312 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Thu, 19 May 2022 14:09:01 +0100 Subject: [PATCH] Improvements to contribution generation - Parse Co-authored-by lines too. There's several contributors (mostly via weblate, but a few GH ones too) who weren't credited otherwise. - Add support for git mailmap, remapping some emails to a canonnical username. This allows us to remove some duplicates - nobody needs both SquidDev and "Jonathan Coates." I'm not making this file public, as it contains email addresses. This does mean that CI builds will still contain the full list with duplicates. --- build.gradle | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 8c90c9e27..3ea9a6beb 100644 --- a/build.gradle +++ b/build.gradle @@ -220,9 +220,32 @@ processResources { try { hash = ["git", "-C", projectDir, "rev-parse", "HEAD"].execute().text.trim() - def blacklist = ['GitHub', 'dan200', 'Daniel Ratcliffe'] - ["git", "-C", projectDir, "log", "--format=tformat:%an%n%cn"].execute().text.split('\n').each { - if (!blacklist.contains(it)) contributors.add(it) + def blacklist = ['GitHub', 'Daniel Ratcliffe', 'Weblate'] + + // Extract all authors, commiters and co-authors from the git log. + def authors = ["git", "-C", projectDir, "log", "--format=tformat:%an <%ae>%n%cn <%ce>%n%(trailers:key=Co-authored-by,valueonly)"] + .execute().text.readLines().unique() + + // We now pass this through git's mailmap to de-duplicate some authors. + def remapAuthors = ["git", "check-mailmap", "--stdin"].execute() + remapAuthors.withWriter { stdin -> + if (stdin !instanceof BufferedWriter) stdin = new BufferedWriter(stdin) + + authors.forEach { + if (it == "") return + if (!it.endsWith(">")) it += ">" // Some commits have broken Co-Authored-By lines! + stdin.writeLine(it) + } + stdin.close() + } + + // And finally extract out the actual name. + def emailRegex = ~/^([^<]+) <.+>$/ + remapAuthors.text.readLines().forEach { + def matcher = it =~ emailRegex + matcher.find() + def name = matcher.group(1) + if (!blacklist.contains(name)) contributors.add(name) } } catch (Exception e) { e.printStackTrace()