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;
}
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;
}
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);
}
}
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);
}
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);
}
Aggregations