Search in sources :

Example 16 with JobStatus

use of fr.inria.spirals.repairnator.process.inspectors.JobStatus in project repairnator by Spirals-Team.

the class TestCheckoutBuggyBuildSourceCode method testCheckoutPreviousBuildSourceCodeWithPR.

@Test
public void testCheckoutPreviousBuildSourceCodeWithPR() throws IOException, GitAPIException, RepairnatorConfigException {
    // HubSpot/Singularity
    int buildId = 223248816;
    int previousBuildId = 222209171;
    ScannedBuildStatus status = ScannedBuildStatus.PASSING_AND_PASSING_WITH_TEST_CHANGES;
    Build build = BuildHelper.getBuildFromId(buildId, null);
    assertThat(build, notNullValue());
    assertThat(buildId, is(build.getId()));
    assertThat(build.isPullRequest(), is(true));
    Build previousBuild = BuildHelper.getBuildFromId(previousBuildId, null);
    assertThat(previousBuild, notNullValue());
    assertThat(previousBuild.getId(), is(previousBuildId));
    assertThat(previousBuild.isPullRequest(), is(true));
    Path tmpDirPath = Files.createTempDirectory("test_checkoutprevious");
    File tmpDir = tmpDirPath.toFile();
    tmpDir.deleteOnExit();
    BuildToBeInspected toBeInspected = new BuildToBeInspected(previousBuild, build, status, "");
    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.getPatchedBuild()).thenReturn(build);
    when(inspector.getBuggyBuild()).thenReturn(previousBuild);
    when(inspector.getGitHelper()).thenReturn(new GitHelper());
    JobStatus jobStatus = new JobStatus(tmpDir.getAbsolutePath() + "/repo");
    when(inspector.getJobStatus()).thenReturn(jobStatus);
    CloneRepository cloneStep = new CloneRepository(inspector);
    CheckoutBuggyBuildSourceCode checkoutBuild = new CheckoutBuggyBuildSourceCode(inspector);
    cloneStep.setNextStep(checkoutBuild);
    cloneStep.execute();
    assertThat(checkoutBuild.getPipelineState(), is(PipelineState.PREVIOUSBUILDCODECHECKEDOUT));
    assertThat(jobStatus.getPipelineState(), is(PipelineState.PREVIOUSBUILDCODECHECKEDOUT));
    assertThat(checkoutBuild.isShouldStop(), is(false));
    Git gitDir = Git.open(new File(tmpDir, "repo"));
    Iterable<RevCommit> logs = gitDir.log().call();
    Iterator<RevCommit> iterator = logs.iterator();
    boolean foundRightCommitAfterRepairCommits = false;
    boolean foundUndoSourceCodeCommit = false;
    boolean stopSearch = false;
    while (iterator.hasNext() && !stopSearch) {
        RevCommit revCommit = iterator.next();
        System.out.println(revCommit.getShortMessage());
        if (revCommit.getShortMessage().equals("Undo changes on source code")) {
            foundUndoSourceCodeCommit = true;
            CanonicalTreeParser oldTreeIter = new CanonicalTreeParser();
            CanonicalTreeParser newTreeIter = new CanonicalTreeParser();
            ObjectReader reader = gitDir.getRepository().newObjectReader();
            RevCommit prevCommit = iterator.next();
            oldTreeIter.reset(reader, prevCommit.getTree());
            newTreeIter.reset(reader, revCommit.getTree());
            List<DiffEntry> diff = gitDir.diff().setOldTree(oldTreeIter).setNewTree(newTreeIter).call();
            for (DiffEntry entry : diff) {
                assertThat(entry.getOldPath(), startsWith("src/main/java/"));
            }
            revCommit = prevCommit;
        }
        if (!revCommit.getShortMessage().contains("repairnator") && !revCommit.getShortMessage().contains("merge")) {
            stopSearch = true;
        }
    }
    assertThat(foundUndoSourceCodeCommit, is(true));
}
Also used : Path(java.nio.file.Path) GitHelper(fr.inria.spirals.repairnator.process.git.GitHelper) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) CanonicalTreeParser(org.eclipse.jgit.treewalk.CanonicalTreeParser) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) CloneRepository(fr.inria.spirals.repairnator.process.step.CloneRepository) Git(org.eclipse.jgit.api.Git) ScannedBuildStatus(fr.inria.spirals.repairnator.states.ScannedBuildStatus) Build(fr.inria.jtravis.entities.Build) ObjectReader(org.eclipse.jgit.lib.ObjectReader) File(java.io.File) RevCommit(org.eclipse.jgit.revwalk.RevCommit) DiffEntry(org.eclipse.jgit.diff.DiffEntry) Test(org.junit.Test)

