Exemplo n.º 1
0
  @Override
  public void process(SCMRepository repo, Commit commit, PersistenceMechanism writer) {

    if (!noKeywordsIn(commit)) return;

    SCM scm = repo.getScm();

    for (Modification modification : commit.getModifications()) {
      if (modification.wasDeleted()) continue;

      String fileName = modification.getFileName();
      if (!Languages.contains(fileName)) continue;
      Language lang = Languages.forFile(fileName);
      if (lang.isTest(fileName)) continue;

      List<Integer> lines = findLinesToBeBlamedIn(modification);
      if (!lines.isEmpty()) {
        bugInFile(modification);
      }

      for (Integer buggedLine : lines) {

        String hash = scm.blame(modification.getNewPath(), commit.getHash(), buggedLine);
        if (hash == null || hash.isEmpty()) continue;

        Commit buggedCommit = scm.getCommit(hash);

        bugInCommit(buggedCommit);
      }
    }
  }
  @Override
  public List<ChangeSet> get(SCM scm) {
    List<ChangeSet> commits = scm.getChangeSets();

    for (ChangeSet cs : commits) {
      if (cs.getId().equals(commit)) return Arrays.asList(cs);
    }
    throw new RuntimeException("commit " + commit + " does not exist");
  }
Exemplo n.º 3
0
  @Test
  public void should_get_commits_in_range() {
    range = new Range("2", "4");

    ChangeSet c1 = new ChangeSet("1", new GregorianCalendar(2015, Calendar.JANUARY, 23));
    ChangeSet c2 = new ChangeSet("2", new GregorianCalendar(2015, Calendar.MARCH, 24));
    ChangeSet c3 = new ChangeSet("3", new GregorianCalendar(2015, Calendar.APRIL, 25));
    ChangeSet c4 = new ChangeSet("4", new GregorianCalendar(2014, Calendar.APRIL, 25));
    ChangeSet c5 = new ChangeSet("5", new GregorianCalendar(2013, Calendar.APRIL, 25));

    Mockito.when(scm.getChangeSets()).thenReturn(Arrays.asList(c1, c2, c3, c4, c5));

    List<ChangeSet> list = range.get(scm);

    Assert.assertEquals(3, list.size());
    Assert.assertEquals(c2, list.get(0));
    Assert.assertEquals(c3, list.get(1));
    Assert.assertEquals(c4, list.get(2));
  }