< prev index next >

bots/mlbridge/src/main/java/org/openjdk/skara/bots/mlbridge/ArchiveMessages.java

Print this page

 42         return body.strip();
 43     }
 44 
 45     private static String quoteBody(String body) {
 46         return Arrays.stream(body.strip().split("\\R"))
 47                      .map(line -> line.length() > 0 ? line.charAt(0) == '>' ? ">" + line : "> " + line : "> ")
 48                      .collect(Collectors.joining("\n"));
 49     }
 50 
 51     private static String replyFooter(PullRequestInstance prInstance) {
 52         return "PR: " + prInstance.pr().getWebUrl();
 53     }
 54 
 55     // When changing this, ensure that the PR pattern in the notifier still matches
 56     static String composeConversation(PullRequestInstance prInstance, URI webrev) {
 57         var commitMessages = prInstance.formatCommitMessages(prInstance.baseHash(), prInstance.headHash(), ArchiveMessages::formatCommit);
 58         var filteredBody = filterComments(prInstance.pr().getBody());
 59         if (filteredBody.isEmpty()) {
 60             filteredBody = prInstance.pr().getTitle().strip();
 61         }

 62         return filteredBody + "\n\n" +
 63                 infoSeparator + "\n\n" +
 64                 "Commits:\n" +
 65                 commitMessages + "\n\n" +
 66                 "Changes: " + prInstance.changeUrl() + "\n" +
 67                 " Webrev: " + webrev.toString() + "\n" +

 68                 "  Stats: " + prInstance.stats(prInstance.baseHash(), prInstance.headHash()) + "\n" +
 69                 "  Patch: " + prInstance.diffUrl() + "\n" +
 70                 "  Fetch: " + prInstance.fetchCommand() + "\n\n" +
 71                 replyFooter(prInstance);
 72     }
 73 
 74     static String composeRebaseComment(PullRequestInstance prInstance, URI fullWebrev) {
 75         var commitMessages = prInstance.formatCommitMessages(prInstance.baseHash(), prInstance.headHash(), ArchiveMessages::formatCommit);

 76         return "The pull request has been updated with a complete new set of changes (possibly due to a rebase).\n\n" +
 77                 infoSeparator + "\n\n" +
 78                 "Commits:\n" +
 79                 commitMessages + "\n\n" +
 80                 "Changes: " + prInstance.changeUrl() + "\n" +
 81                 " Webrev: " + fullWebrev.toString() + "\n" +

 82                 "  Stats: " + prInstance.stats(prInstance.baseHash(), prInstance.headHash()) + "\n" +
 83                 "  Patch: " + prInstance.diffUrl() + "\n" +
 84                 "  Fetch: " + prInstance.fetchCommand() + "\n\n" +
 85                 replyFooter(prInstance);    }
 86 
 87     static String composeIncrementalComment(Hash lastHead, PullRequestInstance prInstance, URI fullWebrev, URI incrementalWebrev) {
 88         var newCommitMessages = prInstance.formatCommitMessages(lastHead, prInstance.headHash(), ArchiveMessages::formatCommit);

 89         return "The pull request has been updated with additional changes.\n\n" +
 90                 infoSeparator + "\n\n" +
 91                 "Added commits:\n" +
 92                 newCommitMessages + "\n\n" +
 93                 "Changes:\n" +
 94                 "  - all: " + prInstance.pr().getWebUrl() + "/files\n" +
 95                 "  - new: " + prInstance.changeUrl(lastHead, prInstance.headHash()) + "\n\n" +
 96                 "Webrevs:\n" +
 97                 " - full: " + fullWebrev.toString() + "\n" +
 98                 " - incr: " + incrementalWebrev.toString() + "\n\n" +

 99                 "  Stats: " + prInstance.stats(lastHead, prInstance.headHash()) + "\n" +
100                 "  Patch: " + prInstance.diffUrl() + "\n" +
101                 "  Fetch: " + prInstance.fetchCommand() + "\n\n" +
102                 replyFooter(prInstance);
103     }
104 
105     private static String filterParentBody(Email parent, PullRequestInstance prInstance) {
106         var parentFooter = ArchiveMessages.replyFooter(prInstance);
107         var filteredParentBody = parent.body().strip();
108         if (filteredParentBody.endsWith(parentFooter)) {
109             return filteredParentBody.substring(0, filteredParentBody.length() - parentFooter.length()).strip();
110         } else {
111             return filteredParentBody;
112         }
113     }
114 
115     static String composeReply(Email parent, String body, PullRequestInstance prInstance) {
116         return "On " + parent.date().format(DateTimeFormatter.RFC_1123_DATE_TIME) + ", " + parent.author().toString() + " wrote:\n" +
117                 "\n" +
118                 quoteBody(filterParentBody(parent, prInstance)) +

 42         return body.strip();
 43     }
 44 
 45     private static String quoteBody(String body) {
 46         return Arrays.stream(body.strip().split("\\R"))
 47                      .map(line -> line.length() > 0 ? line.charAt(0) == '>' ? ">" + line : "> " + line : "> ")
 48                      .collect(Collectors.joining("\n"));
 49     }
 50 
 51     private static String replyFooter(PullRequestInstance prInstance) {
 52         return "PR: " + prInstance.pr().getWebUrl();
 53     }
 54 
 55     // When changing this, ensure that the PR pattern in the notifier still matches
 56     static String composeConversation(PullRequestInstance prInstance, URI webrev) {
 57         var commitMessages = prInstance.formatCommitMessages(prInstance.baseHash(), prInstance.headHash(), ArchiveMessages::formatCommit);
 58         var filteredBody = filterComments(prInstance.pr().getBody());
 59         if (filteredBody.isEmpty()) {
 60             filteredBody = prInstance.pr().getTitle().strip();
 61         }
 62         var issueString = prInstance.issueUrl().map(url -> "  Issue: " + url + "\n").orElse("");
 63         return filteredBody + "\n\n" +
 64                 infoSeparator + "\n\n" +
 65                 "Commits:\n" +
 66                 commitMessages + "\n\n" +
 67                 "Changes: " + prInstance.changeUrl() + "\n" +
 68                 " Webrev: " + webrev.toString() + "\n" +
 69                 issueString +
 70                 "  Stats: " + prInstance.stats(prInstance.baseHash(), prInstance.headHash()) + "\n" +
 71                 "  Patch: " + prInstance.diffUrl() + "\n" +
 72                 "  Fetch: " + prInstance.fetchCommand() + "\n\n" +
 73                 replyFooter(prInstance);
 74     }
 75 
 76     static String composeRebaseComment(PullRequestInstance prInstance, URI fullWebrev) {
 77         var commitMessages = prInstance.formatCommitMessages(prInstance.baseHash(), prInstance.headHash(), ArchiveMessages::formatCommit);
 78         var issueString = prInstance.issueUrl().map(url -> "  Issue: " + url + "\n").orElse("");
 79         return "The pull request has been updated with a complete new set of changes (possibly due to a rebase).\n\n" +
 80                 infoSeparator + "\n\n" +
 81                 "Commits:\n" +
 82                 commitMessages + "\n\n" +
 83                 "Changes: " + prInstance.changeUrl() + "\n" +
 84                 " Webrev: " + fullWebrev.toString() + "\n" +
 85                 issueString +
 86                 "  Stats: " + prInstance.stats(prInstance.baseHash(), prInstance.headHash()) + "\n" +
 87                 "  Patch: " + prInstance.diffUrl() + "\n" +
 88                 "  Fetch: " + prInstance.fetchCommand() + "\n\n" +
 89                 replyFooter(prInstance);    }
 90 
 91     static String composeIncrementalComment(Hash lastHead, PullRequestInstance prInstance, URI fullWebrev, URI incrementalWebrev) {
 92         var newCommitMessages = prInstance.formatCommitMessages(lastHead, prInstance.headHash(), ArchiveMessages::formatCommit);
 93         var issueString = prInstance.issueUrl().map(url -> "  Issue: " + url + "\n").orElse("");
 94         return "The pull request has been updated with additional changes.\n\n" +
 95                 infoSeparator + "\n\n" +
 96                 "Added commits:\n" +
 97                 newCommitMessages + "\n\n" +
 98                 "Changes:\n" +
 99                 "  - all: " + prInstance.pr().getWebUrl() + "/files\n" +
100                 "  - new: " + prInstance.changeUrl(lastHead, prInstance.headHash()) + "\n\n" +
101                 "Webrevs:\n" +
102                 " - full: " + fullWebrev.toString() + "\n" +
103                 " - incr: " + incrementalWebrev.toString() + "\n\n" +
104                 issueString +
105                 "  Stats: " + prInstance.stats(lastHead, prInstance.headHash()) + "\n" +
106                 "  Patch: " + prInstance.diffUrl() + "\n" +
107                 "  Fetch: " + prInstance.fetchCommand() + "\n\n" +
108                 replyFooter(prInstance);
109     }
110 
111     private static String filterParentBody(Email parent, PullRequestInstance prInstance) {
112         var parentFooter = ArchiveMessages.replyFooter(prInstance);
113         var filteredParentBody = parent.body().strip();
114         if (filteredParentBody.endsWith(parentFooter)) {
115             return filteredParentBody.substring(0, filteredParentBody.length() - parentFooter.length()).strip();
116         } else {
117             return filteredParentBody;
118         }
119     }
120 
121     static String composeReply(Email parent, String body, PullRequestInstance prInstance) {
122         return "On " + parent.date().format(DateTimeFormatter.RFC_1123_DATE_TIME) + ", " + parent.author().toString() + " wrote:\n" +
123                 "\n" +
124                 quoteBody(filterParentBody(parent, prInstance)) +
< prev index next >