Skip to content

Commit fd74f20

Browse files
author
TP Honey
committed
(DRON-237) cards add link to image repo, minor cleanup
1 parent b6c9110 commit fd74f20

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

card.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"io/ioutil"
99
"os"
1010
"os/exec"
11+
"path"
12+
"strings"
1113
"time"
1214

1315
"github.com/drone/drone-go/drone"
@@ -36,7 +38,9 @@ func (p Plugin) writeCard() error {
3638
for _, tag := range inspect.RepoTags {
3739
sliceTagStruct = append(sliceTagStruct, TagStruct{Tag: tag})
3840
}
39-
inspect.ParsedRepoTags = sliceTagStruct
41+
inspect.ParsedRepoTags = sliceTagStruct[1:] // remove the first tag which is always "hash:latest"
42+
// create the url from repo and registry
43+
inspect.URL = mapRegistryToURL(p.Daemon.Registry, p.Build.Repo)
4044
cardData, _ := json.Marshal(inspect)
4145

4246
card := drone.CardInput{
@@ -67,3 +71,18 @@ func writeCardTo(out io.Writer, data []byte) {
6771
io.WriteString(out, "\u001B]0m")
6872
io.WriteString(out, "\n")
6973
}
74+
75+
func mapRegistryToURL(registry, repo string) (url string) {
76+
url = "https://"
77+
var domain string
78+
if strings.Contains(registry, "amazonaws.com") {
79+
domain = "gallery.ecr.aws/"
80+
} else if strings.Contains(registry, "gcr.io") {
81+
domain = "console.cloud.google.com/gcr/images"
82+
} else {
83+
// default to docker hub
84+
domain = "hub.docker.com/r/"
85+
}
86+
url = path.Join(url, domain, repo)
87+
return url
88+
}

docker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ type (
9494
SizeString string
9595
VirtualSizeString string
9696
Time string
97+
URL string `json:"URL"`
9798
}
9899
TagStruct struct {
99100
Tag string `json:"Tag"`

docs/card.data.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@
3636
},
3737
"SizeString": "13.40MB",
3838
"VirtualSizeString": "13.40MB",
39-
"Time": "2022-02-16T11:13:40Z"
39+
"Time": "2022-02-16T11:13:40Z",
40+
"URL": "http://hub.docker.com/repositories/tphoney/test/"
4041
}

docs/card.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,15 @@
6161
"type": "FactSet",
6262
"facts": [
6363
{
64-
"title": "-",
64+
"title": "",
6565
"value": "${Tag}"
6666
}
6767
],
6868
"spacing": "Small",
69-
"$data": "${ParsedRepoTags}"
69+
"$data": "${ParsedRepoTags}",
70+
"wrap": true,
71+
"size": "Small",
72+
"weight": "Bolder"
7073
}
7174
],
7275
"separator": true,
@@ -125,6 +128,13 @@
125128
"separator": true
126129
}
127130
],
131+
"actions": [
132+
{
133+
"type": "Action.OpenUrl",
134+
"title": "Go to image",
135+
"url": "${url}"
136+
}
137+
],
128138
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
129139
"version": "1.5"
130140
}

0 commit comments

Comments
 (0)