File tree Expand file tree Collapse file tree 2 files changed +66
-1
lines changed
Expand file tree Collapse file tree 2 files changed +66
-1
lines changed Original file line number Diff line number Diff line change @@ -140,7 +140,12 @@ func (p Plugin) Exec() error {
140140}
141141
142142func templateMessage (t string , plugin Plugin ) (string , error ) {
143- return template .RenderTrim (t , plugin )
143+ c , err := contents (t )
144+ if err != nil {
145+ return "" , fmt .Errorf ("could not read template: %w" , err )
146+ }
147+
148+ return template .RenderTrim (c , plugin )
144149}
145150
146151func message (repo Repo , build Build ) string {
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "fmt"
5+ "io"
6+ "net/http"
7+ "net/url"
8+ "os"
9+ )
10+
11+ func contents (str string ) (string , error ) {
12+ // Check for the empty string
13+ if str == "" {
14+ return str , nil
15+ }
16+
17+ isFilePath := false
18+
19+ // See if the string is referencing a URL
20+ if u , err := url .Parse (str ); err == nil {
21+ switch u .Scheme {
22+ case "http" , "https" :
23+ res , err := http .Get (str )
24+ if err != nil {
25+ return "" , err
26+ }
27+
28+ defer res .Body .Close ()
29+ b , err := io .ReadAll (res .Body )
30+ if err != nil {
31+ return "" , fmt .Errorf ("could not read response: %w" , err )
32+ }
33+
34+ return string (b ), nil
35+
36+ case "file" :
37+ // Fall through to file loading
38+ str = u .Path
39+ isFilePath = true
40+ }
41+ }
42+
43+ // See if the string is referencing a file
44+ _ , err := os .Stat (str )
45+ if err == nil {
46+ b , err := os .ReadFile (str )
47+ if err != nil {
48+ return "" , fmt .Errorf ("could not load file %s: %w" , str , err )
49+ }
50+
51+ return string (b ), nil
52+ }
53+
54+ if isFilePath {
55+ return "" , fmt .Errorf ("could not load file %s: %w" , str , err )
56+ }
57+
58+ // Its a regular string
59+ return str , nil
60+ }
You can’t perform that action at this time.
0 commit comments