-
Notifications
You must be signed in to change notification settings - Fork 7
/
artifact_id.go
57 lines (49 loc) · 1.41 KB
/
artifact_id.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
package actions
import (
"fmt"
"net/http"
"net/url"
httpinternal "github.com/lunarway/release-manager/internal/http"
)
func ArtifactIDFromEnvironment(client *httpinternal.Client, service, namespace, environment string) (string, error) {
var statusResp httpinternal.StatusResponse
params := url.Values{}
params.Add("service", service)
if namespace != "" {
params.Add("namespace", namespace)
}
path, err := client.URLWithQuery("status", params)
if err != nil {
return "", err
}
err = client.Do(http.MethodGet, path, nil, &statusResp)
if err != nil {
return "", err
}
switch environment {
case "dev":
return statusResp.Dev.Tag, nil
case "staging":
return statusResp.Staging.Tag, nil
case "prod":
return statusResp.Prod.Tag, nil
}
return "", fmt.Errorf("unknown environment %s", environment)
}
func ArtifactIDFromBranch(client *httpinternal.Client, service string, branch string) (string, error) {
var describeResp httpinternal.DescribeArtifactResponse
params := url.Values{}
params.Add("branch", branch)
path, err := client.URLWithQuery(fmt.Sprintf("describe/latest-artifact/%s/%s", service, branch), params)
if err != nil {
return "", err
}
err = client.Do(http.MethodGet, path, nil, &describeResp)
if err != nil {
return "", err
}
if len(describeResp.Artifacts) == 0 {
return "", fmt.Errorf("no artifacts found on from branch '%s'", branch)
}
return describeResp.Artifacts[0].ID, nil
}