use of com.meisolsson.githubsdk.service.repositories.RepositoryBranchService in project gh4a by slapperwan.
the class RefPathDisambiguationTask method resolve.
// returns ref, path
private Single<Optional<Pair<String, String>>> resolve() throws ApiRequestException {
// first check whether the path redirects to HEAD
if (mRefAndPath.startsWith("HEAD")) {
return Single.just(Optional.of(Pair.create("HEAD", mRefAndPath.startsWith("HEAD/") ? mRefAndPath.substring(5) : null)));
}
final RepositoryBranchService branchService = ServiceFactory.get(RepositoryBranchService.class, false);
final RepositoryService repoService = ServiceFactory.get(RepositoryService.class, false);
// then look for matching branches
return ApiHelpers.PageIterator.toSingle(page -> branchService.getBranches(mRepoOwner, mRepoName, page)).compose(this::matchBranch).flatMap(result -> result.orOptionalSingle(() -> ApiHelpers.PageIterator.toSingle(page -> repoService.getTags(mRepoOwner, mRepoName, page)).compose(this::matchBranch))).map(resultOpt -> resultOpt.orOptional(() -> {
// at this point, the first item may still be a SHA1 - check with a simple regex
int slashPos = mRefAndPath.indexOf('/');
String potentialSha = slashPos > 0 ? mRefAndPath.substring(0, slashPos) : mRefAndPath;
if (SHA1_PATTERN.matcher(potentialSha).matches()) {
return Optional.of(Pair.create(potentialSha, slashPos > 0 ? mRefAndPath.substring(slashPos + 1) : ""));
}
return Optional.absent();
}));
}
use of com.meisolsson.githubsdk.service.repositories.RepositoryBranchService in project gh4a by slapperwan.
the class RepositoryActivity method loadOrShowRefSelection.
private void loadOrShowRefSelection() {
if (mBranches != null) {
showRefSelectionDialog();
} else {
final RepositoryBranchService branchService = ServiceFactory.get(RepositoryBranchService.class, false);
final RepositoryService repoService = ServiceFactory.get(RepositoryService.class, false);
Single<List<Branch>> branchSingle = ApiHelpers.PageIterator.toSingle(page -> branchService.getBranches(mRepoOwner, mRepoName, page));
Single<List<Branch>> tagSingle = ApiHelpers.PageIterator.toSingle(page -> repoService.getTags(mRepoOwner, mRepoName, page));
registerTemporarySubscription(Single.zip(branchSingle, tagSingle, Pair::create).compose(RxUtils::doInBackground).compose(RxUtils.wrapWithProgressDialog(this, R.string.loading_msg)).subscribe(result -> {
mBranches = result.first;
mTags = result.second;
showRefSelectionDialog();
}, this::handleLoadFailure));
}
}
Aggregations