Skip to content

Commit

Permalink
Support Squashed Commits
Browse files Browse the repository at this point in the history
This returns the single commit when a PR is squashed
  • Loading branch information
gastaldi committed Aug 22, 2024
1 parent fe82bcb commit c85fca2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/main/java/io/quarkus/backports/GitHubService.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,20 @@ public Collection<PullRequest> getBackportCandidatesPullRequests() throws IOExce
JsonObject pr = pullRequests.getJsonObject(i);
JsonArray commits = pr.getJsonObject("commits").getJsonArray("nodes");
List<Commit> commitList = new ArrayList<>();
for (int j = 0; j < commits.size(); j++) {
JsonObject commitNode = commits.getJsonObject(j);
Commit commit = commitNode.getJsonObject("commit").mapTo(Commit.class);
commit.url = commitNode.getString("url");
// Was the PR squashed? If so, we only have one commit
JsonObject mergeCommit = pr.getJsonObject("mergeCommit");
boolean squashed = mergeCommit.getJsonObject("parents").getInteger("totalCount") == 1;
if (squashed) {
Commit commit = mergeCommit.mapTo(Commit.class);
commit.url = mergeCommit.getString("url");
commitList.add(commit);
} else {
for (int j = 0; j < commits.size(); j++) {
JsonObject commitNode = commits.getJsonObject(j);
Commit commit = commitNode.getJsonObject("commit").mapTo(Commit.class);
commit.url = commitNode.getString("url");
commitList.add(commit);
}
}
// Sort by commit date
Collections.sort(commitList);
Expand Down Expand Up @@ -301,4 +310,4 @@ private static class Templates {

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
url
}
}
mergeCommit {
url
message
oid
abbreviatedOid
committedDate
parents {
totalCount
}
}
commits(last: 100) {
nodes {
url
Expand Down

0 comments on commit c85fca2

Please sign in to comment.