From ec855291d80b572d2f0205bc114c0f4df7034edf Mon Sep 17 00:00:00 2001 From: dimqua Date: Thu, 11 Oct 2018 19:17:31 +0300 Subject: [PATCH] add Snippet plugin --- AU/Plugins/Git.ps1 | 8 ++++--- AU/Plugins/Snippet.ps1 | 48 ++++++++++++++++++++++++++++++++++++++++++ CHANGELOG.md | 1 + Plugins.md | 13 +++++++++++- 4 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 AU/Plugins/Snippet.ps1 diff --git a/AU/Plugins/Git.ps1 b/AU/Plugins/Git.ps1 index b41cacc7..1e3919f0 100644 --- a/AU/Plugins/Git.ps1 +++ b/AU/Plugins/Git.ps1 @@ -62,8 +62,9 @@ if ($commitStrategy -like 'atomic*') { Write-Host "Commiting $($_.Name)" $message = "AU: $($_.Name) upgraded from $($_.NuspecVersion) to $($_.RemoteVersion)" $gist_url = $Info.plugin_results.Gist -split '\n' | select -Last 1 - git commit -m "$message`n[skip ci] $gist_url" --allow-empty - + $snippet_url = $Info.plugin_results.Snippet -split '\n' | select -Last 1 + git commit -m "$message`n[skip ci] $gist_url $snippet_url" --allow-empty + if ($commitStrategy -eq 'atomictag') { $tagcmd = "git tag -a $($_.Name)-$($_.RemoteVersion) -m '$($_.Name)-$($_.RemoteVersion)'" Invoke-Expression $tagcmd @@ -78,7 +79,8 @@ else { Write-Host "Commiting" $message = "AU: $($packages.Length) updated - $($packages | % Name)" $gist_url = $Info.plugin_results.Gist -split '\n' | select -Last 1 - git commit -m "$message`n[skip ci] $gist_url" --allow-empty + $snippet_url = $Info.plugin_results.Snippet -split '\n' | select -Last 1 + git commit -m "$message`n[skip ci] $gist_url $snippet_url" --allow-empty } Write-Host "Pushing changes" diff --git a/AU/Plugins/Snippet.ps1 b/AU/Plugins/Snippet.ps1 new file mode 100644 index 00000000..cbbd184b --- /dev/null +++ b/AU/Plugins/Snippet.ps1 @@ -0,0 +1,48 @@ +# Author: dimqua +# Last Change: 11-Oct-2018. +<# +.SYNOPSIS + Upload update history report to Gitlab snippet. + +.DESCRIPTION + Plugin uploads update history report (created by Report plugin) to the snippet with the given id and filename. You can use gitlab.com instance (default) or self-hosted one. +#> +param( + $Info, + + # Snippet id + [string] $Id, + + # Gitlab API Token, create in User Settings -> Access Tokens -> Create personal access token + # Make sure token has 'api' scope. + [string] $ApiToken, + + # File paths to attach to snippet + [string[]] $Path, + + # Snippet file name + [string] $FileName = 'Update-AUPackages.md', + + # GitLab instance's (sub)domain name + [string] $Domain = 'gitlab.com' + +) + +# Create snippet +ls $Path | % { + $file_name = Split-Path $_ -Leaf + $content = gc $_ -Raw + $snippet = '{"content": "' + $content + '"}' + } + +$params = @{ + ContentType = 'application/json' + Method = "PUT" + Uri = "https://$Domain/api/v4/snippets/$Id" + Body = ($snippet | ConvertTo-Json).replace('"{\"content\": \"','{"content": "').replace('\"}"','"') + ', "file_name": "' + $FileName + '"}' + Headers = @{ 'PRIVATE-TOKEN'=$ApiToken } +} + +# Request +$res = Invoke-WebRequest @params +"https://$Domain/snippets/$Id" diff --git a/CHANGELOG.md b/CHANGELOG.md index fc75be1a..55b62459 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - `Get-RemoteChecksum`: New parameter `Headers` - Plugins: - New plugin: Gitter + - New plugin: Snippet ### Bugfixes diff --git a/Plugins.md b/Plugins.md index e8508bf6..8a0cc718 100644 --- a/Plugins.md +++ b/Plugins.md @@ -71,4 +71,15 @@ The plugin saves state of all packages in a file that can be used locally or upl **Save run info to the file and exclude sensitive information**. Run this plugin as the last one to save all other info produced during the run in such way that it can be recreated as object. -To load it for inspection use `$info = Import-CliXml update_info.xml`. \ No newline at end of file +To load it for inspection use `$info = Import-CliXml update_info.xml`. + +## [Snippet](https://github.com/majkinetor/au/blob/master/AU/Plugins/Snippet.ps1) + +**Upload update history report to GitLab snippet**. + +To set up plugin to create snippet under your user name you need to give it your snippet id and authentication: + +* Log into https://gitlab.com/users/sign_in with the user you want to use. +* [Create a snippet](https://gitlab.com/snippets/new) (private or not) with a title and some random content. Grab the id at the end of it - `https://gitlab.com/snippets/{id}`. Set it as `$Env:snippet_id` environment variable. +* Create [GitLab personal access token](https://gitlab.com/profile/personal_access_tokens) and **make sure token has _api_ scope selected**. Authenticating with username and password isn't supported for security reasons. Set it as `$Env:gitlab_api_token` environment variable. +