mirror of
				https://github.com/scm-manager/scm-manager.git
				synced 2025-10-31 10:35:56 +01:00 
			
		
		
		
	Improve committer accuracy
Changes made by the SCM-Manager, like those through the editor and pull requests, now more accurately define the committer on the underlying changeset. Committed-by: Eduard Heimbuch <eduard.heimbuch@cloudogu.com> Co-authored-by: Eduard Heimbuch <eduard.heimbuch@cloudogu.com>
This commit is contained in:
		
				
					committed by
					
						 SCM-Manager
						SCM-Manager
					
				
			
			
				
	
			
			
			
						parent
						
							8eb2687e10
						
					
				
				
					commit
					7e83d34fc0
				
			
							
								
								
									
										2
									
								
								gradle/changelog/committers.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								gradle/changelog/committers.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | ||||
| - type: changed | ||||
|   description: Improve committer accuracy | ||||
| @@ -232,7 +232,7 @@ class AbstractGitCommand { | ||||
|         if (!status.isClean() || isInMerge()) { | ||||
|           return of(clone.commit() | ||||
|             .setAuthor(authorToUse.getName(), authorToUse.getMail()) | ||||
|             .setCommitter("SCM-Manager", "noreply@scm-manager.org") | ||||
|             .setCommitter(authorToUse.getName(), authorToUse.getMail()) | ||||
|             .setMessage(message) | ||||
|             .setSign(sign) | ||||
|             .setSigningKey(sign ? "SCM-MANAGER-DEFAULT-KEY" : null) | ||||
|   | ||||
| @@ -24,6 +24,9 @@ | ||||
|  | ||||
| package sonia.scm.repository.spi; | ||||
|  | ||||
| import com.github.sdorra.shiro.SubjectAware; | ||||
| import org.apache.shiro.subject.SimplePrincipalCollection; | ||||
| import org.apache.shiro.subject.Subject; | ||||
| import org.eclipse.jgit.api.Git; | ||||
| import org.eclipse.jgit.api.errors.GitAPIException; | ||||
| import org.eclipse.jgit.lib.ObjectId; | ||||
| @@ -39,6 +42,7 @@ import sonia.scm.ScmConstraintViolationException; | ||||
| import sonia.scm.repository.GitTestHelper; | ||||
| import sonia.scm.repository.Person; | ||||
| import sonia.scm.repository.RepositoryHookType; | ||||
| import sonia.scm.user.User; | ||||
|  | ||||
| import java.io.File; | ||||
| import java.io.IOException; | ||||
| @@ -55,6 +59,8 @@ import static org.mockito.Mockito.verify; | ||||
|  | ||||
| public class GitModifyCommandTest extends GitModifyCommandTestBase { | ||||
|  | ||||
|   private static final String REALM = "AdminRealm"; | ||||
|  | ||||
|   @Override | ||||
|   protected String getZippedRepositoryResource() { | ||||
|     return "sonia/scm/repository/spi/scm-git-spi-move-test.zip"; | ||||
| @@ -75,6 +81,8 @@ public class GitModifyCommandTest extends GitModifyCommandTestBase { | ||||
|       RevCommit lastCommit = getLastCommit(git); | ||||
|       assertThat(lastCommit.getFullMessage()).isEqualTo("Make some change"); | ||||
|       assertThat(lastCommit.getAuthorIdent().getName()).isEqualTo("Dirk Gently"); | ||||
|       assertThat(lastCommit.getCommitterIdent().getName()).isEqualTo("Dirk Gently"); | ||||
|       assertThat(lastCommit.getCommitterIdent().getEmailAddress()).isEqualTo("dirk@holistic.det"); | ||||
|       assertThat(newRef).isEqualTo(lastCommit.toObjectId().name()); | ||||
|     } | ||||
|   } | ||||
| @@ -528,4 +536,11 @@ public class GitModifyCommandTest extends GitModifyCommandTestBase { | ||||
|     return request; | ||||
|   } | ||||
|  | ||||
|   private ModifyCommandRequest prepareModifyCommandRequestWithoutAuthorEmail() { | ||||
|     ModifyCommandRequest request = new ModifyCommandRequest(); | ||||
|     request.setAuthor(new Person("Dirk Gently", "")); | ||||
|     request.setCommitMessage("Make some change"); | ||||
|     return request; | ||||
|   } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -91,6 +91,14 @@ public class SvnModifyCommand implements ModifyCommand { | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   private String getCurrentUserName() { | ||||
|     if (SecurityUtils.getSubject() != null && SecurityUtils.getSubject().getPrincipal() != null) { | ||||
|       return SecurityUtils.getSubject().getPrincipal().toString(); | ||||
|     } else { | ||||
|       return "SCM-Manager"; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   private String commitChanges(SVNClientManager clientManager, File workingDirectory, String commitMessage) { | ||||
|     try { | ||||
|       clientManager.setAuthenticationManager(SVNWCUtil.createDefaultAuthenticationManager(getCurrentUserName(), new char[0])); | ||||
| @@ -110,14 +118,6 @@ public class SvnModifyCommand implements ModifyCommand { | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   private String getCurrentUserName() { | ||||
|     if (SecurityUtils.getSubject() != null && SecurityUtils.getSubject().getPrincipal() != null) { | ||||
|       return SecurityUtils.getSubject().getPrincipal().toString(); | ||||
|     } else { | ||||
|       return "SCM-Manager"; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   private void modifyWorkingDirectory(ModifyCommandRequest request, SVNClientManager clientManager, File workingDirectory) { | ||||
|     for (ModifyCommandRequest.PartialRequest partialRequest : request.getRequests()) { | ||||
|       try { | ||||
|   | ||||
| @@ -25,6 +25,7 @@ | ||||
| package sonia.scm.repository.spi; | ||||
|  | ||||
| import io.micrometer.core.instrument.simple.SimpleMeterRegistry; | ||||
| import org.apache.shiro.subject.PrincipalCollection; | ||||
| import org.apache.shiro.subject.Subject; | ||||
| import org.apache.shiro.util.ThreadContext; | ||||
| import org.junit.After; | ||||
| @@ -41,6 +42,7 @@ import sonia.scm.repository.api.FileLockedException; | ||||
| import sonia.scm.repository.work.NoneCachingWorkingCopyPool; | ||||
| import sonia.scm.repository.work.WorkdirProvider; | ||||
| import sonia.scm.repository.work.WorkingCopy; | ||||
| import sonia.scm.user.User; | ||||
|  | ||||
| import java.io.File; | ||||
| import java.io.IOException; | ||||
| @@ -75,7 +77,10 @@ public class SvnModifyCommandTest extends AbstractSvnCommandTestBase { | ||||
|   @Before | ||||
|   public void initSecurityManager() { | ||||
|     Subject subject = mock(Subject.class); | ||||
|     PrincipalCollection principalCollection = mock(PrincipalCollection.class); | ||||
|     when(subject.getPrincipal()).thenReturn("alThor"); | ||||
|     when(subject.getPrincipals()).thenReturn(principalCollection); | ||||
|     when(principalCollection.oneByType(User.class)).thenReturn(new User("galaxy", "quest", "galaxy@quest.com")); | ||||
|     ThreadContext.bind(subject); | ||||
|   } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user