/// <summary>
        /// Generates the message displayed in HipChat when the Integration is Successful.
        /// </summary>
        /// <param name="result">The <see cref="IIntegrationResult"/>.</param>
        /// <returns>The message to be sent to HipChat when the Integration is Successful.</returns>
        internal static SendNotification IntegrationSuccessfulMessage(IIntegrationResult result)
        {
            SendNotification successMessage =
                new SendNotification()
                {
                    Color = MessageColor.Green,
                    Message = string.Format("<b>[SUCCESSFUL]</b> {0}", result.ProjectName),
                    Notify = true
                };

            return successMessage;
        }
        /// <summary>
        /// Generates the message displayed in HipChat when the Integration is Fixed.
        /// </summary>
        /// <param name="result">The <see cref="IIntegrationResult"/>.</param>
        /// <returns>The message to be sent to HipChat when the Integration is Fixed.</returns>
        internal static SendNotification IntegrationFixedMessage(IIntegrationResult result)
        {
            SendNotification fixedMessage =
                new SendNotification()
                {
                    Color = MessageColor.Green,
                    Message = string.Format("<b>[FIXED]</b> {0}", result.ProjectName),
                    Notify = true
                };

            return fixedMessage;
        }
Пример #3
0
    /// <summary>
    /// Send room notification
    /// </summary>
    /// <param name="room">The room.</param>
    /// <param name="message">The message.</param>
    /// <param name="notifyRoom">if set to <c>true</c> [notify room].</param>
    /// <param name="format">The format.</param>
    /// <param name="color">The color.</param>
    /// <returns>Task&lt;IResponse&lt;System.Boolean&gt;&gt;.</returns>
    public async Task<IResponse<bool>> SendNotificationAsync(string room, string message, bool notifyRoom = true, MessageFormat format = MessageFormat.Html, MessageColor color = MessageColor.Gray)
    {    
      var notification = new SendNotification
      {
        Color = color,
        Message = message,
        Notify = notifyRoom,
        Format = format
      };

      return await SendNotificationAsync(room, notification);
    }
        /// <summary>
        /// Generates the message displayed in HipChat when the Integration fails.
        /// </summary>
        /// <param name="result">The <see cref="IIntegrationResult"/>.</param>
        /// <returns>The message to be sent to HipChat when the Integration fails.</returns>
        internal static SendNotification IntegrationFailedMessage(IIntegrationResult result)
        {
            // Append @ for Mentions, Currently this is broken, but a message is out to
            // HipChat Support to see if we can get support for this when using an HTML
            IEnumerable<string> mentions =
                result.FailureUsers.ToArray().Select(failureUser => "@" + failureUser);
            string failureUsers = string.Join(",", mentions);

            SendNotification failedMessage =
                new SendNotification()
                {
                    Color = MessageColor.Red,
                    Message = string.Format("<b>[FAILED]</b> {0} <a href=\"{1}\">Build Log</a>. Breakers: {2}", result.ProjectName, result.ProjectUrl, failureUsers),
                    Notify = true
                };

            return failedMessage;
        }
Пример #5
0
    /// <summary>
    /// Send room notification.
    /// </summary>
    /// <param name="room">The room.</param>
    /// <param name="notification">The notification.</param>
    /// <returns>Task&lt;IResponse&lt;System.Boolean&gt;&gt;.</returns>
    public async Task<IResponse<bool>> SendNotificationAsync(string room, SendNotification notification)
    {
      Validate.NotNull(notification, "SendNotification argument");
      Validate.Length(notification.Message, 10000, "Notification Message");

      var json = JsonConvert.SerializeObject(notification, Formatting.None, _jsonSettings);

      var payload = new StringContent(json, Encoding.UTF8, "application/json");

      var result = await ApiConnection.Client.PostAsync(string.Format("room/{0}/notification", room), payload);
      var content = await result.Content.ReadAsStringAsync();
      var response = new Response<bool>(true)
      {
        Code = result.StatusCode,
        Body = content,
        ContentType = result.Content.Headers.ContentType.MediaType
      };
      return response;
    }