summaryrefslogtreecommitdiff
path: root/rill.go
blob: 312970b0a62464d087203de2340af82e37017a8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package forgepb

import (
	"github.com/destel/rill"
	"go.wit.com/lib/protobuf/gitpb"
	"go.wit.com/log"
)

// rill is awesome. long live rill
// attempt scan with rill
func (f *Forge) rillUpdate(pool1 int, pool2 int) (int, error) {
	var repos []*gitpb.Repo
	all := f.Repos.SortByFullPath()
	for all.Scan() {
		repo := all.Next()
		repos = append(repos, repo)
	}

	// Convert a slice of user IDs into a channel
	ids := rill.FromSlice(repos, nil)

	// Read users from the API.
	// Concurrency = 20
	rills := rill.Map(ids, pool1, func(repo *gitpb.Repo) (*gitpb.Repo, error) {
		return repo, nil
	})

	var counter int
	// Activate users.
	// Concurrency = 10
	err := rill.ForEach(rills, pool2, func(repo *gitpb.Repo) error {
		counter += 1
		return f.updateRepo(repo)
	})

	return counter, err
}

func (f *Forge) updateRepo(repo *gitpb.Repo) error {
	if !repo.IsValidDir() {
		log.Printf("%10s %-50s", "bad git dir\n", repo.FullPath)
		f.Repos.DeleteByFullPath(repo.FullPath)
		f.configSave = true
		return nil
	}

	if repo.DidRepoChange() {
		f.configSave = true
		log.Info("repo changed       ", repo.FullPath, repo.StateChange)
		if err := repo.Reload(); err != nil {
			return err
		}
	} else {
		// log.Info("repo did not change", repo.FullPath, repo.StateChange)
	}
	if f.Config.IsReadOnly(repo.GetGoPath()) {
		if repo.ReadOnly {
		} else {
			log.Info("readonly flag on repo is wrong", repo.GetGoPath())
			repo.ReadOnly = true
			f.configSave = true
		}
	}
	return nil
}