Last active
April 27, 2024 20:07
-
-
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to change tags of runner by PowerShell script ?