Search in sources :

Example 1 with PullRequestPayload

use of com.meisolsson.githubsdk.model.payload.PullRequestPayload in project PocketHub by pockethub.

the class IconAndViewTextManager method formatPullRequest.

void formatPullRequest(GitHubEvent event, StyledText main, StyledText details) {
    boldActor(main, event);
    PullRequestPayload payload = (PullRequestPayload) event.payload();
    String action = payload.action();
    if ("synchronize".equals(action)) {
        action = "updated";
    }
    main.append(' ');
    main.append(action);
    main.append(' ');
    main.bold("pull request " + payload.number());
    main.append(" on ");
    boldRepo(main, event);
    if (ISSUES_PAYLOAD_ACTION_OPENED.equals(action) || "closed".equals(action)) {
        PullRequest request = payload.pullRequest();
        if (request != null) {
            String title = request.title();
            if (!TextUtils.isEmpty(title)) {
                details.append(title);
            }
        }
    }
}
Also used : PullRequestPayload(com.meisolsson.githubsdk.model.payload.PullRequestPayload) PullRequest(com.meisolsson.githubsdk.model.PullRequest)

Example 2 with PullRequestPayload

use of com.meisolsson.githubsdk.model.payload.PullRequestPayload in project PocketHub by pockethub.

the class NewsEventTextTest method testPullRequest.

/**
 * Verify text of pull request event
 */
@UiThreadTest
public void testPullRequest() {
    PullRequestPayload payload = PullRequestPayload.builder().number(30).action(PullRequestPayload.Action.Closed).build();
    GitHubEvent event = createEvent(GitHubEventType.PullRequestEvent, payload);
    updateView(event);
    verify("user closed pull request 30 on user/repo");
}
Also used : PullRequestPayload(com.meisolsson.githubsdk.model.payload.PullRequestPayload) GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) UiThreadTest(android.test.UiThreadTest)

Example 3 with PullRequestPayload

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

