Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

A powershell version of the SVN post-commit handler #16

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ services-examples
Examples of third-party integration scripts for [Slack](https://slack.com/)

* [Nagios](https://github.com/tinyspeck/services-examples/blob/master/nagios.pl)
* [SVN](https://github.com/tinyspeck/services-examples/blob/master/subversion.pl)
* [SVN (perl)](https://github.com/tinyspeck/services-examples/blob/master/subversion.pl)
* [SVN (powershell)](https://github.com/matteosp/services-examples/blob/master/subversion.ps1)

[slack_room_message.pl](/slack_room_message.pl) is a simple wrapper for use from the command line, with
minimal dependencies. Use it like so:
Expand Down
43 changes: 43 additions & 0 deletions subversion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Requires Powershell 3.0
#
# An SVN post-commit handler for posting to Slack. Setup the channel and get the token
# from your team's services page. Change the options below to reflect your team's settings.

Param(
[string]$svnPath,
[string]$revision,
[string]$repoName
)

$domain = "YOUR_DOMAIN.slack.com"
$token = "TOKEN"
$endpoint = "https://${domain}/services/hooks/subversion?token=${token}"
#$revisionUrlBase = "WEB_VIEW_BASE URL" #if any

$log = (svnlook log -r $revision $svnPath)
$who = (svnlook author -r $revision $svnPath)
$changes = (svnlook changed -r $revision $svnPath)
$changes = [string]::Join("`r`n", $changes) # $changes was an array of strings

$payload = @{
attachments = @(@{
pretext = "Commit completed: $repoName rev. $revision"
text = "Message: $log"
fallback = "Commit completed: $repoName rev. $revision"
title = "Commit details"
# title_link = "$revisionUrlBase$revision"
color = '#439FE0'
fields = @(@{
title = "Changes"
value = $changes
short = $false
}, @{
title = "Author"
value = $who
short = $true
})
})
}

$json = (ConvertTo-Json $payload -Depth 99)
Invoke-RestMethod -Uri $endpoint -Method Post -ContentType "application/json" -Body $json