-
Notifications
You must be signed in to change notification settings - Fork 1
/
github.go
53 lines (44 loc) · 1.1 KB
/
github.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
package covid19brazilimporter
import (
"fmt"
"time"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
)
func cloneRepo(folder, password, branch string) (*git.Repository, error) {
url := fmt.Sprintf("https://luiz290788:%s@github.com/luiz290788/covid19-brazil-data.git", password)
return git.PlainClone(folder, false, &git.CloneOptions{
URL: url,
Depth: 1,
ReferenceName: plumbing.NewBranchReferenceName(branch),
})
}
func commitAll(repository *git.Repository, message, name, email string) (hash string, err error) {
var worktree *git.Worktree
worktree, err = repository.Worktree()
if err != nil {
return
}
err = worktree.AddGlob("data/*.json")
if err != nil {
return
}
var commitHash plumbing.Hash
commitHash, err = worktree.Commit(message, &git.CommitOptions{
Author: &object.Signature{
Email: email,
Name: name,
When: time.Now(),
},
Committer: &object.Signature{
Email: email,
Name: name,
When: time.Now(),
},
})
if err != nil {
return
}
return commitHash.String(), nil
}