Example 17 with JobStatus

use of fr.inria.spirals.repairnator.process.inspectors.JobStatus in project repairnator by Spirals-Team.

the class TestCheckoutBuild method testCheckoutBuildFromPROtherRepo.

@Test
public void testCheckoutBuildFromPROtherRepo() throws IOException, GitAPIException {
    // surli/failingProject build
    int buildId = 196568333;
    Build build = BuildHelper.getBuildFromId(buildId, null);
    assertThat(build, notNullValue());
    assertThat(buildId, is(build.getId()));
    Path tmpDirPath = Files.createTempDirectory("test_checkout");
    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);
    CheckoutBuggyBuild checkoutBuggyBuild = new CheckoutBuggyBuild(inspector);
    cloneStep.setNextStep(checkoutBuggyBuild);
    cloneStep.execute();
    // cannot get the PR information so it stop now
    assertThat(checkoutBuggyBuild.getPipelineState(), is(PipelineState.BUILDNOTCHECKEDOUT));
    assertThat(jobStatus.getPipelineState(), is(PipelineState.BUILDNOTCHECKEDOUT));
    assertThat(checkoutBuggyBuild.isShouldStop(), is(true));
}
Also used : Path(java.nio.file.Path) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) CloneRepository(fr.inria.spirals.repairnator.process.step.CloneRepository) 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)

Example 18 with JobStatus

use of fr.inria.spirals.repairnator.process.inspectors.JobStatus in project repairnator by Spirals-Team.

the class TestCheckoutBuild method testCheckoutBuildFromPRWithMissingMerge.

@Test
public void testCheckoutBuildFromPRWithMissingMerge() throws IOException, GitAPIException {
    // surli/failingProject build
    int buildId = 199527447;
    Build build = BuildHelper.getBuildFromId(buildId, null);
    assertThat(build, notNullValue());
    assertThat(buildId, is(build.getId()));
    Path tmpDirPath = Files.createTempDirectory("test_checkout");
    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);
    CheckoutBuggyBuild checkoutBuggyBuild = new CheckoutBuggyBuild(inspector);
    cloneStep.setNextStep(checkoutBuggyBuild);
    cloneStep.execute();
    assertThat(checkoutBuggyBuild.getPipelineState(), is(PipelineState.BUILDNOTCHECKEDOUT));
    assertThat(jobStatus.getPipelineState(), is(PipelineState.BUILDNOTCHECKEDOUT));
    assertThat(checkoutBuggyBuild.isShouldStop(), is(true));
}
Also used : Path(java.nio.file.Path) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) CloneRepository(fr.inria.spirals.repairnator.process.step.CloneRepository) 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)

Example 19 with JobStatus

use of fr.inria.spirals.repairnator.process.inspectors.JobStatus in project repairnator by Spirals-Team.

the class FixerBuildNotifier method observe.

public void observe(ProjectInspector inspector) {
    JobStatus status = inspector.getJobStatus();
    if (!alreadyNotified && (status.getPipelineState() == PipelineState.FIXERBUILDCASE1 || status.getPipelineState() == PipelineState.FIXERBUILDCASE2)) {
        String slug = inspector.getRepoSlug();
        String subject = "Fixer build found: " + inspector.getPatchedBuild().getId() + " - " + slug;
        Build patchedBuild = inspector.getPatchedBuild();
        Build buggyBuild = inspector.getBuggyBuild();
        String text = "Hurray !\n\n" + "A fixer build has been found for the following project: " + slug + ".\n";
        if (status.isHasBeenPushed()) {
            text += "Data about this fixer build has been pushed on the following branch: " + status.getGitBranchUrl() + ".\n";
        }
        text += "You can find several information on the following about it: \n";
        text += "\t Fixer build type: " + status.getPipelineState().name() + "\n" + "\t Type of build: " + inspector.getBuildToBeInspected().getStatus().name() + "\n" + "\t Date of the buggy build: " + Utils.formatCompleteDate(buggyBuild.getFinishedAt()) + "\n" + "\t Url of the buggy build: " + Utils.getTravisUrl(buggyBuild.getId(), slug) + "\n" + "\t Date of the patched build: " + Utils.formatCompleteDate(patchedBuild.getFinishedAt()) + "\n" + "\t Url of the patched build: " + Utils.getTravisUrl(patchedBuild.getId(), slug) + "\n" + "\t Contact: " + patchedBuild.getCommit().getCommitterEmail();
        this.notifyEngines(subject, text);
        this.alreadyNotified = true;
    }
}
Also used : JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) Build(fr.inria.jtravis.entities.Build)

