Search in sources :

Example 1 with GitService

use of com.meisolsson.githubsdk.service.git.GitService in project PocketHub by pockethub.

the class RefreshTreeTask method subscribe.

@Override
public void subscribe(ObservableEmitter<FullTree> emitter) throws Exception {
    GitReference ref = reference;
    String branch = RefUtils.getPath(ref);
    if (branch == null) {
        branch = repo.defaultBranch();
        if (TextUtils.isEmpty(branch)) {
            branch = ServiceGenerator.createService(context, RepositoryService.class).getRepository(repo.owner().login(), repo.name()).blockingGet().defaultBranch();
            if (TextUtils.isEmpty(branch)) {
                emitter.onError(new IOException("Repository does not have master branch"));
            }
        }
    }
    GitService gitService = ServiceGenerator.createService(context, GitService.class);
    if (!isValidRef(ref)) {
        branch = branch.replace("heads/", "");
        ref = gitService.getGitReference(repo.owner().login(), repo.name(), branch).blockingGet();
        if (!isValidRef(ref)) {
            emitter.onError(new IOException("Reference does not have associated commit SHA-1"));
            return;
        }
    }
    GitCommit commit = gitService.getGitCommit(repo.owner().login(), repo.name(), ref.object().sha()).blockingGet();
    if (commit == null || commit.tree() == null || TextUtils.isEmpty(commit.tree().sha())) {
        emitter.onError(new IOException("Commit does not have associated tree SHA-1"));
        return;
    }
    GitTree tree = gitService.getGitTreeRecursive(repo.owner().login(), repo.name(), commit.tree().sha()).blockingGet();
    emitter.onNext(new FullTree(tree, ref));
}
Also used : GitTree(com.meisolsson.githubsdk.model.git.GitTree) GitCommit(com.meisolsson.githubsdk.model.git.GitCommit) GitService(com.meisolsson.githubsdk.service.git.GitService) IOException(java.io.IOException) GitReference(com.meisolsson.githubsdk.model.git.GitReference)

Aggregations

GitCommit (com.meisolsson.githubsdk.model.git.GitCommit)1 GitReference (com.meisolsson.githubsdk.model.git.GitReference)1 GitTree (com.meisolsson.githubsdk.model.git.GitTree)1 GitService (com.meisolsson.githubsdk.service.git.GitService)1 IOException (java.io.IOException)1