This repository has been archived by the owner on Oct 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 71
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 #177 from dimqua/master
Add GitLab Snippets plugin
- Loading branch information
Showing
4 changed files
with
66 additions
and
4 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
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,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" |
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
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