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

437: Skara should invalidate approved reviews if the target branch changes #689

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
@@ -33,6 +33,7 @@
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.Function;
import java.util.logging.Logger;
import java.util.stream.Collectors;

@@ -78,6 +79,15 @@ public HostUser author() {
return host.parseUserField(json);
}

private Optional<ZonedDateTime> lastBaseRefChange() {
return request.get("issues/" + json.get("number").toString() + "/timeline").execute().stream()
.map(JSONValue::asObject)
.filter(obj -> obj.contains("event"))
.filter(obj -> obj.get("event").asString().equals("base_ref_changed"))
.map(o -> ZonedDateTime.parse(o.get("created_at").asString()))
.max(Comparator.comparing(Function.identity()));
}

@Override
public List<Review> reviews() {
var reviews = request.get("pulls/" + json.get("number").toString() + "/reviews").execute().stream()
@@ -104,6 +114,15 @@ public List<Review> reviews() {
return new Review(createdAt, reviewer, verdict, hash, id, body);
})
.collect(Collectors.toList());

// In the unlikely event that the base ref has changed after a review, we treat those as invalid
var lastBaseRefChange = lastBaseRefChange();
if (lastBaseRefChange.isPresent()) {
reviews = reviews.stream()
.filter(r -> r.createdAt().isAfter(lastBaseRefChange.get()))
.collect(Collectors.toList());;
}

return reviews;
}

@@ -57,7 +57,8 @@ public class GitHubRepository implements HostedRepository {
"Accept", "application/vnd.github.machine-man-preview+json",
"Accept", "application/vnd.github.antiope-preview+json",
"Accept", "application/vnd.github.shadow-cat-preview+json",
"Accept", "application/vnd.github.comfort-fade-preview+json"));
"Accept", "application/vnd.github.comfort-fade-preview+json",
"Accept", "application/vnd.github.mockingbird-preview+json"));
var token = gitHubHost.getInstallationToken();
if (token.isPresent()) {
headers.add("Authorization");