Search in sources :

Example 1 with GitHelper

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);
}
Also used : Path(java.nio.file.Path) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) RepairnatorConfig(fr.inria.spirals.repairnator.config.RepairnatorConfig) GitHelper(fr.inria.spirals.repairnator.process.git.GitHelper) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) CloneRepository(fr.inria.spirals.repairnator.process.step.CloneRepository) Build(fr.inria.jtravis.entities.Build) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) File(java.io.File) Test(org.junit.Test)

Example 2 with GitHelper

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));
}
Also used : Path(java.nio.file.Path) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) RepairnatorConfig(fr.inria.spirals.repairnator.config.RepairnatorConfig) GitHelper(fr.inria.spirals.repairnator.process.git.GitHelper) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) CloneRepository(fr.inria.spirals.repairnator.process.step.CloneRepository) Git(org.eclipse.jgit.api.Git) Build(fr.inria.jtravis.entities.Build) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) File(java.io.File) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 3 with GitHelper

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));
}
Also used : Path(java.nio.file.Path) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) Build(fr.inria.jtravis.entities.Build) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) GitHelper(fr.inria.spirals.repairnator.process.git.GitHelper) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) File(java.io.File) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) Test(org.junit.Test)

Example 4 with GitHelper

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;
    }
}
Also used : GitHelper(fr.inria.spirals.repairnator.process.git.GitHelper) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URI(java.net.URI) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Metrics(fr.inria.spirals.repairnator.process.inspectors.Metrics) Git(org.eclipse.jgit.api.Git) PRInformation(fr.inria.jtravis.entities.PRInformation) PersonIdent(org.eclipse.jgit.lib.PersonIdent) Build(fr.inria.jtravis.entities.Build) File(java.io.File)

Example 5 with GitHelper

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()));
}
Also used : Path(java.nio.file.Path) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) Ref(org.eclipse.jgit.lib.Ref) Git(org.eclipse.jgit.api.Git) Build(fr.inria.jtravis.entities.Build) GitHelper(fr.inria.spirals.repairnator.process.git.GitHelper) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) File(java.io.File) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) Test(org.junit.Test)

Aggregations

Build (fr.inria.jtravis.entities.Build)31 GitHelper (fr.inria.spirals.repairnator.process.git.GitHelper)31 File (java.io.File)31 BuildToBeInspected (fr.inria.spirals.repairnator.BuildToBeInspected)30 JobStatus (fr.inria.spirals.repairnator.process.inspectors.JobStatus)30 ProjectInspector (fr.inria.spirals.repairnator.process.inspectors.ProjectInspector)30 Path (java.nio.file.Path)30 Test (org.junit.Test)30 CheckoutBuggyBuild (fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild)21 CloneRepository (fr.inria.spirals.repairnator.process.step.CloneRepository)10 CheckoutPatchedBuild (fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutPatchedBuild)8 Git (org.eclipse.jgit.api.Git)8 RevCommit (org.eclipse.jgit.revwalk.RevCommit)6 GatherTestInformation (fr.inria.spirals.repairnator.process.step.gatherinfo.GatherTestInformation)5 RepairnatorConfig (fr.inria.spirals.repairnator.config.RepairnatorConfig)4 BuildShouldFail (fr.inria.spirals.repairnator.process.step.gatherinfo.BuildShouldFail)4 ScannedBuildStatus (fr.inria.spirals.repairnator.states.ScannedBuildStatus)3 DiffEntry (org.eclipse.jgit.diff.DiffEntry)3 ObjectReader (org.eclipse.jgit.lib.ObjectReader)3 CanonicalTreeParser (org.eclipse.jgit.treewalk.CanonicalTreeParser)3