Skip to content

Commit 332b73d

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

File tree

6 files changed

+39
-8
lines changed

6 files changed

+39
-8
lines changed

card.go

+20-1
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

+1
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

+2-1
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

+13-5
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,15 @@
6161
"type": "FactSet",
6262
"facts": [
6363
{
64-
"title": "-",
65-
"value": "${Tag}"
64+
"title": "${Tag}",
65+
"value": ""
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,
@@ -88,7 +91,6 @@
8891
"spacing": "Small",
8992
"text": "${SizeString}",
9093
"wrap": true,
91-
"size": "Small",
9294
"weight": "Bolder"
9395
}
9496
],
@@ -112,7 +114,6 @@
112114
"spacing": "Small",
113115
"text": "{{DATE(${Time})}} - {{TIME(${Time})}}",
114116
"wrap": true,
115-
"size": "Small",
116117
"weight": "Bolder"
117118
}
118119
],
@@ -125,6 +126,13 @@
125126
"separator": true
126127
}
127128
],
129+
"actions": [
130+
{
131+
"type": "Action.OpenUrl",
132+
"title": "Go to image",
133+
"url": "${url}"
134+
}
135+
],
128136
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
129137
"version": "1.5"
130138
}

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ require (
1818
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
1919
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 // indirect
2020
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 // indirect
21+
gopkg.in/yaml.v2 v2.2.8 // indirect
2122
)
2223

2324
go 1.17

go.sum

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnf
3838
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8=
3939
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
4040
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
41-
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
4241
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
42+
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
43+
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

0 commit comments

Comments
 (0)