(DRON-237) cards add link to image repo, minor cleanup

This commit is contained in:
TP Honey 2022-02-23 11:55:46 +00:00
parent b6c9110c83
commit 332b73d3b0
6 changed files with 39 additions and 8 deletions

21
card.go
View File

@ -8,6 +8,8 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path"
"strings"
"time" "time"
"github.com/drone/drone-go/drone" "github.com/drone/drone-go/drone"
@ -36,7 +38,9 @@ func (p Plugin) writeCard() error {
for _, tag := range inspect.RepoTags { for _, tag := range inspect.RepoTags {
sliceTagStruct = append(sliceTagStruct, TagStruct{Tag: tag}) 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) cardData, _ := json.Marshal(inspect)
card := drone.CardInput{ card := drone.CardInput{
@ -67,3 +71,18 @@ func writeCardTo(out io.Writer, data []byte) {
io.WriteString(out, "\u001B]0m") io.WriteString(out, "\u001B]0m")
io.WriteString(out, "\n") 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
}

View File

@ -94,6 +94,7 @@ type (
SizeString string SizeString string
VirtualSizeString string VirtualSizeString string
Time string Time string
URL string `json:"URL"`
} }
TagStruct struct { TagStruct struct {
Tag string `json:"Tag"` Tag string `json:"Tag"`

View File

@ -36,5 +36,6 @@
}, },
"SizeString": "13.40MB", "SizeString": "13.40MB",
"VirtualSizeString": "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/"
} }

View File

@ -61,12 +61,15 @@
"type": "FactSet", "type": "FactSet",
"facts": [ "facts": [
{ {
"title": "-", "title": "${Tag}",
"value": "${Tag}" "value": ""
} }
], ],
"spacing": "Small", "spacing": "Small",
"$data": "${ParsedRepoTags}" "$data": "${ParsedRepoTags}",
"wrap": true,
"size": "Small",
"weight": "Bolder"
} }
], ],
"separator": true, "separator": true,
@ -88,7 +91,6 @@
"spacing": "Small", "spacing": "Small",
"text": "${SizeString}", "text": "${SizeString}",
"wrap": true, "wrap": true,
"size": "Small",
"weight": "Bolder" "weight": "Bolder"
} }
], ],
@ -112,7 +114,6 @@
"spacing": "Small", "spacing": "Small",
"text": "{{DATE(${Time})}} - {{TIME(${Time})}}", "text": "{{DATE(${Time})}} - {{TIME(${Time})}}",
"wrap": true, "wrap": true,
"size": "Small",
"weight": "Bolder" "weight": "Bolder"
} }
], ],
@ -125,6 +126,13 @@
"separator": true "separator": true
} }
], ],
"actions": [
{
"type": "Action.OpenUrl",
"title": "Go to image",
"url": "${url}"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.5" "version": "1.5"
} }

1
go.mod
View File

@ -18,6 +18,7 @@ require (
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 // indirect golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 // indirect
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 // indirect golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
) )
go 1.17 go 1.17

3
go.sum
View File

@ -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 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 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/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.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=