private void GoToCommits(EventModel.RepoModel repoModel, string branch) { var repoId = new RepositoryIdentifier(repoModel.Name); var vm = this.CreateViewModel <CommitsViewModel>(); NavigateTo(vm.Init(repoId.Owner, repoId.Name, branch)); }
private NewsFeedElement.TextBlock RepoName(EventModel.RepoModel repoModel) { //Most likely indicates a deleted repository if (repoModel == null) { return(new NewsFeedElement.TextBlock("Unknown Repository")); } if (repoModel.Name == null) { return(new NewsFeedElement.TextBlock("<Deleted Repository>", color: UIColor.Red)); } var repoSplit = repoModel.Name.Split('/'); if (repoSplit.Length < 2) { return(new NewsFeedElement.TextBlock(repoModel.Name)); } var repoOwner = repoSplit[0]; var repoName = repoSplit[1]; if (!repoOwner.ToLower().Equals(Application.Accounts.ActiveAccount.Username.ToLower())) { return(new NewsFeedElement.TextBlock(repoModel.Name, () => RepoTapped(repoModel))); } //Just return the name return(new NewsFeedElement.TextBlock(repoName, () => RepoTapped(repoModel))); }
private void GoToRepository(EventModel.RepoModel repo) { var repoId = new RepositoryIdentifier(repo.Name); var vm = this.CreateViewModel <RepositoryViewModel>(); vm.Init(repoId.Owner, repoId.Name); NavigateTo(vm); }
private void RepoTapped(EventModel.RepoModel e) { if (e != null && ValidRepo(e)) { var repoNameSplit = e.Name.Split('/'); NavigationController.PushViewController(new RepositoryViewController(repoNameSplit[0], repoNameSplit[1], repoNameSplit[1]), true); } }
private Action RepoAction(EventModel.RepoModel e) { if (e != null && ValidRepo(e)) { var repoNameSplit = e.Name.Split('/'); return(() => NavigationController.PushViewController(new RepositoryViewController(repoNameSplit[0], repoNameSplit[1]), true)); } return(null); }
private void GoToCommits(EventModel.RepoModel repoModel, string branch) { var repoId = new RepositoryIdentifier(repoModel.Name); var vm = CreateViewModel <ChangesetsViewModel>(); vm.RepositoryOwner = repoId.Owner; vm.RepositoryName = repoId.Name; vm.Branch = branch; ShowViewModel(vm); }
private NSAction NavigateToRepository(EventModel.RepoModel repoModel) { if (ValidRepo(repoModel)) { var repoNameSplit = repoModel.Name.Split('/'); return(() => NavigationController.PushViewController(new RepositoryViewController(repoNameSplit[0], repoNameSplit[1], repoNameSplit[1]), true)); } return(null); }
private void GoToCommits(EventModel.RepoModel repoModel, string branch) { var repoId = new RepositoryIdentifier(repoModel.Name); var vm = this.CreateViewModel <CommitsViewModel>(); vm.RepositoryOwner = repoId.Owner; vm.RepositoryName = repoId.Name; vm.Branch = branch; NavigateTo(vm); }
private void GoToRepository(EventModel.RepoModel eventModel) { var repoId = new RepositoryIdentifier(eventModel.Name); ShowViewModel <RepositoryViewModel>(new RepositoryViewModel.NavObject { Username = repoId.Owner, Repository = repoId.Name }); }
private void GoToTags(EventModel.RepoModel eventModel) { var repoId = new RepositoryIdentifier(eventModel.Name); var vm = this.CreateViewModel <BranchesAndTagsViewModel>(); vm.RepositoryOwner = repoId.Owner; vm.RepositoryName = repoId.Name; vm.SelectedFilter = BranchesAndTagsViewModel.ShowIndex.Tags; NavigateTo(vm); }
private void GoToTag(EventModel.RepoModel eventModel, string tagName) { var repoId = RepositoryIdentifier.FromFullName(eventModel.Name); if (repoId == null) { return; } GoToTagCommand.OnNext(Tuple.Create(repoId, tagName)); }
private void GoToCommits(EventModel.RepoModel repoModel, string branch) { var repoId = new RepositoryIdentifier(repoModel.Name); ShowViewModel <ChangesetsViewModel>(new ChangesetsViewModel.NavObject { Username = repoId.Owner, Repository = repoId.Name, Branch = branch }); }
private void GoToTags(EventModel.RepoModel eventModel) { var repoId = new RepositoryIdentifier(eventModel.Name); ShowViewModel <BranchesAndTagsViewModel>(new BranchesAndTagsViewModel.NavObject { Username = repoId.Owner, Repository = repoId.Name, IsShowingBranches = false }); }
private void GoToRepository(EventModel.RepoModel eventModel) { var repoId = RepositoryIdentifier.FromFullName(eventModel.Name); if (repoId == null) { return; } ShowViewModel <RepositoryViewModel>(new RepositoryViewModel.NavObject { Username = repoId?.Owner, Repository = repoId?.Name }); }
private void GoToTags(EventModel.RepoModel eventModel) { var repoId = RepositoryIdentifier.FromFullName(eventModel.Name); if (repoId == null) { return; } ShowViewModel <BranchesAndTagsViewModel>(new BranchesAndTagsViewModel.NavObject { Username = repoId?.Owner, Repository = repoId?.Name, IsShowingBranches = false }); }
private void GoToCommits(EventModel.RepoModel repoModel, string branch) { var repoId = RepositoryIdentifier.FromFullName(repoModel.Name); if (repoId == null) { return; } ShowViewModel <ChangesetsViewModel>(new ChangesetsViewModel.NavObject { Username = repoId?.Owner, Repository = repoId?.Name, Branch = branch }); }
private TextBlock CreateRepositoryTextBlock(EventModel.RepoModel repoModel) { //Most likely indicates a deleted repository if (repoModel == null) { return(new TextBlock("Unknown Repository")); } if (repoModel.Name == null) { return(new TextBlock("<Deleted Repository>")); } var repoSplit = repoModel.Name.Split('/'); if (repoSplit.Length < 2) { return(new TextBlock(repoModel.Name)); } // var repoOwner = repoSplit[0]; // var repoName = repoSplit[1]; return(new AnchorBlock(repoModel.Name, () => GoToRepositoryCommand.Execute(repoModel))); }
private EventBlock CreateEventTextBlocks(EventModel eventModel) { var eventBlock = new EventBlock(); var repoId = eventModel.Repo != null ? new RepositoryIdentifier(eventModel.Repo.Name) : new RepositoryIdentifier(); var username = eventModel.Actor != null ? eventModel.Actor.Login : null; // Insert the actor eventBlock.Header.Add(new AnchorBlock(username, () => GoToUser(username))); var commitCommentEvent = eventModel.PayloadObject as EventModel.CommitCommentEvent; if (commitCommentEvent != null) { var node = commitCommentEvent.Comment.CommitId.Substring(0, commitCommentEvent.Comment.CommitId.Length > 6 ? 6 : commitCommentEvent.Comment.CommitId.Length); eventBlock.Tapped = () => GoToChangeset(repoId, commitCommentEvent.Comment.CommitId); eventBlock.Header.Add(new TextBlock(" commented on commit ")); eventBlock.Header.Add(new AnchorBlock(node, eventBlock.Tapped)); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); } eventBlock.Body.Add(new TextBlock(commitCommentEvent.Comment.Body)); return(eventBlock); } var createEvent = eventModel.PayloadObject as EventModel.CreateEvent; if (createEvent != null) { if (createEvent.RefType.Equals("repository")) { if (ReportRepository) { eventBlock.Tapped = () => GoToRepositoryCommand.Execute(eventModel.Repo); eventBlock.Header.Add(new TextBlock(" created repository ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); } else { eventBlock.Header.Add(new TextBlock(" created this repository")); } } else if (createEvent.RefType.Equals("branch")) { eventBlock.Tapped = () => GoToBranches(repoId); eventBlock.Header.Add(new TextBlock(" created branch ")); eventBlock.Header.Add(new AnchorBlock(createEvent.Ref, eventBlock.Tapped)); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); } } else if (createEvent.RefType.Equals("tag")) { eventBlock.Tapped = () => GoToTags(eventModel.Repo); eventBlock.Header.Add(new TextBlock(" created tag ")); eventBlock.Header.Add(new AnchorBlock(createEvent.Ref, eventBlock.Tapped)); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); } } } var deleteEvent = eventModel.PayloadObject as EventModel.DeleteEvent; if (deleteEvent != null) { if (deleteEvent.RefType.Equals("branch")) { eventBlock.Tapped = () => GoToBranches(repoId); eventBlock.Header.Add(new TextBlock(" deleted branch ")); } else if (deleteEvent.RefType.Equals("tag")) { eventBlock.Tapped = () => GoToTags(eventModel.Repo); eventBlock.Header.Add(new TextBlock(" deleted tag ")); } else { return(null); } eventBlock.Header.Add(new AnchorBlock(deleteEvent.Ref, eventBlock.Tapped)); if (!ReportRepository) { return(eventBlock); } eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); return(eventBlock); } if (eventModel.PayloadObject is EventModel.DownloadEvent) { // Don't show the download event for now... return(null); } var followEvent = eventModel.PayloadObject as EventModel.FollowEvent; if (followEvent != null) { eventBlock.Tapped = () => GoToUser(followEvent.Target.Login); eventBlock.Header.Add(new TextBlock(" started following ")); eventBlock.Header.Add(new AnchorBlock(followEvent.Target.Login, eventBlock.Tapped)); return(eventBlock); } /* * FORK EVENT */ else if (eventModel.PayloadObject is EventModel.ForkEvent) { var forkEvent = (EventModel.ForkEvent)eventModel.PayloadObject; var forkedRepo = new EventModel.RepoModel { Id = forkEvent.Forkee.Id, Name = forkEvent.Forkee.FullName, Url = forkEvent.Forkee.Url }; eventBlock.Tapped = () => GoToRepositoryCommand.Execute(forkedRepo); eventBlock.Header.Add(new TextBlock(" forked ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); eventBlock.Header.Add(new TextBlock(" to ")); eventBlock.Header.Add(CreateRepositoryTextBlock(forkedRepo)); } /* * FORK APPLY EVENT */ else if (eventModel.PayloadObject is EventModel.ForkApplyEvent) { var forkEvent = (EventModel.ForkApplyEvent)eventModel.PayloadObject; eventBlock.Tapped = () => GoToRepositoryCommand.Execute(eventModel.Repo); eventBlock.Header.Add(new TextBlock(" applied fork to ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); eventBlock.Header.Add(new TextBlock(" on branch ")); eventBlock.Header.Add(new AnchorBlock(forkEvent.Head, () => GoToBranches(repoId))); } /* * GIST EVENT */ else if (eventModel.PayloadObject is EventModel.GistEvent) { var gistEvent = (EventModel.GistEvent)eventModel.PayloadObject; eventBlock.Tapped = () => GoToGistCommand.Execute(gistEvent); if (string.Equals(gistEvent.Action, "create", StringComparison.OrdinalIgnoreCase)) { eventBlock.Header.Add(new TextBlock(" created Gist #")); } else if (string.Equals(gistEvent.Action, "update", StringComparison.OrdinalIgnoreCase)) { eventBlock.Header.Add(new TextBlock(" updated Gist #")); } else if (string.Equals(gistEvent.Action, "fork", StringComparison.OrdinalIgnoreCase)) { eventBlock.Header.Add(new TextBlock(" forked Gist #")); } eventBlock.Header.Add(new AnchorBlock(gistEvent.Gist.Id, eventBlock.Tapped)); eventBlock.Body.Add(new TextBlock(gistEvent.Gist.Description.Replace('\n', ' ').Replace("\r", "").Trim())); } /* * GOLLUM EVENT (WIKI) */ else if (eventModel.PayloadObject is EventModel.GollumEvent) { var gollumEvent = eventModel.PayloadObject as EventModel.GollumEvent; eventBlock.Header.Add(new TextBlock(" modified the wiki in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); if (gollumEvent != null && gollumEvent.Pages != null) { foreach (var page in gollumEvent.Pages) { var p = page; eventBlock.Body.Add(new AnchorBlock(page.PageName, () => GoToUrlCommand.Execute(p.HtmlUrl))); eventBlock.Body.Add(new TextBlock(" - " + page.Action + "\n")); } eventBlock.Multilined = true; } } /* * ISSUE COMMENT EVENT */ else if (eventModel.PayloadObject is EventModel.IssueCommentEvent) { var commentEvent = (EventModel.IssueCommentEvent)eventModel.PayloadObject; if (commentEvent.Issue.PullRequest != null && !string.IsNullOrEmpty(commentEvent.Issue.PullRequest.HtmlUrl)) { eventBlock.Tapped = () => GoToPullRequest(repoId, commentEvent.Issue.Number); eventBlock.Header.Add(new TextBlock(" commented on pull request ")); } else { eventBlock.Tapped = () => GoToIssue(repoId, commentEvent.Issue.Number); eventBlock.Header.Add(new TextBlock(" commented on issue ")); } eventBlock.Header.Add(new AnchorBlock("#" + commentEvent.Issue.Number, eventBlock.Tapped)); eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); eventBlock.Body.Add(new TextBlock(commentEvent.Comment.Body.Replace('\n', ' ').Replace("\r", "").Trim())); } /* * ISSUES EVENT */ else if (eventModel.PayloadObject is EventModel.IssuesEvent) { var issueEvent = (EventModel.IssuesEvent)eventModel.PayloadObject; eventBlock.Tapped = () => GoToIssue(repoId, issueEvent.Issue.Number); if (string.Equals(issueEvent.Action, "opened", StringComparison.OrdinalIgnoreCase)) { eventBlock.Header.Add(new TextBlock(" opened issue ")); } else if (string.Equals(issueEvent.Action, "closed", StringComparison.OrdinalIgnoreCase)) { eventBlock.Header.Add(new TextBlock(" closed issue ")); } else if (string.Equals(issueEvent.Action, "reopened", StringComparison.OrdinalIgnoreCase)) { eventBlock.Header.Add(new TextBlock(" reopened issue ")); } eventBlock.Header.Add(new AnchorBlock("#" + issueEvent.Issue.Number, eventBlock.Tapped)); eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); eventBlock.Body.Add(new TextBlock(issueEvent.Issue.Title.Trim())); } /* * MEMBER EVENT */ else if (eventModel.PayloadObject is EventModel.MemberEvent) { var memberEvent = (EventModel.MemberEvent)eventModel.PayloadObject; eventBlock.Tapped = () => GoToRepositoryCommand.Execute(eventModel.Repo); if (memberEvent.Action.Equals("added")) { eventBlock.Header.Add(new TextBlock(" added as a collaborator")); } else if (memberEvent.Action.Equals("removed")) { eventBlock.Header.Add(new TextBlock(" removed as a collaborator")); } if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" to ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); } } /* * PUBLIC EVENT */ else if (eventModel.PayloadObject is EventModel.PublicEvent) { eventBlock.Tapped = () => GoToRepositoryCommand.Execute(eventModel.Repo); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" has open sourced ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); } else { eventBlock.Header.Add(new TextBlock(" has been open sourced this repository!")); } } /* * PULL REQUEST EVENT */ else if (eventModel.PayloadObject is EventModel.PullRequestEvent) { var pullEvent = (EventModel.PullRequestEvent)eventModel.PayloadObject; eventBlock.Tapped = () => GoToPullRequest(repoId, pullEvent.Number); if (pullEvent.Action.Equals("closed")) { eventBlock.Header.Add(new TextBlock(" closed pull request ")); } else if (pullEvent.Action.Equals("opened")) { eventBlock.Header.Add(new TextBlock(" opened pull request ")); } else if (pullEvent.Action.Equals("synchronize")) { eventBlock.Header.Add(new TextBlock(" synchronized pull request ")); } else if (pullEvent.Action.Equals("reopened")) { eventBlock.Header.Add(new TextBlock(" reopened pull request ")); } eventBlock.Header.Add(new AnchorBlock("#" + pullEvent.PullRequest.Number, eventBlock.Tapped)); eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); eventBlock.Body.Add(new TextBlock(pullEvent.PullRequest.Title)); } /* * PULL REQUEST REVIEW COMMENT EVENT */ else if (eventModel.PayloadObject is EventModel.PullRequestReviewCommentEvent) { var commentEvent = (EventModel.PullRequestReviewCommentEvent)eventModel.PayloadObject; eventBlock.Tapped = () => GoToPullRequests(repoId); eventBlock.Header.Add(new TextBlock(" commented on pull request ")); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); } eventBlock.Body.Add(new TextBlock(commentEvent.Comment.Body.Replace('\n', ' ').Replace("\r", "").Trim())); } /* * PUSH EVENT */ else if (eventModel.PayloadObject is EventModel.PushEvent) { var pushEvent = (EventModel.PushEvent)eventModel.PayloadObject; string branchRef = null; if (!string.IsNullOrEmpty(pushEvent.Ref)) { var lastSlash = pushEvent.Ref.LastIndexOf("/", StringComparison.Ordinal) + 1; branchRef = pushEvent.Ref.Substring(lastSlash); } if (eventModel.Repo != null) { eventBlock.Tapped = () => GoToCommits(eventModel.Repo, pushEvent.Ref); } eventBlock.Header.Add(new TextBlock(" pushed to ")); if (branchRef != null) { eventBlock.Header.Add(new AnchorBlock(branchRef, () => GoToBranches(repoId))); } if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" at ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); } if (pushEvent.Commits != null) { foreach (var commit in pushEvent.Commits) { var desc = (commit.Message ?? ""); var sha = commit.Sha; var firstNewLine = desc.IndexOf("\n"); if (firstNewLine <= 0) { firstNewLine = desc.Length; } desc = desc.Substring(0, firstNewLine); var shortSha = commit.Sha; if (shortSha.Length > 6) { shortSha = shortSha.Substring(0, 6); } eventBlock.Body.Add(new AnchorBlock(shortSha, () => GoToChangeset(repoId, sha))); eventBlock.Body.Add(new TextBlock(" - " + desc + "\n")); eventBlock.Multilined = true; } } } var teamAddEvent = eventModel.PayloadObject as EventModel.TeamAddEvent; if (teamAddEvent != null) { eventBlock.Header.Add(new TextBlock(" added ")); if (teamAddEvent.User != null) { eventBlock.Header.Add(new AnchorBlock(teamAddEvent.User.Login, () => GoToUser(teamAddEvent.User.Login))); } else if (teamAddEvent.Repo != null) { eventBlock.Header.Add(CreateRepositoryTextBlock(new EventModel.RepoModel { Id = teamAddEvent.Repo.Id, Name = teamAddEvent.Repo.FullName, Url = teamAddEvent.Repo.Url })); } else { return(null); } if (teamAddEvent.Team == null) { return(eventBlock); } eventBlock.Header.Add(new TextBlock(" to team ")); eventBlock.Header.Add(new AnchorBlock(teamAddEvent.Team.Name, () => { })); return(eventBlock); } var watchEvent = eventModel.PayloadObject as EventModel.WatchEvent; if (watchEvent != null) { eventBlock.Tapped = () => GoToRepositoryCommand.Execute(eventModel.Repo); eventBlock.Header.Add(watchEvent.Action.Equals("started") ? new TextBlock(" starred ") : new TextBlock(" unstarred ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); return(eventBlock); } var releaseEvent = eventModel.PayloadObject as EventModel.ReleaseEvent; if (releaseEvent != null) { eventBlock.Tapped = () => GoToUrlCommand.Execute(releaseEvent.Release.HtmlUrl); eventBlock.Header.Add(new TextBlock(" " + releaseEvent.Action + " release " + releaseEvent.Release.Name)); return(eventBlock); } return(eventBlock); }
private EventBlock CreateEventTextBlocks(EventModel eventModel) { var eventBlock = new EventBlock(); var repoId = eventModel.Repo != null ? RepositoryIdentifier.FromFullName(eventModel.Repo.Name) : new RepositoryIdentifier(string.Empty, string.Empty); var username = eventModel.Actor != null ? eventModel.Actor.Login : null; // Insert the actor eventBlock.Header.Add(new AnchorBlock(username, () => GoToUser(username))); var commitCommentEvent = eventModel.PayloadObject as EventModel.CommitCommentEvent; if (commitCommentEvent != null) { var node = commitCommentEvent.Comment.CommitId.Substring(0, commitCommentEvent.Comment.CommitId.Length > 6 ? 6 : commitCommentEvent.Comment.CommitId.Length); eventBlock.Tapped = () => GoToChangeset(repoId, commitCommentEvent.Comment.CommitId); eventBlock.Header.Add(new TextBlock(" commented on commit ")); eventBlock.Header.Add(new AnchorBlock(node, eventBlock.Tapped)); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); } eventBlock.Body.Add(new TextBlock(commitCommentEvent.Comment.Body)); return eventBlock; } var createEvent = eventModel.PayloadObject as EventModel.CreateEvent; if (createEvent != null) { if (createEvent.RefType.Equals("repository")) { if (ReportRepository) { eventBlock.Tapped = () => GoToRepositoryCommand.Execute(eventModel.Repo); eventBlock.Header.Add(new TextBlock(" created repository ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); } else eventBlock.Header.Add(new TextBlock(" created this repository")); } else if (createEvent.RefType.Equals("branch")) { eventBlock.Tapped = () => GoToBranches(repoId); eventBlock.Header.Add(new TextBlock(" created branch ")); eventBlock.Header.Add(new AnchorBlock(createEvent.Ref, eventBlock.Tapped)); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); } } else if (createEvent.RefType.Equals("tag")) { eventBlock.Tapped = () => GoToTags(eventModel.Repo); eventBlock.Header.Add(new TextBlock(" created tag ")); eventBlock.Header.Add(new AnchorBlock(createEvent.Ref, eventBlock.Tapped)); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); } } } var deleteEvent = eventModel.PayloadObject as EventModel.DeleteEvent; if (deleteEvent != null) { if (deleteEvent.RefType.Equals("branch")) { eventBlock.Tapped = () => GoToBranches(repoId); eventBlock.Header.Add(new TextBlock(" deleted branch ")); } else if (deleteEvent.RefType.Equals("tag")) { eventBlock.Tapped = () => GoToTags(eventModel.Repo); eventBlock.Header.Add(new TextBlock(" deleted tag ")); } else return null; eventBlock.Header.Add(new AnchorBlock(deleteEvent.Ref, eventBlock.Tapped)); if (!ReportRepository) return eventBlock; eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); return eventBlock; } if (eventModel.PayloadObject is EventModel.DownloadEvent) { // Don't show the download event for now... return null; } var followEvent = eventModel.PayloadObject as EventModel.FollowEvent; if (followEvent != null) { eventBlock.Tapped = () => GoToUser(followEvent.Target.Login); eventBlock.Header.Add(new TextBlock(" started following ")); eventBlock.Header.Add(new AnchorBlock(followEvent.Target.Login, eventBlock.Tapped)); return eventBlock; } /* * FORK EVENT */ else if (eventModel.PayloadObject is EventModel.ForkEvent) { var forkEvent = (EventModel.ForkEvent)eventModel.PayloadObject; var forkedRepo = new EventModel.RepoModel {Id = forkEvent.Forkee.Id, Name = forkEvent.Forkee.FullName, Url = forkEvent.Forkee.Url}; eventBlock.Tapped = () => GoToRepositoryCommand.Execute(forkedRepo); eventBlock.Header.Add(new TextBlock(" forked ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); eventBlock.Header.Add(new TextBlock(" to ")); eventBlock.Header.Add(CreateRepositoryTextBlock(forkedRepo)); } /* * FORK APPLY EVENT */ else if (eventModel.PayloadObject is EventModel.ForkApplyEvent) { var forkEvent = (EventModel.ForkApplyEvent)eventModel.PayloadObject; eventBlock.Tapped = () => GoToRepositoryCommand.Execute(eventModel.Repo); eventBlock.Header.Add(new TextBlock(" applied fork to ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); eventBlock.Header.Add(new TextBlock(" on branch ")); eventBlock.Header.Add(new AnchorBlock(forkEvent.Head, () => GoToBranches(repoId))); } /* * GIST EVENT */ else if (eventModel.PayloadObject is EventModel.GistEvent) { var gistEvent = (EventModel.GistEvent)eventModel.PayloadObject; eventBlock.Tapped = () => GoToGistCommand.Execute(gistEvent); if (string.Equals(gistEvent.Action, "create", StringComparison.OrdinalIgnoreCase)) eventBlock.Header.Add(new TextBlock(" created Gist #")); else if (string.Equals(gistEvent.Action, "update", StringComparison.OrdinalIgnoreCase)) eventBlock.Header.Add(new TextBlock(" updated Gist #")); else if (string.Equals(gistEvent.Action, "fork", StringComparison.OrdinalIgnoreCase)) eventBlock.Header.Add(new TextBlock(" forked Gist #")); eventBlock.Header.Add(new AnchorBlock(gistEvent.Gist.Id, eventBlock.Tapped)); eventBlock.Body.Add(new TextBlock(gistEvent.Gist.Description.Replace('\n', ' ').Replace("\r", "").Trim())); } /* * GOLLUM EVENT (WIKI) */ else if (eventModel.PayloadObject is EventModel.GollumEvent) { var gollumEvent = eventModel.PayloadObject as EventModel.GollumEvent; eventBlock.Header.Add(new TextBlock(" modified the wiki in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); if (gollumEvent != null && gollumEvent.Pages != null) { foreach (var page in gollumEvent.Pages) { var p = page; eventBlock.Body.Add(new AnchorBlock(page.PageName, () => GoToUrlCommand.Execute(p.HtmlUrl))); eventBlock.Body.Add(new TextBlock(" - " + page.Action + "\n")); } eventBlock.Multilined = true; } } /* * ISSUE COMMENT EVENT */ else if (eventModel.PayloadObject is EventModel.IssueCommentEvent) { var commentEvent = (EventModel.IssueCommentEvent)eventModel.PayloadObject; if (commentEvent.Issue.PullRequest != null && !string.IsNullOrEmpty(commentEvent.Issue.PullRequest.HtmlUrl)) { eventBlock.Tapped = () => GoToPullRequest(repoId, commentEvent.Issue.Number); eventBlock.Header.Add(new TextBlock(" commented on pull request ")); } else { eventBlock.Tapped = () => GoToIssue(repoId, commentEvent.Issue.Number); eventBlock.Header.Add(new TextBlock(" commented on issue ")); } eventBlock.Header.Add(new AnchorBlock("#" + commentEvent.Issue.Number, eventBlock.Tapped)); eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); eventBlock.Body.Add(new TextBlock(commentEvent.Comment.Body.Replace('\n', ' ').Replace("\r", "").Trim())); } /* * ISSUES EVENT */ else if (eventModel.PayloadObject is EventModel.IssuesEvent) { var issueEvent = (EventModel.IssuesEvent)eventModel.PayloadObject; eventBlock.Tapped = () => GoToIssue(repoId, issueEvent.Issue.Number); if (string.Equals(issueEvent.Action, "opened", StringComparison.OrdinalIgnoreCase)) eventBlock.Header.Add(new TextBlock(" opened issue ")); else if (string.Equals(issueEvent.Action, "closed", StringComparison.OrdinalIgnoreCase)) eventBlock.Header.Add(new TextBlock(" closed issue ")); else if (string.Equals(issueEvent.Action, "reopened", StringComparison.OrdinalIgnoreCase)) eventBlock.Header.Add(new TextBlock(" reopened issue ")); eventBlock.Header.Add(new AnchorBlock("#" + issueEvent.Issue.Number, eventBlock.Tapped)); eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); eventBlock.Body.Add(new TextBlock(issueEvent.Issue.Title.Trim())); } /* * MEMBER EVENT */ else if (eventModel.PayloadObject is EventModel.MemberEvent) { var memberEvent = (EventModel.MemberEvent)eventModel.PayloadObject; eventBlock.Tapped = () => GoToRepositoryCommand.Execute(eventModel.Repo); if (memberEvent.Action.Equals("added")) eventBlock.Header.Add(new TextBlock(" added as a collaborator")); else if (memberEvent.Action.Equals("removed")) eventBlock.Header.Add(new TextBlock(" removed as a collaborator")); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" to ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); } } /* * PUBLIC EVENT */ else if (eventModel.PayloadObject is EventModel.PublicEvent) { eventBlock.Tapped = () => GoToRepositoryCommand.Execute(eventModel.Repo); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" has open sourced ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); } else eventBlock.Header.Add(new TextBlock(" has been open sourced this repository!")); } /* * PULL REQUEST EVENT */ else if (eventModel.PayloadObject is EventModel.PullRequestEvent) { var pullEvent = (EventModel.PullRequestEvent)eventModel.PayloadObject; eventBlock.Tapped = () => GoToPullRequest(repoId, pullEvent.Number); if (pullEvent.Action.Equals("closed")) eventBlock.Header.Add(new TextBlock(" closed pull request ")); else if (pullEvent.Action.Equals("opened")) eventBlock.Header.Add(new TextBlock(" opened pull request ")); else if (pullEvent.Action.Equals("synchronize")) eventBlock.Header.Add(new TextBlock(" synchronized pull request ")); else if (pullEvent.Action.Equals("reopened")) eventBlock.Header.Add(new TextBlock(" reopened pull request ")); eventBlock.Header.Add(new AnchorBlock("#" + pullEvent.PullRequest.Number, eventBlock.Tapped)); eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); eventBlock.Body.Add(new TextBlock(pullEvent.PullRequest.Title)); } /* * PULL REQUEST REVIEW COMMENT EVENT */ else if (eventModel.PayloadObject is EventModel.PullRequestReviewCommentEvent) { var commentEvent = (EventModel.PullRequestReviewCommentEvent)eventModel.PayloadObject; eventBlock.Tapped = () => GoToPullRequests(repoId); eventBlock.Header.Add(new TextBlock(" commented on pull request ")); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); } eventBlock.Body.Add(new TextBlock(commentEvent.Comment.Body.Replace('\n', ' ').Replace("\r", "").Trim())); } /* * PUSH EVENT */ else if (eventModel.PayloadObject is EventModel.PushEvent) { var pushEvent = (EventModel.PushEvent)eventModel.PayloadObject; string branchRef = null; if (!string.IsNullOrEmpty(pushEvent.Ref)) { var lastSlash = pushEvent.Ref.LastIndexOf("/", StringComparison.Ordinal) + 1; branchRef = pushEvent.Ref.Substring(lastSlash); } if (eventModel.Repo != null) eventBlock.Tapped = () => GoToCommits(eventModel.Repo, pushEvent.Ref); eventBlock.Header.Add(new TextBlock(" pushed to ")); if (branchRef != null) eventBlock.Header.Add(new AnchorBlock(branchRef, () => GoToBranches(repoId))); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" at ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); } if (pushEvent.Commits != null) { foreach (var commit in pushEvent.Commits) { var desc = (commit.Message ?? ""); var sha = commit.Sha; var firstNewLine = desc.IndexOf("\n"); if (firstNewLine <= 0) firstNewLine = desc.Length; desc = desc.Substring(0, firstNewLine); var shortSha = commit.Sha; if (shortSha.Length > 6) shortSha = shortSha.Substring(0, 6); eventBlock.Body.Add(new AnchorBlock(shortSha, () => GoToChangeset(repoId, sha))); eventBlock.Body.Add(new TextBlock(" - " + desc + "\n")); eventBlock.Multilined = true; } } } var teamAddEvent = eventModel.PayloadObject as EventModel.TeamAddEvent; if (teamAddEvent != null) { eventBlock.Header.Add(new TextBlock(" added ")); if (teamAddEvent.User != null) eventBlock.Header.Add(new AnchorBlock(teamAddEvent.User.Login, () => GoToUser(teamAddEvent.User.Login))); else if (teamAddEvent.Repo != null) eventBlock.Header.Add(CreateRepositoryTextBlock(new EventModel.RepoModel { Id = teamAddEvent.Repo.Id, Name = teamAddEvent.Repo.FullName, Url = teamAddEvent.Repo.Url })); else return null; if (teamAddEvent.Team == null) return eventBlock; eventBlock.Header.Add(new TextBlock(" to team ")); eventBlock.Header.Add(new AnchorBlock(teamAddEvent.Team.Name, () => { })); return eventBlock; } var watchEvent = eventModel.PayloadObject as EventModel.WatchEvent; if (watchEvent != null) { eventBlock.Tapped = () => GoToRepositoryCommand.Execute(eventModel.Repo); eventBlock.Header.Add(watchEvent.Action.Equals("started") ? new TextBlock(" starred ") : new TextBlock(" unstarred ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo)); return eventBlock; } var releaseEvent = eventModel.PayloadObject as EventModel.ReleaseEvent; if (releaseEvent != null) { eventBlock.Tapped = () => GoToUrlCommand.Execute(releaseEvent.Release.HtmlUrl); eventBlock.Header.Add(new TextBlock(" " + releaseEvent.Action + " release " + releaseEvent.Release.Name)); return eventBlock; } return eventBlock; }
private static bool ValidRepo(EventModel.RepoModel repoModel) { return(repoModel != null && repoModel.Name != null); }
private EventItemViewModel CreateEventTextBlocks(EventModel eventModel) { Action eventAction = null; var headerBlocks = new List<TextBlock>(); var bodyBlocks = new List<TextBlock>(); var repoId = eventModel.Repo != null ? new RepositoryIdentifier(eventModel.Repo.Name) : new RepositoryIdentifier(); var username = eventModel.Actor != null ? eventModel.Actor.Login : null; // Insert the actor headerBlocks.Add(new AnchorBlock(username, () => GoToUser(username))); /* * COMMIT COMMENT EVENT */ if (eventModel.PayloadObject is EventModel.CommitCommentEvent) { var commitCommentEvent = (EventModel.CommitCommentEvent)eventModel.PayloadObject; var node = commitCommentEvent.Comment.CommitId.Substring(0, commitCommentEvent.Comment.CommitId.Length > 6 ? 6 : commitCommentEvent.Comment.CommitId.Length); eventAction = () => GoToChangeset(repoId, commitCommentEvent.Comment.CommitId); headerBlocks.Add(new TextBlock(" commented on commit ")); headerBlocks.Add(new AnchorBlock(node, eventAction)); if (ReportRepository) { headerBlocks.Add(new TextBlock(" in ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); } var desc = CreateShortMessage(commitCommentEvent.Comment.Body); if (desc != null) bodyBlocks.Add(new TextBlock(desc)); } /* * CREATE EVENT */ else if (eventModel.PayloadObject is EventModel.CreateEvent) { var createEvent = (EventModel.CreateEvent)eventModel.PayloadObject; if (createEvent.RefType.Equals("repository")) { if (ReportRepository) { eventAction = () => GoToRepository(eventModel.Repo); headerBlocks.Add(new TextBlock(" created repository ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); } else headerBlocks.Add(new TextBlock(" created this repository")); } else if (createEvent.RefType.Equals("branch")) { eventAction = () => GoToBranches(repoId); headerBlocks.Add(new TextBlock(" created branch ")); headerBlocks.Add(new AnchorBlock(createEvent.Ref, eventAction)); if (ReportRepository) { headerBlocks.Add(new TextBlock(" in ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); } } else if (createEvent.RefType.Equals("tag")) { eventAction = () => GoToTags(eventModel.Repo); headerBlocks.Add(new TextBlock(" created tag ")); headerBlocks.Add(new AnchorBlock(createEvent.Ref, eventAction)); if (ReportRepository) { headerBlocks.Add(new TextBlock(" in ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); } } } /* * DELETE EVENT */ else if (eventModel.PayloadObject is EventModel.DeleteEvent) { var deleteEvent = (EventModel.DeleteEvent)eventModel.PayloadObject; if (deleteEvent.RefType.Equals("branch")) { eventAction = () => GoToBranches(repoId); headerBlocks.Add(new TextBlock(" deleted branch ")); } else if (deleteEvent.RefType.Equals("tag")) { eventAction = () => GoToTags(eventModel.Repo); headerBlocks.Add(new TextBlock(" deleted tag ")); } else return null; headerBlocks.Add(new AnchorBlock(deleteEvent.Ref, eventAction)); if (ReportRepository) { headerBlocks.Add(new TextBlock(" in ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); } } /* * FOLLOW EVENT */ else if (eventModel.PayloadObject is EventModel.DownloadEvent) { // Don't show the download event for now... return null; } /* * FOLLOW EVENT */ else if (eventModel.PayloadObject is EventModel.FollowEvent) { var followEvent = (EventModel.FollowEvent)eventModel.PayloadObject; eventAction = () => GoToUser(followEvent.Target.Login); headerBlocks.Add(new TextBlock(" started following ")); headerBlocks.Add(new AnchorBlock(followEvent.Target.Login, eventAction)); } /* * FORK EVENT */ else if (eventModel.PayloadObject is EventModel.ForkEvent) { var forkEvent = (EventModel.ForkEvent)eventModel.PayloadObject; var forkedRepo = new EventModel.RepoModel {Id = forkEvent.Forkee.Id, Name = forkEvent.Forkee.FullName, Url = forkEvent.Forkee.Url}; eventAction = () => GoToRepository(forkedRepo); headerBlocks.Add(new TextBlock(" forked ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); headerBlocks.Add(new TextBlock(" to ")); headerBlocks.Add(CreateRepositoryTextBlock(forkedRepo)); } /* * FORK APPLY EVENT */ else if (eventModel.PayloadObject is EventModel.ForkApplyEvent) { var forkEvent = (EventModel.ForkApplyEvent)eventModel.PayloadObject; eventAction = () => GoToRepository(eventModel.Repo); headerBlocks.Add(new TextBlock(" applied fork to ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); headerBlocks.Add(new TextBlock(" on branch ")); headerBlocks.Add(new AnchorBlock(forkEvent.Head, () => GoToBranches(repoId))); } /* * GIST EVENT */ else if (eventModel.PayloadObject is EventModel.GistEvent) { var gistEvent = (EventModel.GistEvent)eventModel.PayloadObject; eventAction = () => GoToGist(gistEvent); if (string.Equals(gistEvent.Action, "create", StringComparison.OrdinalIgnoreCase)) headerBlocks.Add(new TextBlock(" created Gist #")); else if (string.Equals(gistEvent.Action, "update", StringComparison.OrdinalIgnoreCase)) headerBlocks.Add(new TextBlock(" updated Gist #")); else if (string.Equals(gistEvent.Action, "fork", StringComparison.OrdinalIgnoreCase)) headerBlocks.Add(new TextBlock(" forked Gist #")); headerBlocks.Add(new AnchorBlock(gistEvent.Gist.Id, eventAction)); var desc = CreateShortMessage(gistEvent.Gist.Description); if (desc != null) bodyBlocks.Add(new TextBlock(desc)); } /* * GOLLUM EVENT (WIKI) */ else if (eventModel.PayloadObject is EventModel.GollumEvent) { var gollumEvent = eventModel.PayloadObject as EventModel.GollumEvent; headerBlocks.Add(new TextBlock(" modified the wiki in ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); if (gollumEvent != null && gollumEvent.Pages != null) { for (var i = 0; i < gollumEvent.Pages.Count; i++) { var p = gollumEvent.Pages[i]; bodyBlocks.Add(new AnchorBlock(p.PageName, () => GoToUrl(p.HtmlUrl))); var newLine = string.Empty; if (i != gollumEvent.Pages.Count - 1) newLine = Environment.NewLine; bodyBlocks.Add(new TextBlock(" - " + p.Action + newLine)); } } } /* * ISSUE COMMENT EVENT */ else if (eventModel.PayloadObject is EventModel.IssueCommentEvent) { var commentEvent = (EventModel.IssueCommentEvent)eventModel.PayloadObject; if (commentEvent.Issue.PullRequest != null && !string.IsNullOrEmpty(commentEvent.Issue.PullRequest.HtmlUrl)) { eventAction = () => GoToPullRequest(repoId, (int)commentEvent.Issue.Number); headerBlocks.Add(new TextBlock(" commented on pull request ")); } else { eventAction = () => GoToIssue(repoId, commentEvent.Issue.Number); headerBlocks.Add(new TextBlock(" commented on issue ")); } headerBlocks.Add(new AnchorBlock("#" + commentEvent.Issue.Number, eventAction)); headerBlocks.Add(new TextBlock(" in ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); var desc = CreateShortMessage(commentEvent.Comment.Body); if (desc != null) bodyBlocks.Add(new TextBlock(desc)); } /* * ISSUES EVENT */ else if (eventModel.PayloadObject is EventModel.IssuesEvent) { var issueEvent = (EventModel.IssuesEvent)eventModel.PayloadObject; eventAction = () => GoToIssue(repoId, issueEvent.Issue.Number); if (string.Equals(issueEvent.Action, "opened", StringComparison.OrdinalIgnoreCase)) headerBlocks.Add(new TextBlock(" opened issue ")); else if (string.Equals(issueEvent.Action, "closed", StringComparison.OrdinalIgnoreCase)) headerBlocks.Add(new TextBlock(" closed issue ")); else if (string.Equals(issueEvent.Action, "reopened", StringComparison.OrdinalIgnoreCase)) headerBlocks.Add(new TextBlock(" reopened issue ")); headerBlocks.Add(new AnchorBlock("#" + issueEvent.Issue.Number, eventAction)); headerBlocks.Add(new TextBlock(" in ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); bodyBlocks.Add(new TextBlock(issueEvent.Issue.Title)); } /* * MEMBER EVENT */ else if (eventModel.PayloadObject is EventModel.MemberEvent) { var memberEvent = (EventModel.MemberEvent)eventModel.PayloadObject; eventAction = () => GoToRepository(eventModel.Repo); headerBlocks.Add(new TextBlock(memberEvent.Action.Equals("added") ? " added " : " removed ")); if (memberEvent.Member != null) headerBlocks.Add(new AnchorBlock(memberEvent.Member.Login, () => GoToUser(memberEvent.Member.Login))); headerBlocks.Add(new TextBlock(" as a collaborator")); if (ReportRepository) { headerBlocks.Add(new TextBlock(" to ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); } } /* * PUBLIC EVENT */ else if (eventModel.PayloadObject is EventModel.PublicEvent) { eventAction = () => GoToRepository(eventModel.Repo); if (ReportRepository) { headerBlocks.Add(new TextBlock(" has open sourced ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); } else headerBlocks.Add(new TextBlock(" has been open sourced this repository!")); } /* * PULL REQUEST EVENT */ else if (eventModel.PayloadObject is EventModel.PullRequestEvent) { var pullEvent = (EventModel.PullRequestEvent)eventModel.PayloadObject; eventAction = () => GoToPullRequest(repoId, (int)pullEvent.Number); if (pullEvent.Action.Equals("closed")) headerBlocks.Add(new TextBlock(" closed pull request ")); else if (pullEvent.Action.Equals("opened")) headerBlocks.Add(new TextBlock(" opened pull request ")); else if (pullEvent.Action.Equals("synchronize")) headerBlocks.Add(new TextBlock(" synchronized pull request ")); else if (pullEvent.Action.Equals("reopened")) headerBlocks.Add(new TextBlock(" reopened pull request ")); headerBlocks.Add(new AnchorBlock("#" + pullEvent.PullRequest.Number, eventAction)); headerBlocks.Add(new TextBlock(" in ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); bodyBlocks.Add(new TextBlock(pullEvent.PullRequest.Title)); } /* * PULL REQUEST REVIEW COMMENT EVENT */ else if (eventModel.PayloadObject is EventModel.PullRequestReviewCommentEvent) { var commentEvent = (EventModel.PullRequestReviewCommentEvent)eventModel.PayloadObject; eventAction = () => GoToPullRequests(repoId); headerBlocks.Add(new TextBlock(" commented on pull request ")); if (ReportRepository) { headerBlocks.Add(new TextBlock(" in ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); } var desc = CreateShortMessage(commentEvent.Comment.Body); if (desc != null) bodyBlocks.Add(new TextBlock(desc)); } /* * PUSH EVENT */ else if (eventModel.PayloadObject is EventModel.PushEvent) { var pushEvent = (EventModel.PushEvent)eventModel.PayloadObject; string branchRef = null; if (!string.IsNullOrEmpty(pushEvent.Ref)) { var lastSlash = pushEvent.Ref.LastIndexOf("/", StringComparison.Ordinal) + 1; branchRef = pushEvent.Ref.Substring(lastSlash); } if (eventModel.Repo != null) eventAction = () => GoToCommits(eventModel.Repo, pushEvent.Ref); headerBlocks.Add(new TextBlock(" pushed to ")); if (branchRef != null) headerBlocks.Add(new AnchorBlock(branchRef, () => GoToBranches(repoId))); if (ReportRepository) { headerBlocks.Add(new TextBlock(" at ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); } if (pushEvent.Commits != null) { for (var i = 0; i < pushEvent.Commits.Count; i++) { var commit = pushEvent.Commits[i]; var sha = commit.Sha; var desc = CreateShortMessage(commit.Message ?? ""); var shortSha = commit.Sha; if (shortSha.Length > 6) shortSha = shortSha.Substring(0, 6); var newLine = string.Empty; if (i != pushEvent.Commits.Count - 1) newLine = Environment.NewLine; bodyBlocks.Add(new AnchorBlock(shortSha, () => GoToChangeset(repoId, sha))); if (desc != null) bodyBlocks.Add(new TextBlock(" - " + desc + newLine)); } } } else if (eventModel.PayloadObject is EventModel.TeamAddEvent) { var teamAddEvent = (EventModel.TeamAddEvent)eventModel.PayloadObject; headerBlocks.Add(new TextBlock(" added ")); if (teamAddEvent.User != null) headerBlocks.Add(new AnchorBlock(teamAddEvent.User.Login, () => GoToUser(teamAddEvent.User.Login))); else if (teamAddEvent.Repo != null) headerBlocks.Add(CreateRepositoryTextBlock(new EventModel.RepoModel { Id = teamAddEvent.Repo.Id, Name = teamAddEvent.Repo.FullName, Url = teamAddEvent.Repo.Url })); else return null; if (teamAddEvent.Team != null) { headerBlocks.Add(new TextBlock(" to team ")); headerBlocks.Add(new AnchorBlock(teamAddEvent.Team.Name, () => { })); } } else if (eventModel.PayloadObject is EventModel.WatchEvent) { var watchEvent = (EventModel.WatchEvent)eventModel.PayloadObject; eventAction = () => GoToRepository(eventModel.Repo); headerBlocks.Add(watchEvent.Action.Equals("started") ? new TextBlock(" starred ") : new TextBlock(" unstarred ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); } else if (eventModel.PayloadObject is EventModel.ReleaseEvent) { var releaseEvent = (EventModel.ReleaseEvent)eventModel.PayloadObject; eventAction = () => GoToUrl(releaseEvent.Release.HtmlUrl); headerBlocks.Add(new TextBlock(" " + releaseEvent.Action + " release " + releaseEvent.Release.Name)); } var vm = new EventItemViewModel(eventModel, headerBlocks, bodyBlocks); eventAction.Do(x => vm.GoToCommand.Subscribe(_ => x())); return vm; }
private EventItemViewModel CreateEventTextBlocks(EventModel eventModel) { Action eventAction = null; var headerBlocks = new List <TextBlock>(); var bodyBlocks = new List <TextBlock>(); var repoId = eventModel.Repo != null ? new RepositoryIdentifier(eventModel.Repo.Name) : new RepositoryIdentifier(); var username = eventModel.Actor != null ? eventModel.Actor.Login : null; // Insert the actor headerBlocks.Add(new AnchorBlock(username, () => GoToUser(username))); /* * COMMIT COMMENT EVENT */ if (eventModel.PayloadObject is EventModel.CommitCommentEvent) { var commitCommentEvent = (EventModel.CommitCommentEvent)eventModel.PayloadObject; var node = commitCommentEvent.Comment.CommitId.Substring(0, commitCommentEvent.Comment.CommitId.Length > 6 ? 6 : commitCommentEvent.Comment.CommitId.Length); eventAction = () => GoToChangeset(repoId, commitCommentEvent.Comment.CommitId); headerBlocks.Add(new TextBlock(" commented on commit ")); headerBlocks.Add(new AnchorBlock(node, eventAction)); if (ReportRepository) { headerBlocks.Add(new TextBlock(" in ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); } var desc = CreateShortMessage(commitCommentEvent.Comment.Body); if (desc != null) { bodyBlocks.Add(new TextBlock(desc)); } } /* * CREATE EVENT */ else if (eventModel.PayloadObject is EventModel.CreateEvent) { var createEvent = (EventModel.CreateEvent)eventModel.PayloadObject; if (createEvent.RefType.Equals("repository")) { if (ReportRepository) { eventAction = () => GoToRepository(eventModel.Repo); headerBlocks.Add(new TextBlock(" created repository ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); } else { headerBlocks.Add(new TextBlock(" created this repository")); } } else if (createEvent.RefType.Equals("branch")) { eventAction = () => GoToBranches(repoId); headerBlocks.Add(new TextBlock(" created branch ")); headerBlocks.Add(new AnchorBlock(createEvent.Ref, eventAction)); if (ReportRepository) { headerBlocks.Add(new TextBlock(" in ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); } } else if (createEvent.RefType.Equals("tag")) { eventAction = () => GoToTags(eventModel.Repo); headerBlocks.Add(new TextBlock(" created tag ")); headerBlocks.Add(new AnchorBlock(createEvent.Ref, eventAction)); if (ReportRepository) { headerBlocks.Add(new TextBlock(" in ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); } } } /* * DELETE EVENT */ else if (eventModel.PayloadObject is EventModel.DeleteEvent) { var deleteEvent = (EventModel.DeleteEvent)eventModel.PayloadObject; if (deleteEvent.RefType.Equals("branch")) { eventAction = () => GoToBranches(repoId); headerBlocks.Add(new TextBlock(" deleted branch ")); } else if (deleteEvent.RefType.Equals("tag")) { eventAction = () => GoToTags(eventModel.Repo); headerBlocks.Add(new TextBlock(" deleted tag ")); } else { return(null); } headerBlocks.Add(new AnchorBlock(deleteEvent.Ref, eventAction)); if (ReportRepository) { headerBlocks.Add(new TextBlock(" in ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); } } /* * FOLLOW EVENT */ else if (eventModel.PayloadObject is EventModel.DownloadEvent) { // Don't show the download event for now... return(null); } /* * FOLLOW EVENT */ else if (eventModel.PayloadObject is EventModel.FollowEvent) { var followEvent = (EventModel.FollowEvent)eventModel.PayloadObject; eventAction = () => GoToUser(followEvent.Target.Login); headerBlocks.Add(new TextBlock(" started following ")); headerBlocks.Add(new AnchorBlock(followEvent.Target.Login, eventAction)); } /* * FORK EVENT */ else if (eventModel.PayloadObject is EventModel.ForkEvent) { var forkEvent = (EventModel.ForkEvent)eventModel.PayloadObject; var forkedRepo = new EventModel.RepoModel { Id = forkEvent.Forkee.Id, Name = forkEvent.Forkee.FullName, Url = forkEvent.Forkee.Url }; eventAction = () => GoToRepository(forkedRepo); headerBlocks.Add(new TextBlock(" forked ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); headerBlocks.Add(new TextBlock(" to ")); headerBlocks.Add(CreateRepositoryTextBlock(forkedRepo)); } /* * FORK APPLY EVENT */ else if (eventModel.PayloadObject is EventModel.ForkApplyEvent) { var forkEvent = (EventModel.ForkApplyEvent)eventModel.PayloadObject; eventAction = () => GoToRepository(eventModel.Repo); headerBlocks.Add(new TextBlock(" applied fork to ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); headerBlocks.Add(new TextBlock(" on branch ")); headerBlocks.Add(new AnchorBlock(forkEvent.Head, () => GoToBranches(repoId))); } /* * GIST EVENT */ else if (eventModel.PayloadObject is EventModel.GistEvent) { var gistEvent = (EventModel.GistEvent)eventModel.PayloadObject; eventAction = () => GoToGist(gistEvent); if (string.Equals(gistEvent.Action, "create", StringComparison.OrdinalIgnoreCase)) { headerBlocks.Add(new TextBlock(" created Gist #")); } else if (string.Equals(gistEvent.Action, "update", StringComparison.OrdinalIgnoreCase)) { headerBlocks.Add(new TextBlock(" updated Gist #")); } else if (string.Equals(gistEvent.Action, "fork", StringComparison.OrdinalIgnoreCase)) { headerBlocks.Add(new TextBlock(" forked Gist #")); } headerBlocks.Add(new AnchorBlock(gistEvent.Gist.Id, eventAction)); var desc = CreateShortMessage(gistEvent.Gist.Description); if (desc != null) { bodyBlocks.Add(new TextBlock(desc)); } } /* * GOLLUM EVENT (WIKI) */ else if (eventModel.PayloadObject is EventModel.GollumEvent) { var gollumEvent = eventModel.PayloadObject as EventModel.GollumEvent; headerBlocks.Add(new TextBlock(" modified the wiki in ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); if (gollumEvent != null && gollumEvent.Pages != null) { for (var i = 0; i < gollumEvent.Pages.Count; i++) { var p = gollumEvent.Pages[i]; bodyBlocks.Add(new AnchorBlock(p.PageName, () => GoToUrl(p.HtmlUrl))); var newLine = string.Empty; if (i != gollumEvent.Pages.Count - 1) { newLine = Environment.NewLine; } bodyBlocks.Add(new TextBlock(" - " + p.Action + newLine)); } } } /* * ISSUE COMMENT EVENT */ else if (eventModel.PayloadObject is EventModel.IssueCommentEvent) { var commentEvent = (EventModel.IssueCommentEvent)eventModel.PayloadObject; if (commentEvent.Issue.PullRequest != null && !string.IsNullOrEmpty(commentEvent.Issue.PullRequest.HtmlUrl)) { eventAction = () => GoToPullRequest(repoId, (int)commentEvent.Issue.Number); headerBlocks.Add(new TextBlock(" commented on pull request ")); } else { eventAction = () => GoToIssue(repoId, commentEvent.Issue.Number); headerBlocks.Add(new TextBlock(" commented on issue ")); } headerBlocks.Add(new AnchorBlock("#" + commentEvent.Issue.Number, eventAction)); headerBlocks.Add(new TextBlock(" in ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); var desc = CreateShortMessage(commentEvent.Comment.Body); if (desc != null) { bodyBlocks.Add(new TextBlock(desc)); } } /* * ISSUES EVENT */ else if (eventModel.PayloadObject is EventModel.IssuesEvent) { var issueEvent = (EventModel.IssuesEvent)eventModel.PayloadObject; eventAction = () => GoToIssue(repoId, issueEvent.Issue.Number); if (string.Equals(issueEvent.Action, "opened", StringComparison.OrdinalIgnoreCase)) { headerBlocks.Add(new TextBlock(" opened issue ")); } else if (string.Equals(issueEvent.Action, "closed", StringComparison.OrdinalIgnoreCase)) { headerBlocks.Add(new TextBlock(" closed issue ")); } else if (string.Equals(issueEvent.Action, "reopened", StringComparison.OrdinalIgnoreCase)) { headerBlocks.Add(new TextBlock(" reopened issue ")); } headerBlocks.Add(new AnchorBlock("#" + issueEvent.Issue.Number, eventAction)); headerBlocks.Add(new TextBlock(" in ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); bodyBlocks.Add(new TextBlock(issueEvent.Issue.Title)); } /* * MEMBER EVENT */ else if (eventModel.PayloadObject is EventModel.MemberEvent) { var memberEvent = (EventModel.MemberEvent)eventModel.PayloadObject; eventAction = () => GoToRepository(eventModel.Repo); headerBlocks.Add(new TextBlock(memberEvent.Action.Equals("added") ? " added " : " removed ")); if (memberEvent.Member != null) { headerBlocks.Add(new AnchorBlock(memberEvent.Member.Login, () => GoToUser(memberEvent.Member.Login))); } headerBlocks.Add(new TextBlock(" as a collaborator")); if (ReportRepository) { headerBlocks.Add(new TextBlock(" to ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); } } /* * PUBLIC EVENT */ else if (eventModel.PayloadObject is EventModel.PublicEvent) { eventAction = () => GoToRepository(eventModel.Repo); if (ReportRepository) { headerBlocks.Add(new TextBlock(" has open sourced ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); } else { headerBlocks.Add(new TextBlock(" has been open sourced this repository!")); } } /* * PULL REQUEST EVENT */ else if (eventModel.PayloadObject is EventModel.PullRequestEvent) { var pullEvent = (EventModel.PullRequestEvent)eventModel.PayloadObject; eventAction = () => GoToPullRequest(repoId, (int)pullEvent.Number); if (pullEvent.Action.Equals("closed")) { headerBlocks.Add(new TextBlock(" closed pull request ")); } else if (pullEvent.Action.Equals("opened")) { headerBlocks.Add(new TextBlock(" opened pull request ")); } else if (pullEvent.Action.Equals("synchronize")) { headerBlocks.Add(new TextBlock(" synchronized pull request ")); } else if (pullEvent.Action.Equals("reopened")) { headerBlocks.Add(new TextBlock(" reopened pull request ")); } headerBlocks.Add(new AnchorBlock("#" + pullEvent.PullRequest.Number, eventAction)); headerBlocks.Add(new TextBlock(" in ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); bodyBlocks.Add(new TextBlock(pullEvent.PullRequest.Title)); } /* * PULL REQUEST REVIEW COMMENT EVENT */ else if (eventModel.PayloadObject is EventModel.PullRequestReviewCommentEvent) { var commentEvent = (EventModel.PullRequestReviewCommentEvent)eventModel.PayloadObject; eventAction = () => GoToPullRequests(repoId); headerBlocks.Add(new TextBlock(" commented on pull request ")); if (ReportRepository) { headerBlocks.Add(new TextBlock(" in ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); } var desc = CreateShortMessage(commentEvent.Comment.Body); if (desc != null) { bodyBlocks.Add(new TextBlock(desc)); } } /* * PUSH EVENT */ else if (eventModel.PayloadObject is EventModel.PushEvent) { var pushEvent = (EventModel.PushEvent)eventModel.PayloadObject; string branchRef = null; if (!string.IsNullOrEmpty(pushEvent.Ref)) { var lastSlash = pushEvent.Ref.LastIndexOf("/", StringComparison.Ordinal) + 1; branchRef = pushEvent.Ref.Substring(lastSlash); } if (eventModel.Repo != null) { eventAction = () => GoToCommits(eventModel.Repo, pushEvent.Ref); } headerBlocks.Add(new TextBlock(" pushed to ")); if (branchRef != null) { headerBlocks.Add(new AnchorBlock(branchRef, () => GoToBranches(repoId))); } if (ReportRepository) { headerBlocks.Add(new TextBlock(" at ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); } if (pushEvent.Commits != null) { for (var i = 0; i < pushEvent.Commits.Count; i++) { var commit = pushEvent.Commits[i]; var sha = commit.Sha; var desc = CreateShortMessage(commit.Message ?? ""); var shortSha = commit.Sha; if (shortSha.Length > 6) { shortSha = shortSha.Substring(0, 6); } var newLine = string.Empty; if (i != pushEvent.Commits.Count - 1) { newLine = Environment.NewLine; } bodyBlocks.Add(new AnchorBlock(shortSha, () => GoToChangeset(repoId, sha))); if (desc != null) { bodyBlocks.Add(new TextBlock(" - " + desc + newLine)); } } } } else if (eventModel.PayloadObject is EventModel.TeamAddEvent) { var teamAddEvent = (EventModel.TeamAddEvent)eventModel.PayloadObject; headerBlocks.Add(new TextBlock(" added ")); if (teamAddEvent.User != null) { headerBlocks.Add(new AnchorBlock(teamAddEvent.User.Login, () => GoToUser(teamAddEvent.User.Login))); } else if (teamAddEvent.Repo != null) { headerBlocks.Add(CreateRepositoryTextBlock(new EventModel.RepoModel { Id = teamAddEvent.Repo.Id, Name = teamAddEvent.Repo.FullName, Url = teamAddEvent.Repo.Url })); } else { return(null); } if (teamAddEvent.Team != null) { headerBlocks.Add(new TextBlock(" to team ")); headerBlocks.Add(new AnchorBlock(teamAddEvent.Team.Name, () => { })); } } else if (eventModel.PayloadObject is EventModel.WatchEvent) { var watchEvent = (EventModel.WatchEvent)eventModel.PayloadObject; eventAction = () => GoToRepository(eventModel.Repo); headerBlocks.Add(watchEvent.Action.Equals("started") ? new TextBlock(" starred ") : new TextBlock(" unstarred ")); headerBlocks.Add(CreateRepositoryTextBlock(eventModel.Repo)); } else if (eventModel.PayloadObject is EventModel.ReleaseEvent) { var releaseEvent = (EventModel.ReleaseEvent)eventModel.PayloadObject; eventAction = () => GoToUrl(releaseEvent.Release.HtmlUrl); headerBlocks.Add(new TextBlock(" " + releaseEvent.Action + " release " + releaseEvent.Release.Name)); } var vm = new EventItemViewModel(eventModel, headerBlocks, bodyBlocks); eventAction.Do(x => vm.GoToCommand.Subscribe(_ => x())); return(vm); }