-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
86 lines (71 loc) · 1.65 KB
/
main.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
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"fmt"
"os"
"path/filepath"
"time"
)
const numRows = 7
var numCols = 53
func main() {
// print today's date
fmt.Println(time.Now().Format("Mon Jan 2 15:04:05 2006"))
config, err := loadConfig("config.toml")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
commitDate := calendarStartDate()
message := render(config.Message)
if config.IsPreview {
printMessage(message)
return
}
repoURL, err := refreshRemoteDummyRepo(os.Getenv("GH_TOKEN"), config.GitHubUser, config.RepoName)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
localRepoPath := filepath.Join(config.LocalRepoDir, config.RepoName)
err = cloneRepo(repoURL, localRepoPath)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Printf("Committing")
for c := 0; c < numCols; c++ {
for r := 0; r < numRows; r++ {
if message[r][c] > 0 {
err = commit(commitDate, localRepoPath, config)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
commitDate = commitDate.AddDate(0, 0, 1)
}
if c%5 == 0 {
fmt.Print(".")
}
}
fmt.Println()
fmt.Println("Pushing")
err = push(localRepoPath)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Printf("Find your message at https://github.com/%s\n", config.GitHubUser)
}
func calendarStartDate() time.Time {
// find the most recent Saturday (bottom right corner of the calendar)
endDate := time.Now()
weekDay := endDate.Weekday()
if weekDay != time.Saturday {
numCols -= 1
endDate = endDate.AddDate(0, 0, -int(weekDay+1)%7)
}
// work backwards to the first Sunday (top left corner of the calendar)
startDate := endDate.AddDate(0, 0, -1*numCols*numRows+1)
return startDate
}