com.danielflower.apprunner.mgmt.GitCommit Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of app-runner Show documentation
Show all versions of app-runner Show documentation
A self-hosted platform-as-a-service that hosts web apps written in Java, Clojure, NodeJS, Python, golang and Scala.
package com.danielflower.apprunner.mgmt;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.json.JSONObject;
import java.time.Instant;
import java.util.Date;
public class GitCommit {
public final String id;
public final Date commitDate;
public final String author;
public final String message;
public GitCommit(String id, Date commitDate, String author, String message) {
this.id = id;
this.commitDate = commitDate;
this.author = author;
this.message = message;
}
public static GitCommit fromHEAD(Git git) throws Exception {
ObjectId head = git.getRepository().resolve("HEAD");
if (head != null) {
RevCommit mostRecentCommit;
try (RevWalk walk = new RevWalk(git.getRepository())) {
mostRecentCommit = walk.parseCommit(head);
}
Date commitDate = new Date(1000L * mostRecentCommit.getCommitTime());
String id = mostRecentCommit.getId().name();
PersonIdent author = mostRecentCommit.getAuthorIdent();
return new GitCommit(id, commitDate, author.getName(), mostRecentCommit.getFullMessage());
} else {
return null;
}
}
public JSONObject toJSON() {
return new JSONObject()
.put("id", id)
.put("date", commitDate.getTime())
.put("dateISO", Instant.ofEpochMilli(commitDate.getTime()).toString())
.put("author", author)
.put("message", message);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy