From cc706565473bb9583c0b37e2c7b793f4735a5784 Mon Sep 17 00:00:00 2001 From: Cristian Morales Vega Date: Fri, 23 Dec 2022 11:48:57 +0000 Subject: [PATCH] JENKINS-70331: Always honor useExistingAccountWithSameEmail useExistingAccountWithSameEmail makes sense on its own, independently of how a new account may be created if required. --- src/main/java/hudson/plugins/git/GitChangeSet.java | 8 ++++++++ src/test/java/hudson/plugins/git/GitChangeSetTest.java | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/hudson/plugins/git/GitChangeSet.java b/src/main/java/hudson/plugins/git/GitChangeSet.java index 710d17a8c7..a79f93e9fc 100644 --- a/src/main/java/hudson/plugins/git/GitChangeSet.java +++ b/src/main/java/hudson/plugins/git/GitChangeSet.java @@ -480,6 +480,14 @@ public User findOrCreateUser(String csAuthor, String csAuthorEmail, boolean crea } } } else { + if (useExistingAccountWithSameEmail && hasMailerPlugin()) { + for(User existingUser : User.getAll()) { + if (csAuthorEmail.equalsIgnoreCase(getMail(existingUser))) { + return existingUser; + } + } + } + if (csAuthor.isEmpty()) { // Avoid exception from User.get("", false) return User.getUnknown(); diff --git a/src/test/java/hudson/plugins/git/GitChangeSetTest.java b/src/test/java/hudson/plugins/git/GitChangeSetTest.java index caa8cf418e..e2a4aaa60e 100644 --- a/src/test/java/hudson/plugins/git/GitChangeSetTest.java +++ b/src/test/java/hudson/plugins/git/GitChangeSetTest.java @@ -196,7 +196,7 @@ public void testFindOrCreateUserBasedOnExistingUsersEmail() throws IOException { final String existingUserId = "An existing user"; final String existingUserFullName = "Some FullName"; final String email = "jcommitter@nospam.com"; - final boolean createAccountBasedOnEmail = true; + final boolean createAccountBasedOnEmail = random.nextBoolean(); final boolean useExistingAccountBasedOnEmail = true; assertNull(User.get(email, false));