Skip to content

Instantly share code, notes, and snippets.

@nobusugi246
Last active April 27, 2024 20:07
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save nobusugi246/428153783939a5b2b24198fca55b7469 to your computer and use it in GitHub Desktop.
Save nobusugi246/428153783939a5b2b24198fca55b7469 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
@StewMcc
Copy link

StewMcc commented May 21, 2019

Super handy really helped for converting there API to PowerShell commands.

Invoke-RestMethod -Method DELETE -Headers @{ 'PRIVATE-TOKEN'='xxxx' } -Uri http://gitlab.com/api/v4/projects/xx/pipelines/xx

@paulmallon
Copy link

Nice to see some powershell scripts for gitlab!

Here is a script I wrote to quickly clone all projects and setup git to track remote branches. Hope someone finds it useful.

https://gist.github.com/paulmallon/57c046d2ed54974bc4a9c67b315ff0ce

Cheers

@Mayurkale1999
Copy link

How to change tags of runner by PowerShell script ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment