-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync.go
40 lines (34 loc) · 1.15 KB
/
sync.go
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
package main
import (
"github.com/dawidl022/gitlab-contribution-sync/config"
"github.com/dawidl022/gitlab-contribution-sync/contributions"
"github.com/dawidl022/gitlab-contribution-sync/git"
)
func syncContributions(config config.Config) error {
syncedContributions, err := contributions.ReadSyncedContributions(config.TargetDir)
if err != nil {
return err
}
contribs, err := fetchGitlabContributions(config.GitlabUsername)
if err != nil {
return err
}
chronologicalContributions := contributions.SortContributions(contribs)
for _, contrib := range chronologicalContributions {
for syncedContributions[contrib.Date] < contrib.Count {
syncedContributions[contrib.Date]++
err := writeAndCommitContributions(syncedContributions, contrib.Date, config)
if err != nil {
return err
}
}
}
return git.PushContributions(config.TargetDir)
}
func writeAndCommitContributions(contribs map[contributions.Date]int, date contributions.Date, config config.Config) error {
err := contributions.WriteSyncedContributions(contribs, config.TargetDir)
if err != nil {
return err
}
return git.CommitContributions(config.TargetDir, date, contribs[date])
}