Last active
December 5, 2024 17:10
-
-
Save nobusugi246/428153783939a5b2b24198fca55b7469 to your computer and use it in GitHub Desktop.
GitLab API with PowerShell.
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
# 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 |
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
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
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