-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotification-helper.fsx
59 lines (52 loc) · 1.74 KB
/
notification-helper.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
open System.Net.Http
open System.Text
open System.Text.Json
type Message =
{
content: string
username: string
avatar_url: string
tts: bool
embeds: MessageEmbed []
}
and MessageEmbed =
{
color: System.Nullable<int>
title: string
url: string
description: string
}
let hookurl = System.Environment.GetEnvironmentVariable "DISCORD_PACKAGE_FEED"
let packages =
System.IO.Directory.EnumerateFiles("./localnuget")
|> Seq.map (fun f ->
let file = System.IO.FileInfo(f)
let filename = file.Name.Replace(".nupkg", "")
let splitByDots = filename.Split([|'.'|])
let len = splitByDots.Length
let name = splitByDots[0..len-5] |> String.concat "."
let version = splitByDots[len-4..] |> String.concat "."
sprintf "- %s %s [[ link ]](<https://github.com/dotnet-websharper/core/pkgs/nuget/%s>)" name version name
)
|> String.concat "\n"
let client = new HttpClient()
let message: Message =
{
content = sprintf "## Released to GitHub:\n%s" packages
username = "IntelliFactory CI"
avatar_url = "https://raw.githubusercontent.com/dotnet-websharper/core/refs/heads/master/tools/WebSharper.png"
tts = false
embeds = [||]
}
async {
let serializedMessage = JsonSerializer.Serialize message
printfn "%s" serializedMessage
use content = new StringContent(serializedMessage, Encoding.UTF8, "application/json")
let! response = client.PostAsync(hookurl, content) |> Async.AwaitTask
if response.IsSuccessStatusCode then
()
else
let! res = response.Content.ReadAsStringAsync() |> Async.AwaitTask
printfn "%A" res
return ()
} |> Async.RunSynchronously