Search in sources :

Example 1 with RepositoryCommitService

use of com.meisolsson.githubsdk.service.repositories.RepositoryCommitService in project gh4a by slapperwan.

the class CommitActivity method loadCommit.

private void loadCommit(boolean force) {
    RepositoryCommitService service = ServiceFactory.get(RepositoryCommitService.class, force);
    service.getCommit(mRepoOwner, mRepoName, mObjectSha).map(ApiHelpers::throwOnFailure).compose(makeLoaderSingle(ID_LOADER_COMMIT, force)).subscribe(result -> {
        mCommit = result;
        showContentIfReady();
    }, this::handleLoadFailure);
}
Also used : ApiHelpers(com.gh4a.utils.ApiHelpers) RepositoryCommitService(com.meisolsson.githubsdk.service.repositories.RepositoryCommitService)

Example 2 with RepositoryCommitService

use of com.meisolsson.githubsdk.service.repositories.RepositoryCommitService in project gh4a by slapperwan.

the class CommitCommentLoadTask method load.

public static Single<Optional<Intent>> load(Context context, String repoOwner, String repoName, String commitSha, IntentUtils.InitialCommentMarker marker) {
    RepositoryCommitService commitService = ServiceFactory.get(RepositoryCommitService.class, false);
    RepositoryCommentService commentService = ServiceFactory.get(RepositoryCommentService.class, false);
    Single<Commit> commitSingle = commitService.getCommit(repoOwner, repoName, commitSha).map(ApiHelpers::throwOnFailure);
    Single<List<GitComment>> commentSingle = ApiHelpers.PageIterator.toSingle(page -> commentService.getCommitComments(repoOwner, repoName, commitSha, page)).cache();
    Single<Optional<GitHubFile>> fileSingle = commentSingle.compose(RxUtils.filterAndMapToFirst(c -> marker.matches(c.id(), c.createdAt()))).zipWith(commitSingle, (comment, commit) -> {
        if (comment.isPresent()) {
            for (GitHubFile commitFile : commit.files()) {
                if (commitFile.filename().equals(comment.get().path())) {
                    return Optional.of(commitFile);
                }
            }
        }
        return Optional.absent();
    });
    return Single.zip(commitSingle, commentSingle, fileSingle, (commit, comments, fileOpt) -> {
        GitHubFile file = fileOpt.orNull();
        if (file != null && !FileUtils.isImage(file.filename())) {
            return Optional.of(CommitDiffViewerActivity.makeIntent(context, repoOwner, repoName, commitSha, file.filename(), file.patch(), comments, -1, -1, false, marker));
        } else if (file == null) {
            return Optional.of(CommitActivity.makeIntent(context, repoOwner, repoName, commitSha, marker));
        }
        return Optional.absent();
    });
}
Also used : Context(android.content.Context) FileUtils(com.gh4a.utils.FileUtils) CommitDiffViewerActivity(com.gh4a.activities.CommitDiffViewerActivity) ApiHelpers(com.gh4a.utils.ApiHelpers) RepositoryCommentService(com.meisolsson.githubsdk.service.repositories.RepositoryCommentService) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile) Intent(android.content.Intent) Single(io.reactivex.Single) VisibleForTesting(android.support.annotation.VisibleForTesting) Commit(com.meisolsson.githubsdk.model.Commit) GitComment(com.meisolsson.githubsdk.model.git.GitComment) List(java.util.List) RxUtils(com.gh4a.utils.RxUtils) CommitActivity(com.gh4a.activities.CommitActivity) FragmentActivity(android.support.v4.app.FragmentActivity) Optional(com.gh4a.utils.Optional) RepositoryCommitService(com.meisolsson.githubsdk.service.repositories.RepositoryCommitService) ServiceFactory(com.gh4a.ServiceFactory) IntentUtils(com.gh4a.utils.IntentUtils) Commit(com.meisolsson.githubsdk.model.Commit) Optional(com.gh4a.utils.Optional) ApiHelpers(com.gh4a.utils.ApiHelpers) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile) List(java.util.List) RepositoryCommentService(com.meisolsson.githubsdk.service.repositories.RepositoryCommentService) RepositoryCommitService(com.meisolsson.githubsdk.service.repositories.RepositoryCommitService)

Example 3 with RepositoryCommitService

use of com.meisolsson.githubsdk.service.repositories.RepositoryCommitService in project gh4a by slapperwan.

the class CommitCompareFragment method onCreateDataSingle.

@Override
protected Single<List<Commit>> onCreateDataSingle(boolean bypassCache) {
    RepositoryCommitService service = ServiceFactory.get(RepositoryCommitService.class, bypassCache);
    Single<CommitCompare> compareSingle = service.compareCommits(mRepoOwner, mRepoName, mBase, mHead).map(ApiHelpers::throwOnFailure).onErrorResumeNext(error -> {
        if (error instanceof ApiRequestException) {
            ApiRequestException are = (ApiRequestException) error;
            if (are.getStatus() == HttpURLConnection.HTTP_NOT_FOUND && mBaseLabel != null && mHeadLabel != null) {
                // We got a 404; likely the history of the base branch was rewritten. Try the labels.
                return service.compareCommits(mRepoOwner, mRepoName, mBaseLabel, mHeadLabel).map(ApiHelpers::throwOnFailure);
            }
        }
        return Single.error(error);
    });
    return compareSingle.map(CommitCompare::commits).compose(RxUtils.mapFailureToValue(HttpURLConnection.HTTP_NOT_FOUND, new ArrayList<>()));
}
Also used : ApiRequestException(com.gh4a.ApiRequestException) ArrayList(java.util.ArrayList) ApiHelpers(com.gh4a.utils.ApiHelpers) CommitCompare(com.meisolsson.githubsdk.model.CommitCompare) RepositoryCommitService(com.meisolsson.githubsdk.service.repositories.RepositoryCommitService)

Aggregations

ApiHelpers (com.gh4a.utils.ApiHelpers)3 RepositoryCommitService (com.meisolsson.githubsdk.service.repositories.RepositoryCommitService)3 Context (android.content.Context)1 Intent (android.content.Intent)1 VisibleForTesting (android.support.annotation.VisibleForTesting)1 FragmentActivity (android.support.v4.app.FragmentActivity)1 ApiRequestException (com.gh4a.ApiRequestException)1 ServiceFactory (com.gh4a.ServiceFactory)1 CommitActivity (com.gh4a.activities.CommitActivity)1 CommitDiffViewerActivity (com.gh4a.activities.CommitDiffViewerActivity)1 FileUtils (com.gh4a.utils.FileUtils)1 IntentUtils (com.gh4a.utils.IntentUtils)1 Optional (com.gh4a.utils.Optional)1 RxUtils (com.gh4a.utils.RxUtils)1 Commit (com.meisolsson.githubsdk.model.Commit)1 CommitCompare (com.meisolsson.githubsdk.model.CommitCompare)1 GitHubFile (com.meisolsson.githubsdk.model.GitHubFile)1 GitComment (com.meisolsson.githubsdk.model.git.GitComment)1 RepositoryCommentService (com.meisolsson.githubsdk.service.repositories.RepositoryCommentService)1 Single (io.reactivex.Single)1