Search in sources :

Example 56 with TicketModel

use of com.gitblit.models.TicketModel in project gitblit by gitblit.

the class TicketServiceTest method testNotifier.

@Test
public void testNotifier() throws Exception {
    Change kernel = new Change("james");
    kernel.setField(Field.title, "Sample ticket");
    kernel.setField(Field.body, "this **is** my sample body\n\n- I hope\n- you really\n- *really* like it");
    kernel.setField(Field.status, Status.New);
    kernel.setField(Field.type, Type.Proposal);
    kernel.comment("this is a sample comment on a kernel change");
    Patchset patchset = new Patchset();
    patchset.insertions = 100;
    patchset.deletions = 10;
    patchset.number = 1;
    patchset.rev = 25;
    patchset.tip = "50f57913f816d04a16b7407134de5d8406421f37";
    kernel.patchset = patchset;
    TicketModel ticket = service.createTicket(getRepository(), 0L, kernel);
    Change merge = new Change("james");
    merge.setField(Field.mergeSha, patchset.tip);
    merge.setField(Field.mergeTo, "master");
    merge.setField(Field.status, Status.Merged);
    ticket = service.updateTicket(getRepository(), ticket.number, merge);
    ticket.repository = getRepository().name;
    TicketNotifier notifier = service.createNotifier();
    Mailing mailing = notifier.queueMailing(ticket);
    assertNotNull(mailing);
}
Also used : TicketNotifier(com.gitblit.tickets.TicketNotifier) Patchset(com.gitblit.models.TicketModel.Patchset) TicketModel(com.gitblit.models.TicketModel) Change(com.gitblit.models.TicketModel.Change) Mailing(com.gitblit.models.Mailing) Test(org.junit.Test)

Example 57 with TicketModel

use of com.gitblit.models.TicketModel in project gitblit by gitblit.

the class TicketReferenceTest method commitTicketBranchAmendReference.

@Test
public void commitTicketBranchAmendReference() throws Exception {
    setPatchsetAvailable(false);
    TicketModel a = ticketService.createTicket(repo, newTicket("commitTicketBranchAmendReference-A"));
    TicketModel b = ticketService.createTicket(repo, newTicket("commitTicketBranchAmendReference-B"));
    TicketModel c = ticketService.createTicket(repo, newTicket("commitTicketBranchAmendReference-C"));
    assertFalse(c.hasPatchsets());
    String branchName = String.format("ticket/%d", c.number);
    git.checkout().setCreateBranch(true).setName(branchName).call();
    String message = String.format("commit before amend for #%d and #%d", a.number, b.number);
    final RevCommit revCommit1 = makeCommit(message);
    final String commit1Sha = revCommit1.name();
    assertPushSuccess(commit1Sha, branchName);
    a = ticketService.getTicket(repo, a.number);
    b = ticketService.getTicket(repo, b.number);
    c = ticketService.getTicket(repo, c.number);
    assertTrue(a.hasReferences());
    assertTrue(b.hasReferences());
    assertFalse(c.hasReferences());
    assertFalse(c.hasPatchsets());
    List<Reference> cRefA = a.getReferences();
    assertNotNull(cRefA);
    assertEquals(1, cRefA.size());
    assertNull(cRefA.get(0).ticketId);
    assertEquals(commit1Sha, cRefA.get(0).hash);
    List<Reference> cRefB = b.getReferences();
    assertNotNull(cRefB);
    assertEquals(1, cRefB.size());
    assertNull(cRefB.get(0).ticketId);
    assertEquals(commit1Sha, cRefB.get(0).hash);
    //Confirm that old invalid references removed for both tickets
    //and new reference added for one referenced ticket
    message = String.format("commit after amend for #%d", a.number);
    final String commit2Sha = amendCommit(message);
    assertForcePushSuccess(commit2Sha, branchName);
    a = ticketService.getTicket(repo, a.number);
    b = ticketService.getTicket(repo, b.number);
    c = ticketService.getTicket(repo, c.number);
    assertTrue(a.hasReferences());
    assertFalse(b.hasReferences());
    assertFalse(c.hasReferences());
    assertFalse(c.hasPatchsets());
    cRefA = a.getReferences();
    assertNotNull(cRefA);
    assertEquals(1, cRefA.size());
    assertNull(cRefA.get(0).ticketId);
    assertEquals(commit2Sha, cRefA.get(0).hash);
}
Also used : Reference(com.gitblit.models.TicketModel.Reference) TicketModel(com.gitblit.models.TicketModel) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 58 with TicketModel

