mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 23:15:43 +01:00
Feature/branch details (#1876)
Enrich branch overview with more details like last committer and ahead/behind commits. Since calculating this information is pretty intense, we request it in chunks to prevent very long loading times. Also we cache the results in frontend and backend. Co-authored-by: René Pfeuffer <rene.pfeuffer@cloudogu.com>
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import org.junit.Test;
|
||||
import sonia.scm.NotFoundException;
|
||||
import sonia.scm.repository.api.BranchDetailsCommandResult;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class GitBranchDetailsCommandTest extends AbstractGitCommandTestBase {
|
||||
|
||||
@Test
|
||||
public void shouldGetZerosForDefaultBranch() {
|
||||
GitBranchDetailsCommand command = new GitBranchDetailsCommand(createContext());
|
||||
|
||||
BranchDetailsCommandRequest request = new BranchDetailsCommandRequest();
|
||||
request.setBranchName("master");
|
||||
BranchDetailsCommandResult result = command.execute(request);
|
||||
|
||||
assertThat(result.getChangesetsAhead()).get().isEqualTo(0);
|
||||
assertThat(result.getChangesetsBehind()).get().isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCountSimpleAheadAndBehind() {
|
||||
GitBranchDetailsCommand command = new GitBranchDetailsCommand(createContext());
|
||||
|
||||
BranchDetailsCommandRequest request = new BranchDetailsCommandRequest();
|
||||
request.setBranchName("test-branch");
|
||||
BranchDetailsCommandResult result = command.execute(request);
|
||||
|
||||
assertThat(result.getChangesetsAhead()).get().isEqualTo(1);
|
||||
assertThat(result.getChangesetsBehind()).get().isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCountMoreComplexAheadAndBehind() {
|
||||
GitBranchDetailsCommand command = new GitBranchDetailsCommand(createContext());
|
||||
|
||||
BranchDetailsCommandRequest request = new BranchDetailsCommandRequest();
|
||||
request.setBranchName("partially_merged");
|
||||
BranchDetailsCommandResult result = command.execute(request);
|
||||
|
||||
assertThat(result.getChangesetsAhead()).get().isEqualTo(3);
|
||||
assertThat(result.getChangesetsBehind()).get().isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test(expected = NotFoundException.class)
|
||||
public void shouldThrowNotFoundExceptionForUnknownBranch() {
|
||||
GitBranchDetailsCommand command = new GitBranchDetailsCommand(createContext());
|
||||
|
||||
BranchDetailsCommandRequest request = new BranchDetailsCommandRequest();
|
||||
request.setBranchName("no-such-branch");
|
||||
command.execute(request);
|
||||
}
|
||||
}
|
||||
@@ -26,11 +26,14 @@ package sonia.scm.repository.spi;
|
||||
|
||||
import org.junit.Test;
|
||||
import sonia.scm.repository.Branch;
|
||||
import sonia.scm.repository.Person;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static sonia.scm.repository.Branch.defaultBranch;
|
||||
import static sonia.scm.repository.Branch.normalBranch;
|
||||
|
||||
public class GitBranchesCommandTest extends AbstractGitCommandTestBase {
|
||||
|
||||
@@ -40,10 +43,35 @@ public class GitBranchesCommandTest extends AbstractGitCommandTestBase {
|
||||
|
||||
List<Branch> branches = branchesCommand.getBranches();
|
||||
|
||||
assertThat(branches).contains(
|
||||
Branch.defaultBranch("master", "fcd0ef1831e4002ac43ea539f4094334c79ea9ec", 1339428655000L),
|
||||
Branch.normalBranch("mergeable", "91b99de908fcd04772798a31c308a64aea1a5523", 1541586052000L),
|
||||
Branch.normalBranch("rename", "383b954b27e052db6880d57f1c860dc208795247", 1589203061000L)
|
||||
assertThat(findBranch(branches, "master")).isEqualTo(
|
||||
defaultBranch(
|
||||
"master",
|
||||
"fcd0ef1831e4002ac43ea539f4094334c79ea9ec",
|
||||
1339428655000L,
|
||||
new Person("Zaphod Beeblebrox", "zaphod.beeblebrox@hitchhiker.com")
|
||||
)
|
||||
);
|
||||
assertThat(findBranch(branches, "mergeable")).isEqualTo(
|
||||
normalBranch(
|
||||
"mergeable",
|
||||
"91b99de908fcd04772798a31c308a64aea1a5523",
|
||||
1541586052000L,
|
||||
new Person("Douglas Adams",
|
||||
"douglas.adams@hitchhiker.com")
|
||||
)
|
||||
);
|
||||
assertThat(findBranch(branches, "rename")).isEqualTo(
|
||||
normalBranch(
|
||||
"rename",
|
||||
"383b954b27e052db6880d57f1c860dc208795247",
|
||||
1589203061000L,
|
||||
new Person("scmadmin",
|
||||
"scm@admin.com")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private Branch findBranch(List<Branch> branches, String mergeable) {
|
||||
return branches.stream().filter(b -> b.getName().equals(mergeable)).findFirst().get();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user