diff --git a/obs-staging-bot/main.go b/obs-staging-bot/main.go index 380a1b2..03d9002 100644 --- a/obs-staging-bot/main.go +++ b/obs-staging-bot/main.go @@ -57,8 +57,12 @@ func failOnError(err error, msg string) { func fetchPrGit(git common.Git, pr *models.PullRequest) error { // clone PR head and base and return path + cloneURL := pr.Head.Repo.CloneURL + if (giteaUseSshClone) { + cloneURL = pr.Head.Repo.SSHURL + } if _, err := os.Stat(path.Join(git.GetPath(), pr.Head.Sha)); os.IsNotExist(err) { - git.GitExec("", "clone", "--depth", "1", pr.Head.Repo.CloneURL, pr.Head.Sha) + git.GitExec("", "clone", "--depth", "1", cloneURL, pr.Head.Sha) git.GitExec(pr.Head.Sha, "fetch", "--depth", "1", "origin", pr.Head.Sha, pr.Base.Sha) } else if err != nil { return err @@ -287,7 +291,8 @@ func generateObsPrjMeta(git common.Git, gitea common.Gitea, pr *models.PullReque meta.Description = fmt.Sprintf(`Pull request build job PR#%d to branch %s of %s/%s`, pr.Index, pr.Base.Name, pr.Base.Repo.Owner.UserName, pr.Base.Repo.Name) meta.Url = fmt.Sprintf( - "https://src.opensuse.org/%s/%s/pulls/%d", + "https://%s/%s/%s/pulls/%d", + giteaHost, url.PathEscape(pr.Base.Repo.Owner.UserName), url.PathEscape(pr.Base.Repo.Name), pr.Index, @@ -587,6 +592,8 @@ var ListPullNotificationsOnly bool var ProcessIDOnly int64 var Debug bool var BuildRoot string +var giteaHost string +var giteaUseSshClone bool var obsApiHost string var obsWebHost string @@ -603,7 +610,8 @@ func main() { flag.BoolVar(&ListPullNotificationsOnly, "list-notifications-only", false, "Only lists notifications without acting on them") flag.Int64Var(&ProcessIDOnly, "id", -1, "Process only the specific ID and ignore the rest. Use for debugging") flag.StringVar(&BuildRoot, "build-root", "", "Default build location for staging projects. Default is bot's home project") - giteaHost := flag.String("gitea", "src.opensuse.org", "Gitea instance") + flag.StringVar(&giteaHost, "gitea", "src.opensuse.org", "Gitea instance") + flag.BoolVar(&giteaUseSshClone, "use-ssh-clone", false, "enforce cloning via ssh") flag.StringVar(&obsApiHost, "obs", "api.opensuse.org", "API for OBS instance") flag.StringVar(&obsWebHost, "obs-web", "", "Web OBS instance, if not derived from the obs config") flag.Parse() @@ -618,7 +626,7 @@ func main() { // go ProcessingObsMessages("rabbit.opensuse.org", "opensuse", "opensuse", "") for { - pollWorkNotifications(*giteaHost) + pollWorkNotifications(giteaHost) if Debug { break }