Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Add GitLab Snippets plugin #177

Merged
merged 1 commit into from
Feb 15, 2019
Merged
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
8 changes: 5 additions & 3 deletions AU/Plugins/Git.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
48 changes: 48 additions & 0 deletions AU/Plugins/Snippet.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Author: dimqua <[email protected]>
# 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"
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- `Get-RemoteChecksum`: New parameter `Headers`
- Plugins:
- New plugin: Gitter
- New plugin: Snippet

### Bugfixes

Expand Down
13 changes: 12 additions & 1 deletion Plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
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.