mrCommitsEmail.js 960 B

1234567891011121314151617181920212223
  1. const { recordRuleExitStatus } = require("./configParameters.js");
  2. /**
  3. * Check if the author is accidentally making a commit using a personal email
  4. *
  5. * @dangerjs INFO
  6. */
  7. module.exports = function () {
  8. const ruleName = 'Commits from outside Espressif';
  9. const mrCommitAuthorEmails = danger.gitlab.commits.map(commit => commit.author_email);
  10. const mrCommitCommitterEmails = danger.gitlab.commits.map(commit => commit.committer_email);
  11. const emailPattern = /.*@espressif\.com/;
  12. const filteredEmails = [...mrCommitAuthorEmails, ...mrCommitCommitterEmails].filter((email) => !emailPattern.test(email));
  13. if (filteredEmails.length) {
  14. recordRuleExitStatus(ruleName, "Failed");
  15. return message(
  16. `Some of the commits were authored or committed by developers outside Espressif: ${filteredEmails.join(', ')}. Please check if this is expected.`
  17. );
  18. }
  19. // At this point, the rule has passed
  20. recordRuleExitStatus(ruleName, 'Passed');
  21. };