This repository has been archived by the owner on Sep 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutil.go
88 lines (78 loc) · 1.47 KB
/
util.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
package main
import (
"os"
"strconv"
"strings"
"time"
git "gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing/object"
"gopkg.in/src-d/go-git.v4/plumbing/transport/http"
)
var (
gitName string
gitEmail string
gitID string
gitPW string
)
func init() {
for _, val := range os.Args {
arg := strings.Split(val, "=")
if len(arg) < 2 {
continue
} else if arg[0] == "-gitName" {
gitName = arg[1]
} else if arg[0] == "-gitEmail" {
gitEmail = arg[1]
} else if arg[0] == "-gitID" {
gitID = arg[1]
} else if arg[0] == "-gitPW" {
gitPW = arg[1]
}
}
}
func sumStrFloat(s1, s2 string) (sum float64) {
f1, err1 := strconv.ParseFloat(s1, 64)
f2, err2 := strconv.ParseFloat(s2, 64)
if err1 == nil && err2 == nil {
sum = f1 + f2
}
return
}
func toDateStr(timestamp int64) string {
return time.Unix(timestamp, 0).Format(time.RFC3339)
}
// gitPushChanges commits log changes and pushs it
func gitPushChanges() error {
if gitID == "" || gitPW == "" {
return nil
}
// Open
r, err := git.PlainOpen("./")
if err != nil {
return err
}
w, err := r.Worktree()
if err != nil {
return err
}
// Commit
if _, err = w.Commit("log updated", &git.CommitOptions{
Author: &object.Signature{
Name: gitName,
Email: gitEmail,
When: time.Now(),
},
All: true,
}); err != nil {
return err
}
// Push
r.Push(&git.PushOptions{
RemoteName: "origin",
Auth: &http.BasicAuth{
Username: gitID,
Password: gitPW,
},
})
return nil
}