< prev index next >

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

Print this page

 53     @Override
 54     public boolean concurrentWith(WorkItem other) {
 55         if (!(other instanceof CommentPosterWorkItem)) {
 56             return true;
 57         }
 58         CommentPosterWorkItem otherItem = (CommentPosterWorkItem) other;
 59         if (!pr.equals(otherItem.pr)) {
 60             return true;
 61         }
 62         return false;
 63     }
 64 
 65     private void postNewMessage(Email email) {
 66         var marker = String.format(bridgedMailMarker,
 67                                  Base64.getEncoder().encodeToString(email.id().address().getBytes(StandardCharsets.UTF_8)));
 68 
 69         var body = marker + "\n" +
 70                 "*Mailing list message from [" + email.author().fullName().orElse(email.author().localPart()) +
 71                 "](mailto:" + email.author().address() + ") on [" + email.sender().localPart() +
 72                 "](mailto:" + email.sender().address() + "):*\n\n" +
 73                 email.body();
 74         pr.addComment(body);
 75     }
 76 
 77     @Override
 78     public void run(Path scratchPath) {
 79         var comments = pr.comments();
 80 
 81         var alreadyBridged = new HashSet<EmailAddress>();
 82         for (var comment : comments) {
 83             if (!comment.author().equals(pr.repository().forge().currentUser())) {
 84                 continue;
 85             }
 86             var matcher = bridgedMailId.matcher(comment.body());
 87             if (!matcher.find()) {
 88                 continue;
 89             }
 90             var id = new String(Base64.getDecoder().decode(matcher.group(1)), StandardCharsets.UTF_8);
 91             alreadyBridged.add(EmailAddress.from(id));
 92         }
 93 

 53     @Override
 54     public boolean concurrentWith(WorkItem other) {
 55         if (!(other instanceof CommentPosterWorkItem)) {
 56             return true;
 57         }
 58         CommentPosterWorkItem otherItem = (CommentPosterWorkItem) other;
 59         if (!pr.equals(otherItem.pr)) {
 60             return true;
 61         }
 62         return false;
 63     }
 64 
 65     private void postNewMessage(Email email) {
 66         var marker = String.format(bridgedMailMarker,
 67                                  Base64.getEncoder().encodeToString(email.id().address().getBytes(StandardCharsets.UTF_8)));
 68 
 69         var body = marker + "\n" +
 70                 "*Mailing list message from [" + email.author().fullName().orElse(email.author().localPart()) +
 71                 "](mailto:" + email.author().address() + ") on [" + email.sender().localPart() +
 72                 "](mailto:" + email.sender().address() + "):*\n\n" +
 73                 TextToMarkdown.escapeFormatting(email.body());
 74         pr.addComment(body);
 75     }
 76 
 77     @Override
 78     public void run(Path scratchPath) {
 79         var comments = pr.comments();
 80 
 81         var alreadyBridged = new HashSet<EmailAddress>();
 82         for (var comment : comments) {
 83             if (!comment.author().equals(pr.repository().forge().currentUser())) {
 84                 continue;
 85             }
 86             var matcher = bridgedMailId.matcher(comment.body());
 87             if (!matcher.find()) {
 88                 continue;
 89             }
 90             var id = new String(Base64.getDecoder().decode(matcher.group(1)), StandardCharsets.UTF_8);
 91             alreadyBridged.add(EmailAddress.from(id));
 92         }
 93 
< prev index next >