Skip to content

Instantly share code, notes, and snippets.

@danijeljw
Forked from nobusugi246/gitlab-api.ps1
Created June 24, 2020 00:37
Show Gist options
  • Save danijeljw/8e5b783a20f3d0ee03e0320b06b85cee to your computer and use it in GitHub Desktop.
Save danijeljw/8e5b783a20f3d0ee03e0320b06b85cee to your computer and use it in GitHub Desktop.
GitLab API with PowerShell.
# https://docs.gitlab.com/ee/api/projects.html
# https://docs.gitlab.com/ee/api/issues.html
# https://docs.gitlab.com/ee/api/notes.html
# Project List
$r = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'='xxxxx' } -Uri http://xxxxx/api/v4/projects/
$r | Sort-Object -Property id | Format-Table -Property id, name
# Issues List
$r = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'='xxxxx' } -Uri http://xxxxx/api/v4/projects/<xx>/issues
$r | Sort-Object -Property id | Format-Table -Property id, state, title
# New Issue
Invoke-RestMethod -Method Post -Headers @{ 'PRIVATE-TOKEN'='xxxxx' } -Uri 'http://xxxxx/api/v4/projects/<xx>/issues?title=<xxx>&labels=bug'
# Comment on the Issue
Invoke-RestMethod -Method Post -Headers @{ 'PRIVATE-TOKEN'='xxx' } -Uri 'http://xxx/api/v4/projects/<xx>/issues/<xx>/notes?body=memo'
function Register-NewIssue {
param(
[string]$title,
[string]$desc = '',
[string]$uri = 'http://xxxxx/api/v4/projects/xx/issues'
)
$title = [System.Web.HttpUtility]::UrlEncode($title)
$desc = [System.Web.HttpUtility]::UrlEncode($desc)
$u = "$uri`?title=$title&description=$desc"
$r = Invoke-RestMethod -Method Post -Headers @{ 'PRIVATE-TOKEN'='xxxxx' } -Uri $u
$r | Format-List -Property iid, state, title, description
}
Set-Alias rgni Register-NewIssue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment