Scoop-Core icon indicating copy to clipboard operation
Scoop-Core copied to clipboard

Auto-pr tweaks

Open Ash258 opened this issue 4 years ago • 6 comments

  1. [x] Support -C to not force maintainers to change context manually
  2. [x] Adopt Invoke-GitCmd to support non windows
  3. [x] Adopt Invoke-GitCmd instead of direct hub call
  4. [x] Ditch hub for non pull request actions
  5. [x] Upstream is needed only with -Request
  6. [x] Main branch adoption
  7. [ ] Replace hub with gh
  8. [ ] Investigate Auto-pr upstream format
  9. [ ] Automatically compose the Upstream format
  10. [x] Investigate $PSScriptroot override on linux after call operator image

Ash258 avatar Jan 30 '21 14:01 Ash258

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'

nixxo avatar Feb 01 '21 11:02 nixxo

.... #62

Ash258 avatar Feb 01 '21 11:02 Ash258

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

nixxo avatar Feb 01 '21 12:02 nixxo

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.

nixxo avatar Feb 02 '21 10:02 nixxo

Upstream is needed only with -Request

...

Ash258 avatar Feb 02 '21 10:02 Ash258

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?

nixxo avatar Feb 02 '21 14:02 nixxo