use of com.gitblit.models.TicketModel in project gitblit by gitblit.

the class TicketReferenceTest method commitPatchsetNoUnexpectedReference.

@Test
public void commitPatchsetNoUnexpectedReference() throws Exception {
    setPatchsetAvailable(true);
    TicketModel a = ticketService.createTicket(repo, newTicket("commitPatchsetNoUnexpectedReference-A"));
    String branchName = String.format("ticket/%d", a.number);
    git.checkout().setCreateBranch(true).setName(branchName).call();
    makeCommit("commit for 1 - no reference");
    makeCommit("commit for # - no reference");
    final String message = "commit for #999 - ignores invalid reference";
    final RevCommit revCommit1 = makeCommit(message);
    final String commit1Sha = revCommit1.name();
    assertPushSuccess(commit1Sha, branchName);
    a = ticketService.getTicket(repo, a.number);
    assertFalse(a.hasReferences());
}
Also used : TicketModel(com.gitblit.models.TicketModel) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 59 with TicketModel

use of com.gitblit.models.TicketModel in project gitblit by gitblit.

the class TicketReferenceTest method commentSelfAndOtherReference.

@Test
public void commentSelfAndOtherReference() throws Exception {
    TicketModel a = ticketService.createTicket(repo, newTicket("commentSelfAndOtherReference-A"));
    TicketModel b = ticketService.createTicket(repo, newTicket("commentSelfAndOtherReference-B"));
    final Change comment = newComment(String.format("comment for #%d and #%d - self and other reference", a.number, b.number));
    assertNotNull(ticketService.updateTicket(repo, a.number, comment));
    a = ticketService.getTicket(repo, a.number);
    b = ticketService.getTicket(repo, b.number);
    assertFalse(a.hasReferences());
    assertTrue(b.hasReferences());
    List<Reference> cRefB = b.getReferences();
    assertNotNull(cRefB);
    assertEquals(1, cRefB.size());
    assertEquals(a.number, cRefB.get(0).ticketId.longValue());
    assertEquals(comment.comment.id, cRefB.get(0).hash);
}
Also used : Reference(com.gitblit.models.TicketModel.Reference) TicketModel(com.gitblit.models.TicketModel) Change(com.gitblit.models.TicketModel.Change) Test(org.junit.Test)

Example 60 with TicketModel

use of com.gitblit.models.TicketModel in project gitblit by gitblit.

the class TicketReferenceTest method commitPatchsetAmendReference.

