-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrockstar.go
117 lines (103 loc) · 2.81 KB
/
rockstar.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
107
108
109
110
111
112
113
114
115
116
117
package main
import (
"fmt"
"io/ioutil"
"math/rand"
"os"
"os/exec"
"strconv"
"time"
"github.com/nu7hatch/gouuid"
"github.com/urfave/cli"
)
// Repo general information about repo
type Repo struct {
DirPath string
FilePath string
}
func randomName() string {
rand.Seed(time.Now().UnixNano())
return fmt.Sprintf("%v-%v-%v", adjs[rand.Intn(len(adjs))], nouns[rand.Intn(len(nouns))], repos[rand.Intn(len(repos))])
}
func newRepo(filename string) Repo {
dirPath := randomName()
os.Mkdir(dirPath, 0755)
os.Chdir(dirPath)
exec.Command("git", "init", ".").Run()
return Repo{DirPath: dirPath, FilePath: filename}
}
func (r *Repo) appendCommit(data string, date time.Time) {
err := ioutil.WriteFile(r.FilePath, []byte(data), 0644)
if err != nil {
fmt.Println(err)
return
}
os.Setenv("GIT_AUTHOR_DATE", date.Format(time.RFC3339))
os.Setenv("GIT_COMMITTER_DATE", date.Format(time.RFC3339))
exec.Command("git", "add", r.FilePath).Run()
exec.Command("git", "commit", "-m", messages[rand.Intn(len(messages))]).Run()
}
func (r *Repo) createRemoteRepo() {
_, err := exec.Command("hub", "version").Output()
if err != nil {
return
}
fmt.Println("Creating in your github account")
exec.Command("hub", "create").Run()
exec.Command("git", "push", "origin", "master").Run()
}
func main() {
app := cli.NewApp()
app.Name = "rockstar-cli"
app.Usage = "It make you a rockstar in less than 10 seconds"
app.Version = "0.0.1"
app.Author = "Luis Ezcurdia"
app.Email = "[email protected]"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "days, d",
Value: "500",
Usage: "days of activity",
},
cli.StringFlag{
Name: "code, c",
Value: "writeln('Go is Awesome!!!')",
Usage: "code base",
},
cli.StringFlag{
Name: "filename, f",
Value: "main.go",
Usage: "output file",
},
}
app.Action = func(c *cli.Context) {
days, _ := strconv.Atoi(c.String("days"))
if days > 0 {
days *= -1
}
repo := newRepo(c.String("filename"))
for i := days; i < 0; i++ {
d := time.Now().Add(time.Duration(i*24) * time.Hour)
if (d.Weekday() == time.Sunday || d.Weekday() == time.Saturday) && i%3 == 0 {
continue
}
for j := 0; j < rand.Intn(10); j++ {
authorDate := time.Date(d.Year(), d.Month(), d.Day(), int(rand.NormFloat64()*3.0+12.0), rand.Intn(59), rand.Intn(59), 0, d.Location())
uid, err := uuid.NewV5(uuid.NamespaceURL, []byte(time.Now().Format(time.RFC3339Nano)))
commitData := fmt.Sprintf("%s", uid)
if err != nil {
continue
}
repo.appendCommit(commitData, authorDate)
}
fmt.Print(".")
}
repo.appendCommit(c.String("code"), time.Now())
os.Setenv("GIT_AUTHOR_DATE", "")
os.Setenv("GIT_COMMITTER_DATE", "")
repo.createRemoteRepo()
fmt.Printf("\nProyect created on: %v", repo.DirPath)
fmt.Println("\nNow you are a goddamn rockstar!")
}
app.Run(os.Args)
}