Scoop-Core
Scoop-Core copied to clipboard
Auto-pr tweaks
- [x] Support -C to not force maintainers to change context manually
- [x] Adopt Invoke-GitCmd to support non windows
- [x] Adopt Invoke-GitCmd instead of direct hub call
- [x] Ditch hub for non pull request actions
- [x] Upstream is needed only with -Request
- [x] Main branch adoption
- [ ] Replace hub with gh
- [ ] Investigate Auto-pr upstream format
- [ ] Automatically compose the Upstream format
- [x] Investigate $PSScriptroot override on linux after call operator
the $Upsteam
parameter requires this pattern <user>/<repo>:<branch>
but then in the code the <branch>
part is not used and instead is hadcoded with master
instead of extracting the branch from the Upstream parameter
for example, my upstream branch is main
and the auto-pr execution fail becuause every hub execution is hardcoded with master
so I 'fixed' my problem by creating a variable at that holds the upstream branch
$Upstream | Out-Null
$Upstream -match '^(.*)\/(.*):(.*)$'
$UpBranch = $matches[3]
and substituted master
with this variable from execute 'hub checkout master'
to execute "hub checkout $UpBranch"
etc...
is this only my problem or I'm doing something wrong.
diff --git a/auto-pr.orig.ps1 b/auto-pr.ps1
index a91541b..007de1b 100644
--- a/auto-pr.orig.ps1
+++ b/auto-pr.ps1
@@ -56,22 +56,24 @@ param(
}
$Upstream | Out-Null # PowerShell/PSScriptAnalyzer#1472
+$Upstream -match '^.*\/.*:(.*)$'
+$UpBranch = $matches[1]
$Dir = Resolve-Path $Dir
if ($Help -or (!$Push -and !$Request)) {
- Write-UserMessage @'
+ Write-UserMessage @"
Usage: auto-pr.ps1 [OPTION]
Mandatory options:
- -p, -push Push updates directly to 'origin master'
+ -p, -push Push updates directly to 'origin $UpBranch'
-r, -request Create pull-requests on 'upstream master' for each update
Optional options:
-u, -upstream Upstream repository with target branch
Only used if -r is set (default: lukesampson/scoop:master)
-h, -help
-'@
+"@
exit 0
}
@@ -94,7 +96,7 @@ function pull_requests($json, [String] $app, [String] $upstream, [String] $manif
$homepage = $json.homepage
$branch = "manifest/$app-$version"
- execute 'hub checkout master'
+ execute "hub checkout $UpBranch"
Write-UserMessage "hub rev-parse --verify $branch" -ForegroundColor 'Green'
hub rev-parse --verify $branch
@@ -140,8 +142,8 @@ a new version of [$app]($homepage) is available.
Write-UserMessage 'Updating ...' -ForegroundColor 'DarkCyan'
if ($Push) {
- execute 'hub pull origin master'
- execute 'hub checkout master'
+ execute "hub pull origin $UpBranch"
+ execute "hub checkout $UpBranch"
} else {
execute 'hub pull upstream master'
execute 'hub push origin master'
@@ -199,7 +201,7 @@ foreach ($changedFile in hub diff --name-only) {
if ($Push) {
Write-UserMessage 'Pushing updates ...' -ForegroundColor 'DarkCyan'
- execute 'hub push origin master'
+ execute "hub push origin $UpBranch"
} else {
Write-UserMessage 'Returning to master branch and removing unstaged files ...' -ForegroundColor 'DarkCyan'
execute 'hub checkout -f master'
.... #62
ok, thanks for the answer. I' did't see the draft, good job.
I made a suggestion for improvements https://github.com/Ash258/Scoop-Core/pull/62/files#r567796715
plus, I thought another thing, what is the point for a user to pass a parameter if that paramenter is not used.
A user creates a bucket, it passes the owner/repo:branch parameter to the auto-pr script and the script ignores this parameter and gets the branch from somewhere else... IMHO it's not good.
Upstream is needed only with -Request
...
I completely misundertood how the script works, sorry about that, I'm an idiot. For some reason I thought that $Upstream was the repo address and not the upstream address for the PR as the variable name suggest. Sorry wasting your time on this matter.
But the suggestion made about only accepting main or master remain valid imho. Why limiting the script and not make it more generic looking for the branch associated with HEAD regardless of the name?