use of com.meisolsson.githubsdk.model.GitHubFile in project PocketHub by pockethub.
the class DiffStyler method setFiles.
/**
* Set files to styler
*
* @param files
* @return this styler
*/
public DiffStyler setFiles(final Collection<GitHubFile> files) {
diffs.clear();
if (files == null || files.isEmpty()) {
return this;
}
for (GitHubFile file : files) {
String patch = file.patch();
if (TextUtils.isEmpty(patch)) {
continue;
}
int start = 0;
int length = patch.length();
int end = nextLine(patch, start, length);
List<CharSequence> lines = new ArrayList<>();
while (start < length) {
lines.add(patch.substring(start, end));
start = end + 1;
end = nextLine(patch, start, length);
}
diffs.put(file.filename(), lines);
}
return this;
}
use of com.meisolsson.githubsdk.model.GitHubFile in project PocketHub by pockethub.
the class CommitUtilsTest method testGetName.
/**
* Test commit name parsing from path
*/
public void testGetName() {
assertNull(CommitUtils.getName((String) null));
assertNull(CommitUtils.getName((GitHubFile) null));
assertEquals("", CommitUtils.getName(""));
assertEquals("/", CommitUtils.getName("/"));
assertEquals("b", CommitUtils.getName("a/b"));
GitHubFile file = GitHubFile.builder().filename("a/b/c").build();
assertEquals("c", CommitUtils.getName(file));
}
use of com.meisolsson.githubsdk.model.GitHubFile in project PocketHub by pockethub.
the class DiffStylerTest method testEmptyPatch.
/**
* Test styler with empty patch
*/
public void testEmptyPatch() {
DiffStyler styler = new DiffStyler(getContext().getResources());
GitHubFile file = GitHubFile.builder().filename("file.txt").build();
styler.setFiles(Collections.singletonList(file));
assertTrue(styler.get("file.txt").isEmpty());
file = file.toBuilder().filename("").build();
styler.setFiles(Collections.singletonList(file));
assertTrue(styler.get("file.txt").isEmpty());
}
use of com.meisolsson.githubsdk.model.GitHubFile in project PocketHub by pockethub.
the class FullCommitTest method testSingleCommentSingleFile.
/**
* Test commit with one file and one commit comment
*/
public void testSingleCommentSingleFile() {
GitHubFile file = GitHubFile.builder().filename("a.txt").build();
GitComment comment = GitComment.builder().build();
Commit commit = Commit.builder().files(Collections.singletonList(file)).build();
FullCommit full = new FullCommit(commit, Collections.singletonList(comment));
assertFalse(full.isEmpty());
assertEquals(comment, full.get(0));
assertEquals(1, full.getFiles().size());
}
use of com.meisolsson.githubsdk.model.GitHubFile in project PocketHub by pockethub.
the class FullCommitTest method testSingleLineCommentSingleFile.
/**
* Test commit with one file and one line comment
*/
public void testSingleLineCommentSingleFile() {
GitHubFile file = GitHubFile.builder().filename("a.txt").build();
GitComment comment = GitComment.builder().path(file.filename()).position(10).build();
Commit commit = Commit.builder().files(Collections.singletonList(file)).build();
FullCommit full = new FullCommit(commit, new ArrayList<>(Collections.singletonList(comment)));
assertTrue(full.isEmpty());
assertEquals(1, full.getFiles().size());
assertEquals(comment, full.getFiles().get(0).get(10).get(0));
}
Aggregations