-
Notifications
You must be signed in to change notification settings - Fork 25
/
gitlab-client.go
61 lines (56 loc) · 1.34 KB
/
gitlab-client.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
package main
import (
"github.com/plouc/go-gitlab-client"
"strings"
"fmt"
"os/exec"
)
type GitLabClient struct {
GitLab *gogitlab.Gitlab
}
func NewGitLabClient(config GitConfig) (*GitLabClient, error) {
host , e := config.Host()
if e != nil {
return nil, e
}
path , e := config.ApiPath()
if e != nil {
return nil, e
}
token , e := config.Token()
if e != nil {
return nil, e
}
client := GitLabClient{
GitLab: gogitlab.NewGitlab(host, path, token),
}
return &client, e
}
func (this *GitLabClient)clone (remote string, path string) (string, error) {
if this == nil {
return "", nil
}
fmt.Println("search project " + this.GitLab.BaseUrl + "/" + remote)
// search remote repository
projectID := strings.Replace(remote, "/", "%2F", -1)
project , e := this.GitLab.Project(projectID)
if e != nil {
return "", e
}
// get remote URL
remoteURL := project.SshRepoUrl
// clone
var dest string
if len(path) < 0 {
dest = project.Path
} else {
dest = path + "/" + project.Path
}
fmt.Println("clone repository from " + remoteURL + " to " + dest)
repo, e := exec.Command("git","clone", remoteURL, dest).Output()
if e != nil {
return "" ,e
}
res := string(repo)
return res, e
}