Skip to content
Permalink
Browse files
forge: use commit object in GitHubRepository.commitMetadata
Reviewed-by: rwestberg
  • Loading branch information
edvbld committed Jun 12, 2020
1 parent afa5d0a commit f89126d550060eb0118c7afc242c66271b823fac
Showing with 10 additions and 9 deletions.
  1. +10 −9 forge/src/main/java/org/openjdk/skara/forge/github/GitHubRepository.java
@@ -292,21 +292,22 @@ public void addCommitComment(Hash hash, String body) {

@Override
public Optional<CommitMetadata> commitMetadata(Hash hash) {
var c = request.get("commits/" + hash.hex())
var o = request.get("commits/" + hash.hex())
.onError(r -> Optional.of(JSON.of()))
.execute();
if (c.isNull()) {
if (o.isNull()) {
return Optional.empty();
}
var parents = c.get("parents").stream()
var parents = o.get("parents").stream()
.map(p -> new Hash(p.get("sha").asString()))
.collect(Collectors.toList());
var author = new Author(c.get("author").get("name").asString(),
c.get("author").get("email").asString());
var committer = new Author(c.get("committer").get("name").asString(),
c.get("committer").get("email").asString());
var date = ZonedDateTime.parse(c.get("author").get("date").asString());
var message = Arrays.asList(c.get("message").asString().split("\n"));
var commit = o.get("commit").asObject();
var author = new Author(commit.get("author").get("name").asString(),
commit.get("author").get("email").asString());
var committer = new Author(commit.get("committer").get("name").asString(),
commit.get("committer").get("email").asString());
var date = ZonedDateTime.parse(commit.get("author").get("date").asString());
var message = Arrays.asList(commit.get("message").asString().split("\n"));
return Optional.of(new CommitMetadata(hash, parents, author, committer, date, message));
}
}

0 comments on commit f89126d

Please sign in to comment.