summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2019-10-11 17:10:03 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2019-10-14 10:10:56 +0200
commit7a2bd5409ec4308a8e7fca4f3827f975210f0c22 (patch)
tree4f124ff2a78ec723a0c633be53d68dac79ea664b /src
parent25c601642a30050948d7ab1cb2bd93f20aaca3d3 (diff)
Simplify main: Move more of the batch iteration code into a separate helper function
Change-Id: Iff5416c32259dd1d7ec54834748bfdc3e018a41f Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qtmoduleupdater/main.go42
-rw-r--r--src/qtmoduleupdater/moduleupdatebatch.go46
2 files changed, 50 insertions, 38 deletions
diff --git a/src/qtmoduleupdater/main.go b/src/qtmoduleupdater/main.go
index 6dc325d2..0ad79735 100644
--- a/src/qtmoduleupdater/main.go
+++ b/src/qtmoduleupdater/main.go
@@ -92,19 +92,9 @@ func appMain() error {
}
}
- batch := &ModuleUpdateBatch{
- Product: product,
- ProductRef: productRef,
- Branch: branch,
- }
- var err error
-
- err = batch.loadState()
- if os.IsNotExist(err) {
- err = batch.loadTodoList()
- if err != nil {
- return err
- }
+ batch, err := newModuleUpdateBatch(product, branch, productRef)
+ if err != nil {
+ return err
}
if summaryOnly {
@@ -112,31 +102,7 @@ func appMain() error {
return nil
}
- batch.checkPendingModules()
-
- if err := batch.scheduleUpdates(gerrit); err != nil {
- return err
- }
-
- batch.printSummary()
-
- if !batch.isDone() {
- err = batch.saveState()
- if err != nil {
- return err
- }
- } else {
- if batch.FailedModuleCount == 0 {
- fmt.Println("Preparing qt5 update")
- if err = prepareQt5Update(product, batch.Branch, batch.Done, gerrit); err != nil {
- return fmt.Errorf("error preparing qt5 update: %s", err)
- }
- }
-
- batch.clearState()
- }
-
- return nil
+ return batch.runOneIteration(gerrit)
}
func main() {
diff --git a/src/qtmoduleupdater/moduleupdatebatch.go b/src/qtmoduleupdater/moduleupdatebatch.go
index dfdde6fe..d8a7205a 100644
--- a/src/qtmoduleupdater/moduleupdatebatch.go
+++ b/src/qtmoduleupdater/moduleupdatebatch.go
@@ -53,6 +53,24 @@ type ModuleUpdateBatch struct {
FailedModuleCount int
}
+func newModuleUpdateBatch(product string, branch string, productRef string) (*ModuleUpdateBatch, error) {
+ batch := &ModuleUpdateBatch{
+ Product: product,
+ ProductRef: productRef,
+ Branch: branch,
+ }
+ var err error
+
+ err = batch.loadState()
+ if os.IsNotExist(err) {
+ err = batch.loadTodoList()
+ if err != nil {
+ return nil, err
+ }
+ }
+ return batch, nil
+}
+
func (batch *ModuleUpdateBatch) scheduleUpdates(gerrit *gerritInstance) error {
for _, moduleToUpdate := range batch.Todo {
update, err := moduleToUpdate.updateDependenciesForModule(batch.Done)
@@ -241,3 +259,31 @@ func (batch *ModuleUpdateBatch) printSummary() {
fmt.Println()
fmt.Println()
}
+
+func (batch *ModuleUpdateBatch) runOneIteration(gerrit *gerritInstance) error {
+ batch.checkPendingModules()
+
+ if err := batch.scheduleUpdates(gerrit); err != nil {
+ return err
+ }
+
+ batch.printSummary()
+
+ if !batch.isDone() {
+ err := batch.saveState()
+ if err != nil {
+ return err
+ }
+ } else {
+ if batch.FailedModuleCount == 0 {
+ fmt.Println("Preparing qt5 update")
+ if err := prepareQt5Update(batch.Product, batch.Branch, batch.Done, gerrit); err != nil {
+ return fmt.Errorf("error preparing qt5 update: %s", err)
+ }
+ }
+
+ batch.clearState()
+ }
+
+ return nil
+}