Search in sources :

Example 1 with PullRequestMarker

use of com.meisolsson.githubsdk.model.PullRequestMarker in project gh4a by slapperwan.

the class PullRequestFragment method deletePullRequestBranch.

private void deletePullRequestBranch() {
    GitService service = ServiceFactory.get(GitService.class, false);
    PullRequestMarker head = mPullRequest.head();
    String owner = head.repo().owner().login();
    String repo = head.repo().name();
    service.deleteGitReference(owner, repo, "heads/" + head.ref()).map(ApiHelpers::mapToBooleanOrThrowOnFailure).compose(RxUtils.wrapForBackgroundTask(getBaseActivity(), R.string.deleting_msg, R.string.delete_branch_error)).subscribe(result -> {
        mHeadReference = null;
        onHeadReferenceUpdated();
    }, error -> handleActionFailure("Deleting PR branch failed", error));
}
Also used : GitService(com.meisolsson.githubsdk.service.git.GitService) ApiHelpers(com.gh4a.utils.ApiHelpers) PullRequestMarker(com.meisolsson.githubsdk.model.PullRequestMarker)

Example 2 with PullRequestMarker

use of com.meisolsson.githubsdk.model.PullRequestMarker in project gh4a by slapperwan.

the class PullRequestFragment method restorePullRequestBranch.

private void restorePullRequestBranch() {
    PullRequestMarker head = mPullRequest.head();
    if (head.repo() == null) {
        return;
    }
    String owner = head.repo().owner().login();
    String repo = head.repo().name();
    GitService service = ServiceFactory.get(GitService.class, false);
    CreateGitReference request = CreateGitReference.builder().ref("refs/heads/" + head.ref()).sha(head.sha()).build();
    service.createGitReference(owner, repo, request).map(ApiHelpers::throwOnFailure).compose(RxUtils.wrapForBackgroundTask(getBaseActivity(), R.string.saving_msg, R.string.restore_branch_error)).subscribe(result -> {
        mHeadReference = result;
        onHeadReferenceUpdated();
    }, error -> handleActionFailure("Restoring PR branch failed", error));
}
Also used : GitService(com.meisolsson.githubsdk.service.git.GitService) ApiHelpers(com.gh4a.utils.ApiHelpers) PullRequestMarker(com.meisolsson.githubsdk.model.PullRequestMarker) CreateGitReference(com.meisolsson.githubsdk.model.request.git.CreateGitReference)

Example 3 with PullRequestMarker

use of com.meisolsson.githubsdk.model.PullRequestMarker in project gh4a by slapperwan.

the class PullRequestBranchInfoView method onClick.

@Override
public void onClick(View v) {
    PullRequestMarker marker = v.getId() == R.id.tv_pr_from ? mSourceMarker : mTargetMarker;
    if (marker.repo() != null) {
        Intent intent = RepositoryActivity.makeIntent(getContext(), marker.repo(), marker.ref());
        getContext().startActivity(intent);
    }
}
Also used : PullRequestMarker(com.meisolsson.githubsdk.model.PullRequestMarker) Intent(android.content.Intent)

Example 4 with PullRequestMarker

use of com.meisolsson.githubsdk.model.PullRequestMarker in project gh4a by slapperwan.

the class PullRequestFragment method loadHeadReference.

private void loadHeadReference(boolean force) {
    GitService service = ServiceFactory.get(GitService.class, force);
    PullRequestMarker head = mPullRequest.head();
    Repository repo = head.repo();
    Single<Optional<GitReference>> refSingle = repo == null ? Single.just(Optional.absent()) : service.getGitReference(repo.owner().login(), repo.name(), head.ref()).map(ApiHelpers::throwOnFailure).map(Optional::of).compose(RxUtils.mapFailureToValue(HttpURLConnection.HTTP_NOT_FOUND, Optional.<GitReference>absent())).compose(makeLoaderSingle(ID_LOADER_HEAD_REF, force));
    refSingle.subscribe(refOpt -> {
        mHeadReference = refOpt.orNull();
        mHasLoadedHeadReference = true;
        getActivity().invalidateOptionsMenu();
        bindSpecialViews(mListHeaderView);
    }, this::handleLoadFailure);
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) Optional(com.gh4a.utils.Optional) GitService(com.meisolsson.githubsdk.service.git.GitService) ApiHelpers(com.gh4a.utils.ApiHelpers) PullRequestMarker(com.meisolsson.githubsdk.model.PullRequestMarker) GitReference(com.meisolsson.githubsdk.model.git.GitReference) CreateGitReference(com.meisolsson.githubsdk.model.request.git.CreateGitReference)

Example 5 with PullRequestMarker

use of com.meisolsson.githubsdk.model.PullRequestMarker in project gh4a by slapperwan.

the class PullRequestActivity method makeFragment.

@Override
protected Fragment makeFragment(int position) {
    if (position == 1) {
        PullRequestMarker base = mPullRequest.base();
        PullRequestMarker head = mPullRequest.head();
        return CommitCompareFragment.newInstance(mRepoOwner, mRepoName, mPullRequestNumber, base.label(), base.sha(), head.label(), head.sha());
    } else if (position == 2) {
        return PullRequestFilesFragment.newInstance(mRepoOwner, mRepoName, mPullRequestNumber, mPullRequest.head().sha());
    } else {
        Fragment f = PullRequestFragment.newInstance(mPullRequest, mIssue, mIsCollaborator, mInitialComment);
        mInitialComment = null;
        return f;
    }
}
Also used : PullRequestMarker(com.meisolsson.githubsdk.model.PullRequestMarker) CommitCompareFragment(com.gh4a.fragment.CommitCompareFragment) PullRequestFragment(com.gh4a.fragment.PullRequestFragment) Fragment(android.support.v4.app.Fragment) PullRequestFilesFragment(com.gh4a.fragment.PullRequestFilesFragment)

Aggregations

PullRequestMarker (com.meisolsson.githubsdk.model.PullRequestMarker)5 ApiHelpers (com.gh4a.utils.ApiHelpers)3 GitService (com.meisolsson.githubsdk.service.git.GitService)3 CreateGitReference (com.meisolsson.githubsdk.model.request.git.CreateGitReference)2 Intent (android.content.Intent)1 Fragment (android.support.v4.app.Fragment)1 CommitCompareFragment (com.gh4a.fragment.CommitCompareFragment)1 PullRequestFilesFragment (com.gh4a.fragment.PullRequestFilesFragment)1 PullRequestFragment (com.gh4a.fragment.PullRequestFragment)1 Optional (com.gh4a.utils.Optional)1 Repository (com.meisolsson.githubsdk.model.Repository)1 GitReference (com.meisolsson.githubsdk.model.git.GitReference)1