the class EventListFragment method onCreateContextMenu.

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    ContextMenuAwareRecyclerView.RecyclerContextMenuInfo info = (ContextMenuAwareRecyclerView.RecyclerContextMenuInfo) menuInfo;
    GitHubEvent event = mAdapter.getItemFromAdapterPosition(info.position);
    if (EventAdapter.hasInvalidPayload(event)) {
        return;
    }
    GitHubEvent.RepoIdentifier eventRepo = event.repo();
    String[] repoNamePart = eventRepo.repoWithUserName().split("/");
    String repoOwner = repoNamePart.length == 2 ? repoNamePart[0] : null;
    String repoName = repoNamePart.length == 2 ? repoNamePart[1] : null;
    menu.setHeaderTitle(R.string.go_to);
    /* Common menu */
    menu.add(getString(R.string.menu_user, event.actor().login())).setIntent(UserActivity.makeIntent(getActivity(), event.actor()));
    if (repoOwner != null) {
        menu.add(getString(R.string.menu_repo, repoOwner + "/" + repoName)).setIntent(RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName));
    }
    switch(event.type()) {
        case CommitCommentEvent:
            if (repoOwner != null) {
                CommitCommentPayload payload = (CommitCommentPayload) event.payload();
                String sha = payload.comment().commitId();
                menu.add(getString(R.string.menu_commit, sha.substring(0, 7))).setIntent(CommitActivity.makeIntent(getActivity(), repoOwner, repoName, sha));
            }
            break;
        case DownloadEvent:
            {
                DownloadPayload payload = (DownloadPayload) event.payload();
                menu.add(Menu.NONE, MENU_DOWNLOAD_START, Menu.NONE, getString(R.string.menu_file, payload.download().name()));
                break;
            }
        case FollowEvent:
            {
                FollowPayload payload = (FollowPayload) event.payload();
                User target = payload.target();
                if (target != null) {
                    menu.add(getString(R.string.menu_user, target.login())).setIntent(UserActivity.makeIntent(getActivity(), target));
                }
                break;
            }
        case ForkEvent:
            {
                ForkPayload payload = (ForkPayload) event.payload();
                Repository forkee = payload.forkee();
                if (forkee != null) {
                    menu.add(getString(R.string.menu_fork, forkee.owner().login() + "/" + forkee.name())).setIntent(RepositoryActivity.makeIntent(getActivity(), forkee));
                }
                break;
            }
        case GistEvent:
            {
                GistPayload payload = (GistPayload) event.payload();
                String gistId = payload.gist().id();
                menu.add(getString(R.string.menu_gist, gistId)).setIntent(GistActivity.makeIntent(getActivity(), gistId));
                break;
            }
        case GollumEvent:
            {
                GollumPayload payload = (GollumPayload) event.payload();
                List<GitHubWikiPage> pages = payload.pages();
                if (pages != null && !pages.isEmpty()) {
                    // TODO: now just open the first page
                    menu.add(getString(R.string.menu_wiki)).setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(pages.get(0).htmlUrl())));
                }
                break;
            }
        case IssueCommentEvent:
            {
                IssueCommentPayload payload = (IssueCommentPayload) event.payload();
                boolean isPullRequest = payload.issue().pullRequest() != null;
                menu.add(getString(isPullRequest ? R.string.menu_pulls : R.string.menu_issues)).setIntent(IssueListActivity.makeIntent(getActivity(), repoOwner, repoName, isPullRequest));
                break;
            }
        case IssuesEvent:
            {
                IssuesPayload payload = (IssuesPayload) event.payload();
                int issueNumber = payload.issue().number();
                menu.add(getString(R.string.menu_issue, issueNumber)).setIntent(IssueActivity.makeIntent(getActivity(), repoOwner, repoName, issueNumber));
                break;
            }
        case PullRequestEvent:
            {
                PullRequestPayload payload = (PullRequestPayload) event.payload();
                menu.add(getString(R.string.menu_pull, payload.number())).setIntent(PullRequestActivity.makeIntent(getActivity(), repoOwner, repoName, payload.number()));
                break;
            }
        case PushEvent:
            {
                if (repoOwner != null) {
                    PushPayload payload = (PushPayload) event.payload();
                    menu.add(getString(R.string.menu_compare, payload.head().substring(0, 7))).setIntent(CompareActivity.makeIntent(getActivity(), repoOwner, repoName, payload.before(), payload.head()));
                    for (GitCommit commit : payload.commits()) {
                        String sha = commit.sha();
                        menu.add(getString(R.string.menu_commit, sha.substring(0, 7))).setIntent(CommitActivity.makeIntent(getActivity(), repoOwner, repoName, sha));
                    }
                }
                break;
            }
        case ReleaseEvent:
            {
                ReleasePayload payload = (ReleasePayload) event.payload();
                List<ReleaseAsset> downloads = payload.release().assets();
                int count = downloads != null ? downloads.size() : 0;
                for (int i = 0; i < count; i++) {
                    menu.add(Menu.NONE, MENU_DOWNLOAD_START + i, Menu.NONE, getString(R.string.menu_file, downloads.get(i).name()));
                }
                break;
            }
    }
}
Also used : ForkPayload(com.meisolsson.githubsdk.model.payload.ForkPayload) GollumPayload(com.meisolsson.githubsdk.model.payload.GollumPayload) PushPayload(com.meisolsson.githubsdk.model.payload.PushPayload) ReleasePayload(com.meisolsson.githubsdk.model.payload.ReleasePayload) FollowPayload(com.meisolsson.githubsdk.model.payload.FollowPayload) User(com.meisolsson.githubsdk.model.User) GitCommit(com.meisolsson.githubsdk.model.git.GitCommit) IssuesPayload(com.meisolsson.githubsdk.model.payload.IssuesPayload) Intent(android.content.Intent) GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) GistPayload(com.meisolsson.githubsdk.model.payload.GistPayload) IssueCommentPayload(com.meisolsson.githubsdk.model.payload.IssueCommentPayload) ContextMenuAwareRecyclerView(com.gh4a.widget.ContextMenuAwareRecyclerView) CommitCommentPayload(com.meisolsson.githubsdk.model.payload.CommitCommentPayload) Repository(com.meisolsson.githubsdk.model.Repository) PullRequestPayload(com.meisolsson.githubsdk.model.payload.PullRequestPayload) List(java.util.List) DownloadPayload(com.meisolsson.githubsdk.model.payload.DownloadPayload)

Example 4 with PullRequestPayload

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

the class EventListFragment method onItemClick.

@Override
public void onItemClick(GitHubEvent event) {
    if (EventAdapter.hasInvalidPayload(event)) {
        return;
    }
    GitHubEvent.RepoIdentifier eventRepo = event.repo();
    String repoOwner = "";
    String repoName = "";
    Intent intent = null;
    Single<Optional<Intent>> intentSingle = null;
    if (eventRepo != null) {
        String[] repoNamePart = eventRepo.repoWithUserName().split("/");
        if (repoNamePart.length == 2) {
            repoOwner = repoNamePart[0];
            repoName = repoNamePart[1];
        }
    }
    if (Arrays.binarySearch(REPO_EVENTS, event.type()) >= 0 && eventRepo == null) {
        Toast.makeText(getActivity(), R.string.repo_not_found_toast, Toast.LENGTH_LONG).show();
        return;
    }
    switch(event.type()) {
        case CommitCommentEvent:
            {
                CommitCommentPayload payload = (CommitCommentPayload) event.payload();
                GitComment comment = payload.comment();
                if (comment != null) {
                    intentSingle = CommitCommentLoadTask.load(getActivity(), repoOwner, repoName, comment.commitId(), new IntentUtils.InitialCommentMarker(comment.id()));
                }
                break;
            }
        case CreateEvent:
            {
                CreatePayload payload = (CreatePayload) event.payload();
                String ref = null;
                if (payload.refType() == ReferenceType.Branch || payload.refType() == ReferenceType.Tag) {
                    ref = payload.ref();
                }
                intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName, ref);
                break;
            }
        case DeleteEvent:
            intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
            break;
        case DownloadEvent:
            {
                DownloadPayload payload = (DownloadPayload) event.payload();
                Download download = payload.download();
                UiUtils.enqueueDownloadWithPermissionCheck((BaseActivity) getActivity(), download.htmlUrl(), download.contentType(), download.name(), download.description(), null);
                break;
            }
        case FollowEvent:
            {
                FollowPayload payload = (FollowPayload) event.payload();
                intent = UserActivity.makeIntent(getActivity(), payload.target());
                break;
            }
        case ForkEvent:
            {
                ForkPayload payload = (ForkPayload) event.payload();
                Repository forkee = payload.forkee();
                if (forkee != null) {
                    intent = RepositoryActivity.makeIntent(getActivity(), forkee);
                } else {
                    Toast.makeText(getActivity(), R.string.repo_not_found_toast, Toast.LENGTH_LONG).show();
                }
                break;
            }
        case ForkApplyEvent:
            intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
            break;
        case GistEvent:
            {
                GistPayload payload = (GistPayload) event.payload();
                intent = GistActivity.makeIntent(getActivity(), payload.gist().id());
                break;
            }
        case GollumEvent:
            {
                GollumPayload payload = (GollumPayload) event.payload();
                intent = WikiListActivity.makeIntent(getActivity(), repoOwner, repoName, payload.pages().isEmpty() ? null : payload.pages().get(0));
                break;
            }
        case IssueCommentEvent:
            {
                IssueCommentPayload payload = (IssueCommentPayload) event.payload();
                Issue issue = payload.issue();
                PullRequest request = issue != null ? issue.pullRequest() : null;
                IntentUtils.InitialCommentMarker initialComment = payload.comment() != null ? new IntentUtils.InitialCommentMarker(payload.comment().id()) : null;
                if (request != null && request.htmlUrl() != null) {
                    intent = PullRequestActivity.makeIntent(getActivity(), repoOwner, repoName, issue.number(), initialComment != null ? PullRequestActivity.PAGE_CONVERSATION : -1, initialComment);
                } else if (issue != null) {
                    intent = IssueActivity.makeIntent(getActivity(), repoOwner, repoName, issue.number(), initialComment);
                }
                break;
            }
        case IssuesEvent:
            {
                IssuesPayload payload = (IssuesPayload) event.payload();
                startActivity(IssueActivity.makeIntent(getActivity(), repoOwner, repoName, payload.issue().number()));
                break;
            }
        case MemberEvent:
            intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
            break;
        case PublicEvent:
            intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
            break;
        case PullRequestEvent:
            {
                PullRequestPayload payload = (PullRequestPayload) event.payload();
                intent = PullRequestActivity.makeIntent(getActivity(), repoOwner, repoName, payload.number());
                break;
            }
        case PullRequestReviewCommentEvent:
            {
                PullRequestReviewCommentPayload payload = (PullRequestReviewCommentPayload) event.payload();
                PullRequest pr = payload.pullRequest();
                ReviewComment comment = payload.comment();
                IntentUtils.InitialCommentMarker initialComment = comment != null ? new IntentUtils.InitialCommentMarker(comment.id()) : null;
                if (pr != null) {
                    if (initialComment != null) {
                        intentSingle = PullRequestReviewCommentLoadTask.load(getActivity(), repoOwner, repoName, pr.number(), initialComment);
                    } else {
                        intent = PullRequestActivity.makeIntent(getActivity(), repoOwner, repoName, pr.number(), -1, null);
                    }
                } else if (comment != null) {
                    intent = CommitActivity.makeIntent(getActivity(), repoOwner, repoName, comment.commitId(), initialComment);
                }
                break;
            }
        case PushEvent:
            {
                PushPayload payload = (PushPayload) event.payload();
                List<GitCommit> commits = payload.commits();
                if (commits != null && !commits.isEmpty()) {
                    if (commits.size() > 1) {
                        // if commit > 1, then show compare activity
                        intent = CompareActivity.makeIntent(getActivity(), repoOwner, repoName, payload.before(), payload.head());
                    } else {
                        // only 1 commit, then show the commit details
                        intent = CommitActivity.makeIntent(getActivity(), repoOwner, repoName, commits.get(0).sha());
                    }
                } else {
                    intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
                }
                break;
            }
        case ReleaseEvent:
            {
                ReleasePayload payload = (ReleasePayload) event.payload();
                Release release = payload.release();
                if (release != null) {
                    intent = ReleaseInfoActivity.makeIntent(getActivity(), repoOwner, repoName, release.id());
                }
                break;
            }
        case WatchEvent:
            intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
            break;
    }
    if (intent != null) {
        startActivity(intent);
    } else if (intentSingle != null) {
        intentSingle.compose(RxUtils::doInBackground).compose(RxUtils.wrapWithProgressDialog(getActivity(), R.string.loading_msg)).subscribe(result -> {
            if (result.isPresent() && isAdded()) {
                startActivity(result.get());
            }
        }, error -> Log.d(Gh4Application.LOG_TAG, "Loading click intent failed", error));
    }
}
Also used : ForkPayload(com.meisolsson.githubsdk.model.payload.ForkPayload) CommitCommentLoadTask(com.gh4a.resolver.CommitCommentLoadTask) CommitCommentPayload(com.meisolsson.githubsdk.model.payload.CommitCommentPayload) Arrays(java.util.Arrays) Uri(android.net.Uri) PullRequest(com.meisolsson.githubsdk.model.PullRequest) UserActivity(com.gh4a.activities.UserActivity) WikiListActivity(com.gh4a.activities.WikiListActivity) EventAdapter(com.gh4a.adapter.EventAdapter) Issue(com.meisolsson.githubsdk.model.Issue) View(android.view.View) PullRequestReviewCommentPayload(com.meisolsson.githubsdk.model.payload.PullRequestReviewCommentPayload) Log(android.util.Log) IntentUtils(com.gh4a.utils.IntentUtils) ReferenceType(com.meisolsson.githubsdk.model.ReferenceType) IssueCommentPayload(com.meisolsson.githubsdk.model.payload.IssueCommentPayload) GistPayload(com.meisolsson.githubsdk.model.payload.GistPayload) IssuesPayload(com.meisolsson.githubsdk.model.payload.IssuesPayload) ReleaseInfoActivity(com.gh4a.activities.ReleaseInfoActivity) GistActivity(com.gh4a.activities.GistActivity) GitCommit(com.meisolsson.githubsdk.model.git.GitCommit) List(java.util.List) RxUtils(com.gh4a.utils.RxUtils) CommitActivity(com.gh4a.activities.CommitActivity) PullRequestPayload(com.meisolsson.githubsdk.model.payload.PullRequestPayload) Optional(com.gh4a.utils.Optional) GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) IssueListActivity(com.gh4a.activities.IssueListActivity) Release(com.meisolsson.githubsdk.model.Release) ContextMenu(android.view.ContextMenu) FollowPayload(com.meisolsson.githubsdk.model.payload.FollowPayload) Repository(com.meisolsson.githubsdk.model.Repository) ReleasePayload(com.meisolsson.githubsdk.model.payload.ReleasePayload) ContextMenuInfo(android.view.ContextMenu.ContextMenuInfo) Intent(android.content.Intent) Download(com.meisolsson.githubsdk.model.Download) Single(io.reactivex.Single) PushPayload(com.meisolsson.githubsdk.model.payload.PushPayload) MenuItem(android.view.MenuItem) PullRequestReviewCommentLoadTask(com.gh4a.resolver.PullRequestReviewCommentLoadTask) UiUtils(com.gh4a.utils.UiUtils) User(com.meisolsson.githubsdk.model.User) ContextMenuAwareRecyclerView(com.gh4a.widget.ContextMenuAwareRecyclerView) Toast(android.widget.Toast) Menu(android.view.Menu) R(com.gh4a.R) GollumPayload(com.meisolsson.githubsdk.model.payload.GollumPayload) GitHubWikiPage(com.meisolsson.githubsdk.model.GitHubWikiPage) CompareActivity(com.gh4a.activities.CompareActivity) LayoutInflater(android.view.LayoutInflater) IssueActivity(com.gh4a.activities.IssueActivity) ReviewComment(com.meisolsson.githubsdk.model.ReviewComment) DownloadPayload(com.meisolsson.githubsdk.model.payload.DownloadPayload) PullRequestActivity(com.gh4a.activities.PullRequestActivity) CreatePayload(com.meisolsson.githubsdk.model.payload.CreatePayload) RecyclerView(android.support.v7.widget.RecyclerView) RootAdapter(com.gh4a.adapter.RootAdapter) ReleaseAsset(com.meisolsson.githubsdk.model.ReleaseAsset) GitComment(com.meisolsson.githubsdk.model.git.GitComment) RepositoryActivity(com.gh4a.activities.RepositoryActivity) Gh4Application(com.gh4a.Gh4Application) BaseActivity(com.gh4a.BaseActivity) GitHubEventType(com.meisolsson.githubsdk.model.GitHubEventType) ForkPayload(com.meisolsson.githubsdk.model.payload.ForkPayload) GollumPayload(com.meisolsson.githubsdk.model.payload.GollumPayload) ReleasePayload(com.meisolsson.githubsdk.model.payload.ReleasePayload) FollowPayload(com.meisolsson.githubsdk.model.payload.FollowPayload) Issue(com.meisolsson.githubsdk.model.Issue) PullRequest(com.meisolsson.githubsdk.model.PullRequest) GistPayload(com.meisolsson.githubsdk.model.payload.GistPayload) IssueCommentPayload(com.meisolsson.githubsdk.model.payload.IssueCommentPayload) PullRequestPayload(com.meisolsson.githubsdk.model.payload.PullRequestPayload) List(java.util.List) GitComment(com.meisolsson.githubsdk.model.git.GitComment) Download(com.meisolsson.githubsdk.model.Download) Release(com.meisolsson.githubsdk.model.Release) PushPayload(com.meisolsson.githubsdk.model.payload.PushPayload) Optional(com.gh4a.utils.Optional) ReviewComment(com.meisolsson.githubsdk.model.ReviewComment) IssuesPayload(com.meisolsson.githubsdk.model.payload.IssuesPayload) Intent(android.content.Intent) GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) PullRequestReviewCommentPayload(com.meisolsson.githubsdk.model.payload.PullRequestReviewCommentPayload) CommitCommentPayload(com.meisolsson.githubsdk.model.payload.CommitCommentPayload) CreatePayload(com.meisolsson.githubsdk.model.payload.CreatePayload) Repository(com.meisolsson.githubsdk.model.Repository) IntentUtils(com.gh4a.utils.IntentUtils) BaseActivity(com.gh4a.BaseActivity) DownloadPayload(com.meisolsson.githubsdk.model.payload.DownloadPayload)

