diff --git a/DOCS.md b/DOCS.md index f4c8bba..333ddf7 100644 --- a/DOCS.md +++ b/DOCS.md @@ -37,7 +37,7 @@ steps: + text: "Hello Repo {{ .RepositoryName }}!" ``` -Sample of sending a message with attachment file: +Sample of sending a message with local attachment file: ```diff steps: @@ -47,6 +47,22 @@ steps: parameters: - text: "Hello World!" filepath: slack_attachment.json + remote: false + registry: https://github.com +``` + +Sample of sending a message with remote attachment file: + +```diff +steps: + - name: message-with-remote-attachment + image: target/vela-slack:latest + secrets: [ webhook ] + parameters: +- text: "Hello World!" + filepath: slack_attachment.json + remote: true + registry: https://github.com ``` content of `slack_attachment.json`: diff --git a/cmd/vela-slack/plugin.go b/cmd/vela-slack/plugin.go index 3e41ff4..92ce6a6 100644 --- a/cmd/vela-slack/plugin.go +++ b/cmd/vela-slack/plugin.go @@ -204,11 +204,9 @@ func (p *Plugin) Validate() error { return nil } -// getRemoteAttachment function to open and parse slack attachment json file into -// slack webhook message payload. +// getRemoteAttachment function converts bytes into string and replaces variables +// such as {{ .BuildCreated }} with a correct values before returning it back into bytes again. func replaceString(bytes []byte, p *Plugin) []byte { - // Converts bytes into string and replaces {{ .BuildCreated }} - // with a timestamp before returning it back into bytes again. bStr := string(bytes) bStr = strings.ReplaceAll(bStr, "{{ .BuildCreated }}", strconv.Itoa(p.Env.BuildCreated)) bStr = strings.ReplaceAll(bStr, "{{ .BuildEnqueued }}", strconv.Itoa(p.Env.BuildEnqueued))