コード例 #1
0
  private void verboseCommitLog(
      RepositoryPushEvent event,
      RefChange refChange,
      SlackPayload payload,
      NavBuilder.Repo urlBuilder,
      String text,
      List<Changeset> myChanges) {
    for (Changeset ch : myChanges) {
      SlackAttachment attachment = new SlackAttachment();
      attachment.setFallback(text);
      attachment.setColor(ColorCode.GRAY.getCode());
      SlackAttachmentField field = new SlackAttachmentField();

      attachment.setTitle(
          String.format(
              "[%s:%s] - %s",
              event.getRepository().getName(),
              refChange.getRefId().replace("refs/heads", ""),
              ch.getId()));
      attachment.setTitle_link(urlBuilder.changeset(ch.getId()).buildAbsolute());

      field.setTitle("comment");
      field.setValue(ch.getMessage());
      field.setShort(false);
      attachment.addField(field);
      payload.addAttachment(attachment);
    }
  }
コード例 #2
0
  private void compactCommitLog(
      RepositoryPushEvent event,
      RefChange refChange,
      SlackPayload payload,
      NavBuilder.Repo urlBuilder,
      List<Changeset> myChanges) {
    if (myChanges.size() == 0) {
      // If there are no commits, no reason to add anything
    }
    SlackAttachment commits = new SlackAttachment();
    commits.setColor(ColorCode.GRAY.getCode());
    // Since the branch is now in the main commit line, title is not needed
    // commits.setTitle(String.format("[%s:%s]", event.getRepository().getName(),
    // refChange.getRefId().replace("refs/heads", "")));
    StringBuilder attachmentFallback = new StringBuilder();
    StringBuilder commitListBlock = new StringBuilder();
    for (Changeset ch : myChanges) {
      String commitUrl = urlBuilder.changeset(ch.getId()).buildAbsolute();
      String firstCommitMessageLine = ch.getMessage().split("\n")[0];

      // Note that we changed this to put everything in one attachment because otherwise it
      // doesn't get collapsed in slack (the see more... doesn't appear)
      commitListBlock.append(
          String.format(
              "<%s|`%s`>: %s - _%s_\n",
              commitUrl, ch.getDisplayId(), firstCommitMessageLine, ch.getAuthor().getName()));

      attachmentFallback.append(
          String.format("%s: %s\n", ch.getDisplayId(), firstCommitMessageLine));
    }
    commits.setText(commitListBlock.toString());
    commits.setFallback(attachmentFallback.toString());

    payload.addAttachment(commits);
  }