Last active
May 19, 2017 11:33
-
-
Save Hallmanac/e5de6ab074ed6f86fb168e51da6a8e61 to your computer and use it in GitHub Desktop.
A PowerShell file for local development against the VSTS API. This specifically works with a Git commit and filters out certain files. Replace the place holder values with what's appropriate for you.
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
# Place for local script to be developed | |
# Please note that all place holders are in all caps | |
$urlBase = "https://{YOUR_VSTS_ACCOUNT}.visualstudio.com/DefaultCollection/{PROJECT_NAME}/_apis/"; | |
# You can leave the username blank | |
$username = ""; | |
$password = "YOUR_PERSONAL_ACCESS_TOKEN"; | |
# Need to Base 64 Encode the username password combination in the form that a "Basic Authorization" Http header expects | |
$base64authinfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username, $password))); | |
# Value of the Authorization Http header to be sent with the request | |
$auth = "Basic {0}" -f $base64authinfo; | |
# Value of the accept header | |
$accept = "application/json"; | |
# set the headers into one object | |
$headers = @{authorization=$auth;accept=$accept}; | |
# Form the URL including the commit ID | |
$commitChangesUrl = $urlBase + "git/repositories/{NAME_OF_REPO}/commits/{COMMIT_HASH_ID}/changes?api-versio=1.0"; | |
# Get the changes from the commit | |
$commitChanges = Invoke-RestMethod -Uri $commitChangesUrl -Method Get -Headers $headers -ContentType "application/json"; | |
# Filter the changes down to blob files and only .rdl file types | |
[string[]]$rdlFilePaths = $commitChanges.changes ` | |
| Where-Object {$_.item.gitObjectType -eq "blob" -and $_.item.path.EndsWith(".rdl") -and ($_.changeType -eq "edit" -or $_.changeType -eq "add" -or $_.changeType -eq "edit, rename")} ` | |
| Select-Object item ` | |
| ForEach-Object {$_.item.path}; | |
# Uncomment the lines below to see different outputs to the console | |
#$jsonOutput = $rdlFilePaths | ConvertTo-Json | |
#$jsonOutput | |
#Write-Host "rdlFilePaths are: " $rdlFilePaths; | |
for($i=0; $i -lt $rdlFilePaths.Length; $i++){ | |
[string]$pathItem = [string]$rdlFilePaths[$i]; | |
Write-Host "Iteration $i || The pathItem is $pathItem"; | |
# Get the file name and replace all spaces with dashes to make it more path friendly | |
[int]$fileIndex = $pathItem.LastIndexOf('/'); | |
[string]$fileName = $pathItem.Substring($fileIndex + 1); | |
$fileName = $fileName.Replace(' ', '-').Trim(); | |
$pathInstance = "Test-Directory" + $pathItem.Replace("/", "\"); | |
Write-Host "Iteration $i || The Path Instance: $pathInstance"; | |
Write-Host "Iteration $i || The Destination file name is: $fileName"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment