Package com.gitblit.models

Examples of com.gitblit.models.TicketModel$Change


          List<Change> changes = TicketSerializer.deserializeJournal(json);
          if (ArrayUtils.isEmpty(changes)) {
            log.warn("Empty journal for {}:{}", repository, path.path);
            continue;
          }
          TicketModel ticket = TicketModel.buildTicket(changes);
          ticket.project = repository.projectPath;
          ticket.repository = repository.name;
          ticket.number = ticketId;

          // add the ticket, conditionally, to the list
View Full Code Here


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

    if (ticketId <= 0L) {
      return null;
    }

    // deserialize the ticket model so that we have the attachment metadata
    TicketModel ticket = getTicket(repository, ticketId);
    Attachment attachment = ticket.getAttachment(filename);

    // attachment not found
    if (attachment == null) {
      return null;
    }
View Full Code Here

      ticketId = Long.parseLong(h);
    } catch (Exception e) {
      setResponsePage(TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName));
    }

    TicketModel ticket = app().tickets().getTicket(getRepositoryModel(), ticketId);
    if (ticket == null
        || !currentUser.canEdit(ticket, getRepositoryModel())
        || !app().tickets().isAcceptingTicketUpdates(getRepositoryModel())) {
      setResponsePage(TicketsPage.class, WicketUtils.newObjectParameter(repositoryName, "" + ticketId));

      // create a placeholder object so we don't trigger NPEs
      ticket = new TicketModel();
    }

    typeModel = Model.of(ticket.type);
    titleModel = Model.of(ticket.title);
    topicModel = Model.of(ticket.topic == null ? "" : ticket.topic);
    responsibleModel = Model.of();
    milestoneModel = Model.of();
    mergeToModel = Model.of(ticket.mergeTo == null ? getRepositoryModel().mergeTo : ticket.mergeTo);
    statusModel = Model.of(ticket.status);

    setStatelessHint(false);
    setOutputMarkupId(true);

    Form<Void> form = new Form<Void>("editForm");
    add(form);

    List<Type> typeChoices;
    if (ticket.isProposal()) {
      typeChoices = Arrays.asList(Type.Proposal);
    } else {
      typeChoices = Arrays.asList(TicketModel.Type.choices());
    }
    form.add(new DropDownChoice<TicketModel.Type>("type", typeModel, typeChoices));

    form.add(new TextField<String>("title", titleModel));
    form.add(new TextField<String>("topic", topicModel));

    final IModel<String> markdownPreviewModel = new Model<String>();
    descriptionPreview = new Label("descriptionPreview", markdownPreviewModel);
    descriptionPreview.setEscapeModelStrings(false);
    descriptionPreview.setOutputMarkupId(true);
    form.add(descriptionPreview);

    descriptionEditor = new MarkdownTextArea("description", markdownPreviewModel, descriptionPreview);
    descriptionEditor.setRepository(repositoryName);
    descriptionEditor.setText(ticket.body);
    form.add(descriptionEditor);

    // status
    List<Status> statusChoices;
    if (ticket.isClosed()) {
      statusChoices = Arrays.asList(ticket.status, Status.Open);
    } else if (ticket.isProposal()) {
      statusChoices = Arrays.asList(TicketModel.Status.proposalWorkflow);
    } else if (ticket.isBug()) {
      statusChoices = Arrays.asList(TicketModel.Status.bugWorkflow);
    } else {
      statusChoices = Arrays.asList(TicketModel.Status.requestWorkflow);
    }
    Fragment status = new Fragment("status", "statusFragment", this);
    status.add(new DropDownChoice<TicketModel.Status>("status", statusModel, statusChoices));
    form.add(status);

    if (currentUser.canAdmin(ticket, getRepositoryModel())) {
      // responsible
      Set<String> userlist = new TreeSet<String>(ticket.getParticipants());

      if (UserModel.ANONYMOUS.canPush(getRepositoryModel())) {
        // anonymous push
        userlist.addAll(app().users().getAllUsernames());
      } else {
        // authenticated push
        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>();
      for (String username : userlist) {
        UserModel user = app().users().getUserModel(username);
        if (user != null && !user.disabled) {
          TicketResponsible responsible = new TicketResponsible(user);
          responsibles.add(responsible);
          if (user.username.equals(ticket.responsible)) {
            responsibleModel.setObject(responsible);
          }
        }
      }
      Collections.sort(responsibles);
      responsibles.add(new TicketResponsible(NIL, "", ""));
      Fragment responsible = new Fragment("responsible", "responsibleFragment", this);
      responsible.add(new DropDownChoice<TicketResponsible>("responsible", responsibleModel, responsibles));
      form.add(responsible.setVisible(!responsibles.isEmpty()));

      // milestone
      List<TicketMilestone> milestones = app().tickets().getMilestones(getRepositoryModel(), Status.Open);
      for (TicketMilestone milestone : milestones) {
        if (milestone.name.equals(ticket.milestone)) {
          milestoneModel.setObject(milestone);
          break;
        }
      }
      if (milestoneModel.getObject() == null && !StringUtils.isEmpty(ticket.milestone)) {
        // ensure that this unrecognized milestone is listed
        // so that we get the <nil> selection.
        TicketMilestone tms = new TicketMilestone(ticket.milestone);
        milestones.add(tms);
        milestoneModel.setObject(tms);
      }
      if (!milestones.isEmpty()) {
        milestones.add(new TicketMilestone(NIL));
      }

      Fragment milestone = new Fragment("milestone", "milestoneFragment", this);

      milestone.add(new DropDownChoice<TicketMilestone>("milestone", milestoneModel, milestones));
      form.add(milestone.setVisible(!milestones.isEmpty()));

      // mergeTo (integration branch)
      List<String> branches = new ArrayList<String>();
      for (String branch : getRepositoryModel().getLocalBranches()) {
        // exclude ticket branches
        if (!branch.startsWith(Constants.R_TICKET)) {
          branches.add(Repository.shortenRefName(branch));
        }
      }
      branches.remove(Repository.shortenRefName(getRepositoryModel().mergeTo));
      branches.add(0, Repository.shortenRefName(getRepositoryModel().mergeTo));

      Fragment mergeto = new Fragment("mergeto", "mergeToFragment", this);
      mergeto.add(new DropDownChoice<String>("mergeto", mergeToModel, branches));
      form.add(mergeto.setVisible(!branches.isEmpty()));
    } else {
      // user can not admin this ticket
      form.add(new Label("responsible").setVisible(false));
      form.add(new Label("milestone").setVisible(false));
      form.add(new Label("mergeto").setVisible(false));
    }

    form.add(new AjaxButton("update") {

      private static final long serialVersionUID = 1L;

      @Override
      protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
        long ticketId = 0L;
        try {
          String h = WicketUtils.getObject(getPageParameters());
          ticketId = Long.parseLong(h);
        } catch (Exception e) {
          setResponsePage(TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName));
        }

        TicketModel ticket = app().tickets().getTicket(getRepositoryModel(), ticketId);

        String createdBy = GitBlitWebSession.get().getUsername();
        Change change = new Change(createdBy);

        String title = titleModel.getObject();
        if (StringUtils.isEmpty(title)) {
          return;
        }

        if (!ticket.title.equals(title)) {
          // title change
          change.setField(Field.title, title);
        }

        String description = descriptionEditor.getText();
        if ((StringUtils.isEmpty(ticket.body) && !StringUtils.isEmpty(description))
            || (!StringUtils.isEmpty(ticket.body) && !ticket.body.equals(description))) {
          // description change
          change.setField(Field.body, description);
        }

        Status status = statusModel.getObject();
        if (!ticket.status.equals(status)) {
          // status change
          change.setField(Field.status, status);
        }

        Type type = typeModel.getObject();
        if (!ticket.type.equals(type)) {
          // type change
          change.setField(Field.type, type);
        }

        String topic = topicModel.getObject();
        if ((StringUtils.isEmpty(ticket.topic) && !StringUtils.isEmpty(topic))
            || (!StringUtils.isEmpty(topic) && !topic.equals(ticket.topic))) {
          // topic change
          change.setField(Field.topic, topic);
        }

        TicketResponsible responsible = responsibleModel == null ? null : responsibleModel.getObject();
        if (responsible != null && !responsible.username.equals(ticket.responsible)) {
          // responsible change
          change.setField(Field.responsible, responsible.username);
          if (!StringUtils.isEmpty(responsible.username)) {
            if (!ticket.isWatching(responsible.username)) {
              change.watch(responsible.username);
            }
          }
        }

        TicketMilestone milestone = milestoneModel == null ? null : milestoneModel.getObject();
        if (milestone != null && !milestone.name.equals(ticket.milestone)) {
          // milestone change
          if (NIL.equals(milestone.name)) {
            change.setField(Field.milestone, "");
          } else {
            change.setField(Field.milestone, milestone.name);
          }
        }

        String mergeTo = mergeToModel.getObject();
        if ((StringUtils.isEmpty(ticket.mergeTo) && !StringUtils.isEmpty(mergeTo))
            || (!StringUtils.isEmpty(mergeTo) && !mergeTo.equals(ticket.mergeTo))) {
          // integration branch change
          change.setField(Field.mergeTo, mergeTo);
        }

        if (change.hasFieldChanges()) {
          if (!ticket.isWatching(createdBy)) {
            change.watch(createdBy);
          }
          ticket = app().tickets().updateTicket(getRepositoryModel(), ticket.number, change);
          if (ticket != null) {
            TicketNotifier notifier = app().tickets().createNotifier();
View Full Code Here

            patchsetCmd.getTicketBranch(),
            patchsetCmd.getNewId(),
            patchsetCmd.getPatchsetType());
        updateReflog(ru);

        TicketModel ticket = processPatchset(patchsetCmd);
        if (ticket != null) {
          ticketNotifier.queueMailing(ticket);
        }
      }
    }
View Full Code Here

   */
  private PatchsetCommand preparePatchset(ReceiveCommand cmd) {
    String branch = getIntegrationBranch(cmd.getRefName());
    long number = getTicketId(cmd.getRefName());

    TicketModel ticket = null;
    if (number > 0 && ticketService.hasTicket(repository, number)) {
      ticket = ticketService.getTicket(repository, number);
    }

    if (ticket == null) {
      if (number > 0) {
        // requested ticket does not exist
        sendError("Sorry, {0} does not have ticket {1,number,0}!", repository.name, number);
        sendRejection(cmd, "Invalid ticket number");
        return null;
      }
    } else {
      if (ticket.isMerged()) {
        // ticket already merged & resolved
        Change mergeChange = null;
        for (Change change : ticket.changes) {
          if (change.isMerge()) {
            mergeChange = change;
            break;
          }
        }
        if (mergeChange != null) {
          sendError("Sorry, {0} already merged {1} from ticket {2,number,0} to {3}!",
            mergeChange.author, mergeChange.patchset, number, ticket.mergeTo);
        }
        sendRejection(cmd, "Ticket {0,number,0} already resolved", number);
        return null;
      } else if (!StringUtils.isEmpty(ticket.mergeTo)) {
        // ticket specifies integration branch
        branch = ticket.mergeTo;
      }
    }

    final int shortCommitIdLen = settings.getInteger(Keys.web.shortCommitIdLength, 6);
    final String shortTipId = cmd.getNewId().getName().substring(0, shortCommitIdLen);
    final RevCommit tipCommit = JGitUtils.getCommit(getRepository(), cmd.getNewId().getName());
    final String forBranch = branch;
    RevCommit mergeBase = null;
    Ref forBranchRef = getAdvertisedRefs().get(Constants.R_HEADS + forBranch);
    if (forBranchRef == null || forBranchRef.getObjectId() == null) {
      // unknown integration branch
      sendError("Sorry, there is no integration branch named ''{0}''.", forBranch);
      sendRejection(cmd, "Invalid integration branch specified");
      return null;
    } else {
      // determine the merge base for the patchset on the integration branch
      String base = JGitUtils.getMergeBase(getRepository(), forBranchRef.getObjectId(), tipCommit.getId());
      if (StringUtils.isEmpty(base)) {
        sendError("");
        sendError("There is no common ancestry between {0} and {1}.", forBranch, shortTipId);
        sendError("Please reconsider your proposed integration branch, {0}.", forBranch);
        sendError("");
        sendRejection(cmd, "no merge base for patchset and {0}", forBranch);
        return null;
      }
      mergeBase = JGitUtils.getCommit(getRepository(), base);
    }

    // ensure that the patchset can be cleanly merged right now
    MergeStatus status = JGitUtils.canMerge(getRepository(), tipCommit.getName(), forBranch);
    switch (status) {
    case ALREADY_MERGED:
      sendError("");
      sendError("You have already merged this patchset.", forBranch);
      sendError("");
      sendRejection(cmd, "everything up-to-date");
      return null;
    case MERGEABLE:
      break;
    default:
      if (ticket == null || requireMergeablePatchset) {
        sendError("");
        sendError("Your patchset can not be cleanly merged into {0}.", forBranch);
        sendError("Please rebase your patchset and push again.");
        sendError("NOTE:", number);
        sendError("You should push your rebase to refs/for/{0,number,0}", number);
        sendError("");
        sendError("  git push origin HEAD:refs/for/{0,number,0}", number);
        sendError("");
        sendRejection(cmd, "patchset not mergeable");
        return null;
      }
    }

    // check to see if this commit is already linked to a ticket
    long id = identifyTicket(tipCommit, false);
    if (id > 0) {
      sendError("{0} has already been pushed to ticket {1,number,0}.", shortTipId, id);
      sendRejection(cmd, "everything up-to-date");
      return null;
    }

    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
    boolean pushPermitted = ticket == null
        || !ticket.hasPatchsets()
        || ticket.isAuthor(user.username)
        || ticket.isPatchsetAuthor(user.username)
        || ticket.isResponsible(user.username)
        || user.canPush(repository);

    switch (psCmd.getPatchsetType()) {
    case Proposal:
      // proposals (first patchset) are always acceptable
View Full Code Here

  private TicketModel processPatchset(PatchsetCommand cmd) {
    Change change = cmd.getChange();

    if (cmd.isNewTicket()) {
      // create the ticket object
      TicketModel ticket = ticketService.createTicket(repository, cmd.getTicketId(), change);
      if (ticket != null) {
        sendInfo("");
        sendHeader("#{0,number,0}: {1}", ticket.number, StringUtils.trimString(ticket.title, Constants.LEN_SHORTLOG));
        sendInfo("created proposal ticket from patchset");
        sendInfo(ticketService.getTicketUrl(ticket));
        sendInfo("");

        // log the new patch ref
        RefLogUtils.updateRefLog(user, getRepository(),
            Arrays.asList(new ReceiveCommand(cmd.getOldId(), cmd.getNewId(), cmd.getRefName())));

        // call any patchset hooks
        for (PatchsetHook hook : gitblit.getExtensions(PatchsetHook.class)) {
          try {
            hook.onNewPatchset(ticket);
          } catch (Exception e) {
            LOGGER.error("Failed to execute extension", e);
          }
        }

        return ticket;
      } else {
        sendError("FAILED to create ticket");
      }
    } else {
      // update an existing ticket
      TicketModel ticket = ticketService.updateTicket(repository, cmd.getTicketId(), change);
      if (ticket != null) {
        sendInfo("");
        sendHeader("#{0,number,0}: {1}", ticket.number, StringUtils.trimString(ticket.title, Constants.LEN_SHORTLOG));
        if (change.patchset.rev == 1) {
          // new patchset
View Full Code Here

        long ticketNumber = identifyTicket(c, true);
        if (ticketNumber == 0L || mergedTickets.containsKey(ticketNumber)) {
          continue;
        }

        TicketModel ticket = ticketService.getTicket(repository, ticketNumber);
        if (ticket == null) {
          continue;
        }
        String integrationBranch;
        if (StringUtils.isEmpty(ticket.mergeTo)) {
          // unspecified integration branch
          integrationBranch = null;
        } else {
          // specified integration branch
          integrationBranch = Constants.R_HEADS + ticket.mergeTo;
        }

        // ticket must be open and, if specified, the ref must match the integration branch
        if (ticket.isClosed() || (integrationBranch != null && !integrationBranch.equals(cmd.getRefName()))) {
          continue;
        }

        String baseRef = PatchsetCommand.getBasePatchsetBranch(ticket.number);
        boolean knownPatchset = false;
        Set<Ref> refs = getRepository().getAllRefsByPeeledObjectId().get(c.getId());
        if (refs != null) {
          for (Ref ref : refs) {
            if (ref.getName().startsWith(baseRef)) {
              knownPatchset = true;
              break;
            }
          }
        }

        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)) {
              patchset = ps;
              break;
            }
          }
View Full Code Here

        String mergeTo = mergeToModel.getObject();
        if (!StringUtils.isEmpty(mergeTo)) {
          change.setField(Field.mergeTo, mergeTo);
        }

        TicketModel ticket = app().tickets().createTicket(getRepositoryModel(), 0L, change);
        if (ticket != null) {
          TicketNotifier notifier = app().tickets().createNotifier();
          notifier.sendMailing(ticket);
          setResponsePage(TicketsPage.class, WicketUtils.newObjectParameter(getRepositoryModel().name, "" + ticket.number));
        } else {
View Full Code Here

        List<Change> changes = getJournal(jedis, repository, ticketId);
        if (ArrayUtils.isEmpty(changes)) {
          log.warn("Empty journal for {}:{}", repository, ticketId);
          continue;
        }
        TicketModel ticket = TicketModel.buildTicket(changes);
        ticket.project = repository.projectPath;
        ticket.repository = repository.name;
        ticket.number = ticketId;

        // add the ticket, conditionally, to the list
View Full Code Here

TOP

Related Classes of com.gitblit.models.TicketModel$Change

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.