Skip to content

Commit

Permalink
Merge branch 'release/0.5.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
micheljung committed May 5, 2017
2 parents 6235b8c + 0a40a00 commit 10ec03a
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 47 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ apply plugin: 'org.springframework.boot'
apply plugin: 'propdeps'

group = 'micheljung'
version = '0.5.1'
version = '0.5.2'

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
import lombok.extern.slf4j.Slf4j;
import org.kohsuke.github.GHDeployment;
import org.kohsuke.github.GHEventPayload.Push;
import org.kohsuke.github.GHEventPayload.Push.PushCommit;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Objects;
import java.util.Optional;


Expand All @@ -32,16 +30,7 @@ public GitHubDeploymentService(ApplicationContext applicationContext, FafApiProp

@SneakyThrows
public void createDeploymentIfEligible(Push push) {
PushCommit headCommit = push.getCommits().stream()
.filter(commit -> Objects.equals(commit.getSha(), push.getHead()))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Head commit '" + push.getHead() + "' is not in the list of commits"));

String ref = push.getRef();
if (!headCommit.isDistinct()) {
log.debug("Ignoring non-distinct commit to ref: {}", ref);
return;
}
Optional<DeploymentConfiguration> optional = fafApiProperties.getDeployment().getConfigurations().stream()
.filter(configuration ->
push.getRepository().gitHttpTransportUrl().equals(configuration.getRepositoryUrl())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
import org.kohsuke.github.GHDeployment;
import org.kohsuke.github.GHDeploymentBuilder;
import org.kohsuke.github.GHEventPayload.Push;
import org.kohsuke.github.GHEventPayload.Push.PushCommit;
import org.kohsuke.github.GHRepository;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.context.ApplicationContext;

import java.util.Collections;
Expand Down Expand Up @@ -44,38 +43,9 @@ public void setUp() throws Exception {
instance = new GitHubDeploymentService(applicationContext, apiProperties, objectMapper);
}

@Test(expected = IllegalArgumentException.class)
public void createDeploymentIfEligibleHeadCommitNotEqualToFirstCommit() throws Exception {
PushCommit pushCommit = mock(PushCommit.class);
when(pushCommit.getSha()).thenReturn("111");

Push push = mock(Push.class);
when(push.getHead()).thenReturn("222");
when(push.getCommits()).thenReturn(Collections.singletonList(pushCommit));

instance.createDeploymentIfEligible(push);
}

@Test
public void createDeploymentIfEligibleDistinctIgnored() throws Exception {
PushCommit pushCommit = mock(PushCommit.class);
when(pushCommit.isDistinct()).thenReturn(false);

Push push = mock(Push.class);
when(push.getCommits()).thenReturn(Collections.singletonList(pushCommit));

instance.createDeploymentIfEligible(push);

verify(push, never()).getRepository();
}

@Test
public void createDeploymentIfEligibleNoConfigurationAvailable() throws Exception {
PushCommit pushCommit = mock(PushCommit.class);
when(pushCommit.isDistinct()).thenReturn(true);

Push push = mock(Push.class);
when(push.getCommits()).thenReturn(Collections.singletonList(pushCommit));

GHRepository repository = mock(GHRepository.class);
when(repository.gitHttpTransportUrl()).thenReturn(EXAMPLE_REPO_URL);
Expand All @@ -88,12 +58,8 @@ public void createDeploymentIfEligibleNoConfigurationAvailable() throws Exceptio

@Test
public void createDeploymentIfEligible() throws Exception {
PushCommit pushCommit = mock(PushCommit.class);
when(pushCommit.isDistinct()).thenReturn(true);

Push push = mock(Push.class);
when(push.getRef()).thenReturn("refs/heads/master");
when(push.getCommits()).thenReturn(Collections.singletonList(pushCommit));

GHRepository repository = mock(GHRepository.class);
when(repository.gitHttpTransportUrl()).thenReturn(EXAMPLE_REPO_URL);
Expand Down

0 comments on commit 10ec03a

Please sign in to comment.