forked from microsoft/Application-Insights-Workbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hotfix-merge-tool.ps1
57 lines (39 loc) · 1.67 KB
/
hotfix-merge-tool.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
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
#Requires -Version 3.0
[CmdletBinding()]
Param(
[switch]$resolved,
[System.Collections.ArrayList]$cherrypicks
)
Import-Module ([System.IO.Path]::Combine($PSScriptRoot, './MergeHelper')) -Global -Force -ErrorAction Stop
Get-CleanWorkspace
$currentBranch = & git rev-parse --abbrev-ref HEAD
if ($resolved -ne $true) {
Write-Host "Welcome to the Hotfix creator tool!"
$environment = Get-UserInput -prompt "First, tell me the environment you are trying to hotfix. Enter 'ppe' 'production' or 'mpac'." -validInputs '(ppe)|(production)|(mpac)'
$commit = Get-UserInput -prompt "OK, now I need the commit in master branch currently in $environment" -validInputs '(^([a-f]|[\d]){8}$)|(^([a-f]|[\d]){40})$'
$cherrypicks = @()
$null = Get-Cherrypicks | ForEach-Object { $cherrypicks.Add($_) }
$hotfix = "hotfix"
Write-Host "Thanks for the info!"
Sync-Branch -branch master
Sync-Branch -branch $hotfix
& git checkout $commit
Write-Host "Checking out $hotfix branch"
& git checkout $hotfix
$hotfixBranch = Get-NewBranch -branch $hotfix -commit $commit
Write-Host "Checking out new branch $hotfixBranch"
& git checkout -b $hotfixBranch
git checkout $hotfixBranch
git merge $commit
if ($LASTEXITCODE -ne 0) {
Write-Warning "Oh no! The merge failed. If there were merge conflicts, resolve them and then rerun this script with parameters '-resolved $true'"
$resolved = $false
} else {
$resolved = $true
}
}
if ($resolved -eq $true) {
Invoke-Cherrypicks -cherrypicks $cherrypicks
New-PullRequest -sourceBranch $hotfixBranch -targetBranch $hotfix
& git checkout $currentBranch
}