protected override IEnumerable <Notifications.INotification> CreateNotifications(TeamFoundationRequestContext requestContext, StatusUpdateNotification ev, int maxLines) { var repositoryService = requestContext.GetService <TeamFoundationGitRepositoryService>(); var identityService = requestContext.GetService <ITeamFoundationIdentityService>(); var commonService = requestContext.GetService <ICommonStructureService>(); var identity = identityService.ReadIdentity(requestContext, IdentitySearchFactor.Identifier, ev.Updater.Identifier); using (TfsGitRepository repository = repositoryService.FindRepositoryById(requestContext, ev.RepositoryId)) { var pullRequestService = requestContext.GetService <ITeamFoundationGitPullRequestService>(); TfsGitPullRequest pullRequest; if (pullRequestService.TryGetPullRequestDetails(requestContext, repository, ev.PullRequestId, out pullRequest)) { string repoUri = repository.GetRepositoryUri(requestContext); var creator = identityService.ReadIdentities(requestContext, new[] { pullRequest.Creator }).First(); var reviewers = identityService.ReadIdentities(requestContext, pullRequest.Reviewers.Select(r => r.Reviewer).ToArray()); var notification = new Notifications.PullRequestStatusUpdateNotification() { TeamProjectCollection = requestContext.ServiceHost.Name, CreatorUserName = creator.UniqueName, Status = ev.Status, UniqueName = identity.UniqueName, DisplayName = identity.DisplayName, ProjectName = commonService.GetProject(requestContext, ev.TeamProjectUri).Name, RepoUri = repoUri, RepoName = ev.RepositoryName, PrId = pullRequest.PullRequestId, PrUrl = string.Format("{0}/pullrequest/{1}#view=discussion", repoUri, ev.PullRequestId), PrTitle = pullRequest.Title, TeamNames = GetUserTeamsByProjectUri(requestContext, ev.TeamProjectUri, ev.Updater), SourceBranch = new Notifications.GitRef(pullRequest.SourceBranchName), TargetBranch = new Notifications.GitRef(pullRequest.TargetBranchName), ReviewerUserNames = reviewers.Select(r => r.UniqueName) }; yield return(notification); } else { throw new TfsNotificationRelayException("Unable to get pull request " + ev.PullRequestId); } } }
protected override Notifications.INotification CreateNotification(TeamFoundationRequestContext requestContext, StatusUpdateNotification ev, int maxLines) { var repositoryService = requestContext.GetService <TeamFoundationGitRepositoryService>(); var identityService = requestContext.GetService <ITeamFoundationIdentityService>(); var commonService = requestContext.GetService <ICommonStructureService>(); var identity = identityService.ReadIdentity(requestContext, IdentitySearchFactor.Identifier, ev.Updater.Identifier); using (TfsGitRepository repository = repositoryService.FindRepositoryById(requestContext, ev.RepositoryId)) { var pullRequestService = requestContext.GetService <ITeamFoundationGitPullRequestService>(); TfsGitPullRequest pullRequest; if (pullRequestService.TryGetPullRequestDetails(requestContext, repository, ev.PullRequestId, out pullRequest)) { string repoUri = repository.GetRepositoryUri(requestContext); var notification = new Notifications.PullRequestStatusUpdateNotification() { TeamProjectCollection = requestContext.ServiceHost.Name, Status = ev.Status, UniqueName = identity.UniqueName, DisplayName = identity.DisplayName, ProjectName = commonService.GetProject(requestContext, ev.TeamProjectUri).Name, RepoUri = repoUri, RepoName = ev.RepositoryName, PrId = pullRequest.PullRequestId, PrUrl = string.Format("{0}/pullrequest/{1}#view=discussion", repoUri, ev.PullRequestId), PrTitle = pullRequest.Title }; return(notification); } else { throw new TfsNotificationRelayException("Unable to get pull request " + ev.PullRequestId); } } }