Search in sources :

Example 11 with GitHubFile

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;
}
Also used : ArrayList(java.util.ArrayList) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile)

Example 12 with GitHubFile

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));
}
Also used : GitHubFile(com.meisolsson.githubsdk.model.GitHubFile)

Example 13 with GitHubFile

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());
}
Also used : DiffStyler(com.github.pockethub.android.ui.commit.DiffStyler) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile)

Example 14 with GitHubFile

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());
}
Also used : Commit(com.meisolsson.githubsdk.model.Commit) FullCommit(com.github.pockethub.android.core.commit.FullCommit) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile) FullCommit(com.github.pockethub.android.core.commit.FullCommit) GitComment(com.meisolsson.githubsdk.model.git.GitComment)

Example 15 with GitHubFile

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));
}
Also used : Commit(com.meisolsson.githubsdk.model.Commit) FullCommit(com.github.pockethub.android.core.commit.FullCommit) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile) FullCommit(com.github.pockethub.android.core.commit.FullCommit) GitComment(com.meisolsson.githubsdk.model.git.GitComment)

Aggregations

GitHubFile (com.meisolsson.githubsdk.model.GitHubFile)19 Commit (com.meisolsson.githubsdk.model.Commit)6 Intent (android.content.Intent)5 GitComment (com.meisolsson.githubsdk.model.git.GitComment)5 ArrayList (java.util.ArrayList)5 ServiceFactory (com.gh4a.ServiceFactory)4 ApiHelpers (com.gh4a.utils.ApiHelpers)4 IntentUtils (com.gh4a.utils.IntentUtils)4 Optional (com.gh4a.utils.Optional)4 RxUtils (com.gh4a.utils.RxUtils)4 FullCommit (com.github.pockethub.android.core.commit.FullCommit)4 Single (io.reactivex.Single)4 List (java.util.List)4 ReviewComment (com.meisolsson.githubsdk.model.ReviewComment)3 PullRequestReviewCommentService (com.meisolsson.githubsdk.service.pull_request.PullRequestReviewCommentService)3 PullRequestService (com.meisolsson.githubsdk.service.pull_request.PullRequestService)3 Bundle (android.os.Bundle)2 VisibleForTesting (android.support.annotation.VisibleForTesting)2 FragmentActivity (android.support.v4.app.FragmentActivity)2 AlertDialog (android.support.v7.app.AlertDialog)2