use of com.meisolsson.githubsdk.model.Repository 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 "";
}
use of com.meisolsson.githubsdk.model.Repository in project PocketHub by pockethub.
the class IssueUriMatcher method getIssue.
/**
* Parse a {@link Issue} from a non-null {@link Uri}
*
* @param uri
* @return {@link Issue} or null if none found in given
* {@link Uri}
*/
public static Issue getIssue(Uri uri) {
List<String> segments = uri.getPathSegments();
if (segments.size() < 4) {
return null;
}
if (!"issues".equals(segments.get(2)) && !"pull".equals(segments.get(2))) {
return null;
}
String repoOwner = segments.get(0);
if (!RepositoryUtils.isValidOwner(repoOwner)) {
return null;
}
String repoName = segments.get(1);
if (!RepositoryUtils.isValidRepo(repoName)) {
return null;
}
String number = segments.get(3);
if (TextUtils.isEmpty(number)) {
return null;
}
int issueNumber;
try {
issueNumber = Integer.parseInt(number);
} catch (NumberFormatException nfe) {
return null;
}
if (issueNumber < 1) {
return null;
}
Repository repo = InfoUtils.createRepoFromData(repoOwner, repoName);
return Issue.builder().repository(repo).number(issueNumber).build();
}
use of com.meisolsson.githubsdk.model.Repository in project PocketHub by pockethub.
the class RepositoryEventMatcherTest method testIncompleteRepositoryFork.
/**
* Test fork event that has an incomplete forkee in the payload
*/
@Test
public void testIncompleteRepositoryFork() {
RepositoryEventMatcher matcher = new RepositoryEventMatcher();
ForkPayload payload = ForkPayload.builder().build();
GitHubEvent event = GitHubEvent.builder().type(GitHubEventType.ForkEvent).payload(payload).build();
assertNull(matcher.getRepository(event));
Repository repository = Repository.builder().build();
payload = payload.toBuilder().forkee(repository).build();
event = event.toBuilder().payload(payload).build();
assertNull(matcher.getRepository(event));
repository = repository.toBuilder().name("repo").build();
payload = payload.toBuilder().forkee(repository).build();
event = event.toBuilder().payload(payload).build();
assertNull(matcher.getRepository(event));
User user = User.builder().build();
repository = repository.toBuilder().owner(user).build();
payload = payload.toBuilder().forkee(repository).build();
event = event.toBuilder().payload(payload).build();
assertNull(matcher.getRepository(event));
user = user.toBuilder().login("owner").build();
repository = repository.toBuilder().owner(user).build();
payload = payload.toBuilder().forkee(repository).build();
event = event.toBuilder().payload(payload).build();
assertEquals(repository, matcher.getRepository(event));
}
use of com.meisolsson.githubsdk.model.Repository in project PocketHub by pockethub.
the class CommitUriMatcher method getCommit.
/**
* Attempt to parse a {@link CommitMatch} from the given {@link Uri}
*
* @param uri
* @return {@link CommitMatch} or null if unparseable
*/
public static CommitMatch getCommit(Uri uri) {
List<String> segments = uri.getPathSegments();
if (segments.size() < 4) {
return null;
}
if (!"commit".equals(segments.get(2))) {
return null;
}
String repoOwner = segments.get(0);
if (!RepositoryUtils.isValidOwner(repoOwner)) {
return null;
}
String repoName = segments.get(1);
if (!RepositoryUtils.isValidRepo(repoName)) {
return null;
}
String commit = segments.get(3);
if (!CommitUtils.isValidCommit(commit)) {
return null;
}
Repository repository = InfoUtils.createRepoFromData(repoOwner, repoName);
return new CommitMatch(repository, commit);
}
use of com.meisolsson.githubsdk.model.Repository in project PocketHub by pockethub.
the class IssuesPagerAdapter method getItem.
@Override
public Fragment getItem(int position) {
IssueFragment fragment = new IssueFragment();
Bundle args = new Bundle();
if (repo != null) {
args.putString(EXTRA_REPOSITORY_NAME, repo.name());
User owner = repo.owner();
args.putString(EXTRA_REPOSITORY_OWNER, owner.login());
args.putParcelable(EXTRA_USER, owner);
} else {
Repository repo = repos.get(position);
args.putString(EXTRA_REPOSITORY_NAME, repo.name());
args.putString(EXTRA_REPOSITORY_OWNER, repo.owner().login());
Issue issue = store.getIssue(repo, issues[position]);
if (issue != null && issue.user() != null) {
Repository fullRepo = issue.repository();
if (fullRepo != null && fullRepo.owner() != null) {
args.putParcelable(EXTRA_USER, fullRepo.owner());
}
}
}
args.putInt(EXTRA_ISSUE_NUMBER, issues[position]);
args.putBoolean(EXTRA_CAN_WRITE_REPO, canWrite);
fragment.setArguments(args);
return fragment;
}
Aggregations