Search in sources :

Example 1 with PatchIdDiffFormatter

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();
    }
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) ArrayList(java.util.ArrayList) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Date(java.util.Date) IOException(java.io.IOException) MessageRevFilter(org.eclipse.jgit.revwalk.filter.MessageRevFilter) RevFilter(org.eclipse.jgit.revwalk.filter.RevFilter) FileHeader(org.eclipse.jgit.patch.FileHeader) RevCommit(org.eclipse.jgit.revwalk.RevCommit) PatchIdDiffFormatter(org.eclipse.jgit.diff.PatchIdDiffFormatter) DiffEntry(org.eclipse.jgit.diff.DiffEntry)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 DiffEntry (org.eclipse.jgit.diff.DiffEntry)1 PatchIdDiffFormatter (org.eclipse.jgit.diff.PatchIdDiffFormatter)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1 FileHeader (org.eclipse.jgit.patch.FileHeader)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1 RevWalk (org.eclipse.jgit.revwalk.RevWalk)1 MessageRevFilter (org.eclipse.jgit.revwalk.filter.MessageRevFilter)1 RevFilter (org.eclipse.jgit.revwalk.filter.RevFilter)1