use of fr.inria.spirals.repairnator.config.RepairnatorConfig in project repairnator by Spirals-Team.
the class TestInitRepoToPush method testInitRepoShouldRemoveNotificationInTravisYML.
@Test
public void testInitRepoShouldRemoveNotificationInTravisYML() throws IOException {
int buildId = 331637757;
RepairnatorConfig repairnatorConfig = RepairnatorConfig.getInstance();
repairnatorConfig.setClean(false);
repairnatorConfig.setPush(true);
Build build = BuildHelper.getBuildFromId(buildId, null);
assertThat(build, notNullValue());
assertThat(buildId, is(build.getId()));
Path tmpDirPath = Files.createTempDirectory("test_initRepoToPush");
File tmpDir = tmpDirPath.toFile();
tmpDir.deleteOnExit();
BuildToBeInspected toBeInspected = new BuildToBeInspected(build, null, ScannedBuildStatus.ONLY_FAIL, "");
ProjectInspector inspector = mock(ProjectInspector.class);
when(inspector.getWorkspace()).thenReturn(tmpDir.getAbsolutePath());
when(inspector.getRepoLocalPath()).thenReturn(tmpDir.getAbsolutePath() + "/repo");
when(inspector.getRepoToPushLocalPath()).thenReturn(tmpDir.getAbsolutePath() + "/repotopush");
when(inspector.getBuildToBeInspected()).thenReturn(toBeInspected);
when(inspector.getBuggyBuild()).thenReturn(build);
when(inspector.getGitHelper()).thenReturn(new GitHelper());
JobStatus jobStatus = new JobStatus(tmpDir.getAbsolutePath() + "/repo");
when(inspector.getJobStatus()).thenReturn(jobStatus);
CloneRepository cloneStep = new CloneRepository(inspector);
cloneStep.setNextStep(new CheckoutBuggyBuild(inspector)).setNextStep(new InitRepoToPush(inspector));
cloneStep.execute();
assertThat(jobStatus.getPushState(), is(PushState.REPO_INITIALIZED));
File bak = new File(tmpDir.getAbsolutePath() + "/repotopush/bak.travis.yml");
File travis = new File(tmpDir.getAbsolutePath() + "/repotopush/.travis.yml");
assertTrue(bak.exists());
assertTrue(travis.exists());
boolean detected = false;
List<String> lines = Files.readAllLines(travis.toPath());
for (String l : lines) {
if (l.contains("notification")) {
assertTrue(l.trim().startsWith("#"));
detected = true;
}
if (l.contains("script")) {
assertFalse(l.trim().startsWith("#"));
}
}
assertTrue(detected);
}
use of fr.inria.spirals.repairnator.config.RepairnatorConfig in project repairnator by Spirals-Team.
the class TestInitRepoToPush method testInitRepoToPushSimpleCase.
@Test
public void testInitRepoToPushSimpleCase() throws IOException, GitAPIException, RepairnatorConfigException {
// surli/failingProject build
int buildId = 207924136;
RepairnatorConfig repairnatorConfig = RepairnatorConfig.getInstance();
repairnatorConfig.setClean(false);
repairnatorConfig.setPush(true);
Build build = BuildHelper.getBuildFromId(buildId, null);
assertThat(build, notNullValue());
assertThat(buildId, is(build.getId()));
Path tmpDirPath = Files.createTempDirectory("test_initRepoToPush");
File tmpDir = tmpDirPath.toFile();
tmpDir.deleteOnExit();
BuildToBeInspected toBeInspected = new BuildToBeInspected(build, null, ScannedBuildStatus.ONLY_FAIL, "");
ProjectInspector inspector = mock(ProjectInspector.class);
when(inspector.getWorkspace()).thenReturn(tmpDir.getAbsolutePath());
when(inspector.getRepoLocalPath()).thenReturn(tmpDir.getAbsolutePath() + "/repo");
when(inspector.getRepoToPushLocalPath()).thenReturn(tmpDir.getAbsolutePath() + "/repotopush");
when(inspector.getBuildToBeInspected()).thenReturn(toBeInspected);
when(inspector.getBuggyBuild()).thenReturn(build);
when(inspector.getGitHelper()).thenReturn(new GitHelper());
JobStatus jobStatus = new JobStatus(tmpDir.getAbsolutePath() + "/repo");
when(inspector.getJobStatus()).thenReturn(jobStatus);
CloneRepository cloneStep = new CloneRepository(inspector);
cloneStep.setNextStep(new CheckoutBuggyBuild(inspector)).setNextStep(new InitRepoToPush(inspector));
cloneStep.execute();
assertThat(jobStatus.getPushState(), is(PushState.REPO_INITIALIZED));
Git gitDir = Git.open(new File(tmpDir, "repotopush"));
Iterable<RevCommit> logs = gitDir.log().call();
Iterator<RevCommit> iterator = logs.iterator();
assertThat(iterator.hasNext(), is(true));
RevCommit commit = iterator.next();
assertThat(commit.getShortMessage(), containsString("End of the repairnator process"));
RevCommit firstCommit = iterator.next();
assertThat(firstCommit.getShortMessage(), containsString("Bug commit"));
assertThat(iterator.hasNext(), is(false));
}
use of fr.inria.spirals.repairnator.config.RepairnatorConfig in project repairnator by Spirals-Team.
the class LauncherUtils method initSpreadsheetSerializerEngineWithAccessToken.
public static SerializerEngine initSpreadsheetSerializerEngineWithAccessToken(Logger logger) {
RepairnatorConfig config = RepairnatorConfig.getInstance();
if (config.getSpreadsheetId() != null && config.getGoogleAccessToken() != null) {
logger.info("Initialize Google spreadsheet serializer engine.");
GoogleSpreadSheetFactory.setSpreadsheetId(config.getSpreadsheetId());
try {
if (GoogleSpreadSheetFactory.initWithAccessToken(config.getGoogleAccessToken())) {
return new GoogleSpreadsheetSerializerEngine();
} else {
logger.error("Error while initializing Google Spreadsheet, no information will be serialized in spreadsheets.");
}
} catch (IOException | GeneralSecurityException e) {
logger.error("Error while initializing Google Spreadsheet, no information will be serialized in spreadsheets.", e);
}
} else {
logger.info("Google Spreadsheet won't be used for serialization.");
}
return null;
}
use of fr.inria.spirals.repairnator.config.RepairnatorConfig in project repairnator by Spirals-Team.
the class LauncherUtils method initNotifierEngines.
public static List<NotifierEngine> initNotifierEngines(Logger logger) {
List<NotifierEngine> notifierEngines = new ArrayList<>();
RepairnatorConfig config = RepairnatorConfig.getInstance();
if (config.getSmtpServer() != null && config.getNotifyTo() != null) {
logger.info("The email notifier engine will be used.");
notifierEngines.add(new EmailNotifierEngine(config.getNotifyTo(), config.getSmtpServer()));
} else {
logger.info("The email notifier engine won't be used.");
}
return notifierEngines;
}
use of fr.inria.spirals.repairnator.config.RepairnatorConfig in project repairnator by Spirals-Team.
the class LauncherUtils method initFileSerializerEngines.
public static List<SerializerEngine> initFileSerializerEngines(Logger logger) {
List<SerializerEngine> fileSerializerEngines = new ArrayList<>();
RepairnatorConfig config = RepairnatorConfig.getInstance();
if (config.getOutputPath() != null) {
logger.info("Initialize file serializer engines.");
String path = config.getOutputPath();
path += config.getBuildId() > 0 ? "/" + config.getBuildId() : "";
fileSerializerEngines.add(new CSVSerializerEngine(path));
fileSerializerEngines.add(new JSONFileSerializerEngine(path));
} else {
logger.info("File serializers won't be used.");
}
return fileSerializerEngines;
}
Aggregations