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));
}
Aggregations