/
check_prototype.go
51 lines (44 loc) · 1.27 KB
/
check_prototype.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
package concourse
import (
"bytes"
"encoding/json"
"net/http"
"github.com/concourse/concourse/atc"
"github.com/concourse/concourse/go-concourse/concourse/internal"
"github.com/tedsuo/rata"
)
func (team *team) CheckPrototype(pipelineRef atc.PipelineRef, prototypeName string, version atc.Version, shallow bool) (atc.Build, bool, error) {
params := rata.Params{
"pipeline_name": pipelineRef.Name,
"prototype_name": prototypeName,
"team_name": team.Name(),
}
var build atc.Build
jsonBytes, err := json.Marshal(atc.CheckRequestBody{From: version, Shallow: shallow})
if err != nil {
return build, false, err
}
err = team.connection.Send(internal.Request{
RequestName: atc.CheckPrototype,
Params: params,
Query: pipelineRef.QueryParams(),
Body: bytes.NewBuffer(jsonBytes),
Header: http.Header{"Content-Type": []string{"application/json"}},
}, &internal.Response{
Result: &build,
})
switch e := err.(type) {
case nil:
return build, true, nil
case internal.ResourceNotFoundError:
return build, false, nil
case internal.UnexpectedResponseError:
if e.StatusCode == http.StatusInternalServerError {
return build, false, GenericError{e.Body}
} else {
return build, false, err
}
default:
return build, false, err
}
}