private static UIImage ChooseImage(EventModel eventModel) { switch (eventModel.Event) { case EventModel.Type.ForkRepo: return Images.Fork; case EventModel.Type.CreateRepo: return Images.Repo; case EventModel.Type.Commit: case EventModel.Type.Pushed: case EventModel.Type.PullRequestFulfilled: return Images.Commit; case EventModel.Type.WikiUpdated: case EventModel.Type.WikiCreated: case EventModel.Type.PullRequestUpdated: return Images.Pencil; case EventModel.Type.WikiDeleted: case EventModel.Type.DeleteRepo: return Images.BinClosed; case EventModel.Type.StartFollowUser: case EventModel.Type.StartFollowRepo: case EventModel.Type.StopFollowRepo: case EventModel.Type.StartFollowIssue: case EventModel.Type.StopFollowIssue: return Images.Following; case EventModel.Type.IssueComment: case EventModel.Type.ChangeSetCommentCreated: case EventModel.Type.ChangeSetCommentDeleted: case EventModel.Type.ChangeSetCommentUpdated: case EventModel.Type.PullRequestCommentCreated: case EventModel.Type.PullRequestCommentUpdated: case EventModel.Type.PullRequestCommentDeleted: return Images.Comments; case EventModel.Type.IssueUpdated: case EventModel.Type.IssueReported: return Images.Flag; case EventModel.Type.ChangeSetLike: case EventModel.Type.PullRequestLike: return Images.Accept; case EventModel.Type.PullRequestUnlike: case EventModel.Type.PullRequestRejected: case EventModel.Type.ChangeSetUnlike: return Images.Cancel; case EventModel.Type.PullRequestCreated: case EventModel.Type.PullRequestSuperseded: return Images.Hand; } return Images.Priority; }
private static UIImage ChooseImage(EventModel eventModel) { switch (eventModel.Event) { case EventModel.Type.ForkRepo: return AtlassianIcon.Devtoolsrepositoryforked.ToImage(); case EventModel.Type.CreateRepo: return AtlassianIcon.Devtoolsrepository.ToImage(); case EventModel.Type.Commit: case EventModel.Type.Pushed: case EventModel.Type.PullRequestFulfilled: return AtlassianIcon.Devtoolscommit.ToImage(); case EventModel.Type.WikiUpdated: case EventModel.Type.WikiCreated: case EventModel.Type.PullRequestUpdated: return AtlassianIcon.Edit.ToImage(); case EventModel.Type.WikiDeleted: case EventModel.Type.DeleteRepo: return AtlassianIcon.Delete.ToImage(); case EventModel.Type.StartFollowUser: case EventModel.Type.StartFollowRepo: case EventModel.Type.StopFollowRepo: case EventModel.Type.StartFollowIssue: case EventModel.Type.StopFollowIssue: return AtlassianIcon.Star.ToImage(); case EventModel.Type.IssueComment: case EventModel.Type.ChangeSetCommentCreated: case EventModel.Type.ChangeSetCommentDeleted: case EventModel.Type.ChangeSetCommentUpdated: case EventModel.Type.PullRequestCommentCreated: case EventModel.Type.PullRequestCommentUpdated: case EventModel.Type.PullRequestCommentDeleted: return AtlassianIcon.Comment.ToImage(); case EventModel.Type.IssueUpdated: case EventModel.Type.IssueReported: return AtlassianIcon.Flag.ToImage(); case EventModel.Type.ChangeSetLike: case EventModel.Type.PullRequestLike: return AtlassianIcon.Like.ToImage(); case EventModel.Type.PullRequestUnlike: case EventModel.Type.PullRequestRejected: case EventModel.Type.ChangeSetUnlike: return AtlassianIcon.Like.ToImage(); case EventModel.Type.PullRequestCreated: case EventModel.Type.PullRequestSuperseded: return AtlassianIcon.Devtoolspullrequest.ToImage(); } return AtlassianIcon.Info.ToImage(); }
private TextBlock CommitBlock(EventModel e) { var node = e.Node; if (string.IsNullOrEmpty(node)) return null; node = node.Substring(0, node.Length > 6 ? 6 : node.Length); return new AnchorBlock(node, () => GoToChangeset(e.Repository.Owner, e.Repository.Slug, e.Node)); }
private EventBlock CreateEventTextBlocks(EventModel eventModel) { var eventBlock = new EventBlock(); var username = eventModel.User != null ? eventModel.User.Username : null; // Insert the actor eventBlock.Header.Add(new AnchorBlock(username, () => GoToUser(username))); if (eventModel.Event == EventModel.Type.Pushed) { if (eventModel.Repository == null) return null; var data = GetService<CodeFramework.Core.Services.IJsonSerializationService>().Deserialize<PushedEventDescriptionModel>(eventModel.Description); if (eventModel.Repository != null) eventBlock.Tapped = () => GoToCommits(eventModel.Repository, null); eventBlock.Header.Add(new TextBlock(" pushed " + data.TotalCommits + " commit" + (data.TotalCommits > 1 ? "s" : string.Empty))); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" to ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository)); } if (data.Commits != null) { foreach (var commit in data.Commits) { var desc = (commit.Description ?? ""); var sha = commit.Hash; var firstNewLine = desc.IndexOf("\n", StringComparison.Ordinal); if (firstNewLine <= 0) firstNewLine = desc.Length; desc = desc.Substring(0, firstNewLine); var shortSha = commit.Hash; if (shortSha.Length > 6) shortSha = shortSha.Substring(0, 6); eventBlock.Body.Add(new AnchorBlock(shortSha, () => GoToChangeset(eventModel.Repository.Owner, eventModel.Repository.Name, sha))); eventBlock.Body.Add(new TextBlock(" - " + desc + "\n")); } } return eventBlock; } if (eventModel.Event == EventModel.Type.Commit) { if (eventModel.Repository == null) return null; var node = eventModel.Node.Substring(0, eventModel.Node.Length > 6 ? 6 : eventModel.Node.Length); eventBlock.Tapped = () => GoToChangeset(eventModel.Repository.Owner, eventModel.Repository.Name, eventModel.Node); eventBlock.Header.Add(new TextBlock(" commited ")); eventBlock.Header.Add(new AnchorBlock(node, eventBlock.Tapped)); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository)); } var desc = string.IsNullOrEmpty(eventModel.Description) ? "" : eventModel.Description.Replace("\n", " ").Trim(); eventBlock.Body.Add(new TextBlock(desc)); } else if (eventModel.Event == EventModel.Type.ChangeSetCommentCreated || eventModel.Event == EventModel.Type.ChangeSetCommentDeleted || eventModel.Event == EventModel.Type.ChangeSetCommentUpdated || eventModel.Event == EventModel.Type.ChangeSetLike || eventModel.Event == EventModel.Type.ChangeSetUnlike) { if (eventModel.Repository == null) return null; eventBlock.Tapped = () => GoToChangeset(eventModel.Repository.Owner, eventModel.Repository.Slug, eventModel.Node); var nodeBlock = CommitBlock(eventModel); if (eventModel.Event == EventModel.Type.ChangeSetCommentCreated) { eventBlock.Header.Add(new TextBlock(" commented on commit ")); } else if (eventModel.Event == EventModel.Type.ChangeSetCommentDeleted) { eventBlock.Header.Add(new TextBlock(" deleted a comment on commit ")); } else if (eventModel.Event == EventModel.Type.ChangeSetCommentUpdated) { eventBlock.Header.Add(new TextBlock(" updated a comment on commit ")); } else if (eventModel.Event == EventModel.Type.ChangeSetLike) { eventBlock.Header.Add(new TextBlock(" approved commit ")); } else if (eventModel.Event == EventModel.Type.ChangeSetUnlike) { eventBlock.Header.Add(new TextBlock(" unapproved commit ")); } eventBlock.Header.Add(nodeBlock); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository)); } } else if (eventModel.Event == EventModel.Type.PullRequestCreated || eventModel.Event == EventModel.Type.PullRequestRejected || eventModel.Event == EventModel.Type.PullRequestSuperseded || eventModel.Event == EventModel.Type.PullRequestUpdated || eventModel.Event == EventModel.Type.PullRequestFulfilled || eventModel.Event == EventModel.Type.PullRequestLike || eventModel.Event == EventModel.Type.PullRequestUnlike) { if (eventModel.Repository == null) return null; eventBlock.Tapped = () => GoToPullRequests(eventModel.Repository); if (eventModel.Event == EventModel.Type.PullRequestCreated) eventBlock.Header.Add(new TextBlock(" created pull request")); else if (eventModel.Event == EventModel.Type.PullRequestRejected) eventBlock.Header.Add(new TextBlock(" rejected pull request")); else if (eventModel.Event == EventModel.Type.PullRequestSuperseded) eventBlock.Header.Add(new TextBlock(" superseded pull request")); else if (eventModel.Event == EventModel.Type.PullRequestFulfilled) eventBlock.Header.Add(new TextBlock(" fulfilled pull request")); else if (eventModel.Event == EventModel.Type.PullRequestUpdated) eventBlock.Header.Add(new TextBlock(" updated pull request")); else if (eventModel.Event == EventModel.Type.PullRequestLike) eventBlock.Header.Add(new TextBlock(" liked pull request")); else if (eventModel.Event == EventModel.Type.PullRequestUnlike) eventBlock.Header.Add(new TextBlock(" unliked pull request")); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository)); } } else if (eventModel.Event == EventModel.Type.PullRequestCommentCreated || eventModel.Event == EventModel.Type.PullRequestCommentUpdated || eventModel.Event == EventModel.Type.PullRequestCommentDeleted) { if (eventModel.Repository == null) return null; eventBlock.Tapped = () => GoToPullRequests(eventModel.Repository); if (eventModel.Event == EventModel.Type.PullRequestCommentCreated) { eventBlock.Header.Add(new TextBlock(" commented on pull request")); } else if (eventModel.Event == EventModel.Type.PullRequestCommentUpdated) { eventBlock.Header.Add(new TextBlock(" updated comment in pull request")); } else if (eventModel.Event == EventModel.Type.PullRequestCommentDeleted) { eventBlock.Header.Add(new TextBlock(" deleted comment in pull request")); } if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository)); } } else if (eventModel.Event == EventModel.Type.IssueComment) { if (eventModel.Repository == null) return null; eventBlock.Header.Add(new TextBlock(" commented on issue")); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository)); } eventBlock.Tapped = () => GoToRepositoryIssues(eventModel.Repository); } else if (eventModel.Event == EventModel.Type.IssueUpdated) { if (eventModel.Repository == null) return null; eventBlock.Header.Add(new TextBlock(" updated issue")); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository)); } eventBlock.Tapped = () => GoToRepositoryIssues(eventModel.Repository); } else if (eventModel.Event == EventModel.Type.IssueReported) { if (eventModel.Repository == null) return null; eventBlock.Header.Add(new TextBlock(" reported issue")); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository)); } eventBlock.Tapped = () => GoToRepositoryIssues(eventModel.Repository); } else if (eventModel.Event == EventModel.Type.StartFollowUser) { eventBlock.Header.Add(new TextBlock(" started following a user")); } else if (eventModel.Event == EventModel.Type.StopFollowUser) { eventBlock.Header.Add(new TextBlock(" stopped following a user")); } else if (eventModel.Event == EventModel.Type.StartFollowIssue) { if (eventModel.Repository == null) return null; eventBlock.Header.Add(new TextBlock(" started following an issue")); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository)); } } else if (eventModel.Event == EventModel.Type.StopFollowIssue) { if (eventModel.Repository == null) return null; eventBlock.Header.Add(new TextBlock(" stopped following an issue")); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository)); } } else if (eventModel.Event == EventModel.Type.StartFollowRepo) { if (eventModel.Repository == null) return null; eventBlock.Header.Add(new TextBlock(" started following ")); if (ReportRepository) eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository)); eventBlock.Tapped = () => GoToRepository(eventModel.Repository); } else if (eventModel.Event == EventModel.Type.StopFollowRepo) { if (eventModel.Repository == null) return null; eventBlock.Header.Add(new TextBlock(" stopped following ")); if (ReportRepository) eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository)); eventBlock.Tapped = () => GoToRepository(eventModel.Repository); } else if (eventModel.Event == EventModel.Type.CreateRepo) { if (eventModel.Repository == null) return null; eventBlock.Header.Add(new TextBlock(" created repository ")); if (ReportRepository) eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository)); eventBlock.Tapped = () => GoToRepository(eventModel.Repository); } else if (eventModel.Event == EventModel.Type.DeleteRepo) { eventBlock.Header.Add(new TextBlock(" deleted a repository")); } else if (eventModel.Event == EventModel.Type.WikiUpdated) { if (eventModel.Repository == null) return null; eventBlock.Tapped = () => GoToRepositoryWiki(eventModel.Repository, eventModel.Description); eventBlock.Header.Add(new TextBlock(" updated wiki page ")); eventBlock.Header.Add(new AnchorBlock(eventModel.Description.TrimStart('/'), () => GoToRepositoryWiki(eventModel.Repository, eventModel.Description))); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository)); } } else if (eventModel.Event == EventModel.Type.WikiCreated) { if (eventModel.Repository == null) return null; eventBlock.Tapped = () => GoToRepositoryWiki(eventModel.Repository, eventModel.Description); eventBlock.Header.Add(new TextBlock(" created wiki page ")); eventBlock.Header.Add(new AnchorBlock(eventModel.Description.TrimStart('/'), () => GoToRepositoryWiki(eventModel.Repository, eventModel.Description))); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository)); } } else if (eventModel.Event == EventModel.Type.WikiDeleted) { if (eventModel.Repository == null) return null; eventBlock.Header.Add(new TextBlock(" deleted wiki page ")); eventBlock.Header.Add(new AnchorBlock(eventModel.Description.TrimStart('/'), () => GoToRepositoryWiki(eventModel.Repository, eventModel.Description))); if (ReportRepository) { eventBlock.Header.Add(new TextBlock(" in ")); eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository)); } } else if (eventModel.Event == EventModel.Type.ForkRepo) { if (eventModel.Repository == null) return null; eventBlock.Header.Add(new TextBlock(" forked ")); eventBlock.Tapped = () => GoToRepository(eventModel.Repository); if (ReportRepository) eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository)); else eventBlock.Header.Add(new TextBlock("this repository")); } else { System.Diagnostics.Debug.WriteLine("No such event handler for " + eventModel.Event); return null; } return eventBlock; }