Example 20 with JobStatus

use of fr.inria.spirals.repairnator.process.inspectors.JobStatus in project repairnator by Spirals-Team.

the class PatchNotifier method observe.

public void observe(ProjectInspector inspector) {
    JobStatus status = inspector.getJobStatus();
    Build buggyBuild = inspector.getBuggyBuild();
    Repository repository = buggyBuild.getRepository();
    if (status.isHasBeenPatched()) {
        String subject = "Patched build: " + buggyBuild.getId() + " - " + repository.getSlug();
        String text = "Hurray !\n\n" + "Patch(es) has been found for the following build: " + Utils.getTravisUrl(buggyBuild.getId(), repository.getSlug()) + ".\n";
        if (status.isHasBeenPushed()) {
            String slug = repository.getSlug();
            String repoURL = Utils.getGithubRepoUrl(slug);
            String branchName = buggyBuild.getCommit().getBranch();
            String[] divideSlug = slug.split("/");
            String projectName = divideSlug[1];
            text += "Data about patches has been pushed on the following branch: " + status.getGitBranchUrl() + ".\n\n";
            text += "Follow those instruction to create a pull request:\n";
            text += "mkdir " + projectName + "\n";
            text += "cd " + projectName + "\n";
            text += "git init\n";
            text += "git fetch " + repoURL + " " + branchName + "\n";
            text += "git checkout -b patch FETCH_HEAD\n";
            text += "vi [file_to_patch]\n";
            text += "git commit -m \"tentative patch\" -a\n";
            if (status.isHasBeenForked()) {
                text += "git push " + status.getForkURL() + "\n";
            } else {
                text += "Then fork the repository (" + slug + ") from Github interface\n";
                text += "git push [url to the fork]\n";
            }
        }
        text += "You may find several information on the following about those patches: \n";
        if (status.getNopolInformations() != null && !status.getNopolPatches().isEmpty() && !this.alreadyNotifiedForNopol) {
            text += this.notifyForNopol(status);
            this.notifyEngines("[NOPOL] " + subject, text);
        }
        if (status.getNpeFixPatches() != null && !status.getNpeFixPatches().isEmpty() && !this.alreadyNotifiedForNPEFix) {
            text += this.notifyForNPEFix(status);
            this.notifyEngines("[NPEFIX] " + subject, text);
        }
        if (status.getAstorPatches() != null && !status.getAstorPatches().isEmpty() && !this.alreadyNotifiedForAstor) {
            text += this.notifityForAstor(status);
            this.notifyEngines("[ASTOR] " + subject, text);
        }
    }
}
Also used : JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) Repository(fr.inria.jtravis.entities.Repository) Build(fr.inria.jtravis.entities.Build)

Aggregations

JobStatus (fr.inria.spirals.repairnator.process.inspectors.JobStatus)48 ProjectInspector (fr.inria.spirals.repairnator.process.inspectors.ProjectInspector)39 Test (org.junit.Test)38 Build (fr.inria.jtravis.entities.Build)37 BuildToBeInspected (fr.inria.spirals.repairnator.BuildToBeInspected)35 File (java.io.File)34 Path (java.nio.file.Path)33 GitHelper (fr.inria.spirals.repairnator.process.git.GitHelper)30 CheckoutBuggyBuild (fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild)22 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)7 RevCommit (org.eclipse.jgit.revwalk.RevCommit)6 GatherTestInformation (fr.inria.spirals.repairnator.process.step.gatherinfo.GatherTestInformation)5 ArrayList (java.util.ArrayList)5 JsonObject (com.google.gson.JsonObject)4 RepairnatorConfig (fr.inria.spirals.repairnator.config.RepairnatorConfig)4 BuildShouldFail (fr.inria.spirals.repairnator.process.step.gatherinfo.BuildShouldFail)4 Date (java.util.Date)4 ScannedBuildStatus (fr.inria.spirals.repairnator.states.ScannedBuildStatus)3