コード例 #1
0
        /// <summary>
        /// Called when the user checks in a changeset. Posts a summary of
        /// the most recent check-in to Slack based on user preferences.
        /// </summary>
        async void VersionControlServer_CommitCheckin(object sender, CommitCheckinEventArgs e)
        {
            // Only post to Slack if user specified we should post to Slack.
            if (!m_viewModel.PostToSlack)
            {
                return;
            }

            IPendingChangesExt pendingChanges = GetService <IPendingChangesExt>();
            var hyperlinkService = GetService <ITeamFoundationContextManager>()
                                   .CurrentContext.TeamProjectCollection
                                   .GetService <TswaClientHyperlinkService>();

            try
            {
                await SlackServiceAdapter.PostToSlack(requestUri : m_viewModel.WebhookUrl,
                                                      channelName : m_viewModel.Channel,
                                                      userName : e.Workspace.OwnerDisplayName,
                                                      changesetID : e.ChangesetId.ToString(),
                                                      fileChangedCount : pendingChanges.IncludedChanges.Length,
                                                      changesetComment : pendingChanges.CheckinComment,
                                                      changesetUrl : hyperlinkService.GetChangesetDetailsUrl(e.ChangesetId).ToString());

                m_viewModel.NotificationMessage = string.Format("Successfully posted changeset {0} to Slack.", e.ChangesetId);
            }
            catch (WebException ex)
            {
                m_viewModel.NotificationMessage = ex.ToString();
            }
            catch
            {
                m_viewModel.NotificationMessage = "Error posting to Slack. The check-in still occurred. Look for an issue with your Post Check-In to Slack parameters before checking in again.";
            }
        }
コード例 #2
0
        async void vcServer_CommitCheckin(object sender, CommitCheckinEventArgs e)
        {
            // Only post to Slack if user specified we should post to Slack.
            if (!m_viewModel.PostToSlack)
            {
                return;
            }

            IPendingChangesExt pendingChanges = GetService <IPendingChangesExt>();
            var hyperlinkService = GetService <ITeamFoundationContextManager>()
                                   .CurrentContext.TeamProjectCollection
                                   .GetService <TswaClientHyperlinkService>();

            try
            {
                var response = await SlackServiceAdapter.PostToSlack(requestUri : m_viewModel.WebhookUrl,
                                                                     channelName : m_viewModel.Channel,
                                                                     userName : e.Workspace.OwnerDisplayName,
                                                                     changesetID : e.ChangesetId.ToString(),
                                                                     fileChangedCount : pendingChanges.IncludedChanges.Length,
                                                                     changesetComment : pendingChanges.CheckinComment,
                                                                     changesetUrl : hyperlinkService.GetChangesetDetailsUrl(e.ChangesetId).ToString());

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    ShowNotification("Successfully posted check-in message to Slack.", NotificationType.Information);
                }
                else
                {
                    var errorMessage = "Error posting to Slack:\n" + response.StatusCode +
                                       " - " + await response.Content.ReadAsStringAsync();

                    ShowNotification(errorMessage, NotificationType.Error);
                }
            }
            catch
            {
                // FIXME: For some reason, ShowErrorNotification doesn't work in the context of this catch block.
                var errorMessage = "Error posting to Slack. The check-in still occurred. Look for an issue with your Post Check-In to Slack parameters before checking in again.";
                ShowNotification(errorMessage, NotificationType.Error);
            }
        }