Repository navigation
Expand file tree
/
Copy pathplugin.go
More file actions
76 lines (64 loc) · 1.65 KB
/
Copy pathplugin.go
File metadata and controls
76 lines (64 loc) · 1.65 KB
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
package main
import (
"errors"
"log"
"net/url"
"time"
)
type (
// Plugin values.
Plugin struct {
Host string
Token string
Ref string
ID string
Debug bool
}
// Commit struct
Commit struct {
ID int `json:"id"`
Sha string `json:"sha"`
Ref string `json:"ref"`
Status string `json:"status"`
BeforeSha string `json:"before_sha"`
Tag bool `json:"tag"`
YamlErrors interface{} `json:"yaml_errors"`
User struct {
Name string `json:"name"`
Username string `json:"username"`
ID int `json:"id"`
State string `json:"state"`
AvatarURL string `json:"avatar_url"`
WebURL string `json:"web_url"`
} `json:"user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
StartedAt time.Time `json:"started_at"`
FinishedAt time.Time `json:"finished_at"`
CommittedAt time.Time `json:"committed_at"`
Duration interface{} `json:"duration"`
Coverage interface{} `json:"coverage"`
}
)
// Exec executes the plugin.
func (p Plugin) Exec() error {
if len(p.Host) == 0 || len(p.Token) == 0 || len(p.ID) == 0 {
return errors.New("missing gitlab-ci config")
}
ci := NewGitlab(p.Host, p.Debug)
params := url.Values{
"token": []string{p.Token},
"ref": []string{p.Ref},
}
body := &Commit{}
err := ci.trigger(p.ID, params, body)
if err != nil {
log.Println("gitlab-ci error:", err.Error())
return err
}
log.Println("build id:", body.ID)
log.Println("build sha:", body.Sha)
log.Println("build ref:", body.Ref)
log.Println("build status:", body.Status)
return nil
}