-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGet-AzDoRepo.ps1
More file actions
107 lines (95 loc) · 3.06 KB
/
Get-AzDoRepo.ps1
File metadata and controls
107 lines (95 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
function Get-AzDoRepo {
<#
.SYNOPSIS
Gets information about a repo in Azure DevOps.
.DESCRIPTION
Gets information about 1 repo if the parameter $Name is filled in. Otherwise it will list all the repo's.
.EXAMPLE
$Params = @{
CollectionUri = "https://dev.azure.com/contoso"
ProjectName = "Project 1"
Name "Repo 1"
}
Get-AzDoRepo -CollectionUri = "https://dev.azure.com/contoso" -PAT = "***" -ProjectName = "Project 1"
This example will list all the repo's contained in 'Project 1'.
.EXAMPLE
$Params = @{
CollectionUri = "https://dev.azure.com/contoso"
ProjectName = "Project 1"
Name "Repo 1"
}
Get-AzDoRepo -CollectionUri = "https://dev.azure.com/contoso" -PAT = "***" -ProjectName = "Project 1" -Name "Repo 1"
This example will fetch information about the repo with the name 'Repo 1'.
.EXAMPLE
$Params = @{
CollectionUri = "https://dev.azure.com/contoso"
Name "Repo 1"
}
get-AzDoProject -pat $pat -CollectionUri $collectionuri | Get-AzDoRepo -PAT $PAT
This example will fetch information about the repo with the name 'Repo 1'.
.OUTPUTS
PSObject with repo(s).
.NOTES
#>
[CmdletBinding(SupportsShouldProcess)]
param (
# Collection Uri of the organization
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[string]
$CollectionUri,
# Project where the Repos are contained
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[string]
$ProjectName,
# Name of the Repo to get information about
[Parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)]
[string[]]
$RepoName
)
begin {
Write-Verbose "Starting function: Get-AzDoRepo"
}
process {
$params = @{
uri = "$CollectionUri/$ProjectName/_apis/git/repositories"
version = "7.1-preview.1"
method = 'GET'
}
if ($PSCmdlet.ShouldProcess($CollectionUri, "Get Environments from: $($PSStyle.Bold)$ProjectName$($PSStyle.Reset)")) {
$repos = (Invoke-AzDoRestMethod @params).value
if ($RepoName) {
foreach ($name in $RepoName) {
$repo = $repos | Where-Object { $_.name -eq $name }
if (-not($repo)) {
Write-Error "Repo $name not found"
continue
} else {
$result += $repo
}
}
} else {
$result += $repos
}
} else {
Write-Verbose "Calling Invoke-AzDoRestMethod with $($params| ConvertTo-Json -Depth 10)"
}
}
end {
if ($result) {
$result | ForEach-Object {
[PSCustomObject]@{
CollectionURI = $CollectionUri
ProjectName = $ProjectName
RepoName = $_.name
RepoId = $_.id
URL = $_.url
DefaultBranch = $_.defaultBranch
WebUrl = $_.webUrl
RemoteUrl = $_.remoteUrl
SshUrl = $_.sshUrl
IsDisabled = $_.IsDisabled
}
}
}
}
}