Search in sources :

Example 1 with GHDeployment

use of org.kohsuke.github.GHDeployment in project faf-java-api by FAForever.

the class GitHubDeploymentServiceTest method deployEnvironmentMismatch.

@Test
public void deployEnvironmentMismatch() throws Exception {
    apiProperties.getGitHub().setDeploymentEnvironment(ENVIRONMENT);
    Deployment deployment = mock(Deployment.class);
    GHDeployment ghDeployment = mock(GHDeployment.class);
    when(deployment.getDeployment()).thenReturn(ghDeployment);
    when(ghDeployment.getEnvironment()).thenReturn("foobar");
    instance.deploy(deployment);
    verify(applicationContext, never()).getBean(LegacyFeaturedModDeploymentTask.class);
}
Also used : GHDeployment(org.kohsuke.github.GHDeployment) Deployment(org.kohsuke.github.GHEventPayload.Deployment) GHDeployment(org.kohsuke.github.GHDeployment) Test(org.junit.Test)

Example 2 with GHDeployment

use of org.kohsuke.github.GHDeployment in project faf-java-api by FAForever.

the class GitHubDeploymentServiceTest method deployEnvironmentMatch.

@Test
public void deployEnvironmentMatch() throws Exception {
    apiProperties.getGitHub().setDeploymentEnvironment(ENVIRONMENT);
    // Couldn't be mocked since calling ghDeployment.getId() threw an NPE
    GHDeployment ghDeployment = new GHDeployment() {

        @Override
        public int getId() {
            return 1;
        }

        @Override
        public String getEnvironment() {
            return ENVIRONMENT;
        }

        @Override
        public String getPayload() {
            return "faf";
        }
    };
    Deployment deployment = mock(Deployment.class);
    when(deployment.getDeployment()).thenReturn(ghDeployment);
    GHRepository ghRepository = mock(GHRepository.class);
    GHDeploymentStatusBuilder builder = mock(GHDeploymentStatusBuilder.class);
    when(builder.description(any())).thenReturn(builder);
    when(ghRepository.createDeployStatus(anyInt(), any())).thenReturn(builder);
    when(deployment.getRepository()).thenReturn(ghRepository);
    LegacyFeaturedModDeploymentTask task = mock(LegacyFeaturedModDeploymentTask.class);
    when(task.setFeaturedMod(any())).thenReturn(task);
    when(task.setStatusDescriptionListener(any())).thenReturn(task);
    when(applicationContext.getBean(LegacyFeaturedModDeploymentTask.class)).thenReturn(task);
    when(featuredModService.findModByTechnicalName("faf")).thenReturn(Optional.of(new FeaturedMod()));
    instance.deploy(deployment);
    verify(task).run();
    verify(builder).create();
}
Also used : GHRepository(org.kohsuke.github.GHRepository) GHDeployment(org.kohsuke.github.GHDeployment) GHDeploymentStatusBuilder(org.kohsuke.github.GHDeploymentStatusBuilder) Deployment(org.kohsuke.github.GHEventPayload.Deployment) GHDeployment(org.kohsuke.github.GHDeployment) FeaturedMod(com.faforever.api.data.domain.FeaturedMod) Test(org.junit.Test)

Example 3 with GHDeployment

use of org.kohsuke.github.GHDeployment in project faf-java-api by FAForever.

the class GitHubDeploymentService method deploy.

@Async
@SneakyThrows
@Transactional
@CacheEvict(value = FeaturedMod.TYPE_NAME, allEntries = true)
public void deploy(Deployment deployment) {
    GHDeployment ghDeployment = deployment.getDeployment();
    String environment = ghDeployment.getEnvironment();
    String deploymentEnvironment = fafApiProperties.getGitHub().getDeploymentEnvironment();
    if (!deploymentEnvironment.equals(environment)) {
        log.warn("Ignoring deployment for environment '{}' as it does not match the current environment '{}'", deploymentEnvironment, environment);
        return;
    }
    GHRepository repository = deployment.getRepository();
    int deploymentId = ghDeployment.getId();
    try {
        performDeployment(ghDeployment, repository, deploymentId);
    } catch (Exception e) {
        log.error("Deployment failed", e);
        updateDeploymentStatus(deploymentId, repository, GHDeploymentState.FAILURE, e.getMessage());
    }
}
Also used : GHRepository(org.kohsuke.github.GHRepository) GHDeployment(org.kohsuke.github.GHDeployment) IOException(java.io.IOException) Async(org.springframework.scheduling.annotation.Async) CacheEvict(org.springframework.cache.annotation.CacheEvict) SneakyThrows(lombok.SneakyThrows) Transactional(javax.transaction.Transactional)

Example 4 with GHDeployment

use of org.kohsuke.github.GHDeployment in project faf-java-api by FAForever.

the class GitHubDeploymentService method createDeploymentIfEligible.

@SneakyThrows
void createDeploymentIfEligible(Push push) {
    String ref = push.getRef();
    Optional<FeaturedMod> optional = featuredModService.findByGitUrlAndGitBranch(push.getRepository().gitHttpTransportUrl(), push.getRef().replace("refs/heads/", ""));
    if (!optional.isPresent()) {
        log.warn("No configuration present for repository '{}' and ref '{}'", push.getRepository().gitHttpTransportUrl(), push.getRef());
        return;
    }
    GHDeployment ghDeployment = push.getRepository().createDeployment(ref).autoMerge(false).environment(fafApiProperties.getGitHub().getDeploymentEnvironment()).payload(optional.get().getTechnicalName()).requiredContexts(Collections.emptyList()).create();
    log.info("Created deployment: {}", ghDeployment);
}
Also used : GHDeployment(org.kohsuke.github.GHDeployment) FeaturedMod(com.faforever.api.data.domain.FeaturedMod) SneakyThrows(lombok.SneakyThrows)

Aggregations

GHDeployment (org.kohsuke.github.GHDeployment)4 FeaturedMod (com.faforever.api.data.domain.FeaturedMod)2 SneakyThrows (lombok.SneakyThrows)2 Test (org.junit.Test)2 Deployment (org.kohsuke.github.GHEventPayload.Deployment)2 GHRepository (org.kohsuke.github.GHRepository)2 IOException (java.io.IOException)1 Transactional (javax.transaction.Transactional)1 GHDeploymentStatusBuilder (org.kohsuke.github.GHDeploymentStatusBuilder)1 CacheEvict (org.springframework.cache.annotation.CacheEvict)1 Async (org.springframework.scheduling.annotation.Async)1