Package com.gitblit.models.TicketModel

Examples of com.gitblit.models.TicketModel.Patchset


    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";
View Full Code Here


      // if ticket exists
      if (ticket != null) {
        if (ticket.hasPatchsets()) {
          Repository r = repositoryManager.getRepository(repository.name);
          try {
            Patchset patchset = ticket.getCurrentPatchset();
            DiffStat diffStat = DiffUtils.getDiffStat(r, patchset.base, patchset.tip);
            // diffstat could be null if we have ticket data without the
            // commit objects.  e.g. ticket replication without repo
            // mirroring
            if (diffStat != null) {
View Full Code Here

        statusChanges.add(change);
      }
    }

    final Change currentRevision = revisions.isEmpty() ? null : revisions.get(revisions.size() - 1);
    final Patchset currentPatchset = ticket.getCurrentPatchset();

    /*
     * TICKET HEADER
     */
    String href = urlFor(TicketsPage.class, params).toString();
    add(new ExternalLink("ticketNumber", href, "#" + ticket.number));
    Label headerStatus = new Label("headerStatus", ticket.status.toString());
    WicketUtils.setCssClass(headerStatus, getLozengeClass(ticket.status, false));
    add(headerStatus);
    add(new Label("ticketTitle", ticket.title));
    if (currentPatchset == null) {
      add(new Label("diffstat").setVisible(false));
    } else {
      // calculate the current diffstat of the patchset
      add(new DiffStatPanel("diffstat", ticket.insertions, ticket.deletions));
    }


    /*
     * TAB TITLES
     */
    add(new Label("commentCount", "" + comments.size()).setVisible(!comments.isEmpty()));
    add(new Label("commitCount", "" + (currentPatchset == null ? 0 : currentPatchset.commits)).setVisible(currentPatchset != null));


    /*
     * TICKET AUTHOR and DATE (DISCUSSION TAB)
     */
    UserModel createdBy = app().users().getUserModel(ticket.createdBy);
    if (createdBy == null) {
      add(new Label("whoCreated", ticket.createdBy));
    } else {
      add(new LinkPanel("whoCreated", null, createdBy.getDisplayName(),
          UserPage.class, WicketUtils.newUsernameParameter(createdBy.username)));
    }

    if (ticket.isProposal()) {
      // clearly indicate this is a change ticket
      add(new Label("creationMessage", getString("gb.proposedThisChange")));
    } else {
      // standard ticket
      add(new Label("creationMessage", getString("gb.createdThisTicket")));
    }

    String dateFormat = app().settings().getString(Keys.web.datestampLongFormat, "EEEE, MMMM d, yyyy");
    String timestampFormat = app().settings().getString(Keys.web.datetimestampLongFormat, "EEEE, MMMM d, yyyy");
    final TimeZone timezone = getTimeZone();
    final DateFormat df = new SimpleDateFormat(dateFormat);
    df.setTimeZone(timezone);
    final DateFormat tsf = new SimpleDateFormat(timestampFormat);
    tsf.setTimeZone(timezone);
    final Calendar cal = Calendar.getInstance(timezone);

    String fuzzydate;
    TimeUtils tu = getTimeUtils();
    Date createdDate = ticket.created;
    if (TimeUtils.isToday(createdDate, timezone)) {
      fuzzydate = tu.today();
    } else if (TimeUtils.isYesterday(createdDate, timezone)) {
      fuzzydate = tu.yesterday();
    } else {
      // calculate a fuzzy time ago date
          cal.setTime(createdDate);
          cal.set(Calendar.HOUR_OF_DAY, 0);
          cal.set(Calendar.MINUTE, 0);
          cal.set(Calendar.SECOND, 0);
          cal.set(Calendar.MILLISECOND, 0);
          createdDate = cal.getTime();
      fuzzydate = getTimeUtils().timeAgo(createdDate);
    }
    Label when = new Label("whenCreated", fuzzydate + ", " + df.format(createdDate));
    WicketUtils.setHtmlTooltip(when, tsf.format(ticket.created));
    add(when);

    String exportHref = urlFor(ExportTicketPage.class, params).toString();
    add(new ExternalLink("exportJson", exportHref, "json"));


    /*
     * RESPONSIBLE (DISCUSSION TAB)
     */
    if (StringUtils.isEmpty(ticket.responsible)) {
      add(new Label("responsible"));
    } else {
      UserModel responsible = app().users().getUserModel(ticket.responsible);
      if (responsible == null) {
        add(new Label("responsible", ticket.responsible));
      } else {
        add(new LinkPanel("responsible", null, responsible.getDisplayName(),
            UserPage.class, WicketUtils.newUsernameParameter(responsible.username)));
      }
    }

    /*
     * MILESTONE PROGRESS (DISCUSSION TAB)
     */
    if (StringUtils.isEmpty(ticket.milestone)) {
      add(new Label("milestone"));
    } else {
      // link to milestone query
      TicketMilestone milestone = app().tickets().getMilestone(repository, ticket.milestone);
      PageParameters milestoneParameters = new PageParameters();
      milestoneParameters.put("r", repositoryName);
      milestoneParameters.put(Lucene.milestone.name(), ticket.milestone);
      int progress = 0;
      int open = 0;
      int closed = 0;
      if (milestone != null) {
        progress = milestone.getProgress();
        open = milestone.getOpenTickets();
        closed = milestone.getClosedTickets();
      }

      Fragment milestoneProgress = new Fragment("milestone", "milestoneProgressFragment", this);
      milestoneProgress.add(new LinkPanel("link", null, ticket.milestone, TicketsPage.class, milestoneParameters));
      Label label = new Label("progress");
      WicketUtils.setCssStyle(label, "width:" + progress + "%;");
      milestoneProgress.add(label);
      WicketUtils.setHtmlTooltip(milestoneProgress, MessageFormat.format(getString("gb.milestoneProgress"), open, closed));
      add(milestoneProgress);
    }


    /*
     * TICKET DESCRIPTION (DISCUSSION TAB)
     */
    String desc;
    if (StringUtils.isEmpty(ticket.body)) {
      desc = getString("gb.noDescriptionGiven");
    } else {
      desc = MarkdownUtils.transformGFM(app().settings(), ticket.body, ticket.repository);
    }
    add(new Label("ticketDescription", desc).setEscapeModelStrings(false));


    /*
     * PARTICIPANTS (DISCUSSION TAB)
     */
    if (app().settings().getBoolean(Keys.web.allowGravatar, true)) {
      // gravatar allowed
      List<String> participants = ticket.getParticipants();
      add(new Label("participantsLabel", MessageFormat.format(getString(participants.size() > 1 ? "gb.nParticipants" : "gb.oneParticipant"),
          "<b>" + participants.size() + "</b>")).setEscapeModelStrings(false));
      ListDataProvider<String> participantsDp = new ListDataProvider<String>(participants);
      DataView<String> participantsView = new DataView<String>("participants", participantsDp) {
        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<String> item) {
          String username = item.getModelObject();
          UserModel user = app().users().getUserModel(username);
          if (user == null) {
            user = new UserModel(username);
          }
          item.add(new GravatarImage("participant", user.getDisplayName(),
              user.emailAddress, null, 25, true));
        }
      };
      add(participantsView);
    } else {
      // gravatar prohibited
      add(new Label("participantsLabel").setVisible(false));
      add(new Label("participants").setVisible(false));
    }


    /*
     * LARGE STATUS INDICATOR WITH ICON (DISCUSSION TAB->SIDE BAR)
     */
    Fragment ticketStatus = new Fragment("ticketStatus", "ticketStatusFragment", this);
    Label ticketIcon = getStateIcon("ticketIcon", ticket);
    ticketStatus.add(ticketIcon);
    ticketStatus.add(new Label("ticketStatus", ticket.status.toString()));
    WicketUtils.setCssClass(ticketStatus, getLozengeClass(ticket.status, false));
    add(ticketStatus);


    /*
     * UPDATE FORM (DISCUSSION TAB)
     */
    if (user.canEdit(ticket, repository) && app().tickets().isAcceptingTicketUpdates(repository)) {
      if (user.canAdmin(ticket, repository) && ticket.isOpen()) {
        /*
         * OPEN TICKET
         */
        Fragment controls = new Fragment("controls", "openControlsFragment", this);

        /*
         * STATUS
         */
        List<Status> choices = new ArrayList<Status>();
        if (ticket.isProposal()) {
          choices.addAll(Arrays.asList(TicketModel.Status.proposalWorkflow));
        } else if (ticket.isBug()) {
          choices.addAll(Arrays.asList(TicketModel.Status.bugWorkflow));
        } else {
          choices.addAll(Arrays.asList(TicketModel.Status.requestWorkflow));
        }
        choices.remove(ticket.status);

        ListDataProvider<Status> workflowDp = new ListDataProvider<Status>(choices);
        DataView<Status> statusView = new DataView<Status>("newStatus", workflowDp) {
          private static final long serialVersionUID = 1L;

          @Override
          public void populateItem(final Item<Status> item) {
            SimpleAjaxLink<Status> link = new SimpleAjaxLink<Status>("link", item.getModel()) {

              private static final long serialVersionUID = 1L;

              @Override
              public void onClick(AjaxRequestTarget target) {
                Status status = getModel().getObject();
                Change change = new Change(user.username);
                change.setField(Field.status, status);
                if (!ticket.isWatching(user.username)) {
                  change.watch(user.username);
                }
                TicketModel update = app().tickets().updateTicket(repository, ticket.number, change);
                app().tickets().createNotifier().sendMailing(update);
                setResponsePage(TicketsPage.class, getPageParameters());
              }
            };
            String css = getStatusClass(item.getModel().getObject());
            WicketUtils.setCssClass(link, css);
            item.add(link);
          }
        };
        controls.add(statusView);

        /*
         * RESPONSIBLE LIST
         */
        Set<String> userlist = new TreeSet<String>(ticket.getParticipants());
        for (RegistrantAccessPermission rp : app().repositories().getUserAccessPermissions(getRepositoryModel())) {
          if (rp.permission.atLeast(AccessPermission.PUSH) && !rp.isTeam()) {
            userlist.add(rp.registrant);
          }
        }
        List<TicketResponsible> responsibles = new ArrayList<TicketResponsible>();
        if (!StringUtils.isEmpty(ticket.responsible)) {
          // exclude the current responsible
          userlist.remove(ticket.responsible);
        }
        for (String username : userlist) {
          UserModel u = app().users().getUserModel(username);
          if (u != null) {
            responsibles.add(new TicketResponsible(u));
          }
        }
        Collections.sort(responsibles);
        responsibles.add(new TicketResponsible(ESC_NIL, "", ""));
        ListDataProvider<TicketResponsible> responsibleDp = new ListDataProvider<TicketResponsible>(responsibles);
        DataView<TicketResponsible> responsibleView = new DataView<TicketResponsible>("newResponsible", responsibleDp) {
          private static final long serialVersionUID = 1L;

          @Override
          public void populateItem(final Item<TicketResponsible> item) {
            SimpleAjaxLink<TicketResponsible> link = new SimpleAjaxLink<TicketResponsible>("link", item.getModel()) {

              private static final long serialVersionUID = 1L;

              @Override
              public void onClick(AjaxRequestTarget target) {
                TicketResponsible responsible = getModel().getObject();
                Change change = new Change(user.username);
                change.setField(Field.responsible, responsible.username);
                if (!StringUtils.isEmpty(responsible.username)) {
                  if (!ticket.isWatching(responsible.username)) {
                    change.watch(responsible.username);
                  }
                }
                if (!ticket.isWatching(user.username)) {
                  change.watch(user.username);
                }
                TicketModel update = app().tickets().updateTicket(repository, ticket.number, change);
                app().tickets().createNotifier().sendMailing(update);
                setResponsePage(TicketsPage.class, getPageParameters());
              }
            };
            item.add(link);
          }
        };
        controls.add(responsibleView);

        /*
         * MILESTONE LIST
         */
        List<TicketMilestone> milestones = app().tickets().getMilestones(repository, Status.Open);
        if (!StringUtils.isEmpty(ticket.milestone)) {
          for (TicketMilestone milestone : milestones) {
            if (milestone.name.equals(ticket.milestone)) {
              milestones.remove(milestone);
              break;
            }
          }
        }
        milestones.add(new TicketMilestone(ESC_NIL));
        ListDataProvider<TicketMilestone> milestoneDp = new ListDataProvider<TicketMilestone>(milestones);
        DataView<TicketMilestone> milestoneView = new DataView<TicketMilestone>("newMilestone", milestoneDp) {
          private static final long serialVersionUID = 1L;

          @Override
          public void populateItem(final Item<TicketMilestone> item) {
            SimpleAjaxLink<TicketMilestone> link = new SimpleAjaxLink<TicketMilestone>("link", item.getModel()) {

              private static final long serialVersionUID = 1L;

              @Override
              public void onClick(AjaxRequestTarget target) {
                TicketMilestone milestone = getModel().getObject();
                Change change = new Change(user.username);
                if (NIL.equals(milestone.name) || ESC_NIL.equals(milestone.name)) {
                  change.setField(Field.milestone, "");
                } else {
                  change.setField(Field.milestone, milestone.name);
                }
                if (!ticket.isWatching(user.username)) {
                  change.watch(user.username);
                }
                TicketModel update = app().tickets().updateTicket(repository, ticket.number, change);
                app().tickets().createNotifier().sendMailing(update);
                setResponsePage(TicketsPage.class, getPageParameters());
              }
            };
            item.add(link);
          }
        };
        controls.add(milestoneView);

        String editHref = urlFor(EditTicketPage.class, params).toString();
        controls.add(new ExternalLink("editLink", editHref, getString("gb.edit")));

        add(controls);
      } else {
        /*
         * CLOSED TICKET
         */
        Fragment controls = new Fragment("controls", "closedControlsFragment", this);

        String editHref = urlFor(EditTicketPage.class, params).toString();
        controls.add(new ExternalLink("editLink", editHref, getString("gb.edit")));

        add(controls);
      }
    } else {
      add(new Label("controls").setVisible(false));
    }


    /*
     * TICKET METADATA
     */
    add(new Label("ticketType", ticket.type.toString()));
    if (StringUtils.isEmpty(ticket.topic)) {
      add(new Label("ticketTopic").setVisible(false));
    } else {
      // process the topic using the bugtraq config to link things
      String topic = bugtraqProcessor().processPlainCommitMessage(getRepository(), repositoryName, ticket.topic);
      add(new Label("ticketTopic", topic).setEscapeModelStrings(false));
    }


    /*
     * VOTERS
     */
    List<String> voters = ticket.getVoters();
    Label votersCount = new Label("votes", "" + voters.size());
    if (voters.size() == 0) {
      WicketUtils.setCssClass(votersCount, "badge");
    } else {
      WicketUtils.setCssClass(votersCount, "badge badge-info");
    }
    add(votersCount);
    if (user.isAuthenticated && app().tickets().isAcceptingTicketUpdates(repository)) {
      Model<String> model;
      if (ticket.isVoter(user.username)) {
        model = Model.of(getString("gb.removeVote"));
      } else {
        model = Model.of(MessageFormat.format(getString("gb.vote"), ticket.type.toString()));
      }
      SimpleAjaxLink<String> link = new SimpleAjaxLink<String>("voteLink", model) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
          Change change = new Change(user.username);
          if (ticket.isVoter(user.username)) {
            change.unvote(user.username);
          } else {
            change.vote(user.username);
          }
          app().tickets().updateTicket(repository, ticket.number, change);
          setResponsePage(TicketsPage.class, getPageParameters());
        }
      };
      add(link);
    } else {
      add(new Label("voteLink").setVisible(false));
    }


    /*
     * WATCHERS
     */
    List<String> watchers = ticket.getWatchers();
    Label watchersCount = new Label("watchers", "" + watchers.size());
    if (watchers.size() == 0) {
      WicketUtils.setCssClass(watchersCount, "badge");
    } else {
      WicketUtils.setCssClass(watchersCount, "badge badge-info");
    }
    add(watchersCount);
    if (user.isAuthenticated && app().tickets().isAcceptingTicketUpdates(repository)) {
      Model<String> model;
      if (ticket.isWatching(user.username)) {
        model = Model.of(getString("gb.stopWatching"));
      } else {
        model = Model.of(MessageFormat.format(getString("gb.watch"), ticket.type.toString()));
      }
      SimpleAjaxLink<String> link = new SimpleAjaxLink<String>("watchLink", model) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
          Change change = new Change(user.username);
          if (ticket.isWatching(user.username)) {
            change.unwatch(user.username);
          } else {
            change.watch(user.username);
          }
          app().tickets().updateTicket(repository, ticket.number, change);
          setResponsePage(TicketsPage.class, getPageParameters());
        }
      };
      add(link);
    } else {
      add(new Label("watchLink").setVisible(false));
    }


    /*
     * TOPIC & LABELS (DISCUSSION TAB->SIDE BAR)
     */
    ListDataProvider<String> labelsDp = new ListDataProvider<String>(ticket.getLabels());
    DataView<String> labelsView = new DataView<String>("labels", labelsDp) {
      private static final long serialVersionUID = 1L;

      @Override
      public void populateItem(final Item<String> item) {
        final String value = item.getModelObject();
        Label label = new Label("label", value);
        TicketLabel tLabel = app().tickets().getLabel(repository, value);
        String background = MessageFormat.format("background-color:{0};", tLabel.color);
        label.add(new SimpleAttributeModifier("style", background));
        item.add(label);
      }
    };

    add(labelsView);


    /*
     * COMMENTS & STATUS CHANGES (DISCUSSION TAB)
     */
    if (comments.size() == 0) {
      add(new Label("discussion").setVisible(false));
    } else {
      Fragment discussionFragment = new Fragment("discussion", "discussionFragment", this);
      ListDataProvider<Change> discussionDp = new ListDataProvider<Change>(discussion);
      DataView<Change> discussionView = new DataView<Change>("discussion", discussionDp) {
        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<Change> item) {
          final Change entry = item.getModelObject();
          if (entry.isMerge()) {
            /*
             * MERGE
             */
            String resolvedBy = entry.getString(Field.mergeSha);

            // identify the merged patch, it is likely the last
            Patchset mergedPatch = null;
            for (Change c : revisions) {
              if (c.patchset.tip.equals(resolvedBy)) {
                mergedPatch = c.patchset;
                break;
              }
            }

            String commitLink;
            if (mergedPatch == null) {
              // shouldn't happen, but just-in-case
              int len = app().settings().getInteger(Keys.web.shortCommitIdLength, 6);
              commitLink = resolvedBy.substring(0, len);
            } else {
              // expected result
              commitLink = mergedPatch.toString();
            }

            Fragment mergeFragment = new Fragment("entry", "mergeFragment", this);
            mergeFragment.add(new LinkPanel("commitLink", null, commitLink,
                CommitPage.class, WicketUtils.newObjectParameter(repositoryName, resolvedBy)));
            mergeFragment.add(new Label("toBranch", MessageFormat.format(getString("gb.toBranch"),
                "<b>" + ticket.mergeTo + "</b>")).setEscapeModelStrings(false));
            addUserAttributions(mergeFragment, entry, 0);
            addDateAttributions(mergeFragment, entry);

            item.add(mergeFragment);
          } else if (entry.isStatusChange()) {
            /*
             *  STATUS CHANGE
             */
            Fragment frag = new Fragment("entry", "statusFragment", this);
            Label status = new Label("statusChange", entry.getStatus().toString());
            String css = getLozengeClass(entry.getStatus(), false);
            WicketUtils.setCssClass(status, css);
            for (IBehavior b : status.getBehaviors()) {
              if (b instanceof SimpleAttributeModifier) {
                SimpleAttributeModifier sam = (SimpleAttributeModifier) b;
                if ("class".equals(sam.getAttribute())) {
                  status.add(new SimpleAttributeModifier("class", "status-change " + sam.getValue()));
                  break;
                }
              }
            }
            frag.add(status);
            addUserAttributions(frag, entry, avatarWidth);
            addDateAttributions(frag, entry);
            item.add(frag);
          } else {
            /*
             * COMMENT
             */
            String comment = MarkdownUtils.transformGFM(app().settings(), entry.comment.text, repositoryName);
            Fragment frag = new Fragment("entry", "commentFragment", this);
            Label commentIcon = new Label("commentIcon");
            if (entry.comment.src == CommentSource.Email) {
              WicketUtils.setCssClass(commentIcon, "iconic-mail");
            } else {
              WicketUtils.setCssClass(commentIcon, "iconic-comment-alt2-stroke");
            }
            frag.add(commentIcon);
            frag.add(new Label("comment", comment).setEscapeModelStrings(false));
            addUserAttributions(frag, entry, avatarWidth);
            addDateAttributions(frag, entry);
            item.add(frag);
          }
        }
      };
      discussionFragment.add(discussionView);
      add(discussionFragment);
    }

    /*
     * ADD COMMENT PANEL
     */
    if (UserModel.ANONYMOUS.equals(user)
        || !repository.isBare
        || repository.isFrozen
        || repository.isMirror) {

      // prohibit comments for anonymous users, local working copy repos,
      // frozen repos, and mirrors
      add(new Label("newComment").setVisible(false));
    } else {
      // permit user to comment
      Fragment newComment = new Fragment("newComment", "newCommentFragment", this);
      GravatarImage img = new GravatarImage("newCommentAvatar", user.username, user.emailAddress,
          "gravatar-round", avatarWidth, true);
      newComment.add(img);
      CommentPanel commentPanel = new CommentPanel("commentPanel", user, ticket, null, TicketsPage.class);
      commentPanel.setRepository(repositoryName);
      newComment.add(commentPanel);
      add(newComment);
    }


    /*
     *  PATCHSET TAB
     */
    if (currentPatchset == null) {
      // no patchset available
      RepositoryUrl repoUrl = getRepositoryUrl(user, repository);
      boolean canPropose = repoUrl != null && repoUrl.permission.atLeast(AccessPermission.CLONE) && !UserModel.ANONYMOUS.equals(user);
      if (ticket.isOpen() && app().tickets().isAcceptingNewPatchsets(repository) && canPropose) {
        // ticket & repo will accept a proposal patchset
        // show the instructions for proposing a patchset
        Fragment changeIdFrag = new Fragment("patchset", "proposeFragment", this);
        changeIdFrag.add(new Label("proposeInstructions", MarkdownUtils.transformMarkdown(getString("gb.proposeInstructions"))).setEscapeModelStrings(false));
        changeIdFrag.add(new Label("ptWorkflow", MessageFormat.format(getString("gb.proposeWith"), "Barnum")));
        changeIdFrag.add(new Label("ptWorkflowSteps", getProposeWorkflow("propose_pt.md", repoUrl.url, ticket.number)).setEscapeModelStrings(false));
        changeIdFrag.add(new Label("gitWorkflow", MessageFormat.format(getString("gb.proposeWith"), "Git")));
        changeIdFrag.add(new Label("gitWorkflowSteps", getProposeWorkflow("propose_git.md", repoUrl.url, ticket.number)).setEscapeModelStrings(false));
        add(changeIdFrag);
      } else {
        // explain why you can't propose a patchset
        Fragment fragment = new Fragment("patchset", "canNotProposeFragment", this);
        String reason = "";
        if (ticket.isClosed()) {
          reason = getString("gb.ticketIsClosed");
        } else if (repository.isMirror) {
          reason = getString("gb.repositoryIsMirror");
        } else if (repository.isFrozen) {
          reason = getString("gb.repositoryIsFrozen");
        } else if (!repository.acceptNewPatchsets) {
          reason = getString("gb.repositoryDoesNotAcceptPatchsets");
        } else if (!canPropose) {
          if (UserModel.ANONYMOUS.equals(user)) {
            reason = getString("gb.anonymousCanNotPropose");
          } else {
            reason = getString("gb.youDoNotHaveClonePermission");
          }
        } else {
          reason = getString("gb.serverDoesNotAcceptPatchsets");
        }
        fragment.add(new Label("reason", reason));
        add(fragment);
      }
    } else {
      // show current patchset
      Fragment patchsetFrag = new Fragment("patchset", "patchsetFragment", this);
      patchsetFrag.add(new Label("commitsInPatchset", MessageFormat.format(getString("gb.commitsInPatchsetN"), currentPatchset.number)));

      patchsetFrag.add(createMergePanel(user, repository));

      if (ticket.isOpen()) {
        // current revision
        MarkupContainer panel = createPatchsetPanel("panel", repository, user);
        patchsetFrag.add(panel);
        addUserAttributions(patchsetFrag, currentRevision, avatarWidth);
        addUserAttributions(panel, currentRevision, 0);
        addDateAttributions(panel, currentRevision);
      } else {
        // current revision
        patchsetFrag.add(new Label("panel").setVisible(false));
      }

      // commits
      List<RevCommit> commits = JGitUtils.getRevLog(getRepository(), currentPatchset.base, currentPatchset.tip);
      ListDataProvider<RevCommit> commitsDp = new ListDataProvider<RevCommit>(commits);
      DataView<RevCommit> commitsView = new DataView<RevCommit>("commit", commitsDp) {
        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<RevCommit> item) {
          RevCommit commit = item.getModelObject();
          PersonIdent author = commit.getAuthorIdent();
          item.add(new GravatarImage("authorAvatar", author.getName(), author.getEmailAddress(), null, 16, false));
          item.add(new Label("author", commit.getAuthorIdent().getName()));
          item.add(new LinkPanel("commitId", null, getShortObjectId(commit.getName()),
              CommitPage.class, WicketUtils.newObjectParameter(repositoryName, commit.getName()), true));
          item.add(new LinkPanel("diff", "link", getString("gb.diff"), CommitDiffPage.class,
              WicketUtils.newObjectParameter(repositoryName, commit.getName()), true));
          item.add(new Label("title", StringUtils.trimString(commit.getShortMessage(), Constants.LEN_SHORTLOG_REFS)));
          item.add(WicketUtils.createDateLabel("commitDate", JGitUtils.getCommitDate(commit), GitBlitWebSession
              .get().getTimezone(), getTimeUtils(), false));
          item.add(new DiffStatPanel("commitDiffStat", 0, 0, true));
        }
      };
      patchsetFrag.add(commitsView);
      add(patchsetFrag);
    }


    /*
     * ACTIVITY TAB
     */
    Fragment revisionHistory = new Fragment("activity", "activityFragment", this);
    List<Change> events = new ArrayList<Change>(ticket.changes);
    Collections.sort(events);
    Collections.reverse(events);
    ListDataProvider<Change> eventsDp = new ListDataProvider<Change>(events);
    DataView<Change> eventsView = new DataView<Change>("event", eventsDp) {
      private static final long serialVersionUID = 1L;

      @Override
      public void populateItem(final Item<Change> item) {
        Change event = item.getModelObject();

        addUserAttributions(item, event, 16);

        if (event.hasPatchset()) {
          // patchset
          Patchset patchset = event.patchset;
          String what;
          if (event.isStatusChange() && (Status.New == event.getStatus())) {
            what = getString("gb.proposedThisChange");
          } else if (patchset.rev == 1) {
            what = MessageFormat.format(getString("gb.uploadedPatchsetN"), patchset.number);
          } else {
            if (patchset.added == 1) {
              what = getString("gb.addedOneCommit");
            } else {
              what = MessageFormat.format(getString("gb.addedNCommits"), patchset.added);
            }
          }
          item.add(new Label("what", what));

          LinkPanel psr = new LinkPanel("patchsetRevision", null, patchset.number + "-" + patchset.rev,
              ComparePage.class, WicketUtils.newRangeParameter(repositoryName, patchset.parent == null ? patchset.base : patchset.parent, patchset.tip), true);
          WicketUtils.setHtmlTooltip(psr, patchset.toString());
          item.add(psr);
          String typeCss = getPatchsetTypeCss(patchset.type);
          Label typeLabel = new Label("patchsetType", patchset.type.toString());
          if (typeCss == null) {
            typeLabel.setVisible(false);
View Full Code Here

    md = md.replace("${integrationBranch}", integrationBranch);
    return MarkdownUtils.transformMarkdown(md);
  }

  protected Fragment createPatchsetPanel(String wicketId, RepositoryModel repository, UserModel user) {
    final Patchset currentPatchset = ticket.getCurrentPatchset();
    List<Patchset> patchsets = new ArrayList<Patchset>(ticket.getPatchsetRevisions(currentPatchset.number));
    patchsets.remove(currentPatchset);
    Collections.reverse(patchsets);

    Fragment panel = new Fragment(wicketId, "collapsiblePatchsetFragment", this);

    // patchset header
    String ps = "<b>" + currentPatchset.number + "</b>";
    if (currentPatchset.rev == 1) {
      panel.add(new Label("uploadedWhat", MessageFormat.format(getString("gb.uploadedPatchsetN"), ps)).setEscapeModelStrings(false));
    } else {
      String rev = "<b>" + currentPatchset.rev + "</b>";
      panel.add(new Label("uploadedWhat", MessageFormat.format(getString("gb.uploadedPatchsetNRevisionN"), ps, rev)).setEscapeModelStrings(false));
    }
    panel.add(new LinkPanel("patchId", null, "rev " + currentPatchset.rev,
        CommitPage.class, WicketUtils.newObjectParameter(repositoryName, currentPatchset.tip), true));

    // compare menu
    panel.add(new LinkPanel("compareMergeBase", null, getString("gb.compareToMergeBase"),
        ComparePage.class, WicketUtils.newRangeParameter(repositoryName, currentPatchset.base, currentPatchset.tip), true));

    ListDataProvider<Patchset> compareMenuDp = new ListDataProvider<Patchset>(patchsets);
    DataView<Patchset> compareMenu = new DataView<Patchset>("comparePatch", compareMenuDp) {
      private static final long serialVersionUID = 1L;
      @Override
      public void populateItem(final Item<Patchset> item) {
        Patchset patchset = item.getModelObject();
        LinkPanel link = new LinkPanel("compareLink", null,
            MessageFormat.format(getString("gb.compareToN"), patchset.number + "-" + patchset.rev),
            ComparePage.class, WicketUtils.newRangeParameter(getRepositoryModel().name,
                patchset.tip, currentPatchset.tip), true);
        item.add(link);
View Full Code Here

    return String.format("%1$s (%2$+d)", description, score.getValue());
  }

  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);
    }
View Full Code Here

   * @param c
   * @param user
   * @param repository
   */
  protected Component createMergePanel(UserModel user, RepositoryModel repository) {
    Patchset patchset = ticket.getCurrentPatchset();
    if (patchset == null) {
      // no patchset to merge
      return new Label("mergePanel");
    }

    boolean allowMerge;
    if (repository.requireApproval) {
      // rpeository requires approval
      allowMerge = ticket.isOpen() && ticket.isApproved(patchset);
    } else {
      // vetos are binding
      allowMerge = ticket.isOpen() && !ticket.isVetoed(patchset);
    }

    MergeStatus mergeStatus = JGitUtils.canMerge(getRepository(), patchset.tip, ticket.mergeTo);
    if (allowMerge) {
      if (MergeStatus.MERGEABLE == mergeStatus) {
        // patchset can be cleanly merged to integration branch OR has already been merged
        Fragment mergePanel = new Fragment("mergePanel", "mergeableFragment", this);
        mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetMergeable"), ticket.mergeTo)));
        if (user.canPush(repository)) {
          // user can merge locally
          SimpleAjaxLink<String> mergeButton = new SimpleAjaxLink<String>("mergeButton", Model.of(getString("gb.merge"))) {

            private static final long serialVersionUID = 1L;

            @Override
            public void onClick(AjaxRequestTarget target) {

              // ensure the patchset is still current AND not vetoed
              Patchset patchset = ticket.getCurrentPatchset();
              final TicketModel refreshedTicket = app().tickets().getTicket(getRepositoryModel(), ticket.number);
              if (patchset.equals(refreshedTicket.getCurrentPatchset())) {
                // patchset is current, check for recent veto
                if (!refreshedTicket.isVetoed(patchset)) {
                  // patchset is not vetoed

                  // execute the merge using the ticket service
View Full Code Here

    DiffStat diffstat = null;

    String pattern;
    if (lastChange.hasPatchset()) {
      // patchset uploaded
      Patchset patchset = lastChange.patchset;
      String base = "";
      // determine the changed paths
      Repository repo = null;
      try {
        repo = repositoryManager.getRepository(ticket.repository);
        if (patchset.isFF() && (patchset.rev > 1)) {
          // fast-forward update, just show the new data
          isFastForward = true;
          Patchset prev = ticket.getPatchset(patchset.number, patchset.rev - 1);
          base = prev.tip;
        } else {
          // proposal OR non-fast-forward update
          isFastForward = false;
          base = patchset.base;
View Full Code Here

    PatchsetCommand psCmd;
    if (ticket == null) {
      /*
       *  NEW TICKET
       */
      Patchset patchset = newPatchset(null, mergeBase.getName(), tipCommit.getName());

      int minLength = 10;
      int maxLength = 100;
      String minTitle = MessageFormat.format("  minimum length of a title is {0} characters.", minLength);
      String maxTitle = MessageFormat.format("  maximum length of a title is {0} characters.", maxLength);

      if (patchset.commits > 1) {
        sendError("");
        sendError("To create a proposal ticket, please squash your commits and");
        sendError("provide a meaningful commit message with a short title &");
        sendError("an optional description/body.");
        sendError("");
        sendError(minTitle);
        sendError(maxTitle);
        sendError("");
        sendRejection(cmd, "please squash to one commit");
        return null;
      }

      // require a reasonable title/subject
      String title = tipCommit.getFullMessage().trim().split("\n")[0];
      if (title.length() < minLength) {
        // reject, title too short
        sendError("");
        sendError("Please supply a longer title in your commit message!");
        sendError("");
        sendError(minTitle);
        sendError(maxTitle);
        sendError("");
        sendRejection(cmd, "ticket title is too short [{0}/{1}]", title.length(), maxLength);
        return null;
      }
      if (title.length() > maxLength) {
        // reject, title too long
        sendError("");
        sendError("Please supply a more concise title in your commit message!");
        sendError("");
        sendError(minTitle);
        sendError(maxTitle);
        sendError("");
        sendRejection(cmd, "ticket title is too long [{0}/{1}]", title.length(), maxLength);
        return null;
      }

      // assign new id
      long ticketId = ticketService.assignNewId(repository);

      // create the patchset command
      psCmd = new PatchsetCommand(user.username, patchset);
      psCmd.newTicket(tipCommit, forBranch, ticketId, cmd.getRefName());
    } else {
      /*
       *  EXISTING TICKET
       */
      Patchset patchset = newPatchset(ticket, mergeBase.getName(), tipCommit.getName());
      psCmd = new PatchsetCommand(user.username, patchset);
      psCmd.updateTicket(tipCommit, forBranch, ticket, cmd.getRefName());
    }

    // confirm user can push the patchset
View Full Code Here

        }

        String mergeSha = c.getName();
        String mergeTo = Repository.shortenRefName(cmd.getRefName());
        Change change;
        Patchset patchset;
        if (knownPatchset) {
          // identify merged patchset by the patchset tip
          patchset = null;
          for (Patchset ps : ticket.getPatchsets()) {
            if (ps.tip.equals(mergeSha)) {
View Full Code Here

   * @param tip
   */
  private Patchset newPatchset(TicketModel ticket, String mergeBase, String tip) {
    int totalCommits = countCommits(mergeBase, tip);

    Patchset newPatchset = new Patchset();
    newPatchset.tip = tip;
    newPatchset.base = mergeBase;
    newPatchset.commits = totalCommits;

    Patchset currPatchset = ticket == null ? null : ticket.getCurrentPatchset();
    if (currPatchset == null) {
      /*
       * PROPOSAL PATCHSET
       * patchset 1, rev 1
       */
 
View Full Code Here

TOP

Related Classes of com.gitblit.models.TicketModel.Patchset

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.