forked from majkinetor/au
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request majkinetor#155 from AdmiringWorm/gitter-plugin
Gitter plugin for displaying update status
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Author: Kim Nordmo <kim.nordmo@gmail.com> | ||
# Last Change: 2018-06-13 | ||
<# | ||
.SYNOPSIS | ||
Publishes the package update status to gitter. | ||
.PARAMETER WebHookUrl | ||
This is the cusotm webhook url created through gitter integrations. | ||
.PARAMETER MessageFormat | ||
The format of the message that is meant to be published on gitter. | ||
{0} = The total number of automated packages. | ||
{1} = The number of updated packages, | ||
{2} = The number of published packages. | ||
{3} = The number of failed packages. | ||
{4} = The url to the github gist. | ||
#> | ||
param( | ||
$Info, | ||
[string]$WebHookUrl, | ||
[string]$MessageFormat = "[Update Status:{0} packages.`n {1} updated, {2} Published, {3} Failed]({4})" | ||
) | ||
|
||
if (!$WebHookUrl) { return } # If we don't have a webhookurl we can't push status messages, so ignore. | ||
|
||
$updatedPackages = @($Info.result.updated).Count | ||
$publishedPackages = @($Info.result.pushed).Count | ||
$failedPackages = $Info.error_count.total | ||
$gistUrl = $Info.plugin_results.Gist -split '\n' | select -Last 1 | ||
$packageCount = $Info.result.all.Length | ||
|
||
$gitterMessage = ($MessageFormat = -f $packageCount, $updatedPackages, $publishedPackages, $failedPackages, $gistUrl) | ||
|
||
$arguments = @{ | ||
Body = if ($failedPackages -gt 0) { "message=$gitterMessage&level=error" } else { "message=$gitterMessage" } | ||
UseBasicParsing = $true | ||
Uri = $WebHookUrl | ||
ContentType = 'application/x-www-form-urlencoded' | ||
Method = 'Post' | ||
} | ||
|
||
"Submitting message to gitter" | ||
Invoke-RestMethod @arguments | ||
"Message submitted to gitter" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters