-
-
Save nevidanniu/263e12c8aa323736a1a7a431d60b5a62 to your computer and use it in GitHub Desktop.
GitLab API with PowerShell.
This file contains hidden or 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