Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tag annotation if present when sending notifications #243

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -35,7 +35,7 @@
import java.util.*;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.*;

class JNotifyBot implements Bot, WorkItem {
private final Logger log = Logger.getLogger("org.openjdk.skara.bots");;
@@ -166,33 +166,55 @@ private void handleTags(Repository localRepo, UpdateHistory history) throws IOEx
.map(Optional::get)
.collect(Collectors.toSet());
var newJdkTags = newTags.stream()
.map(OpenJDKTag::create)
.filter(Optional::isPresent)
.map(Optional::get)
.sorted(Comparator.comparingInt(OpenJDKTag::buildNum))
.collect(Collectors.toList());

.map(OpenJDKTag::create)
.filter(Optional::isPresent)
.map(Optional::get)
.sorted(Comparator.comparingInt(OpenJDKTag::buildNum))
.collect(Collectors.toList());
for (var tag : newJdkTags) {
// Update the history first - if there is a problem here we don't want to send out multiple updates
history.addTags(List.of(tag.tag()));

var commits = new ArrayList<Commit>();

// Try to determine which commits are new since the last build
var previous = existingPrevious(tag, allJdkTags);
if (previous.isEmpty()) {
if (previous.isPresent()) {
commits.addAll(localRepo.commits(previous.get().tag() + ".." + tag.tag()).asList());
}

// If none are found, just include the commit that was tagged
if (commits.isEmpty()) {
var commit = localRepo.lookup(tag.tag());
if (commit.isEmpty()) {
throw new RuntimeException("Failed to lookup tag '" + tag.toString() + "'");
} else {
commits.add(commit.get());
log.warning("No previous tag found for '" + tag.tag() + "'");
}
} else {
commits.addAll(localRepo.commits(previous.get().tag() + ".." + tag.tag()).asList());
}

Collections.reverse(commits);
var annotation = localRepo.annotate(tag.tag());
for (var updater : updaters) {
updater.handleOpenJDKTagCommits(repository, commits, tag, annotation.orElse(null));
}
}

var newNonJdkTags = newTags.stream()
.filter(tag -> OpenJDKTag.create(tag).isEmpty())
.collect(Collectors.toList());
for (var tag : newNonJdkTags) {
// Update the history first - if there is a problem here we don't want to send out multiple updates
history.addTags(List.of(tag));

var commit = localRepo.lookup(tag);
if (commit.isEmpty()) {
throw new RuntimeException("Failed to lookup tag '" + tag.toString() + "'");
}

var annotation = localRepo.annotate(tag);
for (var updater : updaters) {
updater.handleTagCommits(repository, commits, tag);
updater.handleTagCommit(repository, commit.get(), tag, annotation.orElse(null));
}
}
}
@@ -86,7 +86,7 @@ public void handleCommits(HostedRepository repository, List<Commit> commits, Bra
}

@Override
public void handleTagCommits(HostedRepository repository, List<Commit> commits, OpenJDKTag tag) {
public void handleOpenJDKTagCommits(HostedRepository repository, List<Commit> commits, OpenJDKTag tag, Tag.Annotated annotation) {
var build = String.format("b%02d", tag.buildNum());
try (var writer = new JsonUpdateWriter(path, repository.name())) {
var issues = new ArrayList<Issue>();
@@ -100,7 +100,10 @@ public void handleTagCommits(HostedRepository repository, List<Commit> commits,
}

@Override
public void handleNewBranch(HostedRepository repository, List<Commit> commits, Branch parent, Branch branch) {
public void handleTagCommit(HostedRepository repository, Commit commit, Tag tag, Tag.Annotated annotation) {
}

@Override
public void handleNewBranch(HostedRepository repository, List<Commit> commits, Branch parent, Branch branch) {
}
}
@@ -32,9 +32,9 @@
import java.time.Duration;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.logging.Logger;

public class MailingListUpdater implements UpdateConsumer {
private final MailingList list;
@@ -77,7 +77,7 @@ private String patchToText(Patch patch) {
}
}

private String commitToText(HostedRepository repository, Commit commit) {
private String commitToTextBrief(HostedRepository repository, Commit commit) {
var writer = new StringWriter();
var printer = new PrintWriter(writer);

@@ -88,6 +88,15 @@ private String commitToText(HostedRepository repository, Commit commit) {
}
printer.println("Date: " + commit.date().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss +0000")));
printer.println("URL: " + repository.webUrl(commit.hash()));

return writer.toString();
}

private String commitToText(HostedRepository repository, Commit commit) {
var writer = new StringWriter();
var printer = new PrintWriter(writer);

printer.print(commitToTextBrief(repository, commit));
printer.println();
printer.println(String.join("\n", commit.message()));
printer.println();
@@ -101,9 +110,22 @@ private String commitToText(HostedRepository repository, Commit commit) {
return writer.toString();
}

private EmailAddress commitsToAuthor(List<Commit> commits) {
var commit = commits.get(commits.size() - 1);
var commitAddress = EmailAddress.from(commit.committer().name(), commit.committer().email());
private String tagAnnotationToText(HostedRepository repository, Tag.Annotated annotation) {
var writer = new StringWriter();
var printer = new PrintWriter(writer);

printer.println("Tagged by: " + annotation.author().name() + " <" + annotation.author().email() + ">");
printer.println("Date: " + annotation.date().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss +0000")));
printer.println();
printer.print(String.join("\n", annotation.message()));

return writer.toString();
}

private EmailAddress filteredAuthor(EmailAddress commitAddress) {
if (author != null) {
return author;
}
var allowedAuthorMatcher = allowedAuthorDomains.matcher(commitAddress.domain());
if (!allowedAuthorMatcher.matches()) {
return sender;
@@ -112,6 +134,14 @@ private EmailAddress commitsToAuthor(List<Commit> commits) {
}
}

private EmailAddress commitToAuthor(Commit commit) {
return filteredAuthor(EmailAddress.from(commit.committer().name(), commit.committer().email()));
}

private EmailAddress annotationToAuthor(Tag.Annotated annotation) {
return filteredAuthor(EmailAddress.from(annotation.author().name(), annotation.author().email()));
}

private String commitsToSubject(HostedRepository repository, List<Commit> commits, Branch branch) {
var subject = new StringBuilder();
subject.append(repository.repositoryType().shortName());
@@ -131,12 +161,12 @@ private String commitsToSubject(HostedRepository repository, List<Commit> commit
return subject.toString();
}

private String tagToSubject(HostedRepository repository, Hash hash, OpenJDKTag tag) {
private String tagToSubject(HostedRepository repository, Hash hash, Tag tag) {
return repository.repositoryType().shortName() +
": " +
repository.name() +
": Added tag " +
tag.tag() +
tag +
" for changeset " +
hash.abbreviate();
}
@@ -170,11 +200,11 @@ private String tagToSubject(HostedRepository repository, Hash hash, OpenJDKTag t
continue;
}
var rfr = rfrCandidates.get(0);
var finalAuthor = author != null ? author : commitsToAuthor(commits);

var body = commitToText(repository, commit);
var email = Email.reply(rfr, "Re: [Integrated] " + rfr.subject(), body)
.sender(sender)
.author(finalAuthor)
.author(commitToAuthor(commit))
.recipient(recipient)
.headers(headers)
.build();
@@ -197,10 +227,11 @@ private void sendCombinedCommits(HostedRepository repository, List<Commit> commi
}

var subject = commitsToSubject(repository, commits, branch);
var finalAuthor = author != null ? author : commitsToAuthor(commits);
var lastCommit = commits.get(commits.size() - 1);
var commitAddress = filteredAuthor(EmailAddress.from(lastCommit.committer().name(), lastCommit.committer().email()));
var email = Email.create(subject, writer.toString())
.sender(sender)
.author(finalAuthor)
.author(commitAddress)
.recipient(recipient)
.headers(headers)
.build();
@@ -224,13 +255,19 @@ public void handleCommits(HostedRepository repository, List<Commit> commits, Bra
}

@Override
public void handleTagCommits(HostedRepository repository, List<Commit> commits, OpenJDKTag tag) {
public void handleOpenJDKTagCommits(HostedRepository repository, List<Commit> commits, OpenJDKTag tag, Tag.Annotated annotation) {
if (mode == Mode.PR_ONLY) {
return;
}
var writer = new StringWriter();
var printer = new PrintWriter(writer);

var taggedCommit = commits.get(commits.size() - 1);
if (annotation != null) {
printer.println(tagAnnotationToText(repository, annotation));
}
printer.println(commitToTextBrief(repository, taggedCommit));

printer.println("The following commits are included in " + tag.tag());
printer.println("========================================================");
for (var commit : commits) {
@@ -241,17 +278,47 @@ public void handleTagCommits(HostedRepository repository, List<Commit> commits,
printer.println();
}

var tagCommit = commits.get(commits.size() - 1);
var subject = tagToSubject(repository, tagCommit.hash(), tag);
var finalAuthor = author != null ? author : commitsToAuthor(commits);
var subject = tagToSubject(repository, taggedCommit.hash(), tag.tag());
var email = Email.create(subject, writer.toString())
.sender(sender)
.author(finalAuthor)
.recipient(recipient)
.headers(headers)
.build();
.headers(headers);

list.post(email);
if (annotation != null) {
email.author(annotationToAuthor(annotation));
} else {
email.author(commitToAuthor(taggedCommit));
}

list.post(email.build());
}

@Override
public void handleTagCommit(HostedRepository repository, Commit commit, Tag tag, Tag.Annotated annotation) {
if (mode == Mode.PR_ONLY) {
return;
}
var writer = new StringWriter();
var printer = new PrintWriter(writer);

if (annotation != null) {
printer.println(tagAnnotationToText(repository, annotation));
}
printer.println(commitToTextBrief(repository, commit));

var subject = tagToSubject(repository, commit.hash(), tag);
var email = Email.create(subject, writer.toString())
.sender(sender)
.recipient(recipient)
.headers(headers);

if (annotation != null) {
email.author(annotationToAuthor(annotation));
} else {
email.author(commitToAuthor(commit));
}

list.post(email.build());
}

private String newBranchSubject(HostedRepository repository, List<Commit> commits, Branch parent, Branch branch) {
@@ -279,7 +346,7 @@ public void handleNewBranch(HostedRepository repository, List<Commit> commits, B
var printer = new PrintWriter(writer);

if (commits.size() > 0) {
printer.println("The following commits are unique to the " + branch.name() + " branch");
printer.println("The following commits are unique to the " + branch.name() + " branch:");
printer.println("========================================================");
for (var commit : commits) {
printer.print(commit.hash().abbreviate());
@@ -293,7 +360,8 @@ public void handleNewBranch(HostedRepository repository, List<Commit> commits, B
}

var subject = newBranchSubject(repository, commits, parent, branch);
var finalAuthor = author != null ? author : commits.size() > 0 ? commitsToAuthor(commits) : sender;
var finalAuthor = commits.size() > 0 ? commitToAuthor(commits.get(commits.size() - 1)) : sender;

var email = Email.create(subject, writer.toString())
.sender(sender)
.author(finalAuthor)
@@ -30,6 +30,14 @@

public interface UpdateConsumer {
void handleCommits(HostedRepository repository, List<Commit> commits, Branch branch);
void handleTagCommits(HostedRepository repository, List<Commit> commits, OpenJDKTag tag);
void handleOpenJDKTagCommits(HostedRepository repository, List<Commit> commits, OpenJDKTag tag, Tag.Annotated annotated);
void handleTagCommit(HostedRepository repository, Commit commit, Tag tag, Tag.Annotated annotation);
void handleNewBranch(HostedRepository repository, List<Commit> commits, Branch parent, Branch branch);

default void handleOpenJDKTagCommits(HostedRepository repository, List<Commit> commits, OpenJDKTag tag) {
handleOpenJDKTagCommits(repository, commits, tag, null);
}
default void handleTagCommit(HostedRepository repository, Commit commit, Tag tag) {
handleTagCommit(repository, commit, tag, null);
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.