Skip to content
Permalink
Browse files
1068: [Backport] Bot finds original commit in wrong repository
Reviewed-by: kcr
  • Loading branch information
erikj79 committed Jul 16, 2021
1 parent fd42d90 commit e98965d49dc3836ec99967aabd9f2e7848723c0b
Showing with 15 additions and 5 deletions.
  1. +10 −5 forge/src/main/java/org/openjdk/skara/forge/github/GitHubHost.java
  2. +5 −0 forge/src/main/java/org/openjdk/skara/forge/gitlab/GitLabHost.java
@@ -351,17 +351,22 @@ public boolean isMemberOf(String groupId, HostUser user) {

@Override
public Optional<HostedCommit> search(Hash hash) {
var orgsToSearch = orgs.stream().map(o -> "org:" + o).collect(Collectors.joining("+"));
var orgsToSearch = orgs.stream().map(o -> "org:" + o).collect(Collectors.joining(" "));
if (!orgsToSearch.isEmpty()) {
orgsToSearch = "+" + orgsToSearch;
orgsToSearch = " " + orgsToSearch;
}
var result = runSearch("commits", "hash:" + hash.hex() + orgsToSearch);
var items = result.get("items").asArray();
if (items.isEmpty()) {
return Optional.empty();
}
var first = items.get(0);
var repo = repository(first.get("repository").get("full_name").asString());
return repo.get().commit(hash);
// When searching for a commit, there may be hits in multiple repositories.
// There is no good way of knowing for sure which repository we would rather
// get the commit from, but a reasonable default is to go by the shortest
// name as that is most likely the main repository of the project.
var shortestName = items.stream()
.map(o -> o.get("repository").get("full_name").asString())
.min(Comparator.comparing(String::length));
return shortestName.flatMap(this::repository).flatMap(r -> r.commit(hash));
}
}
@@ -232,6 +232,11 @@ public Optional<HostedCommit> search(Hash hash) {
var ids = request.get("groups/" + group + "/projects")
.execute()
.stream()
// When searching for a commit, there may be hits in multiple repositories.
// There is no good way of knowing for sure which repository we would rather
// get the commit from, but a reasonable default is to go by the shortest
// path name as that is most likely the main repository of the project.
.sorted(Comparator.comparing(o -> o.get("path").asString().length()))
.map(o -> o.get("id").asInt())
.collect(Collectors.toList());
for (var id : ids) {

1 comment on commit e98965d

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on e98965d Jul 16, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.