void ShowMergeRequestNotification(BranchViewModel branchViewModel, MergeRequestHookClient hook) { var mergeStatus = hook.Attributes.State; if (mergeStatus == MergerRequestState.merged) { string message = $"Merge request {hook.Attributes.Title} for branch {hook.Attributes.SourceBranch} was merged."; var notification = NotificationService.CreatePredefinedNotification(message, null, null, null); var task = notification.ShowAsync(); task.ContinueWith(x => PerformClick(x.Result)); return; } if (mergeStatus == MergerRequestState.closed) { string message = $"Merge request {hook.Attributes.Title} for branch {hook.Attributes.SourceBranch} was closed."; var notification = NotificationService.CreatePredefinedNotification(message, null, null, null); var task = notification.ShowAsync(); task.ContinueWith(x => PerformClick(x.Result)); return; } if (branchViewModel.MergeRequest.AssigneeId != hook.Attributes.AssigneeId) { string message = $"Assignee for merge request {hook.Attributes.Title} for branch {hook.Attributes.SourceBranch} was changed."; var notification = NotificationService.CreatePredefinedNotification(message, null, null, null); var task = notification.ShowAsync(); task.ContinueWith(x => PerformClick(x.Result)); return; } }
void ProcessMergeRequestHook(MergeRequestHookClient hook) { if (Repositories == null) { return; } int mergeRequestId = hook.Attributes.Id; var selectedBranch = Repositories.SelectedBranch; if (selectedBranch != null) { var mergeRequest = selectedBranch.MergeRequest; if (mergeRequest != null) { if (mergeRequest.MergeRequestId == mergeRequestId) { selectedBranch.RefreshMergeRequest(); RepositoriesViewModel.RaiseRefreshSelectedBranch(); Log.Message("Selected branch refreshed."); } } } if (Repositories.Repositories == null) { return; } foreach (var repo in Repositories.Repositories) { var branch = repo.Branches.Where(x => x.MergeRequest != null).FirstOrDefault(x => x.MergeRequest.MergeRequestId == mergeRequestId); if (branch != null) { ShowMergeRequestNotification(branch, hook); } break; } }