Skip to content

Commit

Permalink
Merge pull request majkinetor#155 from AdmiringWorm/gitter-plugin
Browse files Browse the repository at this point in the history
Gitter plugin for displaying update status
  • Loading branch information
majkinetor authored Jun 14, 2018
2 parents 0f0c0ad + d500814 commit 3cb8227
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
44 changes: 44 additions & 0 deletions AU/Plugins/Gitter.ps1
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"
17 changes: 17 additions & 0 deletions Plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ To set up plugin to create gist under your user name you need to give it your gi

* It is recommended to add the following line `skip_tags: true` in the `appveyor.yml` file to prevent tags from being built. While it may not be necessary, this is used to prevent packages from being submitted again when `[AU]` or `[PUSH]` is being used in the commit header message.

## [Gitter](https://github.com/majkinetor/au/blob/master/AU/Plugins/Gitter.ps1)

**Setup project to submit gitter status**

* First of all, navigate to the gitter channel you wish to have the status listed (you'll need to have permission to add integrations, and need to do it through the webpage).
1. Click on the icon for room settings, then select `Integrations`.
2. Select a `Custom` Integration
3. Copy the unique webhook url listed in the dialog.
4. Navigate to the `update_all.ps1` file in your repository, and update the `$Options` hashtable with the following
```powershell
Gitter = @{
WebHookUrl = $env:gitter_webhook
}
```
5. Update your appveyor environment variable with your unique webhook, and set the name to `gitter_webhook`.
6. Enjoy your status updates, or frown on failures.
## [History](https://github.com/majkinetor/au/blob/master/AU/Plugins/History.ps1)
**Create update history as markdown report using git log**.
Expand Down

0 comments on commit 3cb8227

Please sign in to comment.