Example 5 with PullRequestPayload

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

the class EventAdapter method formatTitle.

private String formatTitle(GitHubEvent event) {
    GitHubEvent.RepoIdentifier eventRepo = event.repo();
    Resources res = mContext.getResources();
    if (hasInvalidPayload(event)) {
        return event.type().toString();
    }
    switch(event.type()) {
        case CommitCommentEvent:
            {
                CommitCommentPayload payload = (CommitCommentPayload) event.payload();
                return res.getString(R.string.event_commit_comment_title, payload.comment().commitId().substring(0, 7), formatFromRepoIdentifier(eventRepo));
            }
        case CreateEvent:
            {
                CreatePayload payload = (CreatePayload) event.payload();
                switch(payload.refType()) {
                    case Repository:
                        return res.getString(R.string.event_create_repo_title);
                    case Branch:
                        return res.getString(R.string.event_create_branch_title, payload.ref(), formatFromRepoIdentifier(eventRepo));
                    case Tag:
                        return res.getString(R.string.event_create_tag_title, payload.ref(), formatFromRepoIdentifier(eventRepo));
                }
                break;
            }
        case DeleteEvent:
            {
                DeletePayload payload = (DeletePayload) event.payload();
                switch(payload.refType()) {
                    case Branch:
                        return res.getString(R.string.event_delete_branch_title, payload.ref(), formatFromRepoIdentifier(eventRepo));
                    case Tag:
                        return res.getString(R.string.event_delete_tag_title, payload.ref(), formatFromRepoIdentifier(eventRepo));
                }
                break;
            }
        case DownloadEvent:
            return res.getString(R.string.event_download_title, formatFromRepoIdentifier(eventRepo));
        case FollowEvent:
            {
                FollowPayload payload = (FollowPayload) event.payload();
                return res.getString(R.string.event_follow_title, ApiHelpers.getUserLogin(mContext, payload.target()));
            }
        case ForkEvent:
            return res.getString(R.string.event_fork_title, formatFromRepoIdentifier(eventRepo));
        case ForkApplyEvent:
            return res.getString(R.string.event_fork_apply_title, formatFromRepoIdentifier(eventRepo));
        case GistEvent:
            {
                GistPayload payload = (GistPayload) event.payload();
                Gist gist = payload.gist();
                String id = gist != null ? gist.id() : mContext.getString(R.string.deleted);
                int resId = payload.action() == GistPayload.Action.Updated ? R.string.event_update_gist_title : R.string.event_create_gist_title;
                return res.getString(resId, id);
            }
        case GollumEvent:
            {
                GollumPayload payload = (GollumPayload) event.payload();
                List<GitHubWikiPage> pages = payload.pages();
                int count = pages == null ? 0 : pages.size();
                return res.getString(R.string.event_gollum_title, res.getQuantityString(R.plurals.page, count, count), formatFromRepoIdentifier(eventRepo));
            }
        case IssueCommentEvent:
            {
                IssueCommentPayload payload = (IssueCommentPayload) event.payload();
                Issue issue = payload.issue();
                if (issue != null) {
                    int formatResId = issue.pullRequest() != null ? R.string.event_pull_request_comment : R.string.event_issue_comment;
                    return res.getString(formatResId, issue.number(), formatFromRepoIdentifier(eventRepo));
                }
                break;
            }
        case IssuesEvent:
            {
                IssuesPayload payload = (IssuesPayload) event.payload();
                final int resId;
                switch(payload.action()) {
                    case Opened:
                        resId = R.string.event_issues_open_title;
                        break;
                    case Closed:
                        resId = R.string.event_issues_close_title;
                        break;
                    case Reopened:
                        resId = R.string.event_issues_reopen_title;
                        break;
                    default:
                        return "";
                }
                return res.getString(resId, payload.issue().number(), formatFromRepoIdentifier(eventRepo));
            }
        case MemberEvent:
            {
                MemberPayload payload = (MemberPayload) event.payload();
                return res.getString(R.string.event_member_title, ApiHelpers.getUserLogin(mContext, payload.member()), formatFromRepoIdentifier(eventRepo));
            }
        case PublicEvent:
            return res.getString(R.string.event_public_title, formatFromRepoIdentifier(eventRepo));
        case PullRequestEvent:
            {
                PullRequestPayload payload = (PullRequestPayload) event.payload();
                PullRequest pr = payload.pullRequest();
                final int resId;
                switch(payload.action()) {
                    case Opened:
                        resId = R.string.event_pr_open_title;
                        break;
                    case Closed:
                        resId = pr.merged() ? R.string.event_pr_merge_title : R.string.event_pr_close_title;
                        break;
                    case Reopened:
                        resId = R.string.event_pr_reopen_title;
                        break;
                    case Synchronized:
                        resId = R.string.event_pr_update_title;
                        break;
                    default:
                        return "";
                }
                return res.getString(resId, payload.number(), formatFromRepoIdentifier(eventRepo));
            }
        case PullRequestReviewCommentEvent:
            {
                PullRequestReviewCommentPayload payload = (PullRequestReviewCommentPayload) event.payload();
                PullRequest pr = payload.pullRequest();
                ReviewComment comment = payload.comment();
                if (pr != null) {
                    return res.getString(R.string.event_pull_request_review_comment_title, pr.number(), formatFromRepoIdentifier(eventRepo));
                } else if (comment != null) {
                    return res.getString(R.string.event_commit_comment_title, comment.commitId().substring(0, 7), formatFromRepoIdentifier(eventRepo));
                }
                break;
            }
        case PushEvent:
            {
                PushPayload payload = (PushPayload) event.payload();
                String ref = payload.ref();
                if (ref.startsWith("refs/heads/")) {
                    ref = ref.substring(11);
                }
                return res.getString(R.string.event_push_title, ref, formatFromRepoIdentifier(eventRepo));
            }
        case ReleaseEvent:
            return res.getString(R.string.event_release_title, formatFromRepoIdentifier(eventRepo));
        case TeamAddEvent:
            {
                TeamAddPayload payload = (TeamAddPayload) event.payload();
                Team team = payload.team();
                if (team != null) {
                    Repository repo = payload.repository();
                    if (repo != null) {
                        return res.getString(R.string.event_team_repo_add, formatToRepoName(repo), team.name());
                    }
                }
                break;
            }
        case WatchEvent:
            return res.getString(R.string.event_watch_title, formatFromRepoIdentifier(eventRepo));
    }
    return "";
}
Also used : GollumPayload(com.meisolsson.githubsdk.model.payload.GollumPayload) PushPayload(com.meisolsson.githubsdk.model.payload.PushPayload) Gist(com.meisolsson.githubsdk.model.Gist) MemberPayload(com.meisolsson.githubsdk.model.payload.MemberPayload) FollowPayload(com.meisolsson.githubsdk.model.payload.FollowPayload) Issue(com.meisolsson.githubsdk.model.Issue) DeletePayload(com.meisolsson.githubsdk.model.payload.DeletePayload) ReviewComment(com.meisolsson.githubsdk.model.ReviewComment) IssuesPayload(com.meisolsson.githubsdk.model.payload.IssuesPayload) PullRequest(com.meisolsson.githubsdk.model.PullRequest) GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) GistPayload(com.meisolsson.githubsdk.model.payload.GistPayload) IssueCommentPayload(com.meisolsson.githubsdk.model.payload.IssueCommentPayload) PullRequestReviewCommentPayload(com.meisolsson.githubsdk.model.payload.PullRequestReviewCommentPayload) CommitCommentPayload(com.meisolsson.githubsdk.model.payload.CommitCommentPayload) CreatePayload(com.meisolsson.githubsdk.model.payload.CreatePayload) Repository(com.meisolsson.githubsdk.model.Repository) PullRequestPayload(com.meisolsson.githubsdk.model.payload.PullRequestPayload) TeamAddPayload(com.meisolsson.githubsdk.model.payload.TeamAddPayload) List(java.util.List) Team(com.meisolsson.githubsdk.model.Team) Resources(android.content.res.Resources)

