-
Notifications
You must be signed in to change notification settings - Fork 0
/
post2discord.ps1
44 lines (42 loc) · 1.34 KB
/
post2discord.ps1
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
param (
[string]$Source,
[string]$ProjectName,
[string]$DiscordWebhook
)
try
{
$ErrorActionPreference = 'Stop';
$Error.Clear();
$SourcePath = Get-Item -Path $Source;
$GitHubRepoUrl = "https://github.com/$($env:GITHUB_REPOSITORY)"
if (Test-Path -Path $SourcePath)
{
switch ($SourcePath.Extension)
{
".psd1"
{
$Module = Import-PowerShellDataFile -Path $SourcePath
$Version = $Module.ModuleVersion
$PowerShellGalleryUrl = "https://www.powershellgallery.com/packages/$($ProjectName)"
$DiscordMessage = @{
content = "Version $Version of $($ProjectName) released. Please visit Github ($($GitHubRepoUrl)) or PowerShellGallery.com ($($PowerShellGalleryUrl)) to download."
}
}
".csproj"
{
$Project = [xml](Get-Content -Path $SourcePath);
$Version = $Project.Project.PropertyGroup.Version.ToString();
$PackageId = $Project.Project.PropertyGroup.PackageId;
$NugetUrl = "https://nuget.org/packages/$PackageId"
$DiscordMessage = @{
content = "Version $Version of $($ProjectName) released. Please visit Github ($($GitHubRepoUrl)) or Nuget.org ($($NugetUrl)) to download."
}
}
}
Invoke-RestMethod -Uri $DiscordWebhook -Body ($DiscordMessage | ConvertTo-Json -Compress) -Method Post -ContentType 'application/json; charset=UTF-8'
}
}
catch
{
Write-Host "Error occurred: $($_.Exception.Message)"
}