1
0
mirror of https://github.com/jaapbrasser/SharedScripts.git synced 2025-12-24 21:51:38 +02:00
Files
SharedScripts/Get-GitPullRequestLocal/Get-GitPullRequestLocal.ps1
Jaap Brasser 1c71430ed1 Test GPG
2019-07-12 10:11:00 +02:00

45 lines
1.5 KiB
PowerShell

Function Get-GitPullRequestLocal {
<#
.SYNOPSIS
Helper function that creates folder, clones single branch based of a GitHub pull request uri
.DESCRIPTION
This function is created to simplify working with pull requests. In order to get all the files on tbe local system in an organized method, I decided to group together these commands.
.EXAMPLE
Get-GitPullRequestLocal -Uri https://github.com/jaapbrasser/SharedScripts/pull/29
Will create a folder in C:\Temp named after the PR number, and clone the specific branch and display the git status
#>
[cmdletbinding(SupportsShouldProcess)]
param(
[string] $Uri,
[string] $Path = 'C:\Temp'
)
$Request = Invoke-WebRequest $Uri
$Values = @{
Folder = '{0}\PR{1}' -f $Path, ($Uri.Split('/')[-1])
GitHubUri = 'https://github.com/{0}' -f $Request.Links.Where{$_.class -eq 'no-underline'}[1].title.split(':')[0]
Branch = $Request.Links.Where{$_.class -eq 'no-underline'}[1].title.split(':')[1]
}
Write-Information -Message "mkdir -Path $($Values.Folder)"
try {
# Create folder and clone branch to folder
mkdir -Path $Values.Folder -EA Stop
Set-Location $Values.Folder
Write-Information -Message "git clone --single-branch --branch $($Values.Branch) $($Values.GitHubUri)"
git clone --single-branch --branch $Values.Branch $Values.GitHubUri
Set-Location (Get-ChildItem).fullname
# Retrieve status of the current branch
git status
} catch {}
}