generated from KinsonDigital/CSharpLibTemplateRepo
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-pr.ps1
50 lines (37 loc) · 1.48 KB
/
create-pr.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
Clear-Host;
Write-Host -NoNewline "Please enter an issue number: " -ForegroundColor Cyan;
$issueNumber = Read-Host;
if ($issueNumber -notmatch '^\d+$') {
Write-Error "User input is not a number";
exit 1;
}
Write-Host -NoNewline "Please enter a branch name: " -ForegroundColor Cyan;
$branchDescrip = Read-Host;
$branchDescrip = $branchDescrip.ToLower();
$branchDescrip = $branchDescrip.Replace(" ", "-").Replace("_", "-");
$branchDescrip = $branchDescrip.TrimStart("-");
$branchDescrip = $branchDescrip.TrimEnd("-");
$headBranch = "feature/$issueNumber-$branchDescrip";
$commitMsg = "Start owrk for issue #$issueNumber";
$destBranch = "not-set";
$baseBranches = @("main", "preview");
Write-Host -NoNewline "Please choose a base branch from the list [$($baseBranches -join ', ')]: " -ForegroundColor Cyan;
$chosenBaseBranch = Read-Host;
if ($baseBranches -contains $chosenBaseBranch) {
$destBranch = $chosenBaseBranch;
} else {
Write-Error "Invalid base branch.";
exit 1;
}
Write-Host "`n--------------------------------`n";
Write-Host "Creating branch. . ." -ForegroundColor Yellow;
git checkout -B "$headBranch";
Write-Host "";
Write-Host "Creating empty commit. . ." -ForegroundColor Yellow;
git commit --allow-empty -m $commitMsg;
Write-Host "";
Write-Host "Pushing branch to remote. . ." -ForegroundColor Yellow;
git push --set-upstream origin "$headBranch";
Write-Host "";
Write-Host "Creating PR. . ." -ForegroundColor Yellow;
gh pr create -B $destBranch -b "" -t "new pr" -d;