Do not mark default branch as stale

This commit is contained in:
René Pfeuffer
2020-11-23 16:55:40 +01:00
parent 9d25a93558
commit a2341f3ce2
2 changed files with 18 additions and 3 deletions

View File

@@ -196,7 +196,8 @@ public final class Branch implements Serializable, Validateable {
}
public boolean isStale() {
return getLastCommitDate()
return !isDefaultBranch()
&& getLastCommitDate()
.map(Instant::ofEpochMilli)
.map(d -> Duration.between(d, now()))
.map(d -> d.toDays())

View File

@@ -30,6 +30,7 @@ import java.time.temporal.ChronoUnit;
import static java.time.Instant.now;
import static org.assertj.core.api.Assertions.assertThat;
import static sonia.scm.repository.Branch.defaultBranch;
import static sonia.scm.repository.Branch.normalBranch;
class BranchTest {
@@ -49,13 +50,26 @@ class BranchTest {
@Test
void shouldNotTagNotSoOldBranchAsStale() {
long moreThanTwoWeeksAgo =
long notYetTwoWeeksAgo =
now()
.minus(14, ChronoUnit.DAYS)
.plus(1, ChronoUnit.MINUTES)
.toEpochMilli();
Branch branch = normalBranch("hog", "42", moreThanTwoWeeksAgo);
Branch branch = normalBranch("hog", "42", notYetTwoWeeksAgo);
assertThat(branch.isStale()).isFalse();
}
@Test
void shouldNotTagDefaultBranchAsStale() {
long moreThanTwoWeeksAgo =
now()
.minus(14, ChronoUnit.DAYS)
.minus(1, ChronoUnit.MINUTES)
.toEpochMilli();
Branch branch = defaultBranch("hog", "42", moreThanTwoWeeksAgo);
assertThat(branch.isStale()).isFalse();
}