use of com.gitblit.models.GitNote in project gitblit by gitblit.
the class JGitUtilsTest method testCommitNotes.
@Test
public void testCommitNotes() throws Exception {
Repository repository = GitBlitSuite.getJGitRepository();
RevCommit commit = JGitUtils.getCommit(repository, "690c268c793bfc218982130fbfc25870f292295e");
List<GitNote> list = JGitUtils.getNotesOnCommit(repository, commit);
repository.close();
assertTrue(list.size() > 0);
assertEquals("183474d554e6f68478a02d9d7888b67a9338cdff", list.get(0).notesRef.getReferencedObjectId().getName());
}
use of com.gitblit.models.GitNote in project gitblit by gitblit.
the class JGitUtils method getNotesOnCommit.
/**
* Returns the list of notes entered about the commit from the refs/notes
* namespace. If the repository does not exist or is empty, an empty list is
* returned.
*
* @param repository
* @param commit
* @return list of notes
*/
public static List<GitNote> getNotesOnCommit(Repository repository, RevCommit commit) {
List<GitNote> list = new ArrayList<GitNote>();
if (!hasCommits(repository)) {
return list;
}
List<RefModel> noteBranches = getNoteBranches(repository, true, -1);
for (RefModel notesRef : noteBranches) {
RevTree notesTree = JGitUtils.getCommit(repository, notesRef.getName()).getTree();
// flat notes list
String notePath = commit.getName();
String text = getStringContent(repository, notesTree, notePath);
if (!StringUtils.isEmpty(text)) {
List<RevCommit> history = getRevLog(repository, notesRef.getName(), notePath, 0, -1);
RefModel noteRef = new RefModel(notesRef.displayName, null, history.get(history.size() - 1));
GitNote gitNote = new GitNote(noteRef, text);
list.add(gitNote);
continue;
}
// folder structure
StringBuilder sb = new StringBuilder(commit.getName());
sb.insert(2, '/');
notePath = sb.toString();
text = getStringContent(repository, notesTree, notePath);
if (!StringUtils.isEmpty(text)) {
List<RevCommit> history = getRevLog(repository, notesRef.getName(), notePath, 0, -1);
RefModel noteRef = new RefModel(notesRef.displayName, null, history.get(history.size() - 1));
GitNote gitNote = new GitNote(noteRef, text);
list.add(gitNote);
}
}
return list;
}