Skip to content
Permalink
Browse files

Merge pull request #123 from richtmat/master

Fixing JENKINS-16453
  • Loading branch information
ndeloof committed Jan 29, 2013
2 parents a0b9699 + ff2b7e9 commit dcd4f2c1cb21dd0bd7252e9e683df5e45a8a9d98
@@ -11,7 +11,9 @@
import hudson.scm.ChangeLogSet.AffectedFile;
import hudson.scm.EditType;
import hudson.tasks.Mailer;
import hudson.tasks.Mailer.UserProperty;

import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

@@ -259,6 +261,7 @@ public User findOrCreateUser(String csAuthor, String csAuthorEmail, boolean crea
try {
user = User.get(csAuthorEmail, true);
user.setFullName(csAuthor);
user.addProperty(new Mailer.UserProperty(csAuthorEmail));
user.save();
} catch (IOException e) {
// add logging statement?
@@ -271,7 +274,7 @@ public User findOrCreateUser(String csAuthor, String csAuthorEmail, boolean crea
user = User.get(csAuthorEmail.split("@")[0], true);
}
// set email address for user if none is already available
if (fixEmpty(csAuthorEmail) != null && user.getProperty(Mailer.UserProperty.class)==null) {
if (fixEmpty(csAuthorEmail) != null && !isMailerPropertySet(user)) {
try {
user.addProperty(new Mailer.UserProperty(csAuthorEmail));
} catch (IOException e) {
@@ -281,7 +284,19 @@ public User findOrCreateUser(String csAuthor, String csAuthorEmail, boolean crea
return user;
}

private boolean isCreateAccountBasedOnEmail() {
private boolean isMailerPropertySet(User user) {
boolean isPropertySet = false;
UserProperty property = user.getProperty(Mailer.UserProperty.class);
if (property != null) {
if(!StringUtils.isEmpty(property.getAddress())) {
isPropertySet = true;
}
}

return isPropertySet;
}

private boolean isCreateAccountBasedOnEmail() {
DescriptorImpl descriptor = (DescriptorImpl) Hudson.getInstance().getDescriptor(GitSCM.class);

return descriptor.isCreateAccountBasedOnEmail();
@@ -1,14 +1,21 @@
package hudson.plugins.git;

import hudson.model.User;
import hudson.plugins.git.GitChangeSet.Path;
import hudson.scm.EditType;
import hudson.tasks.Mailer;
import hudson.tasks.Mailer.UserProperty;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;

import org.jvnet.hudson.test.HudsonTestCase;

import junit.framework.Assert;
import junit.framework.TestCase;

public class GitChangeSetTest extends TestCase {
public class GitChangeSetTest extends HudsonTestCase {

public GitChangeSetTest(String testName) {
super(testName);
@@ -106,4 +113,21 @@ public void testAuthorOrCommitter() {

Assert.assertEquals("John Author", authorCS.getAuthorName());
}

public void testFindOrCreateUser() {
GitChangeSet committerCS = genChangeSet(false, false);
String csAuthor = "John Author";
String csAuthorEmail = "jauthor@nospam.com";
boolean createAccountBasedOnEmail = true;

User user = committerCS.findOrCreateUser(csAuthor, csAuthorEmail, createAccountBasedOnEmail);
Assert.assertNotNull(user);

UserProperty property = user.getProperty(Mailer.UserProperty.class);
Assert.assertNotNull(property);

String address = property.getAddress();
Assert.assertNotNull(address);
Assert.assertEquals(csAuthorEmail, address);
}
}
@@ -3,7 +3,9 @@
import hudson.EnvVars;
import hudson.FilePath;
import hudson.model.TaskListener;
import hudson.model.UserProperty;
import hudson.model.User;
import hudson.tasks.Mailer;

import java.io.File;
import java.io.IOException;
@@ -36,8 +38,13 @@ public TestGitRepo(String name, HudsonTestCase forTest, TaskListener listener) t
envVars = new EnvVars();

gitDir = forTest.createTmpDir();
User.get(johnDoe.getName(), true);
User.get(janeDoe.getName(), true);
User john = User.get(johnDoe.getName(), true);
UserProperty johnsMailerProperty = new Mailer.UserProperty(johnDoe.getEmailAddress());
john.addProperty(johnsMailerProperty);

User jane = User.get(janeDoe.getName(), true);
UserProperty janesMailerProperty = new Mailer.UserProperty(janeDoe.getEmailAddress());
jane.addProperty(janesMailerProperty);

// initialize the environment
setAuthor(johnDoe);

0 comments on commit dcd4f2c

Please sign in to comment.
You can’t perform that action at this time.