use of fr.inria.spirals.repairnator.process.git.GitHelper 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.process.git.GitHelper 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.process.git.GitHelper in project repairnator by Spirals-Team.
the class TestBuildProject method testBuildProject.
@Test
public void testBuildProject() throws IOException {
// surli/failingProject build
int buildId = 207924136;
Build build = BuildHelper.getBuildFromId(buildId, null);
assertThat(build, notNullValue());
assertThat(buildId, is(build.getId()));
Path tmpDirPath = Files.createTempDirectory("test_build");
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.getBuildToBeInspected()).thenReturn(toBeInspected);
when(inspector.getBuggyBuild()).thenReturn(build);
when(inspector.getM2LocalPath()).thenReturn(tmpDir.getAbsolutePath() + "/.m2");
when(inspector.getGitHelper()).thenReturn(new GitHelper());
JobStatus jobStatus = new JobStatus(tmpDir.getAbsolutePath() + "/repo");
when(inspector.getJobStatus()).thenReturn(jobStatus);
CloneRepository cloneStep = new CloneRepository(inspector);
BuildProject buildStep = new BuildProject(inspector);
cloneStep.setNextStep(new CheckoutBuggyBuild(inspector)).setNextStep(buildStep);
cloneStep.execute();
assertThat(buildStep.shouldStop, is(false));
assertThat(buildStep.getPipelineState(), is(PipelineState.BUILDABLE));
assertThat(jobStatus.getPipelineState(), is(PipelineState.BUILDABLE));
}
use of fr.inria.spirals.repairnator.process.git.GitHelper in project repairnator by Spirals-Team.
the class CheckoutRepository method businessExecute.
@Override
protected void businessExecute() {
Metrics metric = this.getInspector().getJobStatus().getMetrics();
Git git;
try {
GitHelper gitHelper = this.getInspector().getGitHelper();
git = Git.open(new File(inspector.getRepoLocalPath()));
Build build;
switch(checkoutType) {
case CHECKOUT_BUGGY_BUILD:
build = inspector.getBuggyBuild();
metric.setBugCommit(build.getCommit().getSha());
metric.setBugCommitUrl(this.getCommitUrl(build.getCommit().getSha()));
break;
case CHECKOUT_BUGGY_BUILD_SOURCE_CODE:
build = inspector.getBuggyBuild();
metric.setBugCommit(build.getCommit().getSha());
metric.setBugCommitUrl(this.getCommitUrl(build.getCommit().getSha()));
metric.setReconstructedBugCommit(true);
break;
case CHECKOUT_PATCHED_BUILD:
build = inspector.getPatchedBuild();
metric.setPatchCommit(build.getCommit().getSha());
metric.setPatchCommitUrl(this.getCommitUrl(build.getCommit().getSha()));
break;
default:
this.getLogger().warn("A case seems not to have been considered. Buggy build will be used.");
build = inspector.getBuggyBuild();
}
if (build.isPullRequest()) {
PRInformation prInformation = build.getPRInformation();
if (prInformation != null) {
if (checkoutType == CheckoutType.CHECKOUT_PATCHED_BUILD) {
this.writeProperty("is-pr", "true");
this.writeProperty("pr-remote-repo", prInformation.getOtherRepo().getSlug());
this.writeProperty("pr-head-commit-id", prInformation.getHead().getSha());
this.writeProperty("pr-head-commit-id-url", prInformation.getHead().getCompareUrl());
this.writeProperty("pr-base-commit-id", prInformation.getBase().getSha());
this.writeProperty("pr-base-commit-id-url", prInformation.getBase().getCompareUrl());
this.writeProperty("pr-id", build.getPullRequestNumber());
}
} else {
this.addStepError("Error while getting the PR information...");
this.shouldStop = true;
return;
}
gitHelper.addAndCommitRepairnatorLogAndProperties(this.getInspector().getJobStatus(), git, "After getting PR information");
String repository = this.inspector.getRepoSlug();
this.getLogger().debug("Reproduce the PR for " + repository + " by fetching remote branch and merging.");
List<String> pathes;
if (checkoutType == CheckoutType.CHECKOUT_BUGGY_BUILD_SOURCE_CODE) {
pathes = new ArrayList<String>();
for (File path : this.getInspector().getJobStatus().getRepairSourceDir()) {
URI gitRepoURI = git.getRepository().getDirectory().getParentFile().toURI();
URI pathURI = path.getCanonicalFile().toURI();
String relativePath = gitRepoURI.relativize(pathURI).getPath();
pathes.add(relativePath);
}
} else {
pathes = null;
}
boolean successfulMerge = gitHelper.mergeTwoCommitsForPR(git, build, prInformation, repository, this, pathes);
if (!successfulMerge) {
this.getLogger().debug("Error while merging two commits to reproduce the PR.");
this.shouldStop = true;
}
} else {
String commitCheckout = build.getCommit().getSha();
commitCheckout = gitHelper.testCommitExistence(git, commitCheckout, this, build);
if (commitCheckout != null) {
this.getLogger().debug("Get the commit " + commitCheckout + " for repo " + this.inspector.getRepoSlug());
if (checkoutType != CheckoutType.CHECKOUT_BUGGY_BUILD_SOURCE_CODE) {
git.checkout().setName(commitCheckout).call();
} else {
List<String> pathes = new ArrayList<String>();
for (File path : this.getInspector().getJobStatus().getRepairSourceDir()) {
URI gitRepoURI = git.getRepository().getDirectory().getParentFile().toURI();
URI pathURI = path.getCanonicalFile().toURI();
String relativePath = gitRepoURI.relativize(pathURI).getPath();
pathes.add(relativePath);
}
git.checkout().setStartPoint(commitCheckout).addPaths(pathes).call();
PersonIdent personIdent = new PersonIdent("Luc Esape", "luc.esape@gmail.com");
git.commit().setMessage("Undo changes on source code").setAuthor(personIdent).setCommitter(personIdent).call();
}
this.writeProperty("bugCommit", this.inspector.getBuggyBuild().getCommit().getCompareUrl());
} else {
this.addStepError("Error while getting the commit to checkout from the repo.");
this.shouldStop = true;
return;
}
}
} catch (IOException | GitAPIException e) {
this.addStepError("Error while getting the commit to checkout from the repo.");
this.shouldStop = true;
}
this.writeProperty("hostname", Utils.getHostname());
switch(this.getInspector().getBuildToBeInspected().getStatus()) {
case ONLY_FAIL:
this.writeProperty("bugType", "only_fail");
break;
case FAILING_AND_PASSING:
this.writeProperty("bugType", "failing_passing");
break;
case PASSING_AND_PASSING_WITH_TEST_CHANGES:
this.writeProperty("bugType", "passing_passing");
break;
}
}
use of fr.inria.spirals.repairnator.process.git.GitHelper in project repairnator by Spirals-Team.
the class TestCloneRepositoryStep method testCloneMasterBuild.
@Test
public void testCloneMasterBuild() throws IOException {
// surli/failingProject build
int buildId = 207924136;
Build build = BuildHelper.getBuildFromId(buildId, null);
assertThat(build, notNullValue());
assertThat(buildId, is(build.getId()));
Path tmpDirPath = Files.createTempDirectory("test_clone");
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.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.execute();
assertThat(jobStatus.getPipelineState(), is(PipelineState.CLONABLE));
assertThat(cloneStep.getPipelineState(), is(PipelineState.CLONABLE));
assertThat(cloneStep.shouldStop, is(false));
Git gitDir = Git.open(new File(tmpDir, "repo"));
Ref ref = gitDir.getRepository().exactRef("HEAD");
assertThat(ref.isSymbolic(), is(true));
ref = ref.getTarget();
// no check out yet
assertThat(ref.getObjectId().getName(), not(build.getCommit().getSha()));
}
Aggregations