Search in sources :

Example 31 with Change

use of com.gitblit.models.TicketModel.Change 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());
}
Also used : UserModel(com.gitblit.models.UserModel) Patchset(com.gitblit.models.TicketModel.Patchset) TicketModel(com.gitblit.models.TicketModel) Change(com.gitblit.models.TicketModel.Change)

Example 32 with Change

use of com.gitblit.models.TicketModel.Change 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);
}
Also used : Form(org.apache.wicket.markup.html.form.Form) Label(org.apache.wicket.markup.html.basic.Label) TicketModel(com.gitblit.models.TicketModel) Change(com.gitblit.models.TicketModel.Change) RepositoryModel(com.gitblit.models.RepositoryModel) PageParameters(org.apache.wicket.PageParameters) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxButton(org.apache.wicket.ajax.markup.html.form.AjaxButton) RedirectRequestTarget(org.apache.wicket.request.target.basic.RedirectRequestTarget) BasePage(com.gitblit.wicket.pages.BasePage)

Example 33 with Change

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

the class FileTicketService method getTickets.

/**
	 * Returns all the tickets in the repository. Querying tickets from the
	 * repository requires deserializing all tickets. This is an  expensive
	 * process and not recommended. Tickets are indexed by Lucene and queries
	 * should be executed against that index.
	 *
	 * @param repository
	 * @param filter
	 *            optional filter to only return matching results
	 * @return a list of tickets
	 */
@Override
public List<TicketModel> getTickets(RepositoryModel repository, TicketFilter filter) {
    List<TicketModel> list = new ArrayList<TicketModel>();
    Repository db = repositoryManager.getRepository(repository.name);
    try {
        // Collect the set of all json files
        File dir = new File(db.getDirectory(), TICKETS_PATH);
        List<File> journals = findAll(dir, JOURNAL);
        // Deserialize each ticket and optionally filter out unwanted tickets
        for (File journal : journals) {
            String json = null;
            try {
                json = new String(FileUtils.readContent(journal), Constants.ENCODING);
            } catch (Exception e) {
                log.error(null, e);
            }
            if (StringUtils.isEmpty(json)) {
                // journal was touched but no changes were written
                continue;
            }
            try {
                // Reconstruct ticketId from the path
                // id/26/326/journal.json
                String path = FileUtils.getRelativePath(dir, journal);
                String tid = path.split("/")[1];
                long ticketId = Long.parseLong(tid);
                List<Change> changes = TicketSerializer.deserializeJournal(json);
                if (ArrayUtils.isEmpty(changes)) {
                    log.warn("Empty journal for {}:{}", repository, journal);
                    continue;
                }
                TicketModel ticket = TicketModel.buildTicket(changes);
                ticket.project = repository.projectPath;
                ticket.repository = repository.name;
                ticket.number = ticketId;
                // add the ticket, conditionally, to the list
                if (filter == null) {
                    list.add(ticket);
                } else {
                    if (filter.accept(ticket)) {
                        list.add(ticket);
                    }
                }
            } catch (Exception e) {
                log.error("failed to deserialize {}/{}\n{}", new Object[] { repository, journal, e.getMessage() });
                log.error(null, e);
            }
        }
        // sort the tickets by creation
        Collections.sort(list);
        return list;
    } finally {
        db.close();
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ArrayList(java.util.ArrayList) TicketModel(com.gitblit.models.TicketModel) Change(com.gitblit.models.TicketModel.Change) File(java.io.File) IOException(java.io.IOException)

Example 34 with Change

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

the class FileTicketService 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) {
    Repository db = repositoryManager.getRepository(repository.name);
    try {
        List<Change> changes = getJournal(db, ticketId);
        if (ArrayUtils.isEmpty(changes)) {
            log.warn("Empty journal for {}:{}", repository, ticketId);
            return null;
        }
        TicketModel ticket = TicketModel.buildTicket(changes);
        if (ticket != null) {
            ticket.project = repository.projectPath;
            ticket.repository = repository.name;
            ticket.number = ticketId;
        }
        return ticket;
    } finally {
        db.close();
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) TicketModel(com.gitblit.models.TicketModel) Change(com.gitblit.models.TicketModel.Change)

Example 35 with Change

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

the class FileTicketService method getJournal.

/**
	 * Returns the journal for the specified ticket.
	 *
	 * @param db
	 * @param ticketId
	 * @return a list of changes
	 */
private List<Change> getJournal(Repository db, long ticketId) {
    if (ticketId <= 0L) {
        return new ArrayList<Change>();
    }
    String journalPath = toTicketPath(ticketId) + "/" + JOURNAL;
    File journal = new File(db.getDirectory(), journalPath);
    if (!journal.exists()) {
        return new ArrayList<Change>();
    }
    String json = null;
    try {
        json = new String(FileUtils.readContent(journal), Constants.ENCODING);
    } catch (Exception e) {
        log.error(null, e);
    }
    if (StringUtils.isEmpty(json)) {
        return new ArrayList<Change>();
    }
    List<Change> list = TicketSerializer.deserializeJournal(json);
    return list;
}
Also used : ArrayList(java.util.ArrayList) Change(com.gitblit.models.TicketModel.Change) File(java.io.File) IOException(java.io.IOException)

Aggregations

Change (com.gitblit.models.TicketModel.Change)45 TicketModel (com.gitblit.models.TicketModel)32 IOException (java.io.IOException)15 Repository (org.eclipse.jgit.lib.Repository)9 Test (org.junit.Test)9 Patchset (com.gitblit.models.TicketModel.Patchset)8 TicketLink (com.gitblit.models.TicketModel.TicketLink)7 ArrayList (java.util.ArrayList)7 RepositoryModel (com.gitblit.models.RepositoryModel)6 UserModel (com.gitblit.models.UserModel)5 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 Reference (com.gitblit.models.TicketModel.Reference)3 Ref (org.eclipse.jgit.lib.Ref)3 RevWalk (org.eclipse.jgit.revwalk.RevWalk)3 ReceiveCommand (org.eclipse.jgit.transport.ReceiveCommand)3 PatchsetHook (com.gitblit.extensions.PatchsetHook)2 PathChangeModel (com.gitblit.models.PathModel.PathChangeModel)2 RefModel (com.gitblit.models.RefModel)2 Attachment (com.gitblit.models.TicketModel.Attachment)2 Review (com.gitblit.models.TicketModel.Review)2