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);
}
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());
}
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);
}
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");
}
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;
}
}
}
Aggregations