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

1068: [Backport] Bot finds original commit in wrong repository #1203

Closed
wants to merge 3 commits into from
Closed
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
@@ -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) {