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);
}
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();
}
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());
}
}
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);
}
Aggregations