From eb3b2b5a638e4f3f2914a0c2d923af8f84fdd96d Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Wed, 8 Mar 2023 00:02:37 +0100 Subject: [PATCH] ci: danger: check author/committer email --- .gitlab/dangerjs/dangerfile.js | 1 + .gitlab/dangerjs/mrCommitsEmail.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 .gitlab/dangerjs/mrCommitsEmail.js diff --git a/.gitlab/dangerjs/dangerfile.js b/.gitlab/dangerjs/dangerfile.js index dae0a1bc5a..e5bce92615 100644 --- a/.gitlab/dangerjs/dangerfile.js +++ b/.gitlab/dangerjs/dangerfile.js @@ -17,6 +17,7 @@ async function runChecks() { // Checks for MR commits require("./mrCommitsTooManyCommits.js")(); require("./mrCommitsCommitMessage.js")(); + require("./mrCommitsEmail.js")(); // Checks for MR code require("./mrSizeTooLarge.js")(); diff --git a/.gitlab/dangerjs/mrCommitsEmail.js b/.gitlab/dangerjs/mrCommitsEmail.js new file mode 100644 index 0000000000..9ffc1b7eea --- /dev/null +++ b/.gitlab/dangerjs/mrCommitsEmail.js @@ -0,0 +1,16 @@ +/** + * Check if the author is accidentally making a commit using a personal email + * + * @dangerjs INFO + */ +module.exports = function () { + const mrCommitAuthorEmails = danger.gitlab.commits.map(commit => commit.author_email); + const mrCommitCommitterEmails = danger.gitlab.commits.map(commit => commit.committer_email); + const emailPattern = /.*@espressif\.com/; + const filteredEmails = [...mrCommitAuthorEmails, ...mrCommitCommitterEmails].filter((email) => !emailPattern.test(email)); + if (filteredEmails.length) { + return message( + `Some of the commits were authored or committed by developers outside Espressif: ${filteredEmails.join(', ')}. Please check if this is expected.` + ); + } +};