VSTS.User.CLI.psm1
function Open-VSTS { [System.Diagnostics.Process]::Start( "https://softwareone-pc.visualstudio.com/PyraCloud/Avengers/_dashboards") | Out-Null } function Register-VSTS( [Parameter()][string] $Instance = "https://softwareone-pc.visualstudio.com", [Parameter()][string] $Project = "PyraCloud", [Parameter(Mandatory)][string] $Token ) { if(Get-Command vsts -ErrorAction Ignore) { vsts configure -d instance=$Instance vsts configure -d project=$Project vsts login --token $Token } else { throw "VSTS CLI not installed. Please install it from https://docs.microsoft.com/en-us/cli/vsts/overview?view=vsts-cli-latest" } } function Open-Repository ([Parameter(Mandatory)][string] $name) { if (Test-Path $name) { Set-Location $name git fetch } else { $repo = (vsts code repo show --name $name | ConvertFrom-Json) if ($repo) { git clone $repo.remoteUrl Set-Location $repo.name } } } Set-Alias -Name cdr -Value Open-Repository function Find-Repository ($name) { $repos = (vsts code repo list | ConvertFrom-Json) | Where-Object name -like "*$name*" | ForEach-Object name $repos | ForEach-Object { [PSCustomObject]@{ Name = $_ Local = Test-Path $_ } } | Sort-Object Name | Format-Table } Set-Alias -Name lsr -Value Find-Repository function New-PullRequest ( [Parameter(Mandatory)][string] $Title ) { (vsts code pr create --auto-complete --open --title $Title | ConvertFrom-Json) } Set-Alias cpr New-PullRequest function Get-PullRequests( [Parameter()][switch] $Open, [Parameter()][switch] $All ) { if ($All) { $prs = (vsts code pr list | ConvertFrom-Json) } else { $prs = (vsts code pr list --reviewer "me" | ConvertFrom-Json) } $prs | ForEach-Object { $result = [PSCustomObject]@{ Title = $_.title Repository = $_.repository.name Source = $_.sourceRefName Target = $_.targetRefName Status = $_.status MergeStatus = $_.mergeStatus MergeFailureMessage = $_.mergeFailureMessage Url = $_.url.Replace('_apis/git/repositories', '_git').Replace('pullRequests', 'pullrequest') } if ($Open) { Start-Process $result.Url } $result } | Format-Table } Set-Alias lspr Get-PullRequests Export-ModuleMember -Function * -Alias * |