use of com.gh4a.utils.Optional 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.gh4a.utils.Optional in project gh4a by slapperwan.
the class ContentListContainerFragment method loadModuleMap.
private void loadModuleMap() {
RepositoryContentService service = ServiceFactory.get(RepositoryContentService.class, false);
String repoOwner = mRepository.owner().login();
String repoName = mRepository.name();
service.getContents(repoOwner, repoName, ".gitmodules", mSelectedRef).map(ApiHelpers::throwOnFailure).map(Optional::of).compose(RxUtils.mapFailureToValue(HttpURLConnection.HTTP_NOT_FOUND, Optional.<Content>absent())).map(contentOpt -> contentOpt.map(content -> StringUtils.fromBase64(content.content()))).map(this::parseModuleMap).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).compose(mRxLoader.makeSingleTransformer(ID_LOADER_MODULEMAP, true)).subscribe(resultOpt -> {
mGitModuleMap = resultOpt.orNull();
if (mContentListFragment != null) {
mContentListFragment.onSubModuleNamesChanged(getSubModuleNames(mContentListFragment));
}
}, ((BaseActivity) getActivity())::handleLoadFailure);
}
Aggregations