mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-01 19:15:52 +01:00
Extract committer as trailer in git
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
@@ -171,8 +171,8 @@ public class GitChangesetConverter implements Closeable
|
||||
|
||||
long date = GitUtil.getCommitTime(commit);
|
||||
PersonIdent authorIndent = commit.getAuthorIdent();
|
||||
Person author = new Person(authorIndent.getName(),
|
||||
authorIndent.getEmailAddress());
|
||||
PersonIdent committerIdent = commit.getCommitterIdent();
|
||||
Person author = createPersonFor(authorIndent);
|
||||
String message = commit.getFullMessage();
|
||||
|
||||
if (message != null)
|
||||
@@ -181,6 +181,9 @@ public class GitChangesetConverter implements Closeable
|
||||
}
|
||||
|
||||
Changeset changeset = new Changeset(id, date, author, message);
|
||||
if (!committerIdent.equals(authorIndent)) {
|
||||
changeset.addTrailers(Collections.singleton(new Trailer("Committed-by", createPersonFor(committerIdent))));
|
||||
}
|
||||
|
||||
if (parentList != null)
|
||||
{
|
||||
@@ -201,6 +204,9 @@ public class GitChangesetConverter implements Closeable
|
||||
return changeset;
|
||||
}
|
||||
|
||||
public Person createPersonFor(PersonIdent personIndent) {
|
||||
return new Person(personIndent.getName(), personIndent.getEmailAddress());
|
||||
}
|
||||
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
@@ -34,6 +34,7 @@ import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.GitRepositoryConfig;
|
||||
import sonia.scm.repository.Modifications;
|
||||
import sonia.scm.repository.Person;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -271,6 +272,20 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
assertEquals("master", changesets.getBranchName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldAppendCommitterAsTrailer() {
|
||||
LogCommandRequest request = new LogCommandRequest();
|
||||
request.setStartChangeset("fcd0ef1831e4002ac43ea539f4094334c79ea9ec");
|
||||
request.setEndChangeset("fcd0ef1831e4002ac43ea539f4094334c79ea9ec");
|
||||
|
||||
ChangesetPagingResult changesets = createCommand().getChangesets(request);
|
||||
Changeset changeset = changesets.getChangesets().get(0);
|
||||
|
||||
assertThat(changeset.getTrailers()).hasSize(1);
|
||||
assertThat(changeset.getTrailers().iterator().next().getPerson())
|
||||
.isEqualTo(new Person("Sebastian Sdorra", "s.sdorra@ostfalia.de"));
|
||||
}
|
||||
|
||||
private void setRepositoryHeadReference(String s) throws IOException {
|
||||
Files.write(s, repositoryHeadReferenceFile(), defaultCharset());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user