New-TFSGitRepository.ps1

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
# Author: Miodrag Milic <miodrag.milic@gmail.com>
# Last Change: 14-Apr-2016.

<#
.SYNOPSIS
    Get the TFS Git repositories
#>

function New-TFSGitRepository {
    [CmdletBinding()]
    param (
        #Name of the repository
        [string] $Name
    )
    check_credential

    $uri = "$proj_uri/_apis/git/repositories?api-version=" + $tfs.api_version
    Write-Verbose "URI: $uri"

    $pid = Get-TFSProject $global:tfs.project | % id
    Write-Verbose "Project id: $pid"

    $body = @{ name = $Name; project = @{ id = $pid } }
    $body = $body | ConvertTo-Json
    Write-Verbose $body

    $params = @{ Uri = $uri; Method = 'Post'; ContentType = 'application/json'; Body = $body}
    invoke_rest $params
}