forked from plouc/go-gitlab-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
builds.go
161 lines (123 loc) · 4.05 KB
/
builds.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package gogitlab
import (
"encoding/json"
"io"
)
const (
project_builds = "/projects/:id/builds" // List project builds
project_build = "/projects/:id/builds/:build_id" // Get a single build
project_commit_builds = "/projects/:id/repository/commits/:sha/builds" // List commit builds
project_build_artifacts = "/projects/:id/builds/:build_id/artifacts" // Get build artifacts
project_build_cancel = "/projects/:id/builds/:build_id/cancel" // Cancel a build
project_build_retry = "/projects/:id/builds/:build_id/retry" // Retry a build
project_build_erase = "/projects/:id/builds/:build_id/erase" // Erase a build
)
type ArtifactsFile struct {
Filename string `json:"filename"`
Size int `json:"size"`
}
type Build struct {
Id int `json:"id"`
ArtifactsFile ArtifactsFile `json:"artifacts_file"`
Commit Commit `json:"commit,omitempty"`
CreatedAt string `json:"created_at"`
DownloadURL string `json:"download_url"`
FinishedAt string `json:"finished_at"`
Name string `json:"name"`
Ref string `json:"ref"`
Stage string `json:"stage"`
StartedAt string `json:"started_at"`
Status string `json:"status"`
Tag bool `json:"tag"`
User User `json:"user"`
When string `json:"when,omitempty"`
Manual bool `json:"manual,omitempty"`
}
func (g *Gitlab) ProjectBuilds(id string) ([]*Build, error) {
url, opaque := g.ResourceUrlRaw(project_builds, map[string]string{
":id": id,
})
builds := make([]*Build, 0)
contents, err := g.buildAndExecRequestRaw("GET", url, opaque, nil)
if err != nil {
return builds, err
}
err = json.Unmarshal(contents, &builds)
return builds, err
}
func (g *Gitlab) ProjectCommitBuilds(id, sha1 string) ([]*Build, error) {
url, opaque := g.ResourceUrlRaw(project_commit_builds, map[string]string{
":id": id,
":sha": sha1,
})
builds := make([]*Build, 0)
contents, err := g.buildAndExecRequestRaw("GET", url, opaque, nil)
if err != nil {
return builds, err
}
err = json.Unmarshal(contents, &builds)
return builds, err
}
func (g *Gitlab) ProjectBuild(id, buildId string) (*Build, error) {
url, opaque := g.ResourceUrlRaw(project_build, map[string]string{
":id": id,
":build_id": buildId,
})
build := &Build{}
contents, err := g.buildAndExecRequestRaw("GET", url, opaque, nil)
if err != nil {
return nil, err
}
err = json.Unmarshal(contents, &build)
return build, err
}
func (g *Gitlab) ProjectBuildArtifacts(id, buildId string) (io.ReadCloser, error) {
url, _ := g.ResourceUrlRaw(project_build_artifacts, map[string]string{
":id": id,
":build_id": buildId,
})
resp, err := g.execRequest("GET", url, nil)
if err != nil {
return nil, err
}
return resp.Body, nil
}
func (g *Gitlab) ProjectCancelBuild(id, buildId string) (*Build, error) {
url, opaque := g.ResourceUrlRaw(project_build_cancel, map[string]string{
":id": id,
":build_id": buildId,
})
build := &Build{}
contents, err := g.buildAndExecRequestRaw("POST", url, opaque, nil)
if err != nil {
return nil, err
}
err = json.Unmarshal(contents, &build)
return build, err
}
func (g *Gitlab) ProjectRetryBuild(id, buildId string) (*Build, error) {
url, opaque := g.ResourceUrlRaw(project_build_retry, map[string]string{
":id": id,
":build_id": buildId,
})
build := &Build{}
contents, err := g.buildAndExecRequestRaw("POST", url, opaque, nil)
if err != nil {
return nil, err
}
err = json.Unmarshal(contents, &build)
return build, err
}
func (g *Gitlab) ProjectEraseBuild(id, buildId string) (*Build, error) {
url, opaque := g.ResourceUrlRaw(project_build_erase, map[string]string{
":id": id,
":build_id": buildId,
})
build := &Build{}
contents, err := g.buildAndExecRequestRaw("POST", url, opaque, nil)
if err != nil {
return nil, err
}
err = json.Unmarshal(contents, &build)
return build, err
}