Search in sources :

Example 1 with IssuesPayload

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

the class IconAndViewTextManagerTest method when_event_type_is_issues_and_action_is_reopened_then_icon_should_be_issue_reopen_and_its_text_should_be_formatted.

@Test
public void when_event_type_is_issues_and_action_is_reopened_then_icon_should_be_issue_reopen_and_its_text_should_be_formatted() throws Exception {
    // Arrange
    IssuesPayload payload = IssuesPayload.builder().action(IconAndViewTextManager.ISSUES_PAYLOAD_ACTION_REOPENED).build();
    GitHubEvent event = GitHubEvent.builder().type(GitHubEventType.IssuesEvent).payload(payload).build();
    IconAndViewTextManager iconAndViewTextManager = new IconAndViewTextManager(null);
    IconAndViewTextManager spyIconAndViewTextManager = spy(iconAndViewTextManager);
    doNothing().when(spyIconAndViewTextManager).formatIssues(event, null, null);
    // Act
    String icon = spyIconAndViewTextManager.setIconAndFormatStyledText(event, null, null);
    // Assert
    assertEquals(TypefaceUtils.ICON_ISSUE_REOPEN, icon);
    verify(spyIconAndViewTextManager).formatIssues(event, null, null);
}
Also used : IssuesPayload(com.meisolsson.githubsdk.model.payload.IssuesPayload) GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) Test(org.junit.Test)

Example 2 with IssuesPayload

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

the class IconAndViewTextManager method formatIssues.

void formatIssues(GitHubEvent event, StyledText main, StyledText details) {
    boldActor(main, event);
    IssuesPayload payload = (IssuesPayload) event.payload();
    String action = payload.action();
    Issue issue = payload.issue();
    main.append(' ');
    main.append(action);
    main.append(' ');
    main.bold("issue " + issue.number());
    main.append(" on ");
    boldRepo(main, event);
    appendText(details, issue.title());
}
Also used : Issue(com.meisolsson.githubsdk.model.Issue) IssuesPayload(com.meisolsson.githubsdk.model.payload.IssuesPayload)

Example 3 with IssuesPayload

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

the class IconAndViewTextManagerTest method when_event_type_is_issues_and_action_is_opened_then_icon_should_be_issue_open_and_its_text_should_be_formatted.

@Test
public void when_event_type_is_issues_and_action_is_opened_then_icon_should_be_issue_open_and_its_text_should_be_formatted() throws Exception {
    // Arrange
    IssuesPayload payload = IssuesPayload.builder().action(IconAndViewTextManager.ISSUES_PAYLOAD_ACTION_OPENED).build();
    GitHubEvent event = GitHubEvent.builder().type(GitHubEventType.IssuesEvent).payload(payload).build();
    IconAndViewTextManager iconAndViewTextManager = new IconAndViewTextManager(null);
    IconAndViewTextManager spyIconAndViewTextManager = spy(iconAndViewTextManager);
    doNothing().when(spyIconAndViewTextManager).formatIssues(event, null, null);
    // Act
    String icon = spyIconAndViewTextManager.setIconAndFormatStyledText(event, null, null);
    // Assert
    assertEquals(TypefaceUtils.ICON_ISSUE_OPEN, icon);
    verify(spyIconAndViewTextManager).formatIssues(event, null, null);
}
Also used : IssuesPayload(com.meisolsson.githubsdk.model.payload.IssuesPayload) GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) Test(org.junit.Test)

Example 4 with IssuesPayload

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

the class NewsEventTextTest method testIssue.

/**
 * Verify text of issue event
 */
@UiThreadTest
public void testIssue() {
    Issue issue = Issue.builder().number(8).build();
    IssuesPayload payload = IssuesPayload.builder().action(IssuesPayload.Action.Closed).issue(issue).build();
    GitHubEvent event = createEvent(GitHubEventType.IssuesEvent, payload);
    updateView(event);
    verify("user closed issue 8 on user/repo");
}
Also used : Issue(com.meisolsson.githubsdk.model.Issue) IssuesPayload(com.meisolsson.githubsdk.model.payload.IssuesPayload) GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) UiThreadTest(android.test.UiThreadTest)

Example 5 with IssuesPayload

use of com.meisolsson.githubsdk.model.payload.IssuesPayload 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)

Aggregations

IssuesPayload (com.meisolsson.githubsdk.model.payload.IssuesPayload)9 GitHubEvent (com.meisolsson.githubsdk.model.GitHubEvent)8 Issue (com.meisolsson.githubsdk.model.Issue)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 PullRequestPayload (com.meisolsson.githubsdk.model.payload.PullRequestPayload)4 PushPayload (com.meisolsson.githubsdk.model.payload.PushPayload)4 List (java.util.List)4 PullRequest (com.meisolsson.githubsdk.model.PullRequest)3 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