-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
106 lines (90 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println(" ---== Execution Started ==--- \n ")
currBranch, err := currentBranch()
if err != nil {
panic(err)
}
fmt.Println("Current Branch:", currBranch, "\n Make sure it's the default branch.")
commitInDate(time.Now(), true)
today := today()
// initial date
currDate := lastDayLastYear()
// setup file that will be changed
err = updateFile()
if err != nil {
panic(err)
}
err = add(tmpFileName)
if err != nil {
panic(err)
}
for {
currDate = currDate.Add(1 * time.Hour * 24)
if !currDate.Before(today) {
break
}
weekday := currDate.Weekday()
if weekday == time.Sunday || weekday == time.Saturday {
continue
}
err = createHistory(currDate)
if err != nil {
panic(err) // TODO: add log instead to not fail everything?
}
}
fmt.Println("Applying all date")
err = rebaseDates()
if err != nil {
panic(err)
}
fmt.Println("Pushing")
err = pushCurrent(true)
if err != nil {
panic(err)
}
}
func createHistory(date time.Time) error {
commitCount := RandInt(1, 25) // 1-25 commits
fmt.Printf("(%d) Creating history in %v\n", commitCount, date)
for range commitCount {
err := updateFile()
if err != nil {
return err
}
date = date.Add(1 * time.Minute)
err = commitInDate(date, false)
if err != nil {
return err
}
}
return nil
}
func today() time.Time {
return time.Date(
time.Now().Year(),
time.Now().Month(),
time.Now().Day(),
0,
0,
0,
0,
time.Now().Location(),
)
}
func lastDayLastYear() time.Time {
return time.Date(
time.Now().Year(),
1,
0,
12,
0,
0,
0,
time.Now().Location(),
) // one less day than Jan 1st
}