use of org.eclipse.jgit.diff.PatchIdDiffFormatter in project chuidiang-ejemplos by chuidiang.
the class GitAnalyzer method analyze.
public void analyze(HtmlFormat format, String issuePattern, String issueName) throws IOException {
try (RevWalk walk = new RevWalk(repository)) {
RevFilter filter = MessageRevFilter.create(issuePattern);
walk.setRevFilter(filter);
walk.markStart(walk.parseCommit(repository.resolve("HEAD")));
Iterator<RevCommit> iterator = walk.iterator();
if (!iterator.hasNext()) {
return;
}
format.addIssue(issueName);
while (iterator.hasNext()) {
RevCommit commit = iterator.next();
String commitNumber = commit.getId().getName();
Date date = commit.getAuthorIdent().getWhen();
String author = commit.getAuthorIdent().getName();
String comment = commit.getFullMessage();
ObjectId objectId = commit.getTree().getId();
RevCommit parent = commit.getParent(0);
PatchIdDiffFormatter formatter = new PatchIdDiffFormatter();
formatter.setRepository(repository);
ArrayList<String> files = new ArrayList<>();
try {
List<DiffEntry> entries = formatter.scan(parent, objectId);
entries.forEach((entry) -> {
try {
FileHeader header = formatter.toFileHeader(entry);
files.add(header.getChangeType() + " " + getPath(header));
} catch (IOException e) {
e.printStackTrace();
}
});
} catch (Exception e) {
e.printStackTrace();
}
format.addChange(commitNumber, date, author, comment, files.toArray(new String[] {}));
}
format.endIssue();
} catch (Exception e) {
format.endIssue();
}
}
Aggregations