Compare commits

..

165 Commits

Author SHA1 Message Date
Bo-Yi Wu ce15798a06 chore: update message format 2020-06-20 13:51:48 +08:00
Bo-Yi Wu 3bccad3ca8 chore(makefile): remove GOPACKAGE variable 2020-02-01 17:59:32 +08:00
Bo-Yi Wu 2c8ab1428b chore(drone): update default template.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-12-11 10:34:52 +08:00
Bo-Yi Wu 602b560c4d chore: update default template 2019-12-11 07:34:42 +08:00
Bo-Yi Wu ba1db08ad2 chore: update default message in Drone CI/CD. 2019-12-11 07:24:10 +08:00
Bo-Yi Wu e3fc3f805d docs: update docs 2019-12-07 13:26:50 +08:00
Bo-Yi Wu 44ac6f43de fix: testing 2019-12-07 13:03:59 +08:00
Bo-Yi Wu 5ac85a3412 chore: update socks5 message 2019-12-07 13:00:35 +08:00
Bo-Yi Wu 79e531f648 chore: support github parameter 2019-12-07 12:39:27 +08:00
icecream78 abba2cb37d Add socks5 proxy to plugin (#87) 2019-12-07 11:29:47 +08:00
Bo-Yi Wu 7f8bd6ba04 chore: replace ADD with COPY 2019-11-23 21:51:46 +08:00
Bo-Yi Wu 0dc176a2ac docs: update badge 2019-11-23 21:50:20 +08:00
Bo-Yi Wu 2af2c10e0e chore: update appveyor for windows build 2019-11-23 21:48:06 +08:00
Bo-Yi Wu fe798d95b2 chore: update github actions variable 2019-11-02 14:37:46 +08:00
Daniel M. Lambea ace08f12b9 Unescape html entities (#85)
* Create a constant for 'markdown' formatting style, to reduce duplicated strings and make the code less error-prone

* Unescape HTML entities from text messages
2019-10-30 19:50:31 +08:00
Daniel M. Lambea b7f97df101 Add support for generic templates by using custom extra vars (#84)
* Fix DOCS.md example configuration with custom message from file

* Move .test.message to a better named file

* Add support for additional, custom extra vars to be used in the message template

* Add cmdline/envvars to support the extra vars

* Enhance DOCS.md with example configuration using generic template file with custom vars

* Add testcase for custom template vars
2019-10-29 10:57:00 +08:00
kolaente 866e25b433 Fix using datetime in custom template (#83)
Revert f529160760
2019-10-22 23:46:44 +08:00
Daniel M. Lambea f8f311ba1f Add support for auxiliary message file (#81)
* Add support for external message loaded from the file specified in Config.MessageFile

* Enable the message file option in command line/env vars

* Update docs

* Add a testcase

* Fix YAML tag in DOCS.md from 'messageFile' to 'message_file', as is commonly used in Drone

* Remove unintended blank line

* Move .test.message file to tests/ folder
2019-10-22 23:44:50 +08:00
Bo-Yi Wu 75ffa6ef7b docs: update diff format 2019-10-19 10:23:22 +08:00
Bo-Yi Wu f529160760 fix: update build.started env 2019-10-13 02:09:01 +08:00
Bo-Yi Wu 1904582239 chore: testing the latest version 2019-10-12 23:42:47 +08:00
Bo-Yi Wu f15615fb86 chore: add deployTo and author avatar env 2019-10-11 22:25:20 +08:00
Bo-Yi Wu 7564de8e0d fix: lint error 2019-10-11 20:54:47 +08:00
Bo-Yi Wu 41055d2adf chore: replace template library 2019-10-11 20:51:40 +08:00
Bo-Yi Wu eaddfb222e fix: wrong commit message 2019-10-11 20:47:36 +08:00
Bo-Yi Wu 86b2493453 docs: update drone document. 2019-10-04 21:08:06 +08:00
Bo-Yi Wu e13da09398 chore: remove microbadger 2019-09-29 13:05:53 +08:00
Bo-Yi Wu 5d8f84999a chore: testing send message 2019-09-26 00:39:41 +08:00
Bo-Yi Wu 31944fe6c9 docs: markdown lint 2019-09-25 22:24:06 +08:00
Bo-Yi Wu fe44d6f9a2 fix: testing 2019-09-25 21:59:11 +08:00
Bo-Yi Wu b6fad392f8 fix: testing 2019-09-25 21:40:51 +08:00
Bo-Yi Wu 572cabb9c8 chore: fix location message 2019-09-25 21:37:18 +08:00
Bo-Yi Wu 27b2f70f8a debug
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-09-25 21:31:00 +08:00
Bo-Yi Wu 8f0c041de8 support github action
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-09-25 18:46:25 +08:00
Bo-Yi Wu e6bc04f39c upgrade to go1.13
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-09-25 18:43:28 +08:00
Bo-Yi Wu 3d2c9a75cf docs: update windows base image. 2019-03-24 22:15:03 +08:00
Bo-Yi Wu d66e07c53d docs: Add windows badge 2019-03-24 22:08:55 +08:00
Bo-Yi Wu 2b5a521447 feat: support windows image 2019-03-24 22:07:18 +08:00
Bo-Yi Wu 442708dd05 fix #72 null point for bot (#73)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-03-05 12:33:54 +08:00
Bo-Yi Wu 197bad6faf docs: update build section
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-03-04 16:07:50 +08:00
Bo-Yi Wu c80f626d19 chore: update golang to 1.12 2019-02-27 14:41:54 +08:00
Bo-Yi Wu c406a8bc9b Fix manifest template helper
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-02-26 09:22:27 +08:00
Bo-Yi Wu 82b1568868 fix: remove docker secret from dry run mode. 2019-02-23 13:17:06 +08:00
Bo-Yi Wu 13cfae1884 refactor drone pipeline config
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-02-22 10:33:19 +08:00
Bo-Yi Wu 6b07a8b27d feat(docker): using cache-from can speed up your Docker builds 2019-02-22 00:56:48 +08:00
Bo-Yi Wu 2aee0589c9 feat(env): support multiple env 2019-02-19 22:07:32 +08:00
Bo-Yi Wu 9b8c7c6445 remove build num
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-02-19 10:53:06 +08:00
Bo-Yi Wu 4cacf0f558 fix: compatible with 0.8
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-02-19 09:05:13 +08:00
Bo-Yi Wu 131273fc5b fix: remove windows platform 2019-02-17 20:58:13 +08:00
Bo-Yi Wu 2158226bca fix: missing manifest config 2019-02-17 20:38:02 +08:00
Bo-Yi Wu c3640b0765 feat: support manifest 2019-02-17 20:32:59 +08:00
Bo-Yi Wu 0ac15da3e7 feat: add Signature for drone config 2019-02-17 20:29:22 +08:00
Bo-Yi Wu b339fb0238 fix: hide token in CI/CD log (#70)
fix https://github.com/appleboy/drone-telegram/issues/65
2019-02-17 17:39:15 +08:00
Bo-Yi Wu 71a0551697 feat(GitHub): support default message 2019-02-17 16:03:10 +08:00
Bo-Yi Wu 4d2a304048 refactor(message): update default message 2019-02-17 15:44:29 +08:00
Bo-Yi Wu 861d6e1adb feat: add some env from github action 2019-02-17 15:39:47 +08:00
Bo-Yi Wu 2ccf302b69 feat: support GitHub Action. 2019-02-17 15:30:24 +08:00
Bo-Yi Wu 3936acbd84 fix: remove pull request condition in PipelineNotifications 2019-02-17 14:35:19 +08:00
Bo-Yi Wu a28fc42469 fix: trigger ref 2019-02-17 13:37:26 +08:00
Bo-Yi Wu 439e9b13c2 add debug env
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-02-17 12:19:32 +08:00
Bo-Yi Wu db075f376a fix: trigger push 2019-02-17 10:40:32 +08:00
Bo-Yi Wu d066ff420e feat: add deploy binary 2019-02-17 10:33:38 +08:00
Bo-Yi Wu d6b125708f docs: remove unused badge 2019-02-17 00:59:27 +08:00
Bo-Yi Wu 557b8289d3 chore(badge): update drone badge 2019-02-17 00:24:30 +08:00
Bo-Yi Wu c2a8a546cb fix: golint error 2019-02-17 00:23:46 +08:00
Bo-Yi Wu e16175d68c chore: remove appveyor config 2019-02-17 00:18:35 +08:00
Bo-Yi Wu e8f060bafa refactor: docker 2019-02-17 00:02:11 +08:00
Bo-Yi Wu 989fa33240 feat: add revive.toml 2019-02-16 23:41:11 +08:00
Bo-Yi Wu 84b48505d3 feat: replace vendor with go module 2019-02-16 23:39:20 +08:00
Bo-Yi Wu 92fd3a5da7 chore: remove vendor 2019-02-16 23:34:19 +08:00
Bo-Yi Wu e03659cc70 feat: upgrade drone to 1.0 2019-02-16 23:33:00 +08:00
Bo-Yi Wu f267e5254a show message with fatal
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2018-07-28 08:31:33 +08:00
Bo-Yi Wu 31081670b1 feat: upgrade alpine version 2018-07-27 18:47:34 +08:00
Bo-Yi Wu 4c994f5045 fix: Provide a password using STDIN 2018-06-27 14:59:29 +08:00
Bo-Yi Wu d549026e50 upgrade to 1.10
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2018-04-14 23:16:08 +08:00
Bo-Yi Wu a2a49f1249 feat: Support wildcard attachment list (#62) 2018-04-06 10:28:55 +08:00
Bo-Yi Wu 8b6e33fcab fix: wrong docker container name for windows. 2018-04-03 09:37:18 +08:00
Bo-Yi Wu 660c4ddd04 refactor: add commit id in version for windows. 2017-12-21 14:39:19 +08:00
Bo-Yi Wu 6a15a1fd58 fix(docker): add BuildNum variable. 2017-12-20 09:19:57 +08:00
Bo-Yi Wu 8a1870f7d5 fix(appveyor): update version. 2017-12-19 16:59:35 +08:00
Bo-Yi Wu 996bb07855 fix(appveyor): update split 2017-12-19 12:32:23 +08:00
Bo-Yi Wu 9dfbd29ced remove
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-12-19 12:07:02 +08:00
Bo-Yi Wu 8b5adb6493 feat(docker): Add build number. 2017-12-19 10:12:27 +08:00
Bo-Yi Wu fdc76c4f08 feat(windows): support windows docker. 2017-12-19 09:52:09 +08:00
Bo-Yi Wu 5d287eff2c update .appveyor.yml
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-12-19 09:31:38 +08:00
Bo-Yi Wu f22326b26a feat(logs): show logs if send error. (#55)
* feat(logs): show logs if send error.
2017-12-18 15:16:10 +08:00
Bo-Yi Wu 6a0370ab67 refactor(windows): add build screipt 2017-12-09 21:04:35 +08:00
Bo-Yi Wu 376b1be00d feat(docker): support windows docker image. 2017-12-09 18:59:38 +08:00
Bo-Yi Wu 663f165ed1 chore(git): add release folder to ignore list. 2017-12-09 18:51:11 +08:00
Bo-Yi Wu 2d7a8b3379 feat: support arm arm64 i386 docker image. 2017-12-09 18:36:15 +08:00
Bo-Yi Wu 94ed25f353 fix: wrong path in alpine docker image, 2017-12-09 18:19:48 +08:00
Bo-Yi Wu ac5bf03e25 feat(build): support arm arm64 386 amd64 binary. 2017-12-09 18:10:06 +08:00
Bo-Yi Wu 0afb796085 add HTML Entities testing. #50
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-12-02 17:30:28 +08:00
Bo-Yi Wu 5be69ef6f3 update repo variable.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-12-02 16:22:32 +08:00
Bo-Yi Wu 3ef45379c4 upgrade telegram api.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-12-02 16:11:54 +08:00
Bo-Yi Wu fd0eb0f6c1 fix docker repo.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-12-02 15:42:34 +08:00
Bo-Yi Wu b5c380d16b add codecov repo
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-12-02 15:35:52 +08:00
Bo-Yi Wu 6a5e7570ad feat(docker): add alpine docker image 2017-12-02 15:27:50 +08:00
Bo-Yi Wu 53b61735b1 chnage fb to discord.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-12-02 15:19:01 +08:00
Bo-Yi Wu 7007f52007 fix: fix drone workspace 2017-12-02 15:15:33 +08:00
Rafael Bodill 6f651a91d2 Decouple 'commit' object and add commit.link (#51)
* Decouple commit out from build and add commit.link

* Fix tests for Commit decouple

* Update documentation for Commit decouple
2017-09-11 12:34:47 +08:00
Rafael Bodill 709c4ce6a8 Add feature to toggle web-page preview (#52) 2017-09-11 12:03:19 +08:00
Rafael Bodill eaeb3f678e Fix Build.Message retrieval (#48) 2017-08-25 09:08:48 -05:00
Bo-Yi Wu 036ec04567 add new env. (#46)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-07-10 03:10:39 -05:00
Bo-Yi Wu 3abe443f33 update secret key
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-07-05 16:11:52 +08:00
Bo-Yi Wu 172a8d6a7b remove GOPATH
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-07-05 16:07:25 +08:00
Bo-Yi Wu 1138f514e5 fix path
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-07-05 15:53:36 +08:00
koluchiy 3a61750059 escape _ symbol for markdown format (#40)
* escape _ symbol for markdown format

* fmt

* tests

* tests

* tests
2017-07-04 06:03:14 -05:00
Bo-Yi Wu 1c14ff5307 switch travis to drone. (#44)
* switch travis to drone.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* fix missing token

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-07-03 23:45:25 -05:00
Bo-Yi Wu 8c74c44621 switch glide to govendor (#43)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-07-03 23:11:48 -05:00
Bo-Yi Wu dd76024845 update readme.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-07-04 09:21:51 +08:00
Bo-Yi Wu d85b0f05e4 update message format.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-05-30 08:27:35 +08:00
Bo-Yi Wu 09f6fba2e0 update message format.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-05-30 08:24:29 +08:00
Bo-Yi Wu 7a2d870e96 Update DOCS.md 2017-05-30 08:21:15 +08:00
Bo-Yi Wu 612a0037b3 fix document. (#39) 2017-05-29 02:31:03 -05:00
Albert G 4670064089 [ci skip] Modified syntax for if-else #success statement for #34 (#35) 2017-04-26 23:22:24 +08:00
Albert G 781502069a [ci skip] Added a comment about @userinfobot (#33) 2017-04-26 23:21:26 +08:00
Bo-Yi Wu eaabc2c355 docs: [ci skip] add drone plugin document link. 2017-02-08 09:31:39 +08:00
Bo-Yi Wu 4e81aba6a3 docs: [ci skip] remove secret section. 2017-01-20 15:06:58 +08:00
Bo-Yi Wu 271e1a871c docs: [ci skip] update readme. 2017-01-17 14:48:14 +08:00
Bo-Yi Wu 790c555063 docs: add drone plugin docs. (#31) 2017-01-10 13:44:24 +08:00
Bo-Yi Wu 92bb0b736a fix build docker condition.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-12-02 22:04:36 +08:00
Bo-Yi Wu 7c2792c82b Merge pull request #28 from appleboy/pr
support DRONE_PULL_REQUEST env
2016-12-02 21:15:41 +08:00
Bo-Yi Wu 0f09803007 update to 1.6.4 and 1.7.4 testing
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-12-02 21:14:45 +08:00
Bo-Yi Wu ab3463be19 add DRONE_PULL_REQUEST env.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-12-02 21:13:58 +08:00
Bo-Yi Wu d31365c444 remove --rm flag which default as true.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-11-27 16:39:31 +08:00
Bo-Yi Wu 70655117a2 support tag string.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-11-24 09:37:19 +08:00
Bo-Yi Wu b688f301ba update Version comment.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-11-19 22:33:55 +08:00
Bo-Yi Wu b13e983fb5 update clean command.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-11-18 11:01:58 +08:00
Bo-Yi Wu a1c0fa73de update get commit number from latest tag.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-11-18 10:58:36 +08:00
Bo-Yi Wu 42457f46db fix index out of range bug.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-11-17 13:13:43 +08:00
Bo-Yi Wu 91ae3a4c55 Merge pull request #26 from appleboy/cli
support load env from file.
2016-11-12 16:52:25 +08:00
Bo-Yi Wu ac32848570 support load env from file.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-11-12 16:51:14 +08:00
Bo-Yi Wu 9f288d99d9 Merge pull request #24 from appleboy/match
Support MATCH_EMAIL flag
2016-11-09 14:36:56 +08:00
Bo-Yi Wu e6233bb494 update readme.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-11-09 12:23:19 +08:00
Bo-Yi Wu f3e25a0846 Support Match Email condition.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-11-09 12:00:36 +08:00
Bo-Yi Wu eee4278af4 add ONLY_MATCH_EMAIL boolean flag
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-11-09 10:35:55 +08:00
Bo-Yi Wu e0760eaf80 change , to :
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-11-04 11:39:30 +08:00
Bo-Yi Wu b16d4444dc update readme.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-11-04 10:11:39 +08:00
Bo-Yi Wu b154d3d0d0 Merge pull request #22 from appleboy/parseID
Support send notification to commit author by check email.
2016-11-04 10:10:37 +08:00
Bo-Yi Wu ac5786266a remove codecov arg.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-11-04 09:54:12 +08:00
Bo-Yi Wu dbb5972732 update testing.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-11-04 09:43:21 +08:00
Bo-Yi Wu dc6dc4a444 Support send notification to commit author by check email.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-11-04 09:38:21 +08:00
Bo-Yi Wu ee5a200955 [ci skip] update readme.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-11-02 10:01:26 +08:00
Bo-Yi Wu bd3806e778 Merge pull request #20 from appleboy/template
Add support handlebar template
2016-10-31 10:09:34 +08:00
Bo-Yi Wu 8b2af04235 Add 1.7.3 version testing.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-10-31 09:57:51 +08:00
Bo-Yi Wu e2fc930461 support handlebar template
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-10-31 09:57:34 +08:00
Bo-Yi Wu 693f15783c Support Venue Message.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-10-14 03:33:44 -05:00
Bo-Yi Wu b52dcfe9c2 Support Video Message.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-10-14 02:38:08 -05:00
Bo-Yi Wu 3f25341c8b Support Location Message.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-10-14 02:21:12 -05:00
Bo-Yi Wu 1142360e53 Support Voice Message.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-10-14 01:04:34 -05:00
Bo-Yi Wu 8c0a2a65dc Support Audio message.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-10-14 01:04:34 -05:00
Bo-Yi Wu 57468ba50b Support Send with New Sticker.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-10-08 21:19:30 -05:00
Bo-Yi Wu 6cdfb8ba10 fix wrong name.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-10-07 09:09:37 -05:00
Bo-Yi Wu dfd91c671b Support Send with New Document.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-10-07 09:09:37 -05:00
Bo-Yi Wu 78f99c9c7f [ci skip] update readme.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-10-07 17:25:24 +08:00
Bo-Yi Wu 8bd5e965e7 add tests image.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-10-07 03:02:29 -05:00
Bo-Yi Wu 97227c749e [ci skip] update readme.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-10-07 03:02:29 -05:00
Bo-Yi Wu fd83eb04f4 support send photo message.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-10-07 03:02:29 -05:00
Bo-Yi Wu ee4c70fa29 [ci skip] update readme.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-10-07 08:18:50 +08:00
Bo-Yi Wu 09796b1872 update readme.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-10-06 12:00:05 -05:00
Bo-Yi Wu 2e602c4560 support markdown and html format.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-10-06 12:00:05 -05:00
Bo-Yi Wu 75c04eafaa support markdown format.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-10-07 00:28:13 +08:00
Bo-Yi Wu 215d08a0d6 [ci skip] update readme.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-10-05 13:32:07 +08:00
Bo-Yi Wu e370283454 add target on PHONY
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-10-04 23:06:39 +08:00
34 changed files with 2333 additions and 264 deletions
+63
View File
@@ -0,0 +1,63 @@
version: '{build}'
image: 'Visual Studio 2017'
platform: x64
max_jobs: 1
environment:
GOPATH: c:\go
docker_username:
secure: em/TNLUXxG19O/HvbvfJuQ==
docker_password:
secure: Yo9FJJqihaNz5q8T4Jz8tQ==
GO111MODULE: on
branches:
only:
- master
install:
- ps: |
docker version
go version
go env
build_script:
- ps: |
go mod download
if ( $env:APPVEYOR_REPO_TAG -eq 'false' ) {
$version = $env:APPVEYOR_REPO_COMMIT
} else {
$version = $env:APPVEYOR_REPO_TAG_NAME
}
go build -ldflags "-X main.Version=$version" -a -o release/drone-telegram.exe .
docker pull microsoft/nanoserver:10.0.14393.1884
docker build -f docker/Dockerfile.windows.amd64 -t appleboy/drone-telegram:windows-amd64 .
test_script:
- ps: |
docker run --rm appleboy/drone-telegram:windows-amd64 --version
deploy_script:
- ps: |
$ErrorActionPreference = 'Stop';
if ( $env:APPVEYOR_PULL_REQUEST_NUMBER ) {
Write-Host Nothing to deploy.
} else {
echo $env:DOCKER_PASSWORD | docker login --username $env:DOCKER_USERNAME --password-stdin
if ( $env:APPVEYOR_REPO_TAG -eq 'true' ) {
$major,$minor,$patch = $env:APPVEYOR_REPO_TAG_NAME.split('.')
docker push appleboy/drone-telegram:windows-amd64
docker tag appleboy/drone-telegram:windows-amd64 appleboy/drone-telegram:$major.$minor.$patch-windows-amd64
docker push appleboy/drone-telegram:$major.$minor.$patch-windows-amd64
docker tag appleboy/drone-telegram:windows-amd64 appleboy/drone-telegram:$major.$minor-windows-amd64
docker push appleboy/drone-telegram:$major.$minor-windows-amd64
docker tag appleboy/drone-telegram:windows-amd64 appleboy/drone-telegram:$major-windows-amd64
docker push appleboy/drone-telegram:$major-windows-amd64
} else {
if ( $env:APPVEYOR_REPO_BRANCH -eq 'master' ) {
docker push appleboy/drone-telegram:windows-amd64
}
}
}
+17
View File
@@ -0,0 +1,17 @@
local pipeline = import 'pipeline.libsonnet';
local name = 'drone-telegram';
[
pipeline.test,
pipeline.build(name, 'linux', 'amd64'),
pipeline.build(name, 'linux', 'arm64'),
pipeline.build(name, 'linux', 'arm'),
pipeline.release,
pipeline.notifications(depends_on=[
'linux-amd64',
'linux-arm64',
'linux-arm',
'release-binary',
]),
pipeline.signature('9a4dcc3659b6f2cb98486e40e4cb0c16d6fc19ad783d3bca13d30c476daf8213'),
]
+382
View File
@@ -0,0 +1,382 @@
---
kind: pipeline
name: testing
platform:
os: linux
arch: amd64
steps:
- name: vet
pull: always
image: golang:1.13
commands:
- make vet
volumes:
- name: gopath
path: /go
- name: lint
pull: always
image: golang:1.13
commands:
- make lint
volumes:
- name: gopath
path: /go
- name: misspell
pull: always
image: golang:1.13
commands:
- make misspell-check
volumes:
- name: gopath
path: /go
- name: test
pull: always
image: golang:1.13
commands:
- make test
- make coverage
environment:
TELEGRAM_TO:
from_secret: telegram_to
TELEGRAM_TOKEN:
from_secret: telegram_token
volumes:
- name: gopath
path: /go
- name: codecov
pull: always
image: robertstettner/drone-codecov
settings:
token:
from_secret: codecov_token
volumes:
- name: gopath
temp: {}
---
kind: pipeline
name: linux-amd64
platform:
os: linux
arch: amd64
steps:
- name: build-push
pull: always
image: golang:1.13
commands:
- go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-telegram
environment:
CGO_ENABLED: 0
when:
event:
exclude:
- tag
- name: build-tag
pull: always
image: golang:1.13
commands:
- go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-telegram
environment:
CGO_ENABLED: 0
when:
event:
- tag
- name: executable
pull: always
image: golang:1.13
commands:
- ./release/linux/amd64/drone-telegram --help
- name: dryrun
pull: always
image: plugins/docker:linux-amd64
settings:
cache_from: appleboy/drone-telegram
dockerfile: docker/Dockerfile.linux.amd64
dry_run: true
repo: appleboy/drone-telegram
tags: linux-amd64
when:
event:
- pull_request
- name: publish
pull: always
image: plugins/docker:linux-amd64
settings:
auto_tag: true
auto_tag_suffix: linux-amd64
cache_from: appleboy/drone-telegram
daemon_off: false
dockerfile: docker/Dockerfile.linux.amd64
password:
from_secret: docker_password
repo: appleboy/drone-telegram
username:
from_secret: docker_username
when:
event:
exclude:
- pull_request
trigger:
ref:
- refs/heads/master
- refs/pull/**
- refs/tags/**
depends_on:
- testing
---
kind: pipeline
name: linux-arm64
platform:
os: linux
arch: arm64
steps:
- name: build-push
pull: always
image: golang:1.13
commands:
- go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-telegram
environment:
CGO_ENABLED: 0
when:
event:
exclude:
- tag
- name: build-tag
pull: always
image: golang:1.13
commands:
- go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-telegram
environment:
CGO_ENABLED: 0
when:
event:
- tag
- name: executable
pull: always
image: golang:1.13
commands:
- ./release/linux/arm64/drone-telegram --help
- name: dryrun
pull: always
image: plugins/docker:linux-arm64
settings:
cache_from: appleboy/drone-telegram
dockerfile: docker/Dockerfile.linux.arm64
dry_run: true
repo: appleboy/drone-telegram
tags: linux-arm64
when:
event:
- pull_request
- name: publish
pull: always
image: plugins/docker:linux-arm64
settings:
auto_tag: true
auto_tag_suffix: linux-arm64
cache_from: appleboy/drone-telegram
daemon_off: false
dockerfile: docker/Dockerfile.linux.arm64
password:
from_secret: docker_password
repo: appleboy/drone-telegram
username:
from_secret: docker_username
when:
event:
exclude:
- pull_request
trigger:
ref:
- refs/heads/master
- refs/pull/**
- refs/tags/**
depends_on:
- testing
---
kind: pipeline
name: linux-arm
platform:
os: linux
arch: arm
steps:
- name: build-push
pull: always
image: golang:1.13
commands:
- go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-telegram
environment:
CGO_ENABLED: 0
when:
event:
exclude:
- tag
- name: build-tag
pull: always
image: golang:1.13
commands:
- go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-telegram
environment:
CGO_ENABLED: 0
when:
event:
- tag
- name: executable
pull: always
image: golang:1.13
commands:
- ./release/linux/arm/drone-telegram --help
- name: dryrun
pull: always
image: plugins/docker:linux-arm
settings:
cache_from: appleboy/drone-telegram
dockerfile: docker/Dockerfile.linux.arm
dry_run: true
repo: appleboy/drone-telegram
tags: linux-arm
when:
event:
- pull_request
- name: publish
pull: always
image: plugins/docker:linux-arm
settings:
auto_tag: true
auto_tag_suffix: linux-arm
cache_from: appleboy/drone-telegram
daemon_off: false
dockerfile: docker/Dockerfile.linux.arm
password:
from_secret: docker_password
repo: appleboy/drone-telegram
username:
from_secret: docker_username
when:
event:
exclude:
- pull_request
trigger:
ref:
- refs/heads/master
- refs/pull/**
- refs/tags/**
depends_on:
- testing
---
kind: pipeline
name: release-binary
platform:
os: linux
arch: amd64
steps:
- name: build-all-binary
pull: always
image: golang:1.13
commands:
- make release
when:
event:
- tag
- name: deploy-all-binary
pull: always
image: plugins/github-release
settings:
api_key:
from_secret: github_release_api_key
files:
- dist/release/*
when:
event:
- tag
trigger:
ref:
- refs/tags/**
depends_on:
- testing
---
kind: pipeline
name: notifications
platform:
os: linux
arch: amd64
steps:
- name: telegram
pull: always
image: appleboy/drone-telegram
settings:
message: "{{#success build.status}} ✅ Build #{{build.number}} of `{{repo.name}}` succeeded.\n\n📝 Commit by {{commit.author}} on `{{commit.branch}}`:\n``` {{commit.message}} ```\n\n🌐 {{ build.link }} {{else}} ❌ Build #{{build.number}} of `{{repo.name}}` failed.\n\n📝 Commit by {{commit.author}} on `{{commit.branch}}`:\n``` {{commit.message}} ```\n\n🌐 {{ build.link }} {{/success}}\n"
to:
from_secret: telegram_to
token:
from_secret: telegram_token
- name: manifest
pull: always
image: plugins/manifest
settings:
ignore_missing: true
password:
from_secret: docker_password
spec: docker/manifest.tmpl
username:
from_secret: docker_username
trigger:
ref:
- refs/heads/master
- refs/tags/**
depends_on:
- linux-amd64
- linux-arm64
- linux-arm
- release-binary
---
kind: signature
hmac: 9a4dcc3659b6f2cb98486e40e4cb0c16d6fc19ad783d3bca13d30c476daf8213
...
+2 -1
View File
@@ -22,6 +22,7 @@ _testmain.go
*.exe
*.test
*.prof
vendor
drone-telegram
coverage.txt
.env
release
+25
View File
@@ -0,0 +1,25 @@
ignoreGeneratedHeader = false
severity = "warning"
confidence = 0.8
errorCode = 1
warningCode = 1
[rule.blank-imports]
[rule.context-as-argument]
[rule.context-keys-type]
[rule.dot-imports]
[rule.error-return]
[rule.error-strings]
[rule.error-naming]
[rule.exported]
[rule.if-return]
[rule.increment-decrement]
[rule.var-naming]
[rule.var-declaration]
[rule.package-comments]
[rule.range]
[rule.receiver-naming]
[rule.time-naming]
[rule.unexported-return]
[rule.indent-error-flow]
[rule.errorf]
-53
View File
@@ -1,53 +0,0 @@
sudo: required
language: go
services:
- docker
go:
- 1.5.4
- 1.6.3
- 1.7.1
- tip
env:
global:
- DOCKER_CACHE_FILE=${HOME}/docker/cache.tar.gz
cache:
directories:
- vendor
- ${HOME}/.glide
- ${HOME}/docker
before_install:
- mkdir -p $GOPATH/bin
- curl https://glide.sh/get | sh
- if [ -f ${DOCKER_CACHE_FILE} ]; then gunzip -c ${DOCKER_CACHE_FILE} | docker load; fi
install:
- export GO15VENDOREXPERIMENT=1
- make install
script:
- make test
- make docker
- if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
mkdir -p $(dirname ${DOCKER_CACHE_FILE});
docker save $(docker history -q $TRAVIS_REPO_SLUG:latest | grep -v '<missing>') | gzip > ${DOCKER_CACHE_FILE};
fi
after_success:
# ignore main.go coverage
- sed -i '/main.go/d' coverage.txt
- bash <(curl -s https://codecov.io/bash) -f coverage.txt
# deploy from master
- if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_GO_VERSION" == "1.7.1" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD";
make docker_deploy tag=latest;
fi
# deploy from tag
- if [ "$TRAVIS_GO_VERSION" == "1.7.1" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" != "" ]; then
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD";
make docker_deploy tag=$TRAVIS_TAG;
fi
+319
View File
@@ -0,0 +1,319 @@
---
date: 2019-10-19T00:00:00+00:00
title: Telegram
author: appleboy
tags: [ notifications, chat ]
repo: appleboy/drone-telegram
logo: telegram.svg
image: appleboy/drone-telegram
---
The Telegram plugin posts build status messages to your account. The below pipeline configuration demonstrates simple usage:
```yaml
- name: send telegram notification
image: appleboy/drone-telegram
settings:
token: xxxxxxxxxx
to: telegram_user_id
```
Example configuration with photo message:
```diff
- name: send telegram notification
image: appleboy/drone-telegram
settings:
token: xxxxxxxxxx
to: telegram_user_id
+ photo:
+ - tests/1.png
+ - tests/2.png
```
Example configuration with document message:
```diff
- name: send telegram notification
image: appleboy/drone-telegram
settings:
token: xxxxxxxxxx
to: telegram_user_id
+ document:
+ - tests/1.pdf
+ - tests/2.pdf
```
Example configuration with sticker message:
```diff
- name: send telegram notification
image: appleboy/drone-telegram
settings:
token: xxxxxxxxxx
to: telegram_user_id
+ sticker:
+ - tests/3.png
+ - tests/4.png
```
Example configuration with audio message:
```diff
- name: send telegram notification
image: appleboy/drone-telegram
settings:
token: xxxxxxxxxx
to: telegram_user_id
+ audio:
+ - tests/audio1.mp3
+ - tests/audio2.mp3
```
Example configuration with voice message:
```diff
- name: send telegram notification
image: appleboy/drone-telegram
settings:
token: xxxxxxxxxx
to: telegram_user_id
+ voice:
+ - tests/voice1.ogg
+ - tests/voice2.ogg
```
Example configuration with location message:
```diff
- name: send telegram notification
image: appleboy/drone-telegram
settings:
token: xxxxxxxxxx
to: telegram_user_id
+ location:
+ - 24.9163213,121.1424972
+ - 24.9263213,121.1224972
```
Example configuration with venue message:
```diff
- name: send telegram notification
image: appleboy/drone-telegram
settings:
token: xxxxxxxxxx
to: telegram_user_id
+ venue:
+ - 24.9163213,121.1424972,title,address
+ - 24.3163213,121.1824972,title,address
```
Example configuration with video message:
```diff
- name: send telegram notification
image: appleboy/drone-telegram
settings:
token: xxxxxxxxxx
to: telegram_user_id
+ video:
+ - tests/video1.mp4
+ - tests/video2.mp4
```
Example configuration with message format:
```diff
- name: send telegram notification
image: appleboy/drone-telegram
settings:
token: xxxxxxxxxx
to: telegram_user_id
+ format: markdown
```
Example configuration with a custom message template:
```diff
- name: send telegram notification
image: appleboy/drone-telegram
settings:
token: xxxxxxxxxx
to: telegram_user_id
+ message: >
+ {{#success build.status}}
+ build {{build.number}} succeeded. Good job.
+ {{else}}
+ build {{build.number}} failed. Fix me please.
+ {{/success}}
```
Example configuration with a custom message template loaded from file:
```diff
- name: send telegram notification
image: appleboy/drone-telegram
settings:
token: xxxxxxxxxx
to: telegram_user_id
+ message_file: message_file.tpl
```
Example configuration with a generic message template loaded from file, with additional extra vars:
```diff
- name: send telegram notification
image: appleboy/drone-telegram
settings:
token: xxxxxxxxxx
to: telegram_user_id
+ message_file: message_file.tpl
+ template_vars:
+ env: testing
+ app: MyApp
```
Where `message_file.tpl` is:
```bash
Build finished for *{{tpl.app}}* - *{{tpl.env}}*
{{#success build.status}}
build {{build.number}} succeeded. Good job.
{{else}}
build {{build.number}} failed. Fix me please.
{{/success}}
```
Example configuration with a custom socks5 URL:
```diff
- name: send telegram notification
image: appleboy/drone-telegram
settings:
token: xxxxxxxxxx
to: telegram_user_id
message: send message using custom socks5 URL
+ socks5: socks5://67.204.21.1:64312
```
## Parameter Reference
token
: telegram token from [telegram developer center](https://core.telegram.org/bots/api)
to
: telegram user id (can be requested from the @userinfobot inside Telegram)
message
: overwrite the default message template
message_file
: overwrite the default message template with the contents of the specified file
template_vars
: define additional template vars. Example: `var1: hello` can be used within the template as `tpl.var1`
photo
: local file path
document
: local file path
sticker
: local file path
audio
: local file path
voice
: local file path
location
: local file path
video
: local file path
venue
: local file path
format
: `markdown` or `html` format
## Template Reference
repo.owner
: repository owner
repo.name
: repository name
commit.sha
: git sha for current commit
commit.branch
: git branch for current commit
commit.link
: git commit link in remote
commit.author
: git author for current commit
commit.email
: git author email for current commit
commit.message
: git current commit message
build.status
: build status type enumeration, either `success` or `failure`
build.event
: build event type enumeration, one of `push`, `pull_request`, `tag`, `deployment`
build.number
: build number
build.tag
: git tag for current commit
build.link
: link the the build results in drone
build.started
: unix timestamp for build started
build.finished
: unix timestamp for build finished
## Template Function Reference
uppercasefirst
: converts the first letter of a string to uppercase
uppercase
: converts a string to uppercase
lowercase
: converts a string to lowercase. Example `{{lowercase build.author}}`
datetime
: converts a unix timestamp to a date time string. Example `{{datetime build.started}}`
success
: returns true if the build is successful
failure
: returns true if the build is failed
truncate
: returns a truncated string to n characters. Example `{{truncate build.sha 8}}`
urlencode
: returns a url encoded string
since
: returns a duration string between now and the given timestamp. Example `{{since build.started}}`
-5
View File
@@ -1,5 +0,0 @@
FROM centurylink/ca-certs
ADD drone-telegram /
ENTRYPOINT ["/drone-telegram"]
-8
View File
@@ -1,8 +0,0 @@
FROM armhfbuild/alpine:3.4
RUN apk update && \
apk add ca-certificates && \
rm -rf /var/cache/apk/*
ADD drone-telegram /bin/
ENTRYPOINT ["/bin/drone-telegram"]
+100 -19
View File
@@ -1,8 +1,16 @@
.PHONY:
DIST := dist
EXECUTABLE := drone-telegram
GOFMT ?= gofmt "-s"
GO ?= go
VERSION := $(shell git describe --tags || git rev-parse --short HEAD)
DEPLOY_ACCOUNT := "appleboy"
DEPLOY_IMAGE := "drone-telegram"
# for dockerhub
DEPLOY_ACCOUNT := appleboy
DEPLOY_IMAGE := $(EXECUTABLE)
TARGETS ?= linux darwin windows
SOURCES ?= $(shell find . -name "*.go" -type f)
TAGS ?=
LDFLAGS ?= -X 'main.Version=$(VERSION)'
ifneq ($(shell uname), Darwin)
EXTLDFLAGS = -extldflags "-static" $(null)
@@ -10,36 +18,109 @@ else
EXTLDFLAGS =
endif
install:
glide install
ifneq ($(DRONE_TAG),)
VERSION ?= $(DRONE_TAG)
else
VERSION ?= $(shell git describe --tags --always || git rev-parse --short HEAD)
endif
build:
go build -ldflags="$(EXTLDFLAGS)-s -w -X main.Version=$(VERSION)"
all: build
test:
go test -v -coverprofile=coverage.txt
fmt:
$(GOFMT) -w $(SOURCES)
html:
go tool cover -html=coverage.txt
vet:
$(GO) vet ./...
update:
glide up
lint:
@hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/mgechev/revive; \
fi
revive -config .revive.toml ./... || exit 1
docker_build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo -ldflags="-X main.Version=$(VERSION)"
.PHONY: misspell-check
misspell-check:
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/client9/misspell/cmd/misspell; \
fi
misspell -error $(SOURCES)
.PHONY: misspell
misspell:
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/client9/misspell/cmd/misspell; \
fi
misspell -w $(SOURCES)
.PHONY: fmt-check
fmt-check:
@diff=$$($(GOFMT) -d $(SOURCES)); \
if [ -n "$$diff" ]; then \
echo "Please run 'make fmt' and commit the result:"; \
echo "$${diff}"; \
exit 1; \
fi;
test: fmt-check
@$(GO) test -v -cover -coverprofile coverage.txt ./... && echo "\n==>\033[32m Ok\033[m\n" || exit 1
install: $(SOURCES)
$(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
build: $(EXECUTABLE)
$(EXECUTABLE): $(SOURCES)
$(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o $@
release: release-dirs release-build release-copy release-check
release-dirs:
mkdir -p $(DIST)/binaries $(DIST)/release
release-build:
@which gox > /dev/null; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/mitchellh/gox; \
fi
gox -os="$(TARGETS)" -arch="amd64 386" -tags="$(TAGS)" -ldflags="-s -w $(LDFLAGS)" -output="$(DIST)/binaries/$(EXECUTABLE)-$(VERSION)-{{.OS}}-{{.Arch}}"
release-copy:
$(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
release-check:
cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
build_linux_amd64:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/amd64/$(DEPLOY_IMAGE)
build_linux_i386:
CGO_ENABLED=0 GOOS=linux GOARCH=386 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/i386/$(DEPLOY_IMAGE)
build_linux_arm64:
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/arm64/$(DEPLOY_IMAGE)
build_linux_arm:
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/arm/$(DEPLOY_IMAGE)
docker_image:
docker build --rm -t $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE) .
docker build -t $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE) .
docker: docker_build docker_image
docker: docker_image
docker_deploy:
ifeq ($(tag),)
@echo "Usage: make $@ tag=<tag>"
@exit 1
endif
# deploy image
docker tag $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):latest $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):$(tag)
docker push $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):$(tag)
coverage:
sed -i '/main.go/d' coverage.txt
clean:
rm -rf coverage.txt ${DEPLOY_IMAGE}
$(GO) clean -x -i ./...
rm -rf coverage.txt $(EXECUTABLE) $(DIST)
version:
@echo $(VERSION)
+76 -24
View File
@@ -1,58 +1,110 @@
# drone-telegram
[![Build Status](https://travis-ci.org/appleboy/drone-telegram.svg?branch=master)](https://travis-ci.org/appleboy/drone-telegram) [![codecov](https://codecov.io/gh/appleboy/drone-telegram/branch/master/graph/badge.svg)](https://codecov.io/gh/appleboy/drone-telegram) [![Go Report Card](https://goreportcard.com/badge/github.com/appleboy/drone-telegram)](https://goreportcard.com/report/github.com/appleboy/drone-telegram)
![logo](./images/logo.png)
Drone plugin for sending telegram notifications.
[![GoDoc](https://godoc.org/github.com/appleboy/drone-telegram?status.svg)](https://godoc.org/github.com/appleboy/drone-telegram)
[![Build Status](https://cloud.drone.io/api/badges/appleboy/drone-telegram/status.svg)](https://cloud.drone.io/appleboy/drone-telegram)
[![Build status](https://ci.appveyor.com/api/projects/status/cm4l9udn8ywkif42?svg=true)](https://ci.appveyor.com/project/appleboy/drone-telegram-cd47y)
[![codecov](https://codecov.io/gh/appleboy/drone-telegram/branch/master/graph/badge.svg)](https://codecov.io/gh/appleboy/drone-telegram)
[![Go Report Card](https://goreportcard.com/badge/github.com/appleboy/drone-telegram)](https://goreportcard.com/report/github.com/appleboy/drone-telegram)
[![Docker Pulls](https://img.shields.io/docker/pulls/appleboy/drone-telegram.svg)](https://hub.docker.com/r/appleboy/drone-telegram/)
[![microbadger](https://images.microbadger.com/badges/image/appleboy/drone-telegram.svg)](https://microbadger.com/images/appleboy/drone-telegram "Get your own image badge on microbadger.com")
## Build
[Drone](https://github.com/drone/drone) plugin for sending telegram notifications. For the usage
information and a listing of the available options please take a look at [the docs](http://plugins.drone.io/appleboy/drone-telegram/).
Build the binary with the following commands:
## Feature
* [x] Send with Text Message. (`markdown` or `html` format)
* [x] Send with New Photo.
* [x] Send with New Document.
* [x] Send with New Audio.
* [x] Send with New Voice.
* [x] Send with New Location.
* [x] Send with New Venue.
* [x] Send with New Video.
* [x] Send with New Sticker.
## Build or Download a binary
The pre-compiled binaries can be downloaded from [release page](https://github.com/appleboy/drone-telegram/releases). Support the following OS type.
* Windows amd64/386
* Linux arm/amd64/386
* Darwin amd64/386
With `Go` installed
```sh
go get -u -v github.com/appleboy/drone-telegram
```
$ make build
or build the binary with the following command:
```sh
export GOOS=linux
export GOARCH=amd64
export CGO_ENABLED=0
export GO111MODULE=on
go test -cover ./...
go build -v -a -tags netgo -o release/linux/amd64/drone-telegram .
```
## Testing
Test the package with the following command:
```
$ make test
```
## Docker
Build the docker image with the following commands:
```
$ make docker
```
Please note incorrectly building the image for the correct x64 linux and with
GCO disabled will result in an error when running the Docker image:
```
docker: Error response from daemon: Container command
'/bin/drone-telegram' not found or does not exist..
```sh
make test
```
## Usage
Execute from the working directory:
```
```sh
docker run --rm \
-e PLUGIN_TOKEN=xxxxxxx \
-e PLUGIN_TO=xxxxxxx \
-e PLUGIN_MESSAGE=test \
-e PLUGIN_MESSAGE_FILE=testmessage.md \
-e PLUGIN_PHOTO=tests/github.png \
-e PLUGIN_DOCUMENT=tests/gophercolor.png \
-e PLUGIN_STICKER=tests/github-logo.png \
-e PLUGIN_AUDIO=tests/audio.mp3 \
-e PLUGIN_VOICE=tests/voice.ogg \
-e PLUGIN_LOCATION="24.9163213 121.1424972" \
-e PLUGIN_VENUE="24.9163213 121.1424972 title address" \
-e PLUGIN_VIDEO=tests/video.mp4 \
-e PLUGIN_DEBUG=true \
-e PLUGIN_ONLY_MATCH_EMAIL=false \
-e PLUGIN_FORMAT=markdown \
-e DRONE_REPO_OWNER=appleboy \
-e DRONE_REPO_NAME=go-hello \
-e DRONE_COMMIT_SHA=e5e82b5eb3737205c25955dcc3dcacc839b7be52 \
-e DRONE_COMMIT_BRANCH=master \
-e DRONE_COMMIT_LINK=https://github.com/appleboy/go-hello/compare/master... \
-e DRONE_COMMIT_AUTHOR=appleboy \
-e DRONE_COMMIT_AUTHOR_EMAIL=appleboy@gmail.com \
-e DRONE_BUILD_NUMBER=1 \
-e DRONE_BUILD_STATUS=success \
-e DRONE_BUILD_LINK=http://github.com/appleboy/go-hello \
-e DRONE_TAG=1.0.0 \
-e DRONE_JOB_STARTED=1477550550 \
-e DRONE_JOB_FINISHED=1477550750 \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-telegram
```
Load all environments from file.
```bash
docker run --rm \
-e ENV_FILE=your_env_file_path \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-telegram
```
+10
View File
@@ -0,0 +1,10 @@
FROM plugins/base:linux-amd64
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="Drone telegram" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0"
COPY release/linux/amd64/drone-telegram /bin/
ENTRYPOINT ["/bin/drone-telegram"]
+10
View File
@@ -0,0 +1,10 @@
FROM plugins/base:linux-arm
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="Drone telegram" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0"
COPY release/linux/arm/drone-telegram /bin/
ENTRYPOINT ["/bin/drone-telegram"]
+10
View File
@@ -0,0 +1,10 @@
FROM plugins/base:linux-arm64
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="Drone telegram" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0"
COPY release/linux/arm64/drone-telegram /bin/
ENTRYPOINT ["/bin/drone-telegram"]
+10
View File
@@ -0,0 +1,10 @@
FROM microsoft/nanoserver:10.0.14393.1884
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="Drone telegram" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0"
COPY release/drone-telegram.exe /drone-telegram.exe
ENTRYPOINT [ "\\drone-telegram.exe" ]
+25
View File
@@ -0,0 +1,25 @@
image: appleboy/drone-telegram:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
{{#if build.tags}}
tags:
{{#each build.tags}}
- {{this}}
{{/each}}
{{/if}}
manifests:
-
image: appleboy/drone-telegram:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64
platform:
architecture: amd64
os: linux
-
image: appleboy/drone-telegram:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64
platform:
architecture: arm64
os: linux
variant: v8
-
image: appleboy/drone-telegram:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm
platform:
architecture: arm
os: linux
variant: v7
Generated
-26
View File
@@ -1,26 +0,0 @@
hash: b63ca4eb6e194481209bad2e58f3c4eb2c0ef2b4411ead5b3b7a77677ef815ab
updated: 2016-10-04T21:46:25.713693812+08:00
imports:
- name: github.com/joho/godotenv
version: 4ed13390c0acd2ff4e371e64d8b97c8954138243
subpackages:
- autoload
- name: github.com/technoweenie/multipartstreamer
version: a90a01d73ae432e2611d178c18367fbaa13e0154
- name: github.com/urfave/cli
version: d53eb991652b1d438abdd34ce4bfa3ef1539108e
- name: gopkg.in/telegram-bot-api.v4
version: a7f48eb2dd301356942677e65bebe0c9aef07013
testImports:
- name: github.com/davecgh/go-spew
version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9
subpackages:
- spew
- name: github.com/pmezard/go-difflib
version: d8ed2627bdf02c080bf22230dbb337003b7aba2d
subpackages:
- difflib
- name: github.com/stretchr/testify
version: 976c720a22c8eb4eb6a0b4348ad85ad12491a506
subpackages:
- assert
-11
View File
@@ -1,11 +0,0 @@
package: github.com/appleboy/drone-telegram
import:
- package: github.com/joho/godotenv
subpackages:
- autoload
- package: github.com/urfave/cli
- package: gopkg.in/telegram-bot-api.v4
testImport:
- package: github.com/stretchr/testify
subpackages:
- assert
+14
View File
@@ -0,0 +1,14 @@
module github.com/appleboy/drone-telegram
go 1.11
require (
github.com/drone/drone-template-lib v1.0.0
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible // indirect
github.com/joho/godotenv v1.3.0
github.com/stretchr/testify v1.3.0
github.com/technoweenie/multipartstreamer v1.0.1 // indirect
github.com/urfave/cli v1.20.0
gopkg.in/telegram-bot-api.v4 v4.6.4
gopkg.in/yaml.v2 v2.2.2 // indirect
)
+45
View File
@@ -0,0 +1,45 @@
github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg=
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITgsTc=
github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/Masterminds/sprig v2.18.0+incompatible h1:QoGhlbC6pter1jxKnjMFxT8EqsLuDE6FEcNbWEpw+lI=
github.com/Masterminds/sprig v2.18.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
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/bouk/monkey v1.0.0 h1:k6z8fLlPhETfn5l9rlWVE7Q6B23DoaqosTdArvNQRdc=
github.com/bouk/monkey v1.0.0/go.mod h1:PG/63f4XEUlVyW1ttIeOJmJhhe1+t9EC/je3eTjvFhE=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/drone/drone-template-lib v1.0.0 h1:PNBBfUhifRnrPCoWBlTitk3jipXdv8u8WLbIf7h7j00=
github.com/drone/drone-template-lib v1.0.0/go.mod h1:Hqy1tgqPH5mtbFOZmow19l4jOkZvp+WZ00cB4W3MJhg=
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.0 h1:Jf4mxPC/ziBnoPIdpQdPJ9OeiomAUHLvxmPRSPH9m4s=
github.com/google/uuid v1.1.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/huandu/xstrings v1.2.0 h1:yPeWdRnmynF7p+lLYz0H2tthW9lqhMJrQV/U7yy4wX0=
github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4=
github.com/imdario/mergo v0.3.7 h1:Y+UAYTZ7gDEuOfhxKWy+dvb5dRQ6rJjFSdX2HZY1/gI=
github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM=
github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog=
github.com/tkuchiki/faketime v0.0.0-20170607100027-a4500a4f4643 h1:ii/sHfgFMByozryLeiDmn1ClZ/Pena4NgpJ4P7UuX9o=
github.com/tkuchiki/faketime v0.0.0-20170607100027-a4500a4f4643/go.mod h1:RXY/TXAwGGL36IKDjrHFMcjpUrEiyWSEtLhFPw3UWF0=
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 h1:ng3VDlRp5/DHpSWl02R4rM9I+8M2rhmsuLwAMmkLQWE=
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/telegram-bot-api.v4 v4.6.4 h1:hpHWhzn4jTCsAJZZ2loNKfy2QWyPDRJVl3aTFXeMW8g=
gopkg.in/telegram-bot-api.v4 v4.6.4/go.mod h1:5DpGO5dbumb40px+dXcwCpcjmeHNYLpk0bp3XRNvWDM=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

+1
View File
@@ -0,0 +1 @@
<?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'><svg enable-background="new 0 0 512 512" height="512px" id="Layer_1" version="1.1" viewBox="0 0 512 512" width="512px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M492.168,442.732c0,34.171-27.703,61.872-61.873,61.872H80.551c-34.171,0-61.874-27.701-61.874-61.872 V92.987c0-34.171,27.703-61.873,61.874-61.873h349.744c34.17,0,61.873,27.701,61.873,61.873V442.732z" fill="#2A679E"/><path d="M492.168,417.988c0,34.172-27.703,61.873-61.873,61.873H80.551c-34.171,0-61.874-27.701-61.874-61.873 V68.243c0-34.171,27.703-61.872,61.874-61.872h349.744c34.17,0,61.873,27.7,61.873,61.872V417.988z" fill="#64A9DC"/><path d="M491.234,428.645c0.139-0.797,0.26-1.6,0.369-2.407c0.021-0.151,0.039-0.304,0.059-0.456 c0.091-0.715,0.171-1.432,0.238-2.152c0.033-0.367,0.057-0.738,0.084-1.107c0.041-0.544,0.084-1.086,0.109-1.635 c0.045-0.961,0.074-1.926,0.074-2.898V208.19c-0.656-0.645-1.314-1.29-1.965-1.937c-2.088-2.073-4.113-4.229-6.254-6.245 c-2.143-2.017-4.072-4.269-6.259-6.238c-1.942-2.207-4.222-4.127-6.24-6.263c-2.021-2.138-4.161-4.181-6.247-6.254 c-2.088-2.073-4.113-4.229-6.254-6.245c-2.143-2.017-4.072-4.269-6.259-6.238c-1.942-2.207-4.222-4.127-6.24-6.263 c-2.021-2.138-4.161-4.181-6.247-6.254c-2.088-2.073-4.113-4.229-6.254-6.245c-2.143-2.017-4.072-4.269-6.259-6.238 c-1.942-2.207-4.222-4.127-6.24-6.263c-2.021-2.138-4.161-4.181-6.247-6.254c-4.113-4.088-8.096-8.348-12.32-12.318 c-3.787-3.559-9.271-3.986-14.035-2.388c-0.775,0.26-1.516,0.602-2.278,0.896c-1.028,0.396-2.058,0.794-3.087,1.19 c-4.939,1.905-9.879,3.811-14.818,5.716c-8.076,3.115-16.151,6.229-24.227,9.344c-10.361,3.997-20.723,7.993-31.085,11.99 c-11.799,4.551-23.598,9.102-35.396,13.652c-12.388,4.777-24.774,9.555-37.161,14.333c-12.125,4.677-24.251,9.354-36.377,14.031 c-11.015,4.249-22.031,8.498-33.046,12.746c-9.056,3.493-18.112,6.986-27.168,10.479c-6.248,2.409-12.495,4.819-18.743,7.229 c-2.589,1-5.179,1.998-7.769,2.997c-2.942,1.135-5.839,2.569-8.425,4.381c-2.63,1.842-5.561,4.515-5.817,7.941 c-0.271,3.619,2.928,6.014,5.218,8.296c2.083,2.078,4.111,4.237,6.257,6.249c2.148,2.014,4.066,4.291,6.27,6.246 c1.922,2.217,4.224,4.112,6.229,6.254c2.008,2.145,4.163,4.176,6.244,6.251c2.083,2.077,4.111,4.237,6.257,6.249 c2.148,2.014,4.066,4.291,6.27,6.246c1.922,2.217,4.224,4.111,6.229,6.254c2.008,2.145,4.163,4.176,6.244,6.251 c2.083,2.077,4.111,4.237,6.257,6.249c2.148,2.014,4.066,4.291,6.27,6.246c1.922,2.217,4.224,4.111,6.229,6.254 c2.008,2.145,4.163,4.176,6.244,6.251c2.083,2.077,4.111,4.237,6.257,6.249c2.148,2.014,4.066,4.291,6.27,6.246 c1.922,2.217,4.224,4.111,6.229,6.254c0.975,1.041,2.044,1.99,3.025,3.025c0.403,0.426,0.49,0.947,0.672,1.506 c0.452,1.387,0.914,2.77,1.378,4.152c0.763,2.266,1.245,4.637,2.104,6.869c0.697,1.811,2.022,2.861,3.307,4.238 c1.607,1.723,3.393,3.277,5,5c3.214,3.443,6.786,6.555,10,10c3.214,3.443,6.786,6.555,10,10c3.214,3.443,6.786,6.555,10,10 c3.214,3.443,6.786,6.555,10,10c3.214,3.443,6.786,6.555,10,10c3.214,3.443,6.786,6.555,10,10c3.214,3.443,6.786,6.555,10,10 c3.214,3.443,6.786,6.555,10,10c3.214,3.443,6.786,6.555,10,10c3.214,3.443,6.786,6.555,10,10c3.214,3.443,6.786,6.555,10,10 c3.072,3.291,6.463,6.287,9.563,9.553h92.822C460.83,479.861,486.182,457.734,491.234,428.645z" fill="#3C7EC8"/><path d="M386.898,117.316L117.615,221.179c-18.379,7.374-18.27,17.625-3.35,22.196l67.16,20.962l25.697,78.785 c3.124,8.623,1.584,12.043,10.639,12.043c6.988,0,10.088-3.186,13.98-6.988c2.475-2.422,17.17-16.709,33.578-32.662l69.859,51.615 c12.855,7.092,22.137,3.418,25.338-11.939l45.857-216.096C411.068,120.272,399.197,111.734,386.898,117.316z M191.965,259.521 l151.379-95.506c7.557-4.583,14.486-2.119,8.797,2.931L222.521,283.896l-5.047,53.83L191.965,259.521z" fill="#FFFFFF"/></svg>

After

Width:  |  Height:  |  Size: 3.8 KiB

+228 -27
View File
@@ -1,14 +1,18 @@
package main
import (
"log"
"os"
"github.com/joho/godotenv"
_ "github.com/joho/godotenv/autoload"
"github.com/urfave/cli"
)
// Version for command line
var Version string
// Version set at compile-time
var (
Version string
)
func main() {
app := cli.NewApp()
@@ -20,27 +24,98 @@ func main() {
cli.StringFlag{
Name: "token",
Usage: "telegram token",
EnvVar: "PLUGIN_TOKEN,TELEGRAM_TOKEN",
EnvVar: "PLUGIN_TOKEN,TELEGRAM_TOKEN,INPUT_TOKEN",
},
cli.StringSliceFlag{
Name: "to",
Usage: "send message to user",
EnvVar: "PLUGIN_TO",
Usage: "telegram user",
EnvVar: "PLUGIN_TO,TELEGRAM_TO,INPUT_TO",
},
cli.StringSliceFlag{
cli.StringFlag{
Name: "message",
Usage: "send telegram message",
EnvVar: "PLUGIN_MESSAGE",
EnvVar: "PLUGIN_MESSAGE,TELEGRAM_MESSAGE,INPUT_MESSAGE",
},
cli.StringFlag{
Name: "message.file",
Usage: "send telegram message from file",
EnvVar: "PLUGIN_MESSAGE_FILE,TELEGRAM_MESSAGE_FILE,INPUT_MESSAGE_FILE",
},
cli.StringFlag{
Name: "template.vars",
Usage: "additional template vars to be used in message, as JSON string",
EnvVar: "PLUGIN_TEMPLATE_VARS,TELEGRAM_TEMPLATE_VARS,INPUT_TEMPLATE_VARS",
},
cli.StringSliceFlag{
Name: "photo",
Usage: "send photo message",
EnvVar: "PLUGIN_PHOTO,PHOTO,INPUT_PHOTO",
},
cli.StringSliceFlag{
Name: "document",
Usage: "send document message",
EnvVar: "PLUGIN_DOCUMENT,DOCUMENT,INPUT_DOCUMENT",
},
cli.StringSliceFlag{
Name: "sticker",
Usage: "send sticker message",
EnvVar: "PLUGIN_STICKER,STICKER,INPUT_STICKER",
},
cli.StringSliceFlag{
Name: "audio",
Usage: "send audio message",
EnvVar: "PLUGIN_AUDIO,AUDIO,INPUT_AUDIO",
},
cli.StringSliceFlag{
Name: "voice",
Usage: "send voice message",
EnvVar: "PLUGIN_VOICE,VOICE,INPUT_VOICE",
},
cli.StringSliceFlag{
Name: "location",
Usage: "send location message",
EnvVar: "PLUGIN_LOCATION,LOCATION,INPUT_LOCATION",
},
cli.StringSliceFlag{
Name: "venue",
Usage: "send venue message",
EnvVar: "PLUGIN_VENUE,VENUE,INPUT_VENUE",
},
cli.StringSliceFlag{
Name: "video",
Usage: "send video message",
EnvVar: "PLUGIN_VIDEO,VIDEO,INPUT_VIDEO",
},
cli.BoolFlag{
Name: "debug",
Usage: "enable debug message",
EnvVar: "PLUGIN_DEBUG",
EnvVar: "PLUGIN_DEBUG,DEBUG,INPUT_DEBUG",
},
cli.BoolFlag{
Name: "match.email",
Usage: "send message when only match email",
EnvVar: "PLUGIN_ONLY_MATCH_EMAIL,INPUT_ONLY_MATCH_EMAIL",
},
cli.BoolTFlag{
Name: "webpage.preview",
Usage: "toggle web-page preview",
EnvVar: "PLUGIN_WEBPAGE_PREVIEW,INPUT_WEBPAGE_PREVIEW",
},
cli.StringFlag{
Name: "repo.owner",
Usage: "repository owner",
EnvVar: "DRONE_REPO_OWNER",
Name: "format",
Value: formatMarkdown,
Usage: "telegram message format",
EnvVar: "PLUGIN_FORMAT,FORMAT,INPUT_FORMAT",
},
cli.StringFlag{
Name: "repo",
Usage: "repository owner and repository name",
EnvVar: "DRONE_REPO,GITHUB_REPOSITORY",
},
cli.StringFlag{
Name: "repo.namespace",
Usage: "repository namespace",
EnvVar: "DRONE_REPO_OWNER,DRONE_REPO_NAMESPACE,GITHUB_ACTOR",
},
cli.StringFlag{
Name: "repo.name",
@@ -50,7 +125,12 @@ func main() {
cli.StringFlag{
Name: "commit.sha",
Usage: "git commit sha",
EnvVar: "DRONE_COMMIT_SHA",
EnvVar: "DRONE_COMMIT_SHA,GITHUB_SHA",
},
cli.StringFlag{
Name: "commit.ref",
Usage: "git commit ref",
EnvVar: "DRONE_COMMIT_REF,GITHUB_REF",
},
cli.StringFlag{
Name: "commit.branch",
@@ -58,11 +138,26 @@ func main() {
Usage: "git commit branch",
EnvVar: "DRONE_COMMIT_BRANCH",
},
cli.StringFlag{
Name: "commit.link",
Usage: "git commit link",
EnvVar: "DRONE_COMMIT_LINK",
},
cli.StringFlag{
Name: "commit.author",
Usage: "git author name",
EnvVar: "DRONE_COMMIT_AUTHOR",
},
cli.StringFlag{
Name: "commit.author.email",
Usage: "git author email",
EnvVar: "DRONE_COMMIT_AUTHOR_EMAIL",
},
cli.StringFlag{
Name: "commit.author.avatar",
Usage: "git author avatar",
EnvVar: "DRONE_COMMIT_AUTHOR_AVATAR",
},
cli.StringFlag{
Name: "commit.message",
Usage: "commit message",
@@ -90,31 +185,137 @@ func main() {
Usage: "build link",
EnvVar: "DRONE_BUILD_LINK",
},
cli.StringFlag{
Name: "build.tag",
Usage: "build tag",
EnvVar: "DRONE_TAG",
},
cli.StringFlag{
Name: "pull.request",
Usage: "pull request",
EnvVar: "DRONE_PULL_REQUEST",
},
cli.Float64Flag{
Name: "job.started",
Usage: "job started",
EnvVar: "DRONE_BUILD_STARTED",
},
cli.Float64Flag{
Name: "job.finished",
Usage: "job finished",
EnvVar: "DRONE_BUILD_FINISHED",
},
cli.StringFlag{
Name: "env-file",
Usage: "source env file",
EnvVar: "ENV_FILE",
},
cli.BoolFlag{
Name: "github",
Usage: "Boolean value, indicates the runtime environment is GitHub Action.",
EnvVar: "PLUGIN_GITHUB,GITHUB",
},
cli.StringFlag{
Name: "github.workflow",
Usage: "The name of the workflow.",
EnvVar: "GITHUB_WORKFLOW",
},
cli.StringFlag{
Name: "github.action",
Usage: "The name of the action.",
EnvVar: "GITHUB_ACTION",
},
cli.StringFlag{
Name: "github.event.name",
Usage: "The webhook name of the event that triggered the workflow.",
EnvVar: "GITHUB_EVENT_NAME",
},
cli.StringFlag{
Name: "github.event.path",
Usage: "The path to a file that contains the payload of the event that triggered the workflow. Value: /github/workflow/event.json.",
EnvVar: "GITHUB_EVENT_PATH",
},
cli.StringFlag{
Name: "github.workspace",
Usage: "The GitHub workspace path. Value: /github/workspace.",
EnvVar: "GITHUB_WORKSPACE",
},
cli.StringFlag{
Name: "deploy.to",
Usage: "Provides the target deployment environment for the running build. This value is only available to promotion and rollback pipelines.",
EnvVar: "DRONE_DEPLOY_TO",
},
cli.StringFlag{
Name: "socks5",
Usage: "Socks5 proxy URL",
EnvVar: "PLUGIN_SOCKS5,SOCKS5,INPUT_SOCKS5",
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
app.Run(os.Args)
}
func run(c *cli.Context) error {
if c.String("env-file") != "" {
_ = godotenv.Load(c.String("env-file"))
}
plugin := Plugin{
GitHub: GitHub{
Workflow: c.String("github.workflow"),
Workspace: c.String("github.workspace"),
Action: c.String("github.action"),
EventName: c.String("github.event.name"),
EventPath: c.String("github.event.path"),
},
Repo: Repo{
Owner: c.String("repo.owner"),
Name: c.String("repo.name"),
FullName: c.String("repo"),
Namespace: c.String("repo.namespace"),
Name: c.String("repo.name"),
},
Commit: Commit{
Sha: c.String("commit.sha"),
Ref: c.String("commit.ref"),
Branch: c.String("commit.branch"),
Link: c.String("commit.link"),
Author: c.String("commit.author"),
Email: c.String("commit.author.email"),
Avatar: c.String("commit.author.avatar"),
Message: c.String("commit.message"),
},
Build: Build{
Number: c.Int("build.number"),
Event: c.String("build.event"),
Status: c.String("build.status"),
Commit: c.String("commit.sha"),
Branch: c.String("commit.branch"),
Author: c.String("commit.author"),
Message: c.String("commit.message"),
Link: c.String("build.link"),
Tag: c.String("build.tag"),
Number: c.Int("build.number"),
Event: c.String("build.event"),
Status: c.String("build.status"),
Link: c.String("build.link"),
Started: c.Float64("job.started"),
Finished: c.Float64("job.finished"),
PR: c.String("pull.request"),
DeployTo: c.String("deploy.to"),
},
Config: Config{
Token: c.String("token"),
Debug: c.Bool("debug"),
To: c.StringSlice("to"),
Message: c.StringSlice("message"),
Token: c.String("token"),
Debug: c.Bool("debug"),
MatchEmail: c.Bool("match.email"),
WebPreview: c.Bool("webpage.preview"),
To: c.StringSlice("to"),
Message: c.String("message"),
MessageFile: c.String("message.file"),
TemplateVars: c.String("template.vars"),
Photo: c.StringSlice("photo"),
Document: c.StringSlice("document"),
Sticker: c.StringSlice("sticker"),
Audio: c.StringSlice("audio"),
Voice: c.StringSlice("voice"),
Location: c.StringSlice("location"),
Video: c.StringSlice("video"),
Venue: c.StringSlice("venue"),
Format: c.String("format"),
GitHub: c.Bool("github"),
Socks5: c.String("socks5"),
},
}
+268
View File
@@ -0,0 +1,268 @@
{
test:: {
kind: 'pipeline',
name: 'testing',
platform: {
os: 'linux',
arch: 'amd64',
},
steps: [
{
name: 'vet',
image: 'golang:1.13',
pull: 'always',
commands: [
'make vet',
],
volumes: [
{
name: 'gopath',
path: '/go',
},
],
},
{
name: 'lint',
image: 'golang:1.13',
pull: 'always',
commands: [
'make lint',
],
volumes: [
{
name: 'gopath',
path: '/go',
},
],
},
{
name: 'misspell',
image: 'golang:1.13',
pull: 'always',
commands: [
'make misspell-check',
],
volumes: [
{
name: 'gopath',
path: '/go',
},
],
},
{
name: 'test',
image: 'golang:1.13',
pull: 'always',
environment: {
TELEGRAM_TOKEN: { 'from_secret': 'telegram_token' },
TELEGRAM_TO: { 'from_secret': 'telegram_to' },
},
commands: [
'make test',
'make coverage',
],
volumes: [
{
name: 'gopath',
path: '/go',
},
],
},
{
name: 'codecov',
image: 'robertstettner/drone-codecov',
pull: 'always',
settings: {
token: { 'from_secret': 'codecov_token' },
},
},
],
volumes: [
{
name: 'gopath',
temp: {},
},
],
},
build(name, os='linux', arch='amd64'):: {
kind: 'pipeline',
name: os + '-' + arch,
platform: {
os: os,
arch: arch,
},
steps: [
{
name: 'build-push',
image: 'golang:1.13',
pull: 'always',
environment: {
CGO_ENABLED: '0',
},
commands: [
'go build -v -ldflags \'-X main.build=${DRONE_BUILD_NUMBER}\' -a -o release/' + os + '/' + arch + '/' + name,
],
when: {
event: {
exclude: [ 'tag' ],
},
},
},
{
name: 'build-tag',
image: 'golang:1.13',
pull: 'always',
environment: {
CGO_ENABLED: '0',
},
commands: [
'go build -v -ldflags \'-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\' -a -o release/' + os + '/' + arch + '/' + name,
],
when: {
event: [ 'tag' ],
},
},
{
name: 'executable',
image: 'golang:1.13',
pull: 'always',
commands: [
'./release/' + os + '/' + arch + '/' + name + ' --help',
],
},
{
name: 'dryrun',
image: 'plugins/docker:' + os + '-' + arch,
pull: 'always',
settings: {
daemon_off: false,
dry_run: true,
tags: os + '-' + arch,
dockerfile: 'docker/Dockerfile.' + os + '.' + arch,
repo: 'appleboy/' + name,
cache_from: 'appleboy/' + name,
},
when: {
event: [ 'pull_request' ],
},
},
{
name: 'publish',
image: 'plugins/docker:' + os + '-' + arch,
pull: 'always',
settings: {
daemon_off: 'false',
auto_tag: true,
auto_tag_suffix: os + '-' + arch,
dockerfile: 'docker/Dockerfile.' + os + '.' + arch,
repo: 'appleboy/' + name,
cache_from: 'appleboy/' + name,
username: { 'from_secret': 'docker_username' },
password: { 'from_secret': 'docker_password' },
},
when: {
event: {
exclude: [ 'pull_request' ],
},
},
},
],
depends_on: [
'testing',
],
trigger: {
ref: [
'refs/heads/master',
'refs/pull/**',
'refs/tags/**',
],
},
},
release:: {
kind: 'pipeline',
name: 'release-binary',
platform: {
os: 'linux',
arch: 'amd64',
},
steps: [
{
name: 'build-all-binary',
image: 'golang:1.13',
pull: 'always',
commands: [
'make release'
],
when: {
event: [ 'tag' ],
},
},
{
name: 'deploy-all-binary',
image: 'plugins/github-release',
pull: 'always',
settings: {
files: [ 'dist/release/*' ],
api_key: { 'from_secret': 'github_release_api_key' },
},
when: {
event: [ 'tag' ],
},
},
],
depends_on: [
'testing',
],
trigger: {
ref: [
'refs/tags/**',
],
},
},
notifications(os='linux', arch='amd64', depends_on=[]):: {
kind: 'pipeline',
name: 'notifications',
platform: {
os: os,
arch: arch,
},
steps: [
{
name: 'telegram',
image: 'appleboy/drone-telegram',
pull: 'always',
settings: {
to: { from_secret: 'telegram_to' },
token: { from_secret: 'telegram_token' },
message: '{{#success build.status}} Build #{{build.number}} of `{{repo.name}}` succeeded.\n\n📝 Commit by {{commit.author}} on `{{commit.branch}}`:\n``` {{commit.message}} ```\n\n🌐 {{ build.link }} {{else}} Build #{{build.number}} of `{{repo.name}}` failed.\n\n📝 Commit by {{commit.author}} on `{{commit.branch}}`:\n``` {{commit.message}} ```\n\n🌐 {{ build.link }} {{/success}}\n',
},
},
{
name: 'manifest',
image: 'plugins/manifest',
pull: 'always',
settings: {
username: { from_secret: 'docker_username' },
password: { from_secret: 'docker_password' },
spec: 'docker/manifest.tmpl',
ignore_missing: true,
},
},
],
depends_on: depends_on,
trigger: {
ref: [
'refs/heads/master',
'refs/tags/**',
],
},
},
signature(key):: {
kind: 'signature',
hmac: key,
}
}
+390 -45
View File
@@ -1,50 +1,118 @@
package main
import (
"bufio"
"encoding/json"
"errors"
"fmt"
"html"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
"path/filepath"
"strconv"
"strings"
"gopkg.in/telegram-bot-api.v4"
"github.com/drone/drone-template-lib/template"
tgbotapi "gopkg.in/telegram-bot-api.v4"
)
const (
formatMarkdown = "markdown"
)
type (
// GitHub information.
GitHub struct {
Workflow string
Workspace string
Action string
EventName string
EventPath string
}
// Repo information.
Repo struct {
Owner string
Name string
FullName string
Namespace string
Name string
}
// Commit information.
Commit struct {
Sha string
Ref string
Branch string
Link string
Author string
Avatar string
Email string
Message string
}
// Build information.
Build struct {
Event string
Number int
Commit string
Message string
Branch string
Author string
Status string
Link string
Tag string
Event string
Number int
Status string
Link string
Started float64
Finished float64
PR string
DeployTo string
}
// Config for the plugin.
Config struct {
Token string
Debug bool
To []string
Message []string
Token string
Debug bool
MatchEmail bool
WebPreview bool
To []string
Message string
MessageFile string
TemplateVars string
Photo []string
Document []string
Sticker []string
Audio []string
Voice []string
Location []string
Video []string
Venue []string
Format string
GitHub bool
Socks5 string
}
// Plugin values.
Plugin struct {
GitHub GitHub
Repo Repo
Commit Commit
Build Build
Config Config
Tpl map[string]string
}
// Location format
Location struct {
Title string
Address string
Latitude float64
Longitude float64
}
)
var icons = map[string]string{
"failure": "❌",
"cancelled": "❕",
"success": "✅",
}
func trimElement(keys []string) []string {
var newKeys []string
@@ -59,69 +127,346 @@ func trimElement(keys []string) []string {
return newKeys
}
func parseID(keys []string) []int64 {
var newKeys []int64
func escapeMarkdown(keys []string) []string {
var newKeys []string
for _, value := range keys {
id, err := strconv.ParseInt(value, 10, 64)
if err != nil {
log.Println(err.Error())
value = escapeMarkdownOne(value)
if len(value) == 0 {
continue
}
newKeys = append(newKeys, id)
newKeys = append(newKeys, value)
}
return newKeys
}
func escapeMarkdownOne(str string) string {
str = strings.Replace(str, `\_`, `_`, -1)
str = strings.Replace(str, `_`, `\_`, -1)
return str
}
func globList(keys []string) []string {
var newKeys []string
for _, pattern := range keys {
pattern = strings.Trim(pattern, " ")
matches, err := filepath.Glob(pattern)
if err != nil {
fmt.Printf("Glob error for %q: %s\n", pattern, err)
continue
}
newKeys = append(newKeys, matches...)
}
return newKeys
}
func convertLocation(value string) (Location, bool) {
var latitude, longitude float64
var title, address string
var err error
values := trimElement(strings.Split(value, " "))
if len(values) < 2 {
return Location{}, true
}
if len(values) > 2 {
title = values[2]
}
if len(values) > 3 {
title = values[2]
address = values[3]
}
latitude, err = strconv.ParseFloat(values[0], 64)
if err != nil {
log.Println(err.Error())
return Location{}, true
}
longitude, err = strconv.ParseFloat(values[1], 64)
if err != nil {
log.Println(err.Error())
return Location{}, true
}
return Location{
Title: title,
Address: address,
Latitude: latitude,
Longitude: longitude,
}, false
}
func loadTextFromFile(filename string) ([]string, error) {
f, err := os.Open(filename)
if err != nil {
return nil, err
}
defer f.Close()
r := bufio.NewReader(f)
content, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
return []string{string(content)}, nil
}
func parseTo(to []string, authorEmail string, matchEmail bool) []int64 {
var emails []int64
var ids []int64
attachEmail := true
for _, value := range trimElement(to) {
idArray := trimElement(strings.Split(value, ":"))
// check id
id, err := strconv.ParseInt(idArray[0], 10, 64)
if err != nil {
continue
}
// check match author email
if len(idArray) > 1 {
if email := idArray[1]; email != authorEmail {
continue
}
emails = append(emails, id)
attachEmail = false
continue
}
ids = append(ids, id)
}
if matchEmail && !attachEmail {
return emails
}
ids = append(ids, emails...)
return ids
}
// Exec executes the plugin.
func (p Plugin) Exec() error {
func (p Plugin) Exec() (err error) {
if len(p.Config.Token) == 0 || len(p.Config.To) == 0 {
log.Println("missing telegram token or user list")
return errors.New("missing telegram token or user list")
}
var message []string
if len(p.Config.Message) > 0 {
message = p.Config.Message
} else {
message = p.Message(p.Repo, p.Build)
switch {
case len(p.Config.MessageFile) > 0:
message, err = loadTextFromFile(p.Config.MessageFile)
if err != nil {
return fmt.Errorf("error loading message file '%s': %v", p.Config.MessageFile, err)
}
case len(p.Config.Message) > 0:
message = []string{p.Config.Message}
default:
p.Config.Format = formatMarkdown
message = p.Message()
}
bot, err := tgbotapi.NewBotAPI(p.Config.Token)
if p.Config.TemplateVars != "" {
p.Tpl = make(map[string]string)
if err = json.Unmarshal([]byte(p.Config.TemplateVars), &p.Tpl); err != nil {
return fmt.Errorf("unable to unmarshall template vars from JSON string '%s': %v", p.Config.TemplateVars, err)
}
}
var proxyURL *url.URL
if proxyURL, err = url.Parse(p.Config.Socks5); err != nil {
return fmt.Errorf("unable to unmarshall socks5 proxy url from string '%s': %v", p.Config.Socks5, err)
}
var bot *tgbotapi.BotAPI
if len(p.Config.Socks5) > 0 {
proxyClient := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxyURL)}}
bot, err = tgbotapi.NewBotAPIWithClient(p.Config.Token, proxyClient)
} else {
bot, err = tgbotapi.NewBotAPI(p.Config.Token)
}
if err != nil {
log.Println(err.Error())
return err
}
bot.Debug = p.Config.Debug
// parse ids
ids := parseID(p.Config.To)
ids := parseTo(p.Config.To, p.Commit.Email, p.Config.MatchEmail)
photos := globList(trimElement(p.Config.Photo))
documents := globList(trimElement(p.Config.Document))
stickers := globList(trimElement(p.Config.Sticker))
audios := globList(trimElement(p.Config.Audio))
voices := globList(trimElement(p.Config.Voice))
videos := globList(trimElement(p.Config.Video))
locations := trimElement(p.Config.Location)
venues := trimElement(p.Config.Venue)
message = trimElement(message)
if p.Config.Format == formatMarkdown {
message = escapeMarkdown(message)
p.Commit.Message = escapeMarkdownOne(p.Commit.Message)
p.Commit.Branch = escapeMarkdownOne(p.Commit.Branch)
p.Commit.Link = escapeMarkdownOne(p.Commit.Link)
p.Commit.Author = escapeMarkdownOne(p.Commit.Author)
p.Commit.Email = escapeMarkdownOne(p.Commit.Email)
p.Build.Tag = escapeMarkdownOne(p.Build.Tag)
p.Build.Link = escapeMarkdownOne(p.Build.Link)
p.Build.PR = escapeMarkdownOne(p.Build.PR)
p.Repo.Namespace = escapeMarkdownOne(p.Repo.Namespace)
p.Repo.Name = escapeMarkdownOne(p.Repo.Name)
}
// send message.
for _, user := range ids {
for _, value := range trimElement(message) {
msg := tgbotapi.NewMessage(user, value)
bot.Send(msg)
for _, value := range message {
txt, err := template.RenderTrim(value, p)
if err != nil {
return err
}
txt = html.UnescapeString(txt)
msg := tgbotapi.NewMessage(user, txt)
msg.ParseMode = p.Config.Format
msg.DisableWebPagePreview = !p.Config.WebPreview
if err := p.Send(bot, msg); err != nil {
return err
}
}
for _, value := range photos {
msg := tgbotapi.NewPhotoUpload(user, value)
if err := p.Send(bot, msg); err != nil {
return err
}
}
for _, value := range documents {
msg := tgbotapi.NewDocumentUpload(user, value)
if err := p.Send(bot, msg); err != nil {
return err
}
}
for _, value := range stickers {
msg := tgbotapi.NewStickerUpload(user, value)
if err := p.Send(bot, msg); err != nil {
return err
}
}
for _, value := range audios {
msg := tgbotapi.NewAudioUpload(user, value)
msg.Title = "Audio Message."
if err := p.Send(bot, msg); err != nil {
return err
}
}
for _, value := range voices {
msg := tgbotapi.NewVoiceUpload(user, value)
if err := p.Send(bot, msg); err != nil {
return err
}
}
for _, value := range videos {
msg := tgbotapi.NewVideoUpload(user, value)
msg.Caption = "Video Message"
if err := p.Send(bot, msg); err != nil {
return err
}
}
for _, value := range locations {
location, empty := convertLocation(value)
if empty {
continue
}
msg := tgbotapi.NewLocation(user, location.Latitude, location.Longitude)
if err := p.Send(bot, msg); err != nil {
return err
}
}
for _, value := range venues {
location, empty := convertLocation(value)
if empty {
continue
}
msg := tgbotapi.NewVenue(user, location.Title, location.Address, location.Latitude, location.Longitude)
if err := p.Send(bot, msg); err != nil {
return err
}
}
}
return nil
}
// Send bot message.
func (p Plugin) Send(bot *tgbotapi.BotAPI, msg tgbotapi.Chattable) error {
message, err := bot.Send(msg)
if p.Config.Debug {
log.Println("=====================")
log.Printf("Response Message: %#v\n", message)
log.Println("=====================")
}
if err == nil {
return nil
}
return errors.New(strings.Replace(err.Error(), p.Config.Token, "<token>", -1))
}
// Message is plugin default message.
func (p Plugin) Message(repo Repo, build Build) []string {
return []string{fmt.Sprintf("[%s] <%s> (%s)『%s』by %s",
build.Status,
build.Link,
build.Branch,
build.Message,
build.Author,
func (p Plugin) Message() []string {
icon := icons[strings.ToLower(p.Build.Status)]
if p.Config.GitHub {
return []string{fmt.Sprintf("%s/%s triggered by %s (%s)",
p.Repo.FullName,
p.GitHub.Workflow,
p.Repo.Namespace,
p.GitHub.EventName,
)}
}
// ✅ Build #106 of drone-telegram succeeded.
//
// 📝 Commit by appleboy on master:
// chore: update default template
//
// 🌐 https://cloud.drone.io/appleboy/drone-telegram/106
return []string{fmt.Sprintf("%s Build #%d of `%s` %s.\n\n📝 Commit by %s on `%s`:\n``` %s ```\n\n🌐 %s",
icon,
p.Build.Number,
p.Repo.FullName,
p.Build.Status,
p.Commit.Author,
p.Commit.Branch,
p.Commit.Message,
p.Build.Link,
)}
}
+327 -45
View File
@@ -1,10 +1,10 @@
package main
import (
"github.com/stretchr/testify/assert"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestMissingDefaultConfig(t *testing.T) {
@@ -30,78 +30,122 @@ func TestMissingUserConfig(t *testing.T) {
func TestDefaultMessageFormat(t *testing.T) {
plugin := Plugin{
Repo: Repo{
Name: "go-hello",
Owner: "appleboy",
FullName: "appleboy/go-hello",
Name: "go-hello",
Namespace: "appleboy",
},
Build: Build{
Number: 101,
Status: "success",
Link: "https://github.com/appleboy/go-hello",
Commit: Commit{
Sha: "e7c4f0a63ceeb42a39ac7806f7b51f3f0d204fd2",
Author: "Bo-Yi Wu",
Branch: "master",
Message: "update travis",
Commit: "e7c4f0a63ceeb42a39ac7806f7b51f3f0d204fd2",
},
Build: Build{
Number: 101,
Status: "success",
Link: "https://github.com/appleboy/go-hello",
},
}
message := plugin.Message(plugin.Repo, plugin.Build)
message := plugin.Message()
assert.Equal(t, []string{"[success] <https://github.com/appleboy/go-hello> (master)『update travis』by Bo-Yi Wu"}, message)
assert.Equal(t, []string{"✅ Build #101 of `appleboy/go-hello` success.\n\n📝 Commit by Bo-Yi Wu on `master`:\n``` update travis ```\n\n🌐 https://github.com/appleboy/go-hello"}, message)
}
func TestDefaultMessageFormatFromGitHub(t *testing.T) {
plugin := Plugin{
Config: Config{
GitHub: true,
},
Repo: Repo{
FullName: "appleboy/go-hello",
Name: "go-hello",
Namespace: "appleboy",
},
GitHub: GitHub{
Workflow: "test-workflow",
Action: "send notification",
EventName: "push",
},
}
message := plugin.Message()
assert.Equal(t, []string{"appleboy/go-hello/test-workflow triggered by appleboy (push)"}, message)
}
func TestSendMessage(t *testing.T) {
plugin := Plugin{
Repo: Repo{
Name: "go-hello",
Owner: "appleboy",
Name: "go-hello",
Namespace: "appleboy",
},
Build: Build{
Number: 101,
Status: "success",
Link: "https://github.com/appleboy/go-hello",
Commit: Commit{
Sha: "e7c4f0a63ceeb42a39ac7806f7b51f3f0d204fd2",
Author: "Bo-Yi Wu",
Branch: "master",
Message: "update travis by drone plugin",
Commit: "e7c4f0a63ceeb42a39ac7806f7b51f3f0d204fd2",
Email: "test@gmail.com",
},
Build: Build{
Tag: "1.0.0",
Number: 101,
Status: "success",
Link: "https://github.com/appleboy/go-hello",
},
Config: Config{
Token: os.Getenv("TELEGRAM_TOKEN"),
To: []string{os.Getenv("TELEGRAM_TO"), "中文ID", "1234567890"},
Message: []string{"Test Telegram Chat Bot From Travis or Local", " "},
Debug: false,
Token: os.Getenv("TELEGRAM_TOKEN"),
To: []string{os.Getenv("TELEGRAM_TO"), os.Getenv("TELEGRAM_TO") + ":appleboy@gmail.com", "中文ID", "1234567890"},
Message: "Test Telegram Chat Bot From Travis or Local, commit message: 『{{ build.message }}』",
Photo: []string{"tests/github.png", "1234", " "},
Document: []string{"tests/gophercolor.png", "1234", " "},
Sticker: []string{"tests/github-logo.png", "tests/github.png", "1234", " "},
Audio: []string{"tests/audio.mp3", "1234", " "},
Voice: []string{"tests/voice.ogg", "1234", " "},
Location: []string{"24.9163213 121.1424972", "1", " "},
Venue: []string{"35.661777 139.704051 竹北體育館 新竹縣竹北市", "24.9163213 121.1424972", "1", " "},
Video: []string{"tests/video.mp4", "1234", " "},
Debug: false,
},
}
err := plugin.Exec()
assert.Nil(t, err)
assert.NotNil(t, err)
plugin.Config.Format = formatMarkdown
plugin.Config.Message = "Test escape under_score"
err = plugin.Exec()
assert.NotNil(t, err)
// disable message
plugin.Config.Message = []string{}
plugin.Config.Message = ""
err = plugin.Exec()
assert.Nil(t, err)
assert.NotNil(t, err)
}
func TestBotError(t *testing.T) {
plugin := Plugin{
Repo: Repo{
Name: "go-hello",
Owner: "appleboy",
Name: "go-hello",
Namespace: "appleboy",
},
Build: Build{
Number: 101,
Status: "success",
Link: "https://github.com/appleboy/go-hello",
Commit: Commit{
Sha: "e7c4f0a63ceeb42a39ac7806f7b51f3f0d204fd2",
Author: "Bo-Yi Wu",
Branch: "master",
Message: "update travis by drone plugin",
Commit: "e7c4f0a63ceeb42a39ac7806f7b51f3f0d204fd2",
},
Build: Build{
Number: 101,
Status: "success",
Link: "https://github.com/appleboy/go-hello",
},
Config: Config{
Token: "appleboy",
To: []string{os.Getenv("TELEGRAM_TO"), "中文ID", "1234567890"},
Message: []string{"Test Telegram Chat Bot From Travis or Local", " "},
Message: "Test Telegram Chat Bot From Travis or Local",
},
}
@@ -123,17 +167,255 @@ func TestTrimElement(t *testing.T) {
assert.Equal(t, result, trimElement(input))
}
func TestParseID(t *testing.T) {
var input []string
var result []int64
func TestEscapeMarkdown(t *testing.T) {
provider := [][][]string{
{
{"user", "repo"},
{"user", "repo"},
},
{
{"user_name", "repo_name"},
{`user\_name`, `repo\_name`},
},
{
{"user_name_long", "user_name_long"},
{`user\_name\_long`, `user\_name\_long`},
},
{
{`user\_name\_long`, `repo\_name\_long`},
{`user\_name\_long`, `repo\_name\_long`},
},
{
{`user\_name\_long`, `repo\_name\_long`, ""},
{`user\_name\_long`, `repo\_name\_long`},
},
}
input = []string{"1", "測試", "3"}
result = []int64{int64(1), int64(3)}
assert.Equal(t, result, parseID(input))
input = []string{"1", "2"}
result = []int64{int64(1), int64(2)}
assert.Equal(t, result, parseID(input))
for _, testCase := range provider {
assert.Equal(t, testCase[1], escapeMarkdown(testCase[0]))
}
}
func TestEscapeMarkdownOne(t *testing.T) {
provider := [][]string{
{"user", "user"},
{"user_name", `user\_name`},
{"user_name_long", `user\_name\_long`},
{`user\_name\_escaped`, `user\_name\_escaped`},
}
for _, testCase := range provider {
assert.Equal(t, testCase[1], escapeMarkdownOne(testCase[0]))
}
}
func TestParseTo(t *testing.T) {
input := []string{"0", "1:1@gmail.com", "2:2@gmail.com", "3:3@gmail.com", "4", "5"}
ids := parseTo(input, "1@gmail.com", false)
assert.Equal(t, []int64{0, 4, 5, 1}, ids)
ids = parseTo(input, "1@gmail.com", true)
assert.Equal(t, []int64{1}, ids)
ids = parseTo(input, "a@gmail.com", false)
assert.Equal(t, []int64{0, 4, 5}, ids)
ids = parseTo(input, "a@gmail.com", true)
assert.Equal(t, []int64{0, 4, 5}, ids)
// test empty ids
ids = parseTo([]string{"", " ", " "}, "a@gmail.com", true)
assert.Equal(t, 0, len(ids))
}
func TestGlobList(t *testing.T) {
var input []string
var result []string
input = []string{"tests/gophercolor.png", "測試", "3"}
result = []string{"tests/gophercolor.png"}
assert.Equal(t, result, globList(input))
input = []string{"tests/*.mp3"}
result = []string{"tests/audio.mp3"}
assert.Equal(t, result, globList(input))
}
func TestConvertLocation(t *testing.T) {
var input string
var result Location
var empty bool
input = "1"
result, empty = convertLocation(input)
assert.Equal(t, true, empty)
assert.Equal(t, Location{}, result)
// strconv.ParseInt: parsing "測試": invalid syntax
input = "測試 139.704051"
result, empty = convertLocation(input)
assert.Equal(t, true, empty)
assert.Equal(t, Location{}, result)
// strconv.ParseInt: parsing "測試": invalid syntax
input = "35.661777 測試"
result, empty = convertLocation(input)
assert.Equal(t, true, empty)
assert.Equal(t, Location{}, result)
input = "35.661777 139.704051"
result, empty = convertLocation(input)
assert.Equal(t, false, empty)
assert.Equal(t, Location{
Latitude: float64(35.661777),
Longitude: float64(139.704051),
}, result)
input = "35.661777 139.704051 title"
result, empty = convertLocation(input)
assert.Equal(t, false, empty)
assert.Equal(t, Location{
Title: "title",
Address: "",
Latitude: float64(35.661777),
Longitude: float64(139.704051),
}, result)
input = "35.661777 139.704051 title address"
result, empty = convertLocation(input)
assert.Equal(t, false, empty)
assert.Equal(t, Location{
Title: "title",
Address: "address",
Latitude: float64(35.661777),
Longitude: float64(139.704051),
}, result)
}
func TestHTMLMessage(t *testing.T) {
plugin := Plugin{
Repo: Repo{
Name: "go-hello",
Namespace: "appleboy",
},
Commit: Commit{
Sha: "e7c4f0a63ceeb42a39ac7806f7b51f3f0d204fd2",
Author: "Bo-Yi Wu",
Branch: "master",
Message: "Freakin' macOS isn't fully case-sensitive..",
},
Build: Build{
Number: 101,
Status: "success",
Link: "https://github.com/appleboy/go-hello",
},
Config: Config{
Token: os.Getenv("TELEGRAM_TOKEN"),
To: []string{os.Getenv("TELEGRAM_TO")},
},
}
err := plugin.Exec()
assert.Nil(t, err)
}
func TestMessageFile(t *testing.T) {
plugin := Plugin{
Repo: Repo{
Name: "go-hello",
Namespace: "appleboy",
},
Commit: Commit{
Sha: "e7c4f0a63ceeb42a39ac7806f7b51f3f0d204fd2",
Author: "Bo-Yi Wu",
Branch: "master",
Message: "Freakin' macOS isn't fully case-sensitive..",
},
Build: Build{
Number: 101,
Status: "success",
Link: "https://github.com/appleboy/go-hello",
},
Config: Config{
Token: os.Getenv("TELEGRAM_TOKEN"),
To: []string{os.Getenv("TELEGRAM_TO")},
MessageFile: "tests/message.txt",
},
}
err := plugin.Exec()
assert.Nil(t, err)
}
func TestTemplateVars(t *testing.T) {
plugin := Plugin{
Repo: Repo{
Name: "go-hello",
Namespace: "appleboy",
},
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",
},
Config: Config{
Token: os.Getenv("TELEGRAM_TOKEN"),
To: []string{os.Getenv("TELEGRAM_TO")},
Format: formatMarkdown,
MessageFile: "tests/message_template.txt",
TemplateVars: `{"env":"testing","version":"1.2.0-SNAPSHOT"}`,
},
}
err := plugin.Exec()
assert.Nil(t, err)
}
func TestProxySendMessage(t *testing.T) {
plugin := Plugin{
Repo: Repo{
Name: "go-hello",
Namespace: "appleboy",
},
Commit: Commit{
Sha: "e7c4f0a63ceeb42a39ac7806f7b51f3f0d204fd2",
Author: "Bo-Yi Wu",
Branch: "master",
Message: "start use proxy",
Email: "test@gmail.com",
},
Build: Build{
Tag: "1.0.0",
Number: 101,
Status: "success",
Link: "https://github.com/appleboy/go-hello",
},
Config: Config{
Token: os.Getenv("TELEGRAM_TOKEN"),
To: []string{os.Getenv("TELEGRAM_TO")},
Message: "Send message from socks5 proxy URL.",
Debug: false,
Socks5: os.Getenv("SOCKS5"),
},
}
err := plugin.Exec()
assert.Nil(t, err)
}
BIN
View File
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

+4
View File
@@ -0,0 +1,4 @@
Sample message loaded from file.
Commit msg: {{commit.message}}
+7
View File
@@ -0,0 +1,7 @@
Sample message template loaded from file.
*Environ:* {{tpl.env}}
*Version:* {{tpl.version}}
Commit msg: {{commit.message}}
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.