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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -170,29 +170,27 @@ private void handleTags(Repository localRepo, UpdateHistory history) throws IOEx
.filter(Optional::isPresent)
.map(Optional::get)
.sorted(Comparator.comparingInt(OpenJDKTag::buildNum))
.map(OpenJDKTag::tag);
.collect(Collectors.toList());

var newNonJdkTags = newTags.stream()
.filter(tag -> OpenJDKTag.create(tag).isEmpty());
.filter(tag -> OpenJDKTag.create(tag).isEmpty())
.collect(Collectors.toList());
Copy link
Member

@edvbld edvbld Nov 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this below the for loop so it is next to the for loop of newNonJdkTags

Copy link
Member Author

@rwestberg rwestberg Nov 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!


var sortedNewTags = Stream.concat(newJdkTags, newNonJdkTags).collect(Collectors.toList());
for (var tag : sortedNewTags) {
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));
history.addTags(List.of(tag.tag()));

var commits = new ArrayList<Commit>();

// Try to determine which commits are new since the last build
var openjdkTag = OpenJDKTag.create(tag);
if (openjdkTag.isPresent()) {
var previous = existingPrevious(openjdkTag.get(), allJdkTags);
if (previous.isPresent()) {
commits.addAll(localRepo.commits(previous.get().tag() + ".." + tag).asList());
}
var previous = existingPrevious(tag, allJdkTags);
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);
var commit = localRepo.lookup(tag.tag());
if (commit.isEmpty()) {
throw new RuntimeException("Failed to lookup tag '" + tag.toString() + "'");
} else {
@@ -201,13 +199,24 @@ private void handleTags(Repository localRepo, UpdateHistory history) throws IOEx
}

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

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) {
if (annotation.isPresent()) {
updater.handleAnnotatedTagCommits(repository, commits, tag, annotation.get());
} else {
updater.handleTagCommits(repository, commits, tag);
}
updater.handleTagCommit(repository, commit.get(), tag, annotation.orElse(null));
}
}
}
@@ -86,12 +86,8 @@ public void handleCommits(HostedRepository repository, List<Commit> commits, Bra
}

@Override
public void handleTagCommits(HostedRepository repository, List<Commit> commits, Tag tag) {
var openjdkTag = OpenJDKTag.create(tag);
if (openjdkTag.isEmpty()) {
return;
}
var build = String.format("b%02d", openjdkTag.get().buildNum());
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>();
for (var commit : commits) {
@@ -104,12 +100,10 @@ public void handleTagCommits(HostedRepository repository, List<Commit> commits,
}

@Override
public void handleAnnotatedTagCommits(HostedRepository repository, List<Commit> commits, Tag tag, Tag.Annotated annotation) {
handleTagCommits(repository, commits, tag);
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) {

}
}
@@ -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();
@@ -105,10 +114,8 @@ private String tagAnnotationToText(HostedRepository repository, Tag.Annotated an
var writer = new StringWriter();
var printer = new PrintWriter(writer);

printer.println("Changeset: " + annotation.target().abbreviate());
printer.println("Author: " + annotation.author().name() + " <" + annotation.author().email() + ">");
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("URL: " + repository.webUrl(annotation.target()));
printer.println();
printer.print(String.join("\n", annotation.message()));

@@ -248,32 +255,30 @@ public void handleCommits(HostedRepository repository, List<Commit> commits, Bra
}

@Override
public void handleAnnotatedTagCommits(HostedRepository repository, List<Commit> commits, Tag tag, Tag.Annotated annotation) {
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));

var openjdkTag = OpenJDKTag.create(tag);
if (openjdkTag.isPresent()) {
printer.println("The following commits are included in " + tag);
printer.println("========================================================");
for (var commit : commits) {
printer.print(commit.hash().abbreviate());
if (commit.message().size() > 0) {
printer.print(": " + commit.message().get(0));
}
printer.println();
printer.println("The following commits are included in " + tag.tag());
printer.println("========================================================");
for (var commit : commits) {
printer.print(commit.hash().abbreviate());
if (commit.message().size() > 0) {
printer.print(": " + commit.message().get(0));
}
printer.println();
}

var tagCommit = commits.get(commits.size() - 1);
var subject = tagToSubject(repository, tagCommit.hash(), tag);
var subject = tagToSubject(repository, taggedCommit.hash(), tag.tag());
var email = Email.create(subject, writer.toString())
.sender(sender)
.recipient(recipient)
@@ -282,15 +287,38 @@ public void handleAnnotatedTagCommits(HostedRepository repository, List<Commit>
if (annotation != null) {
email.author(annotationToAuthor(annotation));
} else {
email.author(commitToAuthor(tagCommit));
email.author(commitToAuthor(taggedCommit));
}

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

@Override
public void handleTagCommits(HostedRepository repository, List<Commit> commits, Tag tag) {
handleAnnotatedTagCommits(repository, commits, tag, null);
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) {
@@ -318,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());
@@ -24,12 +24,20 @@

import org.openjdk.skara.forge.HostedRepository;
import org.openjdk.skara.vcs.*;
import org.openjdk.skara.vcs.openjdk.OpenJDKTag;

import java.util.List;

public interface UpdateConsumer {
void handleCommits(HostedRepository repository, List<Commit> commits, Branch branch);
void handleTagCommits(HostedRepository repository, List<Commit> commits, Tag tag);
void handleAnnotatedTagCommits(HostedRepository repository, List<Commit> commits, Tag tag, Tag.Annotated annotation);
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);
}
}