use of com.gitblit.models.TicketModel in project gitblit by gitblit.
the class TicketPage method getTicket.
/**
* Returns the ticket (if any) that this commit references.
*
* @param commit
* @return null or a ticket
*/
protected TicketModel getTicket(RevCommit commit) {
try {
Map<String, Ref> refs = getRepository().getRefDatabase().getRefs(Constants.R_TICKETS_PATCHSETS);
for (Map.Entry<String, Ref> entry : refs.entrySet()) {
if (entry.getValue().getObjectId().equals(commit.getId())) {
long id = PatchsetCommand.getTicketNumber(entry.getKey());
TicketModel ticket = app().tickets().getTicket(getRepositoryModel(), id);
return ticket;
}
}
} catch (Exception e) {
logger().error("failed to determine ticket from ref", e);
}
return null;
}
use of com.gitblit.models.TicketModel in project gitblit by gitblit.
the class TicketPage method createDeletePatchsetLink.
private Link<Void> createDeletePatchsetLink(final RepositoryModel repositoryModel, final Patchset patchset) {
Link<Void> deleteLink = new Link<Void>("deleteRevision") {
private static final long serialVersionUID = 1L;
@Override
public void onClick() {
Repository r = app().repositories().getRepository(repositoryModel.name);
UserModel user = GitBlitWebSession.get().getUser();
if (r == null) {
if (app().repositories().isCollectingGarbage(repositoryModel.name)) {
error(MessageFormat.format(getString("gb.busyCollectingGarbage"), repositoryModel.name));
} else {
error(MessageFormat.format("Failed to find repository {0}", repositoryModel.name));
}
return;
}
//Construct the ref name based on the patchset
String ticketShard = String.format("%02d", ticket.number);
ticketShard = ticketShard.substring(ticketShard.length() - 2);
final String refName = String.format("%s%s/%d/%d", Constants.R_TICKETS_PATCHSETS, ticketShard, ticket.number, patchset.number);
Ref ref = null;
boolean success = true;
try {
ref = r.getRef(refName);
if (ref != null) {
success = JGitUtils.deleteBranchRef(r, ref.getName());
} else {
success = false;
}
if (success) {
// clear commit cache
CommitCache.instance().clear(repositoryModel.name, refName);
// optionally update reflog
if (RefLogUtils.hasRefLogBranch(r)) {
RefLogUtils.deleteRef(user, r, ref);
}
TicketModel updatedTicket = app().tickets().deletePatchset(ticket, patchset, user.username);
if (updatedTicket == null) {
success = false;
}
}
} catch (IOException e) {
logger().error("failed to determine ticket from ref", e);
success = false;
} finally {
r.close();
}
if (success) {
getSession().info(MessageFormat.format(getString("gb.deletePatchsetSuccess"), patchset.number));
logger().info(MessageFormat.format("{0} deleted patchset {1} from ticket {2}", user.username, patchset.number, ticket.number));
} else {
getSession().error(MessageFormat.format(getString("gb.deletePatchsetFailure"), patchset.number));
}
//Force reload of the page to rebuild ticket change cache
String relativeUrl = urlFor(TicketsPage.class, getPageParameters()).toString();
String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl);
setResponsePage(new RedirectPage(absoluteUrl));
}
};
WicketUtils.setHtmlTooltip(deleteLink, MessageFormat.format(getString("gb.deletePatchset"), patchset.number));
deleteLink.add(new JavascriptEventConfirmation("onclick", MessageFormat.format(getString("gb.deletePatchset"), patchset.number)));
return deleteLink;
}
use of com.gitblit.models.TicketModel in project gitblit by gitblit.
the class TicketPage method review.
protected void review(Score score) {
UserModel user = GitBlitWebSession.get().getUser();
Patchset ps = ticket.getCurrentPatchset();
Change change = new Change(user.username);
change.review(ps, score, !ticket.isReviewer(user.username));
if (!ticket.isWatching(user.username)) {
change.watch(user.username);
}
TicketModel updatedTicket = app().tickets().updateTicket(getRepositoryModel(), ticket.number, change);
app().tickets().createNotifier().sendMailing(updatedTicket);
redirectTo(TicketsPage.class, getPageParameters());
}
use of com.gitblit.models.TicketModel in project gitblit by gitblit.
the class CommentPanel method onInitialize.
@Override
protected void onInitialize() {
super.onInitialize();
Form<String> form = new Form<String>("editorForm");
add(form);
form.add(new AjaxButton("submit", new Model<String>(getString("gb.comment")), form) {
private static final long serialVersionUID = 1L;
@Override
public void onSubmit(AjaxRequestTarget target, Form<?> form) {
String txt = markdownEditor.getText();
if (change == null) {
// new comment
Change newComment = new Change(user.username);
newComment.comment(txt);
if (!ticket.isWatching(user.username)) {
newComment.watch(user.username);
}
RepositoryModel repository = app().repositories().getRepositoryModel(ticket.repository);
TicketModel updatedTicket = app().tickets().updateTicket(repository, ticket.number, newComment);
if (updatedTicket != null) {
app().tickets().createNotifier().sendMailing(updatedTicket);
redirectTo(pageClass, WicketUtils.newObjectParameter(updatedTicket.repository, "" + ticket.number));
} else {
error("Failed to add comment!");
}
} else {
// TODO update comment
}
}
/**
* Steal from BasePage to realize redirection.
*
* @see BasePage
* @author krulls@GitHub; ECG Leipzig GmbH, Germany, 2015
*
* @param pageClass
* @param parameters
* @return
*/
private void redirectTo(Class<? extends BasePage> pageClass, PageParameters parameters) {
String relativeUrl = urlFor(pageClass, parameters).toString();
String canonicalUrl = RequestUtils.toAbsolutePath(relativeUrl);
getRequestCycle().setRequestTarget(new RedirectRequestTarget(canonicalUrl));
}
}.setVisible(ticket != null && ticket.number > 0));
final IModel<String> markdownPreviewModel = Model.of();
markdownPreview = new Label("markdownPreview", markdownPreviewModel);
markdownPreview.setEscapeModelStrings(false);
markdownPreview.setOutputMarkupId(true);
add(markdownPreview);
markdownEditor = new MarkdownTextArea("markdownEditor", markdownPreviewModel, markdownPreview);
markdownEditor.setRepository(repositoryName);
WicketUtils.setInputPlaceholder(markdownEditor, getString("gb.leaveComment"));
add(markdownEditor);
}
use of com.gitblit.models.TicketModel in project gitblit by gitblit.
the class GitblitReceivePack method executeCommands.
/** Execute commands to update references. */
@Override
protected void executeCommands() {
List<ReceiveCommand> toApply = filterCommands(Result.NOT_ATTEMPTED);
if (toApply.isEmpty()) {
return;
}
ProgressMonitor updating = NullProgressMonitor.INSTANCE;
boolean sideBand = isCapabilityEnabled(CAPABILITY_SIDE_BAND_64K);
if (sideBand) {
SideBandProgressMonitor pm = new SideBandProgressMonitor(msgOut);
pm.setDelayStart(250, TimeUnit.MILLISECONDS);
updating = pm;
}
BatchRefUpdate batch = getRepository().getRefDatabase().newBatchUpdate();
batch.setAllowNonFastForwards(isAllowNonFastForwards());
batch.setRefLogIdent(getRefLogIdent());
batch.setRefLogMessage("push", true);
for (ReceiveCommand cmd : toApply) {
if (Result.NOT_ATTEMPTED != cmd.getResult()) {
// Already rejected by the core receive process.
continue;
}
batch.addCommand(cmd);
}
if (!batch.getCommands().isEmpty()) {
try {
batch.execute(getRevWalk(), updating);
} catch (IOException err) {
for (ReceiveCommand cmd : toApply) {
if (cmd.getResult() == Result.NOT_ATTEMPTED) {
sendRejection(cmd, "lock error: {0}", err.getMessage());
}
}
}
}
//
if (ticketService != null) {
List<ReceiveCommand> allUpdates = ReceiveCommand.filter(batch.getCommands(), Result.OK);
if (!allUpdates.isEmpty()) {
int ticketsProcessed = 0;
for (ReceiveCommand cmd : allUpdates) {
switch(cmd.getType()) {
case CREATE:
case UPDATE:
if (cmd.getRefName().startsWith(Constants.R_HEADS)) {
Collection<TicketModel> tickets = processReferencedTickets(cmd);
ticketsProcessed += tickets.size();
for (TicketModel ticket : tickets) {
ticketNotifier.queueMailing(ticket);
}
}
break;
case UPDATE_NONFASTFORWARD:
if (cmd.getRefName().startsWith(Constants.R_HEADS)) {
String base = JGitUtils.getMergeBase(getRepository(), cmd.getOldId(), cmd.getNewId());
List<TicketLink> deletedRefs = JGitUtils.identifyTicketsBetweenCommits(getRepository(), settings, base, cmd.getOldId().name());
for (TicketLink link : deletedRefs) {
link.isDelete = true;
}
Change deletion = new Change(user.username);
deletion.pendingLinks = deletedRefs;
ticketService.updateTicket(repository, 0, deletion);
Collection<TicketModel> tickets = processReferencedTickets(cmd);
ticketsProcessed += tickets.size();
for (TicketModel ticket : tickets) {
ticketNotifier.queueMailing(ticket);
}
}
break;
case DELETE:
//Identify if the branch has been merged
SortedMap<Integer, String> bases = new TreeMap<Integer, String>();
try {
ObjectId dObj = cmd.getOldId();
Collection<Ref> tips = getRepository().getRefDatabase().getRefs(Constants.R_HEADS).values();
for (Ref ref : tips) {
ObjectId iObj = ref.getObjectId();
String mergeBase = JGitUtils.getMergeBase(getRepository(), dObj, iObj);
if (mergeBase != null) {
int d = JGitUtils.countCommits(getRepository(), getRevWalk(), mergeBase, dObj.name());
bases.put(d, mergeBase);
//All commits have been merged into some other branch
if (d == 0) {
break;
}
}
}
if (bases.isEmpty()) {
//TODO: Handle orphan branch case
} else {
if (bases.firstKey() > 0) {
//Delete references from the remaining commits that haven't been merged
String mergeBase = bases.get(bases.firstKey());
List<TicketLink> deletedRefs = JGitUtils.identifyTicketsBetweenCommits(getRepository(), settings, mergeBase, dObj.name());
for (TicketLink link : deletedRefs) {
link.isDelete = true;
}
Change deletion = new Change(user.username);
deletion.pendingLinks = deletedRefs;
ticketService.updateTicket(repository, 0, deletion);
}
}
} catch (IOException e) {
LOGGER.error(null, e);
}
break;
default:
break;
}
}
if (ticketsProcessed == 1) {
sendInfo("1 ticket updated");
} else if (ticketsProcessed > 1) {
sendInfo("{0} tickets updated", ticketsProcessed);
}
}
// reset the ticket caches for the repository
ticketService.resetCaches(repository);
}
}
Aggregations