Search in sources :

Example 46 with TicketModel

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

the class ITicketService method createTicket.

/**
	 * Creates a ticket.  Your change must include a repository, author & title,
	 * at a minimum. If your change does not have those minimum requirements a
	 * RuntimeException will be thrown.
	 *
	 * @param repository
	 * @param ticketId (if <=0 the ticket id will be assigned)
	 * @param change
	 * @return true if successful
	 * @since 1.4.0
	 */
public TicketModel createTicket(RepositoryModel repository, long ticketId, Change change) {
    if (repository == null) {
        throw new RuntimeException("Must specify a repository!");
    }
    if (StringUtils.isEmpty(change.author)) {
        throw new RuntimeException("Must specify a change author!");
    }
    if (!change.hasField(Field.title)) {
        throw new RuntimeException("Must specify a title!");
    }
    change.watch(change.author);
    if (ticketId <= 0L) {
        ticketId = assignNewId(repository);
    }
    change.setField(Field.status, Status.New);
    boolean success = commitChangeImpl(repository, ticketId, change);
    if (success) {
        TicketModel ticket = getTicket(repository, ticketId);
        indexer.index(ticket);
        // call the ticket hooks
        if (pluginManager != null) {
            for (TicketHook hook : pluginManager.getExtensions(TicketHook.class)) {
                try {
                    hook.onNewTicket(ticket);
                } catch (Exception e) {
                    log.error("Failed to execute extension", e);
                }
            }
        }
        return ticket;
    }
    return null;
}
Also used : TicketHook(com.gitblit.extensions.TicketHook) TicketModel(com.gitblit.models.TicketModel) ParseException(java.text.ParseException) IOException(java.io.IOException)

Example 47 with TicketModel

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

the class RedisTicketService method getTicketImpl.

/**
	 * Retrieves the ticket from the repository.
	 *
	 * @param repository
	 * @param ticketId
	 * @return a ticket, if it exists, otherwise null
	 */
@Override
protected TicketModel getTicketImpl(RepositoryModel repository, long ticketId) {
    Jedis jedis = pool.getResource();
    if (jedis == null) {
        return null;
    }
    try {
        List<Change> changes = getJournal(jedis, repository, ticketId);
        if (ArrayUtils.isEmpty(changes)) {
            log.warn("Empty journal for {}:{}", repository, ticketId);
            return null;
        }
        TicketModel ticket = TicketModel.buildTicket(changes);
        ticket.project = repository.projectPath;
        ticket.repository = repository.name;
        ticket.number = ticketId;
        log.debug("rebuilt ticket {} from Redis @ {}", ticketId, getUrl());
        return ticket;
    } catch (JedisException e) {
        log.error("failed to retrieve ticket from Redis @ " + getUrl(), e);
        pool.returnBrokenResource(jedis);
        jedis = null;
    } finally {
        if (jedis != null) {
            pool.returnResource(jedis);
        }
    }
    return null;
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisException(redis.clients.jedis.exceptions.JedisException) TicketModel(com.gitblit.models.TicketModel) Change(com.gitblit.models.TicketModel.Change)

Example 48 with TicketModel

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

the class TicketIndexer method index.

/**
	 * Bulk Add/Update tickets in the Lucene index
	 *
	 * @param tickets
	 */
public void index(List<TicketModel> tickets) {
    try {
        IndexWriter writer = getWriter();
        for (TicketModel ticket : tickets) {
            Document doc = ticketToDoc(ticket);
            writer.addDocument(doc);
        }
        writer.commit();
        closeSearcher();
    } catch (Exception e) {
        log.error("error", e);
    }
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) TicketModel(com.gitblit.models.TicketModel) Document(org.apache.lucene.document.Document) ParseException(java.text.ParseException) IOException(java.io.IOException)

Example 49 with TicketModel

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

the class TicketReferenceTest method commitMasterMultiReference.

@Test
public void commitMasterMultiReference() throws Exception {
    TicketModel a = ticketService.createTicket(repo, newTicket("commitMasterMultiReference-A"));
    TicketModel b = ticketService.createTicket(repo, newTicket("commitMasterMultiReference-B"));
    final String branchName = "master";
    git.checkout().setCreateBranch(false).setName(branchName).call();
    final String message = String.format("commit for #%d and #%d - multi reference", 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);
    assertTrue(a.hasReferences());
    assertTrue(b.hasReferences());
    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 = a.getReferences();
    assertNotNull(cRefB);
    assertEquals(1, cRefB.size());
    assertNull(cRefB.get(0).ticketId);
    assertEquals(commit1Sha, cRefB.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 50 with TicketModel

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

the class TicketReferenceTest method commitTicketBranchDeletePostMergeReference.

@Test
public void commitTicketBranchDeletePostMergeReference() throws Exception {
    setPatchsetAvailable(false);
    TicketModel a = ticketService.createTicket(repo, newTicket("commitTicketBranchDeletePostMergeReference-A"));
    TicketModel b = ticketService.createTicket(repo, newTicket("commitTicketBranchDeletePostMergeReference-B"));
    TicketModel c = ticketService.createTicket(repo, newTicket("commitTicketBranchDeletePostMergeReference-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());
    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);
    git.checkout().setCreateBranch(false).setName("refs/heads/master").call();
    // merge the tip of the branch into master
    MergeResult mergeResult = git.merge().setFastForward(FastForwardMode.NO_FF).include(revCommit1.getId()).call();
    assertEquals(MergeResult.MergeStatus.MERGED, mergeResult.getMergeStatus());
    // push the merged master to the origin
    Iterable<PushResult> results = git.push().setCredentialsProvider(cp).setRemote("origin").call();
    for (PushResult result : results) {
        RemoteRefUpdate ref = result.getRemoteUpdate("refs/heads/master");
        assertEquals(Status.OK, ref.getStatus());
    }
    //As everything has been merged no references should be changed
    assertDeleteBranch(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());
    cRefA = a.getReferences();
    assertNotNull(cRefA);
    assertEquals(1, cRefA.size());
    assertNull(cRefA.get(0).ticketId);
    assertEquals(commit1Sha, cRefA.get(0).hash);
    cRefB = b.getReferences();
    assertNotNull(cRefB);
    assertEquals(1, cRefB.size());
    assertNull(cRefB.get(0).ticketId);
    assertEquals(commit1Sha, cRefB.get(0).hash);
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) Reference(com.gitblit.models.TicketModel.Reference) MergeResult(org.eclipse.jgit.api.MergeResult) TicketModel(com.gitblit.models.TicketModel) PushResult(org.eclipse.jgit.transport.PushResult) 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