pr: branch forwarding on check

This commit is contained in:
Adam Majer 2024-09-30 10:25:08 +02:00
parent 7234811edc
commit e2498afc4d
2 changed files with 27 additions and 6 deletions

View File

@ -19,6 +19,7 @@ package common
*/ */
import ( import (
"fmt"
"slices" "slices"
"strings" "strings"
) )
@ -28,3 +29,18 @@ func SplitStringNoEmpty(str, sep string) []string {
return len(s) == 0 return len(s) == 0
}) })
} }
func TranslateHttpsToSshUrl(url string) (string, error) {
const url1 = "https://src.opensuse.org/"
const url2 = "https://src.suse.de/"
if len(url) > len(url1) && url[0:len(url1)] == url1 {
return "gitea@src.opensuse.org:" + url[len(url1):], nil
}
if len(url) > len(url2) && url[0:len(url2)] == url2 {
return "gitea@src.suse.de:" + url[len(url2):], nil
}
return "", fmt.Errorf("Unknown input url %s", url)
}

View File

@ -271,15 +271,20 @@ nextSubmodule:
// not found in past, check if we should advance the branch label ... pull the submodule // not found in past, check if we should advance the branch label ... pull the submodule
git.GitExecOrPanic(config.GitProjectName, "submodule", "update", "--init", "--filter", "blob:none", "--", sub) git.GitExecOrPanic(config.GitProjectName, "submodule", "update", "--init", "--filter", "blob:none", "--", sub)
subDir := path.Join(config.GitProjectName, sub) subDir := path.Join(config.GitProjectName, sub)
newCommits := git.GitExecWithOutputOrPanic(subDir, "rev-list", "^origin/"+config.Branch, commitID) newCommits := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(subDir, "rev-list", "^origin/"+config.Branch, commitID), "\n")
if len(common.SplitStringNoEmpty(newCommits, "\n")) >= 1 {
sshUrl, err := git.translateHttpsToSshUrl(git.SubmoduleUrl(config.GitProjectName), sub) if len(newCommits) >= 1 {
if DebugMode {
log.Println(" - updating branch", config.Branch, "to new head", commitID, " - len:", len(newCommits))
}
git.GitExecOrPanic(subDir, "checkout", "-B", config.Branch, commitID)
url := git.GitExecWithOutputOrPanic(subDir, "remote", "get-url", "origin", "--push")
sshUrl, err := common.TranslateHttpsToSshUrl(strings.TrimSpace(url))
if err != nil { if err != nil {
return fmt.Errorf("Cannot traslate HTTPS git URL to SSH_URL. %w", err) return fmt.Errorf("Cannot traslate HTTPS git URL to SSH_URL. %w", err)
} }
git.GitExecOrPanic(subDir, "checkout", "-B", config.Branch, commitID) git.GitExecOrPanic(subDir, "remote", "set-url", "origin", "--push", sshUrl)
git.GitExecOrPanic(subDir, "remote", "add", "update", sshUrl) git.GitExecOrPanic(subDir, "push", "origin", config.Branch)
git.GitExecOrPanic(subDir, "push", "update", config.Branch)
} }
} }