@Test
public void commitPatchsetAmendReference() throws Exception {
    setPatchsetAvailable(true);
    TicketModel a = ticketService.createTicket(repo, newTicket("commitPatchsetAmendReference-A"));
    TicketModel b = ticketService.createTicket(repo, newTicket("commitPatchsetAmendReference-B"));
    TicketModel c = ticketService.createTicket(repo, newTicket("commitPatchsetAmendReference-C"));
    assertFalse(c.hasPatchsets());
    String branchName = String.format("ticket/%d", c.number);
    git.checkout().setCreateBranch(true).setName(branchName).call();
    String message = String.format("commit before amend for #%d and #%d", a.number, b.number);
    final RevCommit revCommit1 = makeCommit(message);
    final String commit1Sha = revCommit1.name();
    assertPushSuccess(commit1Sha, branchName);
    a = ticketService.getTicket(repo, a.number);
    b = ticketService.getTicket(repo, b.number);
    c = ticketService.getTicket(repo, c.number);
    assertTrue(a.hasReferences());
    assertTrue(b.hasReferences());
    assertFalse(c.hasReferences());
    assertTrue(c.hasPatchsets());
    assertNotNull(c.getPatchset(1, 1));
    List<Reference> cRefA = a.getReferences();
    assertNotNull(cRefA);
    assertEquals(1, cRefA.size());
    assertNull(cRefA.get(0).ticketId);
    assertEquals(commit1Sha, cRefA.get(0).hash);
    List<Reference> cRefB = b.getReferences();
    assertNotNull(cRefB);
    assertEquals(1, cRefB.size());
    assertNull(cRefB.get(0).ticketId);
    assertEquals(commit1Sha, cRefB.get(0).hash);
    //As a new patchset is created the references will remain until deleted
    message = String.format("commit after amend for #%d", a.number);
    final String commit2Sha = amendCommit(message);
    assertForcePushSuccess(commit2Sha, branchName);
    a = ticketService.getTicket(repo, a.number);
    b = ticketService.getTicket(repo, b.number);
    c = ticketService.getTicket(repo, c.number);
    assertTrue(a.hasReferences());
    assertTrue(b.hasReferences());
    assertFalse(c.hasReferences());
    assertNotNull(c.getPatchset(1, 1));
    assertNotNull(c.getPatchset(2, 1));
    cRefA = a.getReferences();
    assertNotNull(cRefA);
    assertEquals(2, cRefA.size());
    assertNull(cRefA.get(0).ticketId);
    assertNull(cRefA.get(1).ticketId);
    assertEquals(commit1Sha, cRefA.get(0).hash);
    assertEquals(commit2Sha, cRefA.get(1).hash);
    cRefB = b.getReferences();
    assertNotNull(cRefB);
    assertEquals(1, cRefB.size());
    assertNull(cRefB.get(0).ticketId);
    assertEquals(commit1Sha, cRefB.get(0).hash);
    //Delete the original patchset and confirm old references are removed
    ticketService.deletePatchset(c, c.getPatchset(1, 1), user.username);
    a = ticketService.getTicket(repo, a.number);
    b = ticketService.getTicket(repo, b.number);
    c = ticketService.getTicket(repo, c.number);
    assertTrue(a.hasReferences());
    assertFalse(b.hasReferences());
    assertFalse(c.hasReferences());
    assertNull(c.getPatchset(1, 1));
    assertNotNull(c.getPatchset(2, 1));
    cRefA = a.getReferences();
    assertNotNull(cRefA);
    assertEquals(1, cRefA.size());
    assertNull(cRefA.get(0).ticketId);
    assertEquals(commit2Sha, cRefA.get(0).hash);
}
Also used : Reference(com.gitblit.models.TicketModel.Reference) TicketModel(com.gitblit.models.TicketModel) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

TicketModel (com.gitblit.models.TicketModel)62 Change (com.gitblit.models.TicketModel.Change)32 Test (org.junit.Test)28 RevCommit (org.eclipse.jgit.revwalk.RevCommit)21 IOException (java.io.IOException)18 Reference (com.gitblit.models.TicketModel.Reference)16 Repository (org.eclipse.jgit.lib.Repository)12 Patchset (com.gitblit.models.TicketModel.Patchset)8 RepositoryModel (com.gitblit.models.RepositoryModel)7 TicketLink (com.gitblit.models.TicketModel.TicketLink)7 Ref (org.eclipse.jgit.lib.Ref)5 UserModel (com.gitblit.models.UserModel)4 ArrayList (java.util.ArrayList)4 ReceiveCommand (org.eclipse.jgit.transport.ReceiveCommand)4 Attachment (com.gitblit.models.TicketModel.Attachment)3 ParseException (java.text.ParseException)3 RevWalk (org.eclipse.jgit.revwalk.RevWalk)3 TicketHook (com.gitblit.extensions.TicketHook)2 PathChangeModel (com.gitblit.models.PathModel.PathChangeModel)2 BranchTicketService (com.gitblit.tickets.BranchTicketService)2