Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HipChat notification helper #523

Merged
merged 1 commit into from
Aug 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion help/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ Some of our users are:
* [FundApps](http://www.fundapps.co)
* [Road Ranger, LLC](http://www.roadrangerusa.com)
* [CHECK24 Vergleichsportal GmbH](http://www.check24.de)

* [Olo](http://www.olo.com)
2 changes: 2 additions & 0 deletions src/app/FakeLib/FakeLib.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
<Compile Include="ReportGeneratorHelper.fs" />
<Compile Include="RoundhouseHelper.fs" />
<Compile Include="FscHelper.fs" />
<Compile Include="HipChatNotificationHelper.fs" />
<None Include="app.config" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -186,6 +187,7 @@
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
</ItemGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
Expand Down
66 changes: 66 additions & 0 deletions src/app/FakeLib/HipChatNotificationHelper.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/// Contains a task to send notification messages to a [HipChat](https://www.hipchat.com/) room
module Fake.HipChatNotificationHelper

open System
open System.Web
open Fake

/// The HipChat notification paramater type
type HipChatNotificationParams = {
/// (Required) Auth token from HipChat
AuthToken: string
/// (Required) ID or name of the room to send the notification to
RoomId: string
/// (Required) Name the message will appear to be sent from
From: string
/// (Required) The message body
Message: string
/// The message format, which can either be text or html. Default value: text
MessageFormat: string
/// Whether or not this message should trigger a notification for people in the room. Default value: false
Notify: bool
/// The background color for the message, which can be yellow, red, green, purple, gray, or random. Default value: yellow
Color: string
}

/// The default HipChat notification parameters
let HipChatNotificationDefaults = {
AuthToken = ""
RoomId = ""
From = ""
Message = ""
MessageFormat = "text"
Notify = false
Color = "yellow"
}

/// [omit]
let validateParams param =
if param.AuthToken = "" then failwith "You must provide your auth token"
if param.RoomId = "" then failwith "You must specify which room to notify"
if param.From = "" then failwith "You must specify the name to send the message from"
if param.Message = "" then failwith "You must provide a message to send"

param

/// Sends a notification to a HipChat room
/// ## Parameters
/// - `setParams` - Function used to override the default notification parameters
let HipChatNotification (setParams: HipChatNotificationParams -> HipChatNotificationParams) =
let sendNotification param =
["room_id", param.RoomId
"from", param.From
"message", param.Message
"message_format", param.MessageFormat
"notify", Convert.ToInt32(param.Notify).ToString()
"color", param.Color
"format", "json"]
|> List.map(fun (key, value) -> key + "=" + HttpUtility.UrlEncode(value))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the only reason to reference System.Web, could you use Uri.EscapeDataString() instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point, that should work too. Are there plans to update FAKE to .NET 4.5? If so, WebUtility.UrlEncode() would work as well.

|> String.concat "&"
|> fun curlData -> String.Format("-s -d {0} https://api.hipchat.com/v1/rooms/message?auth_token={1}&format=json", curlData, param.AuthToken)
|> fun curlArgs -> Shell.Exec("curl", curlArgs)

HipChatNotificationDefaults
|> setParams
|> validateParams
|> sendNotification