Skip to content

Commit c68d91c

Browse files
rashil2000se35710
authored andcommitted
fix(auto-pr): Remove hardcoded 'master' branch (ScoopInstaller#4567)
1 parent 03ee6de commit c68d91c

1 file changed

Lines changed: 18 additions & 15 deletions

File tree

bin/auto-pr.ps1

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22
.SYNOPSIS
33
Updates manifests and pushes them or creates pull-requests.
44
.DESCRIPTION
5-
Updates manifests and pushes them directly to the master branch or creates pull-requests for upstream.
5+
Updates manifests and pushes them directly to the origin branch or creates pull-requests for upstream.
66
.PARAMETER Upstream
77
Upstream repository with the target branch.
88
Must be in format '<user>/<repo>:<branch>'
9+
.PARAMETER OriginBranch
10+
Origin (local) branch name.
911
.PARAMETER App
1012
Manifest name to search.
1113
Placeholders are supported.
1214
.PARAMETER Dir
1315
The directory where to search for manifests.
1416
.PARAMETER Push
15-
Push updates directly to 'origin master'.
17+
Push updates directly to 'origin branch'.
1618
.PARAMETER Request
17-
Create pull-requests on 'upstream master' for each update.
19+
Create pull-requests on 'upstream branch' for each update.
1820
.PARAMETER Help
1921
Print help to console.
2022
.PARAMETER SpecialSnowflakes
@@ -37,6 +39,7 @@ param(
3739
$true
3840
})]
3941
[String] $Upstream,
42+
[String] $OriginBranch = 'master',
4043
[String] $App = '*',
4144
[Parameter(Mandatory = $true)]
4245
[ValidateScript( {
@@ -65,12 +68,12 @@ if ((!$Push -and !$Request) -or $Help) {
6568
Usage: auto-pr.ps1 [OPTION]
6669
6770
Mandatory options:
68-
-p, -push push updates directly to 'origin master'
69-
-r, -request create pull-requests on 'upstream master' for each update
71+
-p, -push push updates directly to 'origin branch'
72+
-r, -request create pull-requests on 'upstream branch' for each update
7073
7174
Optional options:
7275
-u, -upstream upstream repository with target branch
73-
only used if -r is set (default: lukesampson/scoop:master)
76+
-o, -originbranch origin (local) branch name
7477
-h, -help
7578
'@
7679
exit 0
@@ -104,7 +107,7 @@ function pull_requests($json, [String] $app, [String] $upstream, [String] $manif
104107
$homepage = $json.homepage
105108
$branch = "manifest/$app-$version"
106109

107-
execute 'hub checkout master'
110+
execute "hub checkout $OriginBranch"
108111
Write-Host "hub rev-parse --verify $branch" -ForegroundColor Green
109112
hub rev-parse --verify $branch
110113

@@ -141,7 +144,7 @@ a new version of [$app]($homepage) is available.
141144
| New version | $version |
142145
"@
143146

144-
hub pull-request -m "$msg" -b '$upstream' -h '$branch'
147+
hub pull-request -m "$msg" -b "$upstream" -h "$branch"
145148
if ($LASTEXITCODE -gt 0) {
146149
execute 'hub reset'
147150
abort "Pull Request failed! (hub pull-request -m '${app}: Update to version $version' -b '$upstream' -h '$branch')"
@@ -150,11 +153,11 @@ a new version of [$app]($homepage) is available.
150153

151154
Write-Host 'Updating ...' -ForegroundColor DarkCyan
152155
if ($Push) {
153-
execute 'hub pull origin master'
154-
execute 'hub checkout master'
156+
execute "hub pull origin $OriginBranch"
157+
execute "hub checkout $OriginBranch"
155158
} else {
156-
execute 'hub pull upstream master'
157-
execute 'hub push origin master'
159+
execute "hub pull upstream $OriginBranch"
160+
execute "hub push origin $OriginBranch"
158161
}
159162

160163
. "$PSScriptRoot\checkver.ps1" -App $App -Dir $Dir -Update -SkipUpdated:$SkipUpdated
@@ -198,10 +201,10 @@ hub diff --name-only | ForEach-Object {
198201

199202
if ($Push) {
200203
Write-Host 'Pushing updates ...' -ForegroundColor DarkCyan
201-
execute 'hub push origin master'
204+
execute "hub push origin $OriginBranch"
202205
} else {
203-
Write-Host 'Returning to master branch and removing unstaged files ...' -ForegroundColor DarkCyan
204-
execute 'hub checkout -f master'
206+
Write-Host "Returning to $OriginBranch branch and removing unstaged files ..." -ForegroundColor DarkCyan
207+
execute "hub checkout -f $OriginBranch"
205208
}
206209

207210
execute 'hub reset --hard'

0 commit comments

Comments
 (0)