github.com/drone/runner-go@v1.12.0/handler/template/template.go (about) 1 // Copyright 2019 Drone.IO Inc. All rights reserved. 2 // Use of this source code is governed by the Polyform License 3 // that can be found in the LICENSE file. 4 5 package template 6 7 import ( 8 "regexp" 9 "strings" 10 "time" 11 ) 12 13 //go:generate togo tmpl -func funcMap -format html 14 15 // regular expression to extract the pull request number 16 // from the git ref (e.g. refs/pulls/{d}/head) 17 var re = regexp.MustCompile("\\d+") 18 19 // mirros the func map in template.go 20 var funcMap = map[string]interface{}{ 21 "timestamp": func(v int64) string { 22 return time.Unix(v, 0).UTC().Format("2006-01-02T15:04:05Z") 23 }, 24 "pr": func(s string) string { 25 return re.FindString(s) 26 }, 27 "sha": func(s string) string { 28 if len(s) > 8 { 29 s = s[:8] 30 } 31 return s 32 }, 33 "tag": func(s string) string { 34 return strings.TrimPrefix(s, "refs/tags/") 35 }, 36 "done": func(s string) bool { 37 return s != "pending" && s != "running" 38 }, 39 }