Aggregations

PullRequestPayload (com.meisolsson.githubsdk.model.payload.PullRequestPayload)6 GitHubEvent (com.meisolsson.githubsdk.model.GitHubEvent)5 PullRequest (com.meisolsson.githubsdk.model.PullRequest)4 CommitCommentPayload (com.meisolsson.githubsdk.model.payload.CommitCommentPayload)4 FollowPayload (com.meisolsson.githubsdk.model.payload.FollowPayload)4 GollumPayload (com.meisolsson.githubsdk.model.payload.GollumPayload)4 IssueCommentPayload (com.meisolsson.githubsdk.model.payload.IssueCommentPayload)4 IssuesPayload (com.meisolsson.githubsdk.model.payload.IssuesPayload)4 PushPayload (com.meisolsson.githubsdk.model.payload.PushPayload)4 List (java.util.List)4 Repository (com.meisolsson.githubsdk.model.Repository)3 ReviewComment (com.meisolsson.githubsdk.model.ReviewComment)3 User (com.meisolsson.githubsdk.model.User)3 GitCommit (com.meisolsson.githubsdk.model.git.GitCommit)3 CreatePayload (com.meisolsson.githubsdk.model.payload.CreatePayload)3 DownloadPayload (com.meisolsson.githubsdk.model.payload.DownloadPayload)3 ForkPayload (com.meisolsson.githubsdk.model.payload.ForkPayload)3 GistPayload (com.meisolsson.githubsdk.model.payload.GistPayload)3 PullRequestReviewCommentPayload (com.meisolsson.githubsdk.model.payload.PullRequestReviewCommentPayload)3 ReleasePayload (com.meisolsson.githubsdk.model.payload.ReleasePayload)3