From 332b73d3b0b9df14ab9d9fcd6418138f9b910aec Mon Sep 17 00:00:00 2001 From: TP Honey Date: Wed, 23 Feb 2022 11:55:46 +0000 Subject: [PATCH] (DRON-237) cards add link to image repo, minor cleanup --- card.go | 21 ++++++++++++++++++++- docker.go | 1 + docs/card.data.json | 3 ++- docs/card.json | 18 +++++++++++++----- go.mod | 1 + go.sum | 3 ++- 6 files changed, 39 insertions(+), 8 deletions(-) diff --git a/card.go b/card.go index edb2a4ff..9702f523 100644 --- a/card.go +++ b/card.go @@ -8,6 +8,8 @@ import ( "io/ioutil" "os" "os/exec" + "path" + "strings" "time" "github.com/drone/drone-go/drone" @@ -36,7 +38,9 @@ func (p Plugin) writeCard() error { for _, tag := range inspect.RepoTags { sliceTagStruct = append(sliceTagStruct, TagStruct{Tag: tag}) } - inspect.ParsedRepoTags = sliceTagStruct + inspect.ParsedRepoTags = sliceTagStruct[1:] // remove the first tag which is always "hash:latest" + // create the url from repo and registry + inspect.URL = mapRegistryToURL(p.Daemon.Registry, p.Build.Repo) cardData, _ := json.Marshal(inspect) card := drone.CardInput{ @@ -67,3 +71,18 @@ func writeCardTo(out io.Writer, data []byte) { io.WriteString(out, "\u001B]0m") io.WriteString(out, "\n") } + +func mapRegistryToURL(registry, repo string) (url string) { + url = "https://" + var domain string + if strings.Contains(registry, "amazonaws.com") { + domain = "gallery.ecr.aws/" + } else if strings.Contains(registry, "gcr.io") { + domain = "console.cloud.google.com/gcr/images" + } else { + // default to docker hub + domain = "hub.docker.com/r/" + } + url = path.Join(url, domain, repo) + return url +} diff --git a/docker.go b/docker.go index cf86afa3..9d53c24f 100644 --- a/docker.go +++ b/docker.go @@ -94,6 +94,7 @@ type ( SizeString string VirtualSizeString string Time string + URL string `json:"URL"` } TagStruct struct { Tag string `json:"Tag"` diff --git a/docs/card.data.json b/docs/card.data.json index 3deeebf6..fbfecb75 100644 --- a/docs/card.data.json +++ b/docs/card.data.json @@ -36,5 +36,6 @@ }, "SizeString": "13.40MB", "VirtualSizeString": "13.40MB", - "Time": "2022-02-16T11:13:40Z" + "Time": "2022-02-16T11:13:40Z", + "URL": "http://hub.docker.com/repositories/tphoney/test/" } \ No newline at end of file diff --git a/docs/card.json b/docs/card.json index 65f612a1..01861f92 100644 --- a/docs/card.json +++ b/docs/card.json @@ -61,12 +61,15 @@ "type": "FactSet", "facts": [ { - "title": "-", - "value": "${Tag}" + "title": "${Tag}", + "value": "" } ], "spacing": "Small", - "$data": "${ParsedRepoTags}" + "$data": "${ParsedRepoTags}", + "wrap": true, + "size": "Small", + "weight": "Bolder" } ], "separator": true, @@ -88,7 +91,6 @@ "spacing": "Small", "text": "${SizeString}", "wrap": true, - "size": "Small", "weight": "Bolder" } ], @@ -112,7 +114,6 @@ "spacing": "Small", "text": "{{DATE(${Time})}} - {{TIME(${Time})}}", "wrap": true, - "size": "Small", "weight": "Bolder" } ], @@ -125,6 +126,13 @@ "separator": true } ], + "actions": [ + { + "type": "Action.OpenUrl", + "title": "Go to image", + "url": "${url}" + } + ], "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "version": "1.5" } \ No newline at end of file diff --git a/go.mod b/go.mod index 4ab477ee..95a47206 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,7 @@ require ( github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 // indirect golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 // indirect + gopkg.in/yaml.v2 v2.2.8 // indirect ) go 1.17 diff --git a/go.sum b/go.sum index 53c17333..795ef389 100644 --- a/go.sum +++ b/go.sum @@ -38,5 +38,6 @@ golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnf golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=