diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2019-10-11 17:00:59 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2019-10-14 10:10:44 +0200 |
commit | 25c601642a30050948d7ab1cb2bd93f20aaca3d3 (patch) | |
tree | d9244e1d40b3670abf6bd459750f6e6bc692411b | |
parent | 6782d52ba4279b5c7400073da1025bbf7b332c20 (diff) |
Clean up gerrit interaction options
Collect the parameters in a struct to reduce the amount of parameters to pass through.
This is done also in preparation for making the code easier when dealing with multiple batches.
Change-Id: I3bbe99286b8cf14f9f948bc27c95664d4959db08
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
-rw-r--r-- | src/qtmoduleupdater/gerrit.go | 17 | ||||
-rw-r--r-- | src/qtmoduleupdater/main.go | 10 | ||||
-rw-r--r-- | src/qtmoduleupdater/moduleupdatebatch.go | 10 | ||||
-rw-r--r-- | src/qtmoduleupdater/qt5.go | 10 |
4 files changed, 26 insertions, 21 deletions
diff --git a/src/qtmoduleupdater/gerrit.go b/src/qtmoduleupdater/gerrit.go index b57292c7..1bd02d25 100644 --- a/src/qtmoduleupdater/gerrit.go +++ b/src/qtmoduleupdater/gerrit.go @@ -205,7 +205,12 @@ func escapeGerritMessage(message string) string { return `"` + replacer.Replace(message) + `"` } -func pushChange(repoPath string, branch string, commitID OID, summary string, pushUserName string) error { +type gerritInstance struct { + pushUserName string + disableStaging bool +} + +func (instance *gerritInstance) pushChange(repoPath string, branch string, commitID OID, summary string) error { repo, err := OpenRepository(repoPath) if err != nil { return err @@ -215,14 +220,18 @@ func pushChange(repoPath string, branch string, commitID OID, summary string, pu if err != nil { return err } - if pushUserName != "" { - pushURL.User = url.User(pushUserName) + if instance.pushUserName != "" { + pushURL.User = url.User(instance.pushUserName) } return repo.Push(pushURL, commitID, "refs/for/"+branch) } -func reviewAndStageChange(repoPath string, branch string, commitID OID, summary string) error { +func (instance *gerritInstance) reviewAndStageChange(repoPath string, branch string, commitID OID, summary string) error { + if instance.disableStaging { + return nil + } + pushURL, err := RepoPushURL(repoPath) if err != nil { return err diff --git a/src/qtmoduleupdater/main.go b/src/qtmoduleupdater/main.go index 9b8f2c57..6dc325d2 100644 --- a/src/qtmoduleupdater/main.go +++ b/src/qtmoduleupdater/main.go @@ -81,10 +81,12 @@ func appMain() error { return fmt.Errorf("missing branch. Please specify -branch=<name of branch>") } - var pushUserName string + gerrit := &gerritInstance{} + gerrit.disableStaging = manualStage + if stageAsBot { var err error - pushUserName, err = setupEnvironmentForSubmoduleUpdateBot() + gerrit.pushUserName, err = setupEnvironmentForSubmoduleUpdateBot() if err != nil { return fmt.Errorf("error preparing environment to work as submodule-update user: %s", err) } @@ -112,7 +114,7 @@ func appMain() error { batch.checkPendingModules() - if err := batch.scheduleUpdates(pushUserName, manualStage); err != nil { + if err := batch.scheduleUpdates(gerrit); err != nil { return err } @@ -126,7 +128,7 @@ func appMain() error { } else { if batch.FailedModuleCount == 0 { fmt.Println("Preparing qt5 update") - if err = prepareQt5Update(product, batch.Branch, batch.Done, pushUserName, manualStage); err != nil { + if err = prepareQt5Update(product, batch.Branch, batch.Done, gerrit); err != nil { return fmt.Errorf("error preparing qt5 update: %s", err) } } diff --git a/src/qtmoduleupdater/moduleupdatebatch.go b/src/qtmoduleupdater/moduleupdatebatch.go index 89e66d9e..dfdde6fe 100644 --- a/src/qtmoduleupdater/moduleupdatebatch.go +++ b/src/qtmoduleupdater/moduleupdatebatch.go @@ -53,7 +53,7 @@ type ModuleUpdateBatch struct { FailedModuleCount int } -func (batch *ModuleUpdateBatch) scheduleUpdates(pushUserName string, manualStage bool) error { +func (batch *ModuleUpdateBatch) scheduleUpdates(gerrit *gerritInstance) error { for _, moduleToUpdate := range batch.Todo { update, err := moduleToUpdate.updateDependenciesForModule(batch.Done) if err != nil { @@ -67,14 +67,12 @@ func (batch *ModuleUpdateBatch) scheduleUpdates(pushUserName string, manualStage // Nothing to be done, we are waiting for indirect dependencies } else if update.result == DependenciesUpdateUpdateScheduled { // push and stage - if err = pushChange(moduleToUpdate.RepoPath, moduleToUpdate.Branch, update.commitID, update.summary, pushUserName); err != nil { + if err = gerrit.pushChange(moduleToUpdate.RepoPath, moduleToUpdate.Branch, update.commitID, update.summary); err != nil { return fmt.Errorf("error pushing change upate: %s", err) } - if !manualStage { - if err = reviewAndStageChange(moduleToUpdate.RepoPath, moduleToUpdate.Branch, update.commitID, update.summary); err != nil { - return fmt.Errorf("error pushing change upate: %s", err) - } + if err = gerrit.reviewAndStageChange(moduleToUpdate.RepoPath, moduleToUpdate.Branch, update.commitID, update.summary); err != nil { + return fmt.Errorf("error pushing change upate: %s", err) } batch.Pending = append(batch.Pending, &PendingUpdate{moduleToUpdate, update.changeID}) diff --git a/src/qtmoduleupdater/qt5.go b/src/qtmoduleupdater/qt5.go index 73710d24..738a084b 100644 --- a/src/qtmoduleupdater/qt5.go +++ b/src/qtmoduleupdater/qt5.go @@ -171,7 +171,7 @@ func getQt5ProductModules(productProject string, branchOrRef string, productFetc return listSubmodules(productRepo, productRepoURL, productHead) } -func prepareQt5Update(product string, branch string, updatedModules map[string]*Module, pushUserName string, manualStage bool) error { +func prepareQt5Update(product string, branch string, updatedModules map[string]*Module, gerrit *gerritInstance) error { productRepoURL, err := RepoURL(product) if err != nil { return fmt.Errorf("Error determining %s repo URL: %s", product, err) @@ -246,13 +246,9 @@ func prepareQt5Update(product string, branch string, updatedModules map[string]* fmt.Printf("Created new commit for submodule update: %s\n", commitOid) - if err = pushChange(product, branch, commitOid, "Updating all submodules with a new consistent set", pushUserName); err != nil { + if err = gerrit.pushChange(product, branch, commitOid, "Updating all submodules with a new consistent set"); err != nil { return fmt.Errorf("Error pushing qt5 change: %s", err) } - if manualStage { - return nil - } - - return reviewAndStageChange(product, branch, commitOid, "Updating all submodules with a new consistent set") + return gerrit.reviewAndStageChange(product, branch, commitOid, "Updating all submodules with a new consistent set") } |