From c1ef308945e1812184456a9fa470221498227572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vidar=20L=2E=20S=C3=B8mme?= Date: Mon, 8 Jun 2015 11:41:01 +0200 Subject: [PATCH 1/2] Raygun deployment helper --- src/app/FakeLib/FakeLib.fsproj | 1 + src/app/FakeLib/RaygunHelper.fs | 109 ++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 src/app/FakeLib/RaygunHelper.fs diff --git a/src/app/FakeLib/FakeLib.fsproj b/src/app/FakeLib/FakeLib.fsproj index d59531768d1..461a89f45b3 100644 --- a/src/app/FakeLib/FakeLib.fsproj +++ b/src/app/FakeLib/FakeLib.fsproj @@ -160,6 +160,7 @@ + diff --git a/src/app/FakeLib/RaygunHelper.fs b/src/app/FakeLib/RaygunHelper.fs new file mode 100644 index 00000000000..7361a7f831d --- /dev/null +++ b/src/app/FakeLib/RaygunHelper.fs @@ -0,0 +1,109 @@ +/// Enables deployment tracking using Raygun.io +/// +/// Thin wrapper around [the Raygun HTTP deployment API](https://raygun.io/docs/deployments/api) +module Fake.RaygunHelper + +open Fake +open Fake.Git +open Newtonsoft.Json +open System.Net + +/// Data describing a deployment to Raygun +type RaygunDeploymentData = + { + /// Application API key + /// Required, no sensible default + apiKey: string + + /// Version string describing deployed version + /// Should be the same as reported by the application + /// to raygun when posting an error + /// Required, no sensible default + version : string + + /// Name of person responsible for deployment + /// Optional, defaults to empty string + ownerName : string + + /// Email address of person responsible for deployment + /// Optional, defaults to empty string + emailAddress : string + + /// Release notes + /// Optional, defaults to empty string + comment: string + + /// Hash code (or other commit identifier) from + /// source control system + /// Optional, Defaults to current git hash if executed from a git repository + /// else defaults to empty string + scmIdentifier : string + + /// Datetime of the deployment + /// Optional, Defaults to System.DateTime.UtcNow + createdAt: System.DateTime + } + +/// Connection configuration +type RaygunConnectionSettings = + { + /// Endpoint to connect to + /// Required, Defaults to: https://app.raygun.io/deployments + endPoint : string + + /// Raygun user access token for allowing API + /// access. (Creatd under User -> My settings in the web application) + /// Required, no sensible default + externalToken: string + } + +let private gitHash = + try + getCurrentHash() + with + | _ -> "" + +let private endPoint = @"https://app.raygun.io/deployments" + +let private defaultData = + { + apiKey = "" + version = "" + ownerName = "" + emailAddress = "" + comment = "" + scmIdentifier = gitHash + createdAt = System.DateTime.UtcNow + } + +let private defaultSettings = + { + endPoint = @"https://app.raygun.io/deployments" + externalToken = "" + } + +let private createQueryStringCollection token = + let collection = (new System.Collections.Specialized.NameValueCollection()) + collection.Add("authToken", token) + collection + +let private serialize data = JsonConvert.SerializeObject(data) + +/// ### Report a deployment to raygun +/// +/// Reports a deployment to raygun so reported errors can be +/// correlated with deployments +/// +/// ### Paramteres +/// +/// * settings : Function that sets the raygun connection settings. +/// * data : Function that sets the deployment data +let reportDeployment (settings:RaygunConnectionSettings->RaygunConnectionSettings) (data:RaygunDeploymentData->RaygunDeploymentData) = + traceStartTask "Raygun.io" "Report new deployment" + let settings = defaultSettings |> settings + let data = defaultData |> data + use client = (new WebClient()) + client.Headers.Add(HttpRequestHeader.ContentType, "application/json") + client.QueryString <- createQueryStringCollection settings.externalToken + client.UploadString(settings.endPoint,"POST", (serialize data)) |> ignore + traceEndTask "Raygun.io" "Report new deployment" From 1648c4cbb61e0d5bb8f43f33dd00fa84714f3c75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vidar=20L=2E=20S=C3=B8mme?= Date: Mon, 8 Jun 2015 14:53:06 +0200 Subject: [PATCH 2/2] Fix casing of main task --- src/app/FakeLib/RaygunHelper.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/FakeLib/RaygunHelper.fs b/src/app/FakeLib/RaygunHelper.fs index 7361a7f831d..7fc926f7b30 100644 --- a/src/app/FakeLib/RaygunHelper.fs +++ b/src/app/FakeLib/RaygunHelper.fs @@ -98,7 +98,7 @@ let private serialize data = JsonConvert.SerializeObject(data) /// /// * settings : Function that sets the raygun connection settings. /// * data : Function that sets the deployment data -let reportDeployment (settings:RaygunConnectionSettings->RaygunConnectionSettings) (data:RaygunDeploymentData->RaygunDeploymentData) = +let ReportDeployment (settings:RaygunConnectionSettings->RaygunConnectionSettings) (data:RaygunDeploymentData->RaygunDeploymentData) = traceStartTask "Raygun.io" "Report new deployment" let settings = defaultSettings |> settings let data = defaultData |> data