sync/reorder: add error cases, remove debug messaging
This commit is contained in:
parent
1e2ad32d54
commit
5430f503e0
23
sync.go
23
sync.go
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"sort"
|
||||
"teafolio/gitea"
|
||||
@ -9,10 +10,10 @@ import (
|
||||
)
|
||||
|
||||
// rearrangeOrder applies rearrangements from the OverrideOrder configuration.
|
||||
func (this *Application) rearrangeOrder(repos []gitea.Repo) []gitea.Repo {
|
||||
func (this *Application) rearrangeOrder(repos []gitea.Repo) ([]gitea.Repo, error) {
|
||||
|
||||
if len(this.cfg.OverrideOrder) == 0 {
|
||||
return repos // nothing to do
|
||||
return repos, nil // nothing to do
|
||||
}
|
||||
|
||||
// Collect pre-existing positions for repos
|
||||
@ -35,8 +36,6 @@ func (this *Application) rearrangeOrder(repos []gitea.Repo) []gitea.Repo {
|
||||
return insertAt[i].pos < insertAt[j].pos
|
||||
})
|
||||
|
||||
log.Printf("insertAt=%#v\n", insertAt)
|
||||
|
||||
// Walking-insertion loop
|
||||
ret := make([]gitea.Repo, 0, len(repos))
|
||||
nextRepo := 0
|
||||
@ -44,7 +43,6 @@ func (this *Application) rearrangeOrder(repos []gitea.Repo) []gitea.Repo {
|
||||
for {
|
||||
if nextOverride < len(insertAt) && insertAt[nextOverride].pos == len(ret) {
|
||||
// We have an override to insert at this position
|
||||
log.Printf("OVERRIDE insert of %q", insertAt[nextOverride].repoName)
|
||||
ret = append(ret, reposByName[insertAt[nextOverride].repoName])
|
||||
nextOverride++
|
||||
|
||||
@ -52,12 +50,10 @@ func (this *Application) rearrangeOrder(repos []gitea.Repo) []gitea.Repo {
|
||||
// There are still other repos to insert generally
|
||||
if _, ok := this.cfg.OverrideOrder[repos[nextRepo].Name]; ok {
|
||||
// This repo has an overridden position. Don't insert it generally here
|
||||
log.Printf("skipping natural insert of %q", repos[nextRepo].Name)
|
||||
nextRepo++
|
||||
|
||||
} else {
|
||||
// This repo does not have an overriden position. Here is fine
|
||||
log.Printf("OK natural insert of %q", repos[nextRepo].Name)
|
||||
ret = append(ret, repos[nextRepo])
|
||||
nextRepo++
|
||||
}
|
||||
@ -70,7 +66,11 @@ func (this *Application) rearrangeOrder(repos []gitea.Repo) []gitea.Repo {
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
if len(ret) != len(repos) {
|
||||
return nil, fmt.Errorf("Failed to apply OverrideOrder (got %d of %d repositories)", len(ret), len(repos))
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (this *Application) sync(ctx context.Context) (bool, error) {
|
||||
@ -144,7 +144,12 @@ func (this *Application) sync(ctx context.Context) (bool, error) {
|
||||
sort.Slice(repos, func(i, j int) bool {
|
||||
return repos[i].GiteaCreated.After(repos[j].GiteaCreated)
|
||||
})
|
||||
repos = this.rearrangeOrder(repos)
|
||||
reordered, err := this.rearrangeOrder(repos)
|
||||
if err != nil {
|
||||
log.Printf("Reorder failure: %s", err.Error())
|
||||
} else {
|
||||
repos = reordered
|
||||
}
|
||||
|
||||
// Commit our changes for the other threads to look at
|
||||
this.reposMut.Lock()
|
||||
|
Loading…
Reference in New Issue
Block a user