Repository: appleboy/drone-telegram (go)

Issue:
Invalid version of github.com/drone/drone-template-lib
You changed the version of `github.com/drone/drone-template-lib` from v1.0.0 in this [commit](https://github.com/appleboy/drone-telegram/commit/47352c6cca24f624b46e5093a77f41a1ba499bd5#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6L6) to v1.0.1-x to fix the issue in #89 and #92. Also see [#47](https://github.com/drone-plugins/drone-webhook/issues/47)

With your latest release / version v1.3.9 you accidentally changed the version of `github.com/drone/drone-template-lib` back to v1.0.0 which breaks the templating functions `duration`, `datetime` and `since` because these functions expect a `float64` value but _build.started_ and _build.finished_ are `int64` values.

I guess there are two possible solutions: Reverting / changing back to version v1.0.1-x or opening a PR on the [drone-template-lib](https://github.com/drone/drone-template-lib) project to release a new version with the correct values; the master branch already has the correct `int64` type, but the released branch v1.0.0 uses the old `float64` type.


Pull request:
Fix can't call duration helper func
fix #102 

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

Patch:
diff --git a/go.mod b/go.mod
index 4dd425a..664bb24 100644
--- a/go.mod
+++ b/go.mod
@@ -3,7 +3,7 @@ module github.com/appleboy/drone-telegram
 go 1.16
 
 require (
-	github.com/drone/drone-template-lib v1.0.1-0.20201006172840-a58a3f26ebca
+	github.com/appleboy/drone-template-lib v1.0.1-0.20210703043441-92442f23f605 // indirect
 	github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible
 	github.com/joho/godotenv v1.3.0
 	github.com/stretchr/testify v1.7.0
diff --git a/go.sum b/go.sum
index 7a97279..71147b1 100644
--- a/go.sum
+++ b/go.sum
@@ -5,6 +5,8 @@ github.com/Masterminds/semver/v3 v3.1.0 h1:Y2lUDsFKVRSYGojLJ1yLxSXdMmMYTYls0rCvo
 github.com/Masterminds/semver/v3 v3.1.0/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
 github.com/Masterminds/sprig/v3 v3.1.0 h1:j7GpgZ7PdFqNsmncycTHsLmVPf5/3wJtlgW9TNDYD9Y=
 github.com/Masterminds/sprig/v3 v3.1.0/go.mod h1:ONGMf7UfYGAbMXCZmQLy8x3lCDIPrEZE/rU8pmrbihA=
+github.com/appleboy/drone-template-lib v1.0.1-0.20210703043441-92442f23f605 h1:13DCA0YYotNdiFodfoWpMVBi4bBTv3OxO2o/IU60kuw=
+github.com/appleboy/drone-template-lib v1.0.1-0.20210703043441-92442f23f605/go.mod h1:Mdr1SPt42qahB+Gfb/QBsQID+tkBkzrR+j+Gwq9XMBs=
 github.com/aymerick/raymond v2.0.2+incompatible h1:VEp3GpgdAnv9B2GFyTvqgcKvY+mfKMjPOA3SbKLtnU0=
 github.com/aymerick/raymond v2.0.2+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
 github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
@@ -12,8 +14,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:ma
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/drone/drone-template-lib v1.0.1-0.20201006172840-a58a3f26ebca h1:8kk7qaQJ1R3aIDMQ04NhKRZQZZgBE9veNYme2Wjudts=
-github.com/drone/drone-template-lib v1.0.1-0.20201006172840-a58a3f26ebca/go.mod h1:4DHXhrDoAGam5Sx6LHygmi2tkhWt2dWXqNFLQNxmWTc=
 github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible h1:2cauKuaELYAEARXRkq2LrJ0yDDv1rW7+wrTEdVL3uaU=
 github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible/go.mod h1:qf9acutJ8cwBUhm1bqgz6Bei9/C/c93FPDljKWwsOgM=
 github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
diff --git a/plugin.go b/plugin.go
index 0fe85ee..8f1c5d2 100644
--- a/plugin.go
+++ b/plugin.go
@@ -15,7 +15,7 @@ import (
 	"strconv"
 	"strings"
 
-	"github.com/drone/drone-template-lib/template"
+	"github.com/appleboy/drone-template-lib/template"
 	tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
 )
 


Test patch:
diff --git a/plugin_test.go b/plugin_test.go
index f5589b3..19d34df 100644
--- a/plugin_test.go
+++ b/plugin_test.go
@@ -5,6 +5,7 @@ import (
 	"testing"
 	"time"
 
+	"github.com/appleboy/drone-template-lib/template"
 	"github.com/stretchr/testify/assert"
 )
 
@@ -497,3 +498,31 @@ func TestProxySendMessage(t *testing.T) {
 	err := plugin.Exec()
 	assert.Nil(t, err)
 }
+
+func TestBuildTemplate(t *testing.T) {
+	plugin := Plugin{
+		Commit: Commit{
+			Sha:     "e7c4f0a63ceeb42a39ac7806f7b51f3f0d204fd2",
+			Author:  "Bo-Yi Wu",
+			Branch:  "master",
+			Message: "This is a test commit msg",
+		},
+		Build: Build{
+			Number:   101,
+			Status:   "success",
+			Link:     "https://github.com/appleboy/go-hello",
+			Started:  time.Now().Unix(),
+			Finished: time.Now().Add(time.Duration(180 * time.Second)).Unix(),
+		},
+	}
+
+	_, err := template.RenderTrim(
+		`
+Sample message loaded from file.
+
+Commit msg:  {{uppercasefirst commit.message}}
+
+duration: {{duration build.started build.finished}}
+`, plugin)
+	assert.Nil(t, err)
+}