Compare commits

...

219 Commits

Author SHA1 Message Date
Bo-Yi Wu cd7b8b4656 chore(docker): bump alpine base image to 3.23
- Upgrade FROM alpine:3.17 to alpine:3.23
- Resolve Trivy CRITICAL/HIGH CVE findings from EOL alpine 3.17
2026-05-08 23:55:41 +08:00
Bo-Yi Wu 530ced4f2a chore: bump go directive to 1.25.10
- Update go.mod go directive from 1.25.9 to 1.25.10
2026-05-08 21:19:20 +08:00
Bo-Yi Wu 072876987d ci: bump golangci-lint to v2.12
- Upgrade golangci-lint version from v2.11 to v2.12
2026-05-08 20:13:40 +08:00
Bo-Yi Wu caaf39fc08 ci(actions): bump trivy-action to v0.36.0 and codecov-action to v6 2026-04-25 16:51:03 +08:00
Bo-Yi Wu d746084872 ci(docker): fail push when trivy finds CRITICAL/HIGH issues 2026-04-16 23:01:15 +08:00
Bo-Yi Wu 6379123ca3 ci: enable check-latest in docker and goreleaser workflows 2026-04-16 22:42:55 +08:00
Bo-Yi Wu cff7d4e183 fix: skip integration tests without telegram secrets; apply modernize fix 2026-04-16 22:39:48 +08:00
Bo-Yi Wu 7007692d2e ci: enable check-latest for setup-go to fetch newest patch 2026-04-16 21:15:46 +08:00
Bo-Yi Wu 23f0958c87 ci: pin golangci-lint to v2.11 2026-04-16 21:11:25 +08:00
Bo-Yi Wu c8c37942c1 ci: bump GitHub Actions and add Go 1.25/1.26 to test matrix 2026-04-16 21:03:32 +08:00
Bo-Yi Wu a7daa0df80 chore: bump go directive to 1.25.9 2026-04-16 20:58:04 +08:00
Bo-Yi Wu f3ace6f519 ci: add Trivy security scanning for source code and Docker image
- Add independent trivy.yml workflow with repo scan and image scan jobs
- Add Trivy image scan step in docker.yml before pushing Docker image
- Add security-events permission for SARIF upload
- Add Trivy Security Scan badge to README
2026-04-16 18:10:12 +08:00
Bo-Yi Wu 4de983b4ef fix(deps): upgrade golang.org/x/crypto to fix CVE vulnerabilities
- bump golang.org/x/crypto to v0.45.0 (fixes CVE-2024-45337 CRITICAL,
  CVE-2025-22869 HIGH, CVE-2025-47914 MEDIUM, CVE-2025-58181 MEDIUM)
- bump golang.org/x/sys to v0.38.0
2026-04-16 12:13:16 +08:00
Bo-Yi Wu b4a51bd6b6 ci(actions): upgrade GitHub Actions to latest versions
- bump actions/checkout to v6
- bump actions/setup-go to v6
- bump actions/cache to v5
- bump goreleaser/goreleaser-action to v7
- bump golangci/golangci-lint-action to v9
- bump github/codeql-action/* to v4
- bump codecov/codecov-action to v5
- bump docker/build-push-action to v7
- bump docker/login-action to v4
- bump docker/metadata-action to v6
- bump docker/setup-buildx-action to v4
- bump docker/setup-qemu-action to v4
- bump hadolint/hadolint-action to v3.3.0
- bump aquasecurity/trivy-action to v0.35.0
2026-04-16 12:06:53 +08:00
Bo-Yi Wu 30b9c501ff perf(plugin): hoist repeated work out of per-user loop
- Pre-render message templates before iterating users
- Pre-parse locations and venues before iterating users
- Inline trivial templateMessage wrapper into call site
- Extract escapeMarkdownFields variadic helper for bulk field escaping
- Use strings.TrimSpace instead of strings.Trim(" ") for robustness
- Pre-allocate slices in trimElement, escapeMarkdown, and globList
- Fix comment typo and inconsistent audio caption trailing period
2026-04-08 23:10:59 +08:00
Bo-Yi Wu cbae1a3737 chore: migrate golangci-lint config to v2
- Add version field and migrate to v2 config format
- Replace deprecated linters with modern equivalents
- Add new linters: bidichk, depguard, forbidigo, revive, testifylint, etc.
- Move gofmt, gofumpt, golines to formatters section
- Configure revive rules, depguard deny list, and exclusion presets
2026-04-08 23:00:38 +08:00
Bo-Yi Wu 0bc6220388 fix: resolve all golangci-lint issues
- Replace fmt.Printf with log.Printf to satisfy forbidigo
- Fix ineffectual assignment to err in proxy block by avoiding variable shadowing
- Format long lines with golines
- Use assert.Error/NoError instead of NotNil/Nil for error assertions
- Use assert.True/False instead of Equal for boolean assertions
- Use assert.Empty instead of Equal with len check
- Use require for mid-test error assertions that guard subsequent operations
- Add testify/require import
2026-04-08 22:47:32 +08:00
Bo-Yi Wu 8587a97ab1 refactor: simplify plugin code and fix minor issues
- Replace os.Open/bufio/io.ReadAll with os.ReadFile in loadTextFromFile
- Guard proxy URL parsing inside socks5 check to avoid false errors
- Remove redundant trimElement wrapping around globList calls
- Remove dead title assignment in convertLocation
- Switch Plugin methods to pointer receivers to avoid struct copying
- Use %w for error wrapping in fmt.Errorf calls
- Fix "unmarshall" typos to "unmarshal" in error messages
- Fix duplicate DIST variable and GXZ_PAGAGE typo in Makefile
2026-04-08 22:40:06 +08:00
Gianluca Boiano 893f3c30bf chore: add DOCS.md metadata for woodpecker plugins (#136) 2024-10-17 23:10:22 +08:00
appleboy 1f66667a65 ci: update Go version in workflow to 1.23
- Update the Go version in the workflow to include 1.23

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-09-06 16:03:56 +08:00
appleboy 47c90ae600 chore: update dependencies to latest versions
- Update the version of `dario.cat/mergo` to `v1.0.1`
- Remove `github.com/Masterminds/semver/v3` version `v3.2.1` and update to `v3.3.0`
- Remove `github.com/Masterminds/sprig/v3` version `v3.2.3` and update to `v3.3.0`
- Remove `github.com/imdario/mergo` version `v0.3.16`
- Update `golang.org/x/crypto` to version `v0.27.0`
- Update `golang.org/x/sys` to version `v0.25.0`

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-09-06 15:59:58 +08:00
Bo-Yi Wu 65d453bece ci: enhance CI workflow with matrix testing and caching
- Replace the testing job with a more structured test job using a matrix strategy for different OS and Go versions.
- Update the Go setup action to version 5.
- Add caching for Go build and module paths to improve build performance.
- Include a step to check out the code with the specific GitHub reference.
- Remove the previous setup tools step and replace it with the new structure.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-08-14 23:10:22 +08:00
Bo-Yi Wu 45cfcd8bb1 chore: configure Goreleaser for multi-OS builds and hooks
- Add a new configuration file for Goreleaser
- Define build settings for multiple operating systems and architectures
- Specify hooks for pre- and post-build processes
- Include options for generating checksums and handling snapshots
- Set up changelog grouping for features, bug fixes, enhancements, and more

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-08-13 23:20:32 +08:00
Bo-Yi Wu a82484f5d7 docs: remove unnecessary badges from the README
- Remove build status badges from the README
- Delete Docker pulls badge from the README

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-08-13 23:18:14 +08:00
Bo-Yi Wu 4b48840e98 chore: upgrade Go version and linting container
- Update Go version from 1.20 to 1.22 in go.mod
- Change the linting container from golang:1.21-alpine to golang:1.22-alpine in the GitHub workflow

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-08-13 23:17:00 +08:00
Bo-Yi Wu 3660832535 chore: remove gocyclo linter from project configuration
- Remove the gocyclo linter from the configuration

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-08-13 23:16:21 +08:00
Bo-Yi Wu 104ffc4fe7 chore: update Dockerfile and Hadolint configuration
- Add a new configuration file for Hadolint with specific ignored rules
- Change the Dockerfile maintainer label from SSH Plugin to Telegram Plugin
- Update the Dockerfile to remove the specific version of ca-certificates and install the latest version instead

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-08-13 23:14:25 +08:00
Bo-Yi Wu 80e7a36e5e ci: update CI workflows for improved build processes
- Update Docker workflow to use version 6 of the build-push-action
- Remove the build_linux_arm step from the Docker workflow
- Update Goreleaser workflow to use version 6 of the goreleaser-action
- Change the args in the Goreleaser workflow from release --rm-dist to release --clean
- Update lint workflow to use version 6 of the golangci-lint-action

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-08-13 23:13:51 +08:00
Bo-Yi Wu 6fdd0872fb chore: upgrade multiple dependencies to latest versions
- Update `github.com/urfave/cli` from version `1.22.14` to `1.22.15`
- Update `github.com/cpuguy83/go-md2man/v2` from version `2.0.3` to `2.0.4`
- Update `github.com/huandu/xstrings` from version `1.4.0` to `1.5.0`
- Update `github.com/shopspring/decimal` from version `1.3.1` to `1.4.0`
- Update `github.com/spf13/cast` from version `1.6.0` to `1.7.0`
- Update `golang.org/x/crypto` from version `0.21.0` to `0.26.0`
- Update `golang.org/x/sys` from version `0.18.0` to `0.24.0`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-08-13 23:12:18 +08:00
Bo-Yi Wu d0cc2a2774 refactor: refactor code and update linter config
- Add a new `.golangci.yml` configuration file with a list of enabled linters
- Exclude `lll` linter for lines starting with `//go:generate`
- Replace `strings.Replace` with `strings.ReplaceAll` in `plugin.go` for markdown escaping and error message sanitization
- Simplify time addition expressions in `plugin_test.go` by removing unnecessary `time.Duration` conversions

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-03-05 21:51:11 +08:00
Bo-Yi Wu 69c7f9efd1 chore: update dependencies and CI configurations
- Update `github.com/stretchr/testify` dependency from version `1.8.4` to `1.9.0`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-03-05 21:39:40 +08:00
Bo-Yi Wu 9d6dcccab5 ci: refactor CI workflows and update Go version management
- Update CodeQL GitHub Action from version 2 to version 3 in codeql.yml
- Replace static Go version with dynamic version from go.mod and enable check for latest Go version in goreleaser.yml
- Add Checkout repository step to lint.yml workflow
- Replace static Go version with dynamic version from go.mod and enable check for latest Go version in lint.yml workflow

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-03-05 21:39:02 +08:00
Bo-Yi Wu 58c63ee76a ci: update GitHub Actions workflows to v4
- Update the GitHub Actions workflow to use version 4 of the `golangci-lint-action`
- Update the GitHub Actions workflow to use version 4 of the `codecov-action`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-03-05 21:37:56 +08:00
Bo-Yi Wu ce010e6672 chore: update dependencies to latest versions
- Update `github.com/google/uuid` dependency from `v1.5.0` to `v1.6.0`
- Upgrade `golang.org/x/crypto` from `v0.18.0` to `v0.21.0`
- Upgrade `golang.org/x/sys` from `v0.16.0` to `v0.18.0`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-03-05 21:36:27 +08:00
appleboy 3b9ad40520 chore: update dependencies to latest versions
- Update the version of `golang.org/x/crypto` to `v0.18.0`
- Update the version of `golang.org/x/sys` to `v0.16.0`

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-01-12 21:24:30 +08:00
appleboy f103b43735 chore: update CodeQL initialization action to v3
- Update the CodeQL initialization action from v2 to v3

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2023-12-24 19:01:12 +08:00
appleboy 361d59920c chore: update dependencies in go.mod file
- Update the version of `github.com/google/uuid` from `v1.4.0` to `v1.5.0` in the `go.mod` file
- Update the version of `golang.org/x/crypto` from `v0.16.0` to `v0.17.0` in the `go.mod` file

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2023-12-24 18:58:08 +08:00
Bo-Yi Wu a77434ffeb chore: update dependencies to latest versions
- Update `github.com/google/uuid` from v1.3.1 to v1.4.0
- Update `github.com/spf13/cast` from v1.5.1 to v1.6.0
- Update `golang.org/x/crypto` from v0.14.0 to v0.16.0
- Update `golang.org/x/sys` from v0.13.0 to v0.15.0

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-12-12 20:43:48 +08:00
Bo-Yi Wu a8e9c83c55 chore: update actions to version 5 in relevant files
- Update the `setup-go` action from version 4 to version 5 in `docker.yml`
- Update the `docker/build-push-action` action from version 4 to version 5 in `docker.yml`
- Update the `setup-go` action from version 4 to version 5 in `goreleaser.yml`
- Update the `goreleaser/goreleaser-action` action from version 4 to version 5 in `goreleaser.yml`
- Update the `setup-go` action from version 4 to version 5 in `lint.yml`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-12-11 22:47:40 +08:00
Bo-Yi Wu 3c91807166 build: update container and package dependencies
- Change the container from `golang:1.19-alpine` to `golang:1.21-alpine`
- Add `build-base`, `zlib-dev`, and `ucl-dev` to the list of packages to be installed

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-10-25 15:58:58 +08:00
Bo-Yi Wu 8239f0f8b1 chore: add setup step for related tools in lint workflow
- Add a step to setup related tools in the lint workflow

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-10-25 15:49:47 +08:00
Bo-Yi Wu de446823b7 refactor: refactor file handling to use os package
- Remove the import of `io/ioutil`
- Replace `ioutil.ReadFile` with `os.ReadFile`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-10-25 15:46:56 +08:00
Bo-Yi Wu d8db8b8eea chore: update docker/setup-qemu-action to version v3
- Update the version of `docker/setup-qemu-action` from `v2` to `v3`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-10-25 15:41:25 +08:00
Bo-Yi Wu 49d1464e69 refactor: refactor file handling and imports
- Change in main.go: Replaced `godotenv.Load(filename)` with `_ = godotenv.Load(filename)`
- Change in main.go: Replaced `godotenv.Overload("/run/drone/env")` with `_ = godotenv.Overload("/run/drone/env")`
- Change in plugin.go: Added import for "io"
- Change in plugin.go: Replaced `ioutil.ReadAll(r)` with `io.ReadAll(r)`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-10-25 15:40:16 +08:00
Bo-Yi Wu 99974ef0e7 chore: update docker/setup-buildx-action to v3
- Update the version of `docker/setup-buildx-action` from `v2` to `v3`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-10-25 15:38:51 +08:00
Bo-Yi Wu dc775b15ea chore: update workflow action versions
- Fix a typo in the cron expression for the codeql.yml workflow
- Update the version of the actions/checkout action in the codeql.yml workflow
- Update the version of the docker/login-action in the docker.yml workflow
- Update the version of the docker/metadata-action in the docker.yml workflow
- Update the version of the actions/checkout action in the goreleaser.yml workflow
- Update the version of the actions/checkout action in the lint.yml workflow

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-10-25 15:36:36 +08:00
Bo-Yi Wu 571987a1f0 chore: update dependencies in go.mod file
- Update the version of Go to 1.20 in the go.mod file
- Update the version of github.com/appleboy/drone-template-lib to v1.3.0 in the go.mod file
- Update the version of github.com/joho/godotenv to v1.5.1 in the go.mod file
- Update the version of github.com/stretchr/testify to v1.8.4 in the go.mod file
- Update the version of github.com/urfave/cli to v1.22.14 in the go.mod file

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-10-25 10:50:56 +08:00
Bo-Yi Wu 92b96294c4 build: add GitHub workflows and Dockerfile
- Add a new file `.github/FUNDING.yml`
- Add a new file `.github/dependabot.yml`
- Add a new file `.github/workflows/codeql.yml`
- Add a new file `.github/workflows/docker.yml`
- Add a new file `.github/workflows/goreleaser.yml`
- Add a new file `.github/workflows/lint.yml`
- Add a new file `docker/Dockerfile`
- Delete the file `docker/Dockerfile.linux.amd64`
- Delete the file `docker/Dockerfile.linux.arm`
- Delete the file `docker/Dockerfile.linux.arm64`
- Delete the file `docker/Dockerfile.windows.amd64`
- Delete the file `docker/manifest.tmpl`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-10-25 10:47:34 +08:00
Bo-Yi Wu 81d4eb4d8f chore: remove unnecessary configuration files
- Deleted file: `.appveyor.yml`
- Deleted file: `.drone.jsonnet`
- Deleted file: `.drone.yml`
- Deleted file: `.editorconfig`
- Deleted file: `.revive.toml`
- Deleted file: `pipeline.libsonnet`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-10-25 10:42:46 +08:00
Alex 8ca83919d2 fix: {{since build.started}} does not reflect the actual build time in a p… (#114) 2023-10-25 07:27:16 +08:00
Bo-Yi Wu ab44454733 chore: remove trim \n from message (#105) 2021-07-12 15:17:02 +08:00
Bo-Yi Wu 2dfbc98fdd chore: remove badge
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2021-07-03 12:46:47 +08:00
Bo-Yi Wu 24f5558e9e chore: update go module
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2021-07-03 12:46:31 +08:00
Bo-Yi Wu ca270b33c8 Fix can't call duration helper func (#104)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2021-07-03 12:39:54 +08:00
Bo-Yi Wu 882afee629 chore: upgrade drone template (#103) 2021-07-03 11:56:16 +08:00
Bo-Yi Wu d5d27734b0 chore: revert to go1.15 2021-04-03 07:08:13 +08:00
Bo-Yi Wu e0f4e9a9e4 chore: upgrade go module 2021-04-03 06:54:55 +08:00
Bo-Yi Wu d6c3514a66 chore: upgrade to go1.16 2021-04-03 06:39:46 +08:00
vaaski 6dbb4b1735 add disable_notification parameter (#99) 2021-04-03 06:38:16 +08:00
Bo-Yi Wu a91d132e3f chore: upgrade go module 2021-03-20 13:00:05 +08:00
Bo-Yi Wu 91cd4c1be5 chore(makefile): change gofmt toll to gofumpt 2021-01-14 21:15:06 +08:00
Bo-Yi Wu 7abe52fd7d chore: update to 1.15 2020-10-03 16:19:54 +08:00
Bo-Yi Wu 80f55d4df9 chore: remove build binary in mac 2020-10-03 15:58:42 +08:00
Bo-Yi Wu 9cab2d0e2b chore: add DISABLE_WEB_PAGE_PREVIEW docs 2020-10-03 15:40:53 +08:00
Bo-Yi Wu d133c8b87c chore(notification): use linux-amd64 image
fixed https://github.com/appleboy/drone-telegram/issues/92

https://cloud.drone.io/appleboy/drone-telegram/143/2/4

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-10-03 10:37:35 +08:00
Bo-Yi Wu 390d4f4d5f chore: upgrade drone template
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-10-03 09:54:38 +08:00
Bo-Yi Wu 792e5b5eab refactor: DisableWebPagePreview
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-10-03 09:36:32 +08:00
Bo-Yi Wu 392621b9a5 refactor: DisableWebPagePreview
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-10-03 09:22:38 +08:00
Bo-Yi Wu dc17cf7288 refactor: DisableWebPagePreview
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-10-03 09:20:17 +08:00
Bo-Yi Wu 737043aa8d chore: update api import path
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-10-03 08:21:57 +08:00
Bo-Yi Wu 4c016c904c chore: upgrade to go1.15
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-09-26 12:45:51 +08:00
Dmitry Bolotin f021aab825 Option to load tempate variables from json file (#98) 2020-09-17 06:52:42 +08:00
Bo-Yi Wu 47352c6cca test: Using since in custom template
See https://github.com/appleboy/drone-telegram/issues/89

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-07-21 10:28:43 +08:00
Bo-Yi Wu ee0358892d chore: support for kubernetes runner (#96)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-07-01 16:45:55 +08:00
Bo-Yi Wu 153fe2cb01 chore: move load .env file to top. (#94) 2020-07-01 06:40:04 +08:00
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
32 changed files with 2294 additions and 430 deletions
-42
View File
@@ -1,42 +0,0 @@
# unifying the coding style for different editors and IDEs => editorconfig.org
; indicate this is the root of the project
root = true
###########################################################
; common
###########################################################
[*]
charset = utf-8
end_of_line = LF
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 2
###########################################################
; make
###########################################################
[Makefile]
indent_style = tab
[makefile]
indent_style = tab
###########################################################
; markdown
###########################################################
[*.md]
trim_trailing_whitespace = false
###########################################################
; golang
###########################################################
[*.go]
indent_style = tab
+13
View File
@@ -0,0 +1,13 @@
# These are supported funding model platforms
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: ['https://www.paypal.me/appleboy46']
+10
View File
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
- package-ecosystem: gomod
directory: /
schedule:
interval: weekly
+54
View File
@@ -0,0 +1,54 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
on:
push:
branches: [master]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
schedule:
- cron: "41 23 * * 6"
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: ["go"]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support
steps:
- name: Checkout repository
uses: actions/checkout@v6
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4
+102
View File
@@ -0,0 +1,102 @@
name: Docker Image
on:
push:
branches:
- master
tags:
- "v*"
pull_request:
branches:
- "master"
permissions:
contents: read
packages: write
security-events: write
jobs:
build-docker:
runs-on: ubuntu-latest
steps:
- name: Setup go
uses: actions/setup-go@v6
with:
go-version: "^1"
check-latest: true
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Build binary
run: |
make build_linux_amd64
make build_linux_arm64
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Login to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: docker-meta
uses: docker/metadata-action@v6
with:
images: |
${{ github.repository }}
ghcr.io/${{ github.repository }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Build image for scanning
uses: docker/build-push-action@v7
with:
context: .
file: docker/Dockerfile
platforms: linux/amd64
push: false
load: true
tags: drone-telegram:scan
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@v0.36.0
with:
image-ref: "drone-telegram:scan"
format: "sarif"
output: "trivy-image-results.sarif"
severity: "CRITICAL,HIGH"
exit-code: '1'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: "trivy-image-results.sarif"
category: "trivy-docker-image"
- name: Build and push
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64,linux/arm64
file: docker/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker-meta.outputs.tags }}
labels: ${{ steps.docker-meta.outputs.labels }}
+33
View File
@@ -0,0 +1,33 @@
name: Goreleaser
on:
push:
tags:
- "*"
permissions:
contents: write
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
check-latest: true
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v7
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+70
View File
@@ -0,0 +1,70 @@
name: Lint and Testing
on:
push:
pull_request:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
check-latest: true
- name: Setup golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.12
args: --verbose
- uses: hadolint/hadolint-action@v3.3.0
name: hadolint for Dockerfile
with:
dockerfile: docker/Dockerfile
test:
strategy:
matrix:
os: [ubuntu-latest]
go: [1.25, 1.26]
include:
- os: ubuntu-latest
go-build: ~/.cache/go-build
name: ${{ matrix.os }} @ Go ${{ matrix.go }}
runs-on: ${{ matrix.os }}
env:
GO111MODULE: on
GOPROXY: https://proxy.golang.org
steps:
- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v6
with:
go-version: ${{ matrix.go }}
check-latest: true
- name: Checkout Code
uses: actions/checkout@v6
with:
ref: ${{ github.ref }}
- uses: actions/cache@v5
with:
path: |
${{ matrix.go-build }}
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run Tests
run: |
make test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v6
with:
flags: ${{ matrix.os }},go-${{ matrix.go }}
+85
View File
@@ -0,0 +1,85 @@
name: Trivy Security Scan
on:
push:
branches:
- master
pull_request:
branches:
- master
schedule:
# Run daily at 00:00 UTC
- cron: "0 0 * * *"
workflow_dispatch:
permissions:
contents: read
security-events: write
jobs:
trivy-repo-scan:
name: Trivy Repository Scan
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Run Trivy vulnerability scanner (repo)
uses: aquasecurity/trivy-action@v0.36.0
with:
scan-type: "fs"
scan-ref: "."
format: "sarif"
output: "trivy-repo-results.sarif"
severity: "CRITICAL,HIGH"
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: "trivy-repo-results.sarif"
trivy-image-scan:
name: Trivy Image Scan
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
check-latest: true
- name: Build binary
run: |
make build_linux_amd64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build Docker image for scanning
uses: docker/build-push-action@v7
with:
context: .
file: docker/Dockerfile
platforms: linux/amd64
push: false
load: true
tags: drone-telegram:scan
- name: Run Trivy vulnerability scanner (image)
uses: aquasecurity/trivy-action@v0.36.0
with:
image-ref: "drone-telegram:scan"
format: "sarif"
output: "trivy-image-results.sarif"
severity: "CRITICAL,HIGH"
- name: Upload Trivy image scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: "trivy-image-results.sarif"
category: "trivy-image"
+3 -1
View File
@@ -22,6 +22,8 @@ _testmain.go
*.exe
*.test
*.prof
vendor
drone-telegram
coverage.txt
.env
release
bin
+114
View File
@@ -0,0 +1,114 @@
version: "2"
output:
sort-order:
- file
linters:
default: none
enable:
- bidichk
- bodyclose
- depguard
- errcheck
- forbidigo
- gocheckcompilerdirectives
- gocritic
- govet
- ineffassign
- mirror
- modernize
- nakedret
- nilnil
- nolintlint
- perfsprint
- revive
- staticcheck
- testifylint
- unconvert
- unparam
- unused
- usestdlibvars
- usetesting
- wastedassign
settings:
depguard:
rules:
main:
deny:
- pkg: io/ioutil
desc: use os or io instead
- pkg: golang.org/x/exp
desc: it's experimental and unreliable
- pkg: github.com/pkg/errors
desc: use builtin errors package instead
nolintlint:
allow-unused: false
require-explanation: true
require-specific: true
gocritic:
enabled-checks:
- equalFold
disabled-checks: []
revive:
severity: error
rules:
- name: blank-imports
- name: constant-logical-expr
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: empty-lines
- name: error-return
- name: error-strings
- name: exported
- name: identical-branches
- name: if-return
- name: increment-decrement
- name: modifies-value-receiver
- name: package-comments
- name: redefines-builtin-id
- name: superfluous-else
- name: time-naming
- name: unexported-return
- name: var-declaration
- name: var-naming
disabled: true
staticcheck:
checks:
- all
testifylint: {}
usetesting:
os-temp-dir: true
perfsprint:
concat-loop: false
govet:
enable:
- nilness
- unusedwrite
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- errcheck
- staticcheck
- unparam
path: _test\.go
issues:
max-issues-per-linter: 0
max-same-issues: 0
formatters:
enable:
- gofmt
- gofumpt
- golines
settings:
gofumpt:
extra-rules: true
exclusions:
generated: lax
run:
timeout: 10m
+123
View File
@@ -0,0 +1,123 @@
before:
hooks:
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
goos:
- darwin
- linux
- windows
- freebsd
goarch:
- amd64
- arm
- arm64
goarm:
- "5"
- "6"
- "7"
ignore:
- goos: darwin
goarch: arm
- goos: darwin
goarch: ppc64le
- goos: darwin
goarch: s390x
- goos: windows
goarch: ppc64le
- goos: windows
goarch: s390x
- goos: windows
goarch: arm
goarm: "5"
- goos: windows
goarch: arm
goarm: "6"
- goos: windows
goarch: arm
goarm: "7"
- goos: windows
goarch: arm64
- goos: freebsd
goarch: ppc64le
- goos: freebsd
goarch: s390x
- goos: freebsd
goarch: arm
goarm: "5"
- goos: freebsd
goarch: arm
goarm: "6"
- goos: freebsd
goarch: arm
goarm: "7"
- goos: freebsd
goarch: arm64
flags:
- -trimpath
ldflags:
- -s -w
- -X main.Version={{.Version}}
binary: >-
{{ .ProjectName }}-
{{- if .IsSnapshot }}{{ .Branch }}-
{{- else }}{{- .Version }}-{{ end }}
{{- .Os }}-
{{- if eq .Arch "amd64" }}amd64
{{- else if eq .Arch "amd64_v1" }}amd64
{{- else if eq .Arch "386" }}386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}-{{ .Arm }}{{ end }}
no_unique_dist_dir: true
hooks:
post:
- cmd: xz -k -9 {{ .Path }}
dir: ./dist/
archives:
- format: binary
name_template: "{{ .Binary }}"
allow_different_binary_count: true
checksum:
name_template: "checksums.txt"
extra_files:
- glob: ./**.xz
snapshot:
name_template: "{{ incpatch .Version }}"
release:
# You can add extra pre-existing files to the release.
# The filename on the release will be the last part of the path (base).
# If another file with the same name exists, the last one found will be used.
#
# Templates: allowed
extra_files:
- glob: ./**.xz
changelog:
use: github
groups:
- title: Features
regexp: "^.*feat[(\\w)]*:+.*$"
order: 0
- title: "Bug fixes"
regexp: "^.*fix[(\\w)]*:+.*$"
order: 1
- title: "Enhancements"
regexp: "^.*chore[(\\w)]*:+.*$"
order: 2
- title: "Refactor"
regexp: "^.*refactor[(\\w)]*:+.*$"
order: 3
- title: "Build process updates"
regexp: ^.*?(build|ci)(\(.+\))??!?:.+$
order: 4
- title: "Documentation updates"
regexp: ^.*?docs?(\(.+\))??!?:.+$
order: 4
- title: Others
order: 999
+3
View File
@@ -0,0 +1,3 @@
ignored:
- DL3018
- DL3008
-53
View File
@@ -1,53 +0,0 @@
sudo: required
language: go
services:
- docker
go:
- 1.5.4
- 1.6.3
- 1.7.3
- 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.3" ] && [ "$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.3" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" != "" ]; then
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD";
make docker_deploy tag=$TRAVIS_TAG;
fi
+379
View File
@@ -0,0 +1,379 @@
---
date: 2019-10-19T00:00:00+00:00
author: appleboy
containerImage: docker.io/appleboy/drone-telegram
containerImageUrl: https://hub.docker.com/r/appleboy/drone-telegram
description: Plugin for sending Telegram notifications
icon: https://raw.githubusercontent.com/appleboy/drone-telegram/refs/heads/master/images/logo.svg
image: appleboy/drone-telegram
logo: telegram.svg
name: Telegram
repo: appleboy/drone-telegram
tags: [ notifications, chat ]
title: Telegram
url: https://github.com/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 (`Markdown` or `HTML`), default as `Markdown`:
```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 message template, with extra vars loaded from file (e.g. from previous build steps):
```diff
- name: send telegram notification
image: appleboy/drone-telegram
settings:
token: xxxxxxxxxx
to: telegram_user_id
+ template_vars_file: build_report.json
+ message: >
+ {{#success build.status}}
+ build {{build.number}} succeeded, artefact version = {{tpl.artefact_version}}.
+ {{else}}
+ build {{build.number}} failed. Fix me please.
+ {{/success}}
```
Where `build_report.json` is:
```
{
...
"artefact_version": "0.2.3452"
...
}
```
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
```
Disables link previews for links in this message
```diff
- name: send telegram notification
image: appleboy/drone-telegram
settings:
token: xxxxxxxxxx
to: telegram_user_id
message: send message without a link preview
+ disable_web_page_preview: true
```
Disables notifications for this message
```diff
- name: send telegram notification
image: appleboy/drone-telegram
settings:
token: xxxxxxxxxx
to: telegram_user_id
message: send message message silently
+ disable_notification: true
```
## 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`
template_vars_file
: load additional template vars from json file. Example: given file content `{"var1":"hello"}`, variable 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"]
+145 -25
View File
@@ -1,8 +1,18 @@
.PHONY: install build test html update docker_build docker_image docker_deploy clean
EXECUTABLE := drone-telegram
GOFMT ?= gofumpt -l
DIST := dist
DIST_DIRS := $(DIST)/binaries $(DIST)/release
GO ?= go
SHASUM ?= shasum -a 256
GOFILES := $(shell find . -name "*.go" -type f)
HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
XGO_VERSION := go-1.19.x
GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.11
VERSION := $(shell git describe --tags || git rev-parse --short HEAD)
DEPLOY_ACCOUNT := "appleboy"
DEPLOY_IMAGE := "drone-telegram"
LINUX_ARCHS ?= linux/amd64,linux/arm64
DARWIN_ARCHS ?= darwin-10.12/amd64,darwin-10.12/arm64
WINDOWS_ARCHS ?= windows/*
ifneq ($(shell uname), Darwin)
EXTLDFLAGS = -extldflags "-static" $(null)
@@ -10,36 +20,146 @@ else
EXTLDFLAGS =
endif
install:
glide install
ifeq ($(HAS_GO), GO)
GOPATH ?= $(shell $(GO) env GOPATH)
export PATH := $(GOPATH)/bin:$(PATH)
build:
go build -ldflags="$(EXTLDFLAGS)-s -w -X main.Version=$(VERSION)"
CGO_EXTRA_CFLAGS := -DSQLITE_MAX_VARIABLE_NUMBER=32766
CGO_CFLAGS ?= $(shell $(GO) env CGO_CFLAGS) $(CGO_EXTRA_CFLAGS)
endif
ifeq ($(OS), Windows_NT)
GOFLAGS := -v -buildmode=exe
EXECUTABLE ?= $(EXECUTABLE).exe
else ifeq ($(OS), Windows)
GOFLAGS := -v -buildmode=exe
EXECUTABLE ?= $(EXECUTABLE).exe
else
GOFLAGS := -v
EXECUTABLE ?= $(EXECUTABLE)
endif
ifneq ($(DRONE_TAG),)
VERSION ?= $(DRONE_TAG)
else
VERSION ?= $(shell git describe --tags --always || git rev-parse --short HEAD)
endif
TAGS ?=
LDFLAGS ?= -X 'main.Version=$(VERSION)'
all: build
fmt:
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) install mvdan.cc/gofumpt; \
fi
$(GOFMT) -w $(GOFILES)
vet:
$(GO) vet ./...
.PHONY: fmt-check
fmt-check:
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) install mvdan.cc/gofumpt; \
fi
@diff=$$($(GOFMT) -d $(GOFILES)); \
if [ -n "$$diff" ]; then \
echo "Please run 'make fmt' and commit the result:"; \
echo "$${diff}"; \
exit 1; \
fi;
test:
go test -v -coverprofile=coverage.txt
@$(GO) test -v -cover -coverprofile coverage.txt ./... && echo "\n==>\033[32m Ok\033[m\n" || exit 1
html:
go tool cover -html=coverage.txt
install: $(GOFILES)
$(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
update:
glide up
build: $(EXECUTABLE)
docker_build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo -ldflags="-X main.Version=$(VERSION)"
$(EXECUTABLE): $(GOFILES)
$(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o bin/$@
docker_image:
docker build --rm -t $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE) .
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)
docker: docker_build docker_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)
docker_deploy:
ifeq ($(tag),)
@echo "Usage: make $@ tag=<tag>"
@exit 1
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)
ssh-server:
adduser -h /home/drone-scp -s /bin/sh -D -S drone-scp
echo drone-scp:1234 | chpasswd
mkdir -p /home/drone-scp/.ssh
chmod 700 /home/drone-scp/.ssh
cat tests/.ssh/id_rsa.pub >> /home/drone-scp/.ssh/authorized_keys
cat tests/.ssh/test.pub >> /home/drone-scp/.ssh/authorized_keys
chmod 600 /home/drone-scp/.ssh/authorized_keys
chown -R drone-scp /home/drone-scp/.ssh
apk add --update openssh openrc
rm -rf /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_dsa_key
sed -i 's/^#PubkeyAuthentication yes/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
sed -i 's/AllowTcpForwarding no/AllowTcpForwarding yes/g' /etc/ssh/sshd_config
./tests/entrypoint.sh /usr/sbin/sshd -D &
coverage:
sed -i '/main.go/d' coverage.txt
.PHONY: deps-backend
deps-backend:
$(GO) mod download
$(GO) install $(GXZ_PACKAGE)
$(GO) install $(XGO_PACKAGE)
.PHONY: release
release: release-linux release-darwin release-windows release-copy release-compress release-check
$(DIST_DIRS):
mkdir -p $(DIST_DIRS)
.PHONY: release-windows
release-windows: | $(DIST_DIRS)
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -buildmode exe -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets '$(WINDOWS_ARCHS)' -out $(EXECUTABLE)-$(VERSION) .
ifeq ($(CI),true)
cp -r /build/* $(DIST)/binaries/
endif
docker tag $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):latest $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):$(tag)
docker push $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):$(tag)
.PHONY: release-linux
release-linux: | $(DIST_DIRS)
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets '$(LINUX_ARCHS)' -out $(EXECUTABLE)-$(VERSION) .
ifeq ($(CI),true)
cp -r /build/* $(DIST)/binaries/
endif
.PHONY: release-darwin
release-darwin: | $(DIST_DIRS)
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '$(LDFLAGS)' -targets '$(DARWIN_ARCHS)' -out $(EXECUTABLE)-$(VERSION) .
ifeq ($(CI),true)
cp -r /build/* $(DIST)/binaries/
endif
.PHONY: release-copy
release-copy: | $(DIST_DIRS)
cd $(DIST); for file in `find . -type f -name "*"`; do cp $${file} ./release/; done;
.PHONY: release-check
release-check: | $(DIST_DIRS)
cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "checksumming $${file}" && $(SHASUM) `echo $${file} | sed 's/^..//'` > $${file}.sha256; done;
.PHONY: release-compress
release-compress: | $(DIST_DIRS)
cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && $(GO) run $(GXZ_PACKAGE) -k -9 $${file}; done;
clean:
rm -rf coverage.txt ${DEPLOY_IMAGE}
$(GO) clean -x -i ./...
rm -rf coverage.txt $(EXECUTABLE) $(DIST)
version:
@echo $(VERSION)
+52 -26
View File
@@ -1,8 +1,14 @@
# 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](https://github.com/drone/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)
[![Trivy Security Scan](https://github.com/appleboy/drone-telegram/actions/workflows/trivy.yml/badge.svg?branch=master)](https://github.com/appleboy/drone-telegram/actions/workflows/trivy.yml)
[![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)
[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/).
## Feature
@@ -16,65 +22,85 @@
* [x] Send with New Video.
* [x] Send with New Sticker.
## Build
## Build or Download a binary
Build the binary with the following commands:
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_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 PLUGIN_ENV_FILE=your_env_file_path \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-telegram
+20
View File
@@ -0,0 +1,20 @@
FROM alpine:3.23
ARG TARGETOS
ARG TARGETARCH
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="Telegram Plugin" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0"
LABEL org.opencontainers.image.source=https://github.com/appleboy/drone-telegram
LABEL org.opencontainers.image.description="plugin for sending telegram notifications"
LABEL org.opencontainers.image.licenses=MIT
RUN apk add --no-cache ca-certificates && \
rm -rf /var/cache/apk/*
COPY release/${TARGETOS}/${TARGETARCH}/drone-telegram /bin/
ENTRYPOINT ["/bin/drone-telegram"]
Generated
-36
View File
@@ -1,36 +0,0 @@
hash: 5bdcf53533d043ba1cb6ab55ae6a93aca40c812a20264406bd6e0fe342f51d61
updated: 2016-10-31T09:50:34.654875319+08:00
imports:
- name: github.com/appleboy/drone-facebook
version: abda8124c404d424b150cf2a9935e3e108519c6e
subpackages:
- template
- name: github.com/aymerick/raymond
version: a2232af10b53ef1ae5a767f5178db3a6c1dab655
subpackages:
- ast
- parser
- lexer
- name: github.com/joho/godotenv
version: 4ed13390c0acd2ff4e371e64d8b97c8954138243
subpackages:
- autoload
- name: github.com/technoweenie/multipartstreamer
version: a90a01d73ae432e2611d178c18367fbaa13e0154
- name: github.com/urfave/cli
version: 3eb41f1bb122ac7535cc7b32db6b78b541879726
- 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
-15
View File
@@ -1,15 +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
- package: github.com/appleboy/drone-facebook
version: ^1.3.0
subpackages:
- template
testImport:
- package: github.com/stretchr/testify
subpackages:
- assert
+34
View File
@@ -0,0 +1,34 @@
module github.com/appleboy/drone-telegram
go 1.25.10
require (
github.com/appleboy/drone-template-lib v1.3.0
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible
github.com/joho/godotenv v1.5.1
github.com/stretchr/testify v1.9.0
github.com/urfave/cli v1.22.15
)
require (
dario.cat/mergo v1.0.1 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.3.0 // indirect
github.com/Masterminds/sprig/v3 v3.3.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/huandu/xstrings v1.5.0 // indirect
github.com/mailgun/raymond/v2 v2.0.48 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/technoweenie/multipartstreamer v1.0.1 // indirect
golang.org/x/crypto v0.45.0 // indirect
golang.org/x/sys v0.38.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
+79
View File
@@ -0,0 +1,79 @@
dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0=
github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/Masterminds/sprig/v3 v3.3.0 h1:mQh0Yrg1XPo6vjYXgtf5OtijNAKJRNcTdOOGZe3tPhs=
github.com/Masterminds/sprig/v3 v3.3.0/go.mod h1:Zy1iXRYNqNLUolqCpL4uhk6SHUMAOSCzdgBfDb35Lz0=
github.com/appleboy/drone-template-lib v1.3.0 h1:aX36/1za3v8JsEyBeMY1Bp/VNRtZa8qPYkfkjBszW+A=
github.com/appleboy/drone-template-lib v1.3.0/go.mod h1:edlmXkFMKYAVypff8r2oN7aFlHfOZE5sLyPEnRHONeA=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
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/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
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/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI=
github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailgun/raymond/v2 v2.0.48 h1:5dmlB680ZkFG2RN/0lvTAghrSxIESeu9/2aeDqACtjw=
github.com/mailgun/raymond/v2 v2.0.48/go.mod h1:lsgvL50kgt1ylcFJYZiULi5fjPBkkhNfj4KA0W54Z18=
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
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/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w=
github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM=
github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog=
github.com/urfave/cli v1.22.15 h1:nuqt+pdC/KqswQKhETJjo7pvn/k4xMUxgW6liI7XpnM=
github.com/urfave/cli v1.22.15/go.mod h1:wSan1hmo5zeyLGBjRJbzRTNk8gwoYa2B9n4q9dmRIc0=
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
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/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
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

+199 -53
View File
@@ -1,16 +1,28 @@
package main
import (
"log"
"os"
_ "github.com/joho/godotenv/autoload"
"github.com/joho/godotenv"
"github.com/urfave/cli"
)
// Version for command line
var Version string
// Version set at compile-time
var (
Version string
)
func main() {
// Load env-file if it exists first
if filename, found := os.LookupEnv("PLUGIN_ENV_FILE"); found {
_ = godotenv.Load(filename)
}
if _, err := os.Stat("/run/drone/env"); err == nil {
_ = godotenv.Overload("/run/drone/env")
}
app := cli.NewApp()
app.Name = "telegram plugin"
app.Usage = "telegram plugin"
@@ -20,73 +32,108 @@ 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: "telegram user",
EnvVar: "PLUGIN_TO",
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.StringFlag{
Name: "template.vars.file",
Usage: "load additional template vars to be used in message, from json file",
EnvVar: "PLUGIN_TEMPLATE_VARS_FILE,TELEGRAM_TEMPLATE_VARS_FILE",
},
cli.StringSliceFlag{
Name: "photo",
Usage: "send photo message",
EnvVar: "PLUGIN_PHOTO",
EnvVar: "PLUGIN_PHOTO,PHOTO,INPUT_PHOTO",
},
cli.StringSliceFlag{
Name: "document",
Usage: "send document message",
EnvVar: "PLUGIN_DOCUMENT",
EnvVar: "PLUGIN_DOCUMENT,DOCUMENT,INPUT_DOCUMENT",
},
cli.StringSliceFlag{
Name: "sticker",
Usage: "send sticker message",
EnvVar: "PLUGIN_STICKER",
EnvVar: "PLUGIN_STICKER,STICKER,INPUT_STICKER",
},
cli.StringSliceFlag{
Name: "audio",
Usage: "send audio message",
EnvVar: "PLUGIN_AUDIO",
EnvVar: "PLUGIN_AUDIO,AUDIO,INPUT_AUDIO",
},
cli.StringSliceFlag{
Name: "voice",
Usage: "send voice message",
EnvVar: "PLUGIN_VOICE",
EnvVar: "PLUGIN_VOICE,VOICE,INPUT_VOICE",
},
cli.StringSliceFlag{
Name: "location",
Usage: "send location message",
EnvVar: "PLUGIN_LOCATION",
EnvVar: "PLUGIN_LOCATION,LOCATION,INPUT_LOCATION",
},
cli.StringSliceFlag{
Name: "venue",
Usage: "send venue message",
EnvVar: "PLUGIN_VENUE",
EnvVar: "PLUGIN_VENUE,VENUE,INPUT_VENUE",
},
cli.StringSliceFlag{
Name: "video",
Usage: "send video message",
EnvVar: "PLUGIN_VIDEO",
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.BoolFlag{
Name: "disable.webpage.preview",
Usage: "disables link previews for links in this message",
EnvVar: "PLUGIN_DISABLE_WEB_PAGE_PREVIEW,INPUT_DISABLE_WEB_PAGE_PREVIEW",
},
cli.BoolFlag{
Name: "disable.notification",
Usage: "sends the message silently. users will receive a notification with no sound.",
EnvVar: "PLUGIN_DISABLE_NOTIFICATION,INPUT_DISABLE_NOTIFICATION",
},
cli.StringFlag{
Name: "format",
Value: "markdown",
Usage: "telegram message format",
EnvVar: "PLUGIN_FORMAT",
Value: formatMarkdown,
Usage: "telegram message format (Markdown or HTML)",
EnvVar: "PLUGIN_FORMAT,FORMAT,INPUT_FORMAT",
},
cli.StringFlag{
Name: "repo.owner",
Usage: "repository owner",
EnvVar: "DRONE_REPO_OWNER",
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",
@@ -96,7 +143,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",
@@ -104,11 +156,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",
@@ -136,52 +203,131 @@ func main() {
Usage: "build link",
EnvVar: "DRONE_BUILD_LINK",
},
cli.Float64Flag{
Name: "job.started",
Usage: "job started",
EnvVar: "DRONE_JOB_STARTED",
cli.StringFlag{
Name: "build.tag",
Usage: "build tag",
EnvVar: "DRONE_TAG",
},
cli.Float64Flag{
Name: "job.finished",
Usage: "job finished",
EnvVar: "DRONE_JOB_FINISHED",
cli.StringFlag{
Name: "pull.request",
Usage: "pull request",
EnvVar: "DRONE_PULL_REQUEST",
},
cli.Int64Flag{
Name: "build.started",
Usage: "build started",
EnvVar: "DRONE_STAGE_STARTED",
},
cli.Int64Flag{
Name: "build.finished",
Usage: "build finished",
EnvVar: "DRONE_BUILD_FINISHED",
},
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",
},
}
app.Run(os.Args)
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
func run(c *cli.Context) error {
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{
Tag: c.String("build.tag"),
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"),
Started: c.Float64("job.started"),
Finished: c.Float64("job.finished"),
Started: c.Int64("build.started"),
Finished: c.Int64("build.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"),
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"),
Token: c.String("token"),
Debug: c.Bool("debug"),
MatchEmail: c.Bool("match.email"),
To: c.StringSlice("to"),
Message: c.String("message"),
MessageFile: c.String("message.file"),
TemplateVars: c.String("template.vars"),
TemplateVarsFile: c.String("template.vars.file"),
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"),
DisableWebPagePreview: c.Bool("disable.webpage.preview"),
DisableNotification: c.Bool("disable.notification"),
},
}
+334 -102
View File
@@ -1,60 +1,104 @@
package main
import (
"encoding/json"
"errors"
"fmt"
"html"
"log"
"maps"
"net/http"
"net/url"
"os"
"path/filepath"
"strconv"
"strings"
"github.com/appleboy/drone-facebook/template"
"gopkg.in/telegram-bot-api.v4"
"github.com/appleboy/drone-template-lib/template"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
)
const (
formatMarkdown = "Markdown"
formatHTML = "HTML"
)
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 {
Tag string
Event string
Number int
Commit string
Message string
Branch string
Author string
Status string
Link string
Started float64
Finished float64
Started int64
Finished int64
PR string
DeployTo string
}
// Config for the plugin.
Config struct {
Token string
Debug bool
To []string
Message []string
Photo []string
Document []string
Sticker []string
Audio []string
Voice []string
Location []string
Video []string
Venue []string
Format string
Token string
Debug bool
MatchEmail bool
To []string
Message string
MessageFile string
TemplateVarsFile 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
DisableWebPagePreview bool
DisableNotification bool
}
// Plugin values.
Plugin struct {
GitHub GitHub
Repo Repo
Commit Commit
Build Build
Config Config
Tpl map[string]string
}
// Location format
@@ -66,11 +110,17 @@ type (
}
)
var icons = map[string]string{
"failure": "❌",
"cancelled": "❕",
"success": "✅",
}
func trimElement(keys []string) []string {
var newKeys []string
newKeys := make([]string, 0, len(keys))
for _, value := range keys {
value = strings.Trim(value, " ")
value = strings.TrimSpace(value)
if len(value) == 0 {
continue
}
@@ -80,11 +130,12 @@ func trimElement(keys []string) []string {
return newKeys
}
func fileExist(keys []string) []string {
var newKeys []string
func escapeMarkdown(keys []string) []string {
newKeys := make([]string, 0, len(keys))
for _, value := range keys {
if _, err := os.Stat(value); os.IsNotExist(err) {
value = escapeMarkdownOne(value)
if len(value) == 0 {
continue
}
newKeys = append(newKeys, value)
@@ -93,11 +144,40 @@ func fileExist(keys []string) []string {
return newKeys
}
func escapeMarkdownOne(str string) string {
str = strings.ReplaceAll(str, `\_`, `_`)
str = strings.ReplaceAll(str, `_`, `\_`)
return str
}
func escapeMarkdownFields(fields ...*string) {
for _, f := range fields {
*f = escapeMarkdownOne(*f)
}
}
func globList(keys []string) []string {
newKeys := make([]string, 0, len(keys))
for _, pattern := range keys {
pattern = strings.TrimSpace(pattern)
matches, err := filepath.Glob(pattern)
if err != nil {
log.Printf("Glob error for %q: %s", 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, ","))
values := trimElement(strings.Split(value, " "))
if len(values) < 2 {
return Location{}, true
@@ -108,19 +188,16 @@ func convertLocation(value string) (Location, bool) {
}
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
@@ -134,124 +211,249 @@ func convertLocation(value string) (Location, bool) {
}, false
}
func parseID(keys []string) []int64 {
var newKeys []int64
func loadTextFromFile(filename string) ([]string, error) {
content, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
return []string{string(content)}, nil
}
for _, value := range keys {
id, err := strconv.ParseInt(value, 10, 64)
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 {
log.Println(err.Error())
continue
}
newKeys = append(newKeys, id)
// 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)
}
return newKeys
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': %w", 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 unmarshal template vars from JSON string '%s': %w",
p.Config.TemplateVars,
err,
)
}
}
if p.Config.TemplateVarsFile != "" {
content, err := os.ReadFile(p.Config.TemplateVarsFile)
if err != nil {
return fmt.Errorf(
"unable to read file with template vars '%s': %w",
p.Config.TemplateVarsFile,
err,
)
}
vars := make(map[string]string)
if err = json.Unmarshal(content, &vars); err != nil {
return fmt.Errorf(
"unable to unmarshal template vars from JSON file '%s': %w",
p.Config.TemplateVarsFile,
err,
)
}
// File variables take precedence over inline variables
if p.Tpl == nil {
p.Tpl = vars
} else {
maps.Copy(p.Tpl, vars)
}
}
var bot *tgbotapi.BotAPI
if len(p.Config.Socks5) > 0 {
var proxyURL *url.URL
proxyURL, err = url.Parse(p.Config.Socks5)
if err != nil {
return fmt.Errorf("unable to parse socks5 proxy URL '%s': %w", p.Config.Socks5, err)
}
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("Initialize New Bot Error:", err.Error())
return err
}
bot.Debug = p.Config.Debug
// parse ids
ids := parseID(p.Config.To)
photos := fileExist(trimElement(p.Config.Photo))
documents := fileExist(trimElement(p.Config.Document))
stickers := fileExist(trimElement(p.Config.Sticker))
audios := fileExist(trimElement(p.Config.Audio))
voices := fileExist(trimElement(p.Config.Voice))
videos := fileExist(trimElement(p.Config.Video))
ids := parseTo(p.Config.To, p.Commit.Email, p.Config.MatchEmail)
photos := globList(p.Config.Photo)
documents := globList(p.Config.Document)
stickers := globList(p.Config.Sticker)
audios := globList(p.Config.Audio)
voices := globList(p.Config.Voice)
videos := globList(p.Config.Video)
locations := trimElement(p.Config.Location)
venues := trimElement(p.Config.Venue)
// send message.
for _, user := range ids {
for _, value := range trimElement(message) {
txt, err := template.RenderTrim(value, p)
if err != nil {
return err
}
message = trimElement(message)
if p.Config.Format == formatMarkdown {
message = escapeMarkdown(message)
escapeMarkdownFields(
&p.Commit.Message, &p.Commit.Branch, &p.Commit.Link,
&p.Commit.Author, &p.Commit.Email,
&p.Build.Tag, &p.Build.Link, &p.Build.PR,
&p.Repo.Namespace, &p.Repo.Name,
)
}
// pre-render message templates (identical for all users)
var renderedMessages []string
for _, value := range message {
txt, err := template.RenderTrim(value, p)
if err != nil {
return err
}
renderedMessages = append(renderedMessages, html.UnescapeString(txt))
}
// pre-parse locations and venues (identical for all users)
var parsedLocations []Location
for _, value := range locations {
loc, empty := convertLocation(value)
if !empty {
parsedLocations = append(parsedLocations, loc)
}
}
var parsedVenues []Location
for _, value := range venues {
loc, empty := convertLocation(value)
if !empty {
parsedVenues = append(parsedVenues, loc)
}
}
for _, user := range ids {
for _, txt := range renderedMessages {
msg := tgbotapi.NewMessage(user, txt)
msg.ParseMode = p.Config.Format
p.Send(bot, msg)
msg.DisableWebPagePreview = p.Config.DisableWebPagePreview
msg.DisableNotification = p.Config.DisableNotification
if err := p.Send(bot, msg); err != nil {
return err
}
}
for _, value := range photos {
msg := tgbotapi.NewPhotoUpload(user, value)
p.Send(bot, msg)
if err := p.Send(bot, msg); err != nil {
return err
}
}
for _, value := range documents {
msg := tgbotapi.NewDocumentUpload(user, value)
p.Send(bot, msg)
if err := p.Send(bot, msg); err != nil {
return err
}
}
for _, value := range stickers {
msg := tgbotapi.NewStickerUpload(user, value)
p.Send(bot, msg)
if err := p.Send(bot, msg); err != nil {
return err
}
}
for _, value := range audios {
msg := tgbotapi.NewAudioUpload(user, value)
msg.Title = "Audio Message."
p.Send(bot, msg)
msg.Title = "Audio Message"
if err := p.Send(bot, msg); err != nil {
return err
}
}
for _, value := range voices {
msg := tgbotapi.NewVoiceUpload(user, value)
p.Send(bot, msg)
if err := p.Send(bot, msg); err != nil {
return err
}
}
for _, value := range videos {
msg := tgbotapi.NewVideoUpload(user, value)
msg.Caption = "Video Message"
p.Send(bot, msg)
if err := p.Send(bot, msg); err != nil {
return err
}
}
for _, value := range locations {
location, empty := convertLocation(value)
if empty == true {
continue
for _, loc := range parsedLocations {
msg := tgbotapi.NewLocation(user, loc.Latitude, loc.Longitude)
if err := p.Send(bot, msg); err != nil {
return err
}
msg := tgbotapi.NewLocation(user, location.Latitude, location.Longitude)
p.Send(bot, msg)
}
for _, value := range venues {
location, empty := convertLocation(value)
if empty == true {
continue
for _, loc := range parsedVenues {
msg := tgbotapi.NewVenue(
user,
loc.Title,
loc.Address,
loc.Latitude,
loc.Longitude,
)
if err := p.Send(bot, msg); err != nil {
return err
}
msg := tgbotapi.NewVenue(user, location.Title, location.Address, location.Latitude, location.Longitude)
p.Send(bot, msg)
}
}
@@ -259,21 +461,51 @@ func (p Plugin) Exec() error {
}
// Send bot message.
func (p Plugin) Send(bot *tgbotapi.BotAPI, msg tgbotapi.Chattable) {
_, err := bot.Send(msg)
func (p *Plugin) Send(bot *tgbotapi.BotAPI, msg tgbotapi.Chattable) error {
message, err := bot.Send(msg)
if err != nil {
log.Println(err.Error())
if p.Config.Debug {
log.Println("=====================")
log.Printf("Response Message: %#v\n", message)
log.Println("=====================")
}
if err == nil {
return nil
}
return errors.New(strings.ReplaceAll(err.Error(), p.Config.Token, "<token>"))
}
// 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,
),
}
}
+422 -64
View File
@@ -1,18 +1,28 @@
package main
import (
"github.com/stretchr/testify/assert"
"os"
"testing"
"time"
"github.com/appleboy/drone-template-lib/template"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func skipIfNoTelegramSecrets(t *testing.T) {
t.Helper()
if os.Getenv("TELEGRAM_TOKEN") == "" || os.Getenv("TELEGRAM_TO") == "" {
t.Skip("TELEGRAM_TOKEN/TELEGRAM_TO not set; skipping integration test")
}
}
func TestMissingDefaultConfig(t *testing.T) {
var plugin Plugin
err := plugin.Exec()
assert.NotNil(t, err)
assert.Error(t, err)
}
func TestMissingUserConfig(t *testing.T) {
@@ -24,97 +34,197 @@ func TestMissingUserConfig(t *testing.T) {
err := plugin.Exec()
assert.NotNil(t, err)
assert.Error(t, err)
}
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", "commit message: 『{{ build.message }}』", " "},
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,
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)
require.Error(t, err)
plugin.Config.Format = formatMarkdown
plugin.Config.Message = "Test escape under_score"
err = plugin.Exec()
require.Error(t, err)
// disable message
plugin.Config.Message = []string{}
plugin.Config.Message = ""
err = plugin.Exec()
assert.Nil(t, err)
assert.Error(t, err)
}
func TestDisableWebPagePreviewMessage(t *testing.T) {
skipIfNoTelegramSecrets(t)
plugin := Plugin{
Config: Config{
Token: os.Getenv("TELEGRAM_TOKEN"),
To: []string{os.Getenv("TELEGRAM_TO")},
DisableWebPagePreview: true,
Debug: false,
},
}
plugin.Config.Message = "DisableWebPagePreview https://www.google.com.tw"
err := plugin.Exec()
require.NoError(t, err)
// disable message
plugin.Config.DisableWebPagePreview = false
plugin.Config.Message = "EnableWebPagePreview https://www.google.com.tw"
err = plugin.Exec()
assert.NoError(t, err)
}
func TestDisableNotificationMessage(t *testing.T) {
skipIfNoTelegramSecrets(t)
plugin := Plugin{
Config: Config{
Token: os.Getenv("TELEGRAM_TOKEN"),
To: []string{os.Getenv("TELEGRAM_TO")},
DisableNotification: true,
Debug: false,
},
}
plugin.Config.Message = "DisableNotification https://www.google.com.tw"
err := plugin.Exec()
require.NoError(t, err)
// disable message
plugin.Config.DisableNotification = false
plugin.Config.Message = "EnableNotification https://www.google.com.tw"
err = plugin.Exec()
assert.NoError(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",
},
}
err := plugin.Exec()
assert.NotNil(t, err)
assert.Error(t, err)
}
func TestTrimElement(t *testing.T) {
@@ -131,29 +241,79 @@ 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 TestCheckFileExist(t *testing.T) {
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.Empty(t, 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))
assert.Equal(t, result, fileExist(input))
input = []string{"tests/*.mp3"}
result = []string{"tests/audio.mp3"}
assert.Equal(t, result, globList(input))
}
func TestConvertLocation(t *testing.T) {
@@ -164,36 +324,36 @@ func TestConvertLocation(t *testing.T) {
input = "1"
result, empty = convertLocation(input)
assert.Equal(t, true, empty)
assert.True(t, empty)
assert.Equal(t, Location{}, result)
// strconv.ParseInt: parsing "測試": invalid syntax
input = "測試,139.704051"
input = "測試 139.704051"
result, empty = convertLocation(input)
assert.Equal(t, true, empty)
assert.True(t, empty)
assert.Equal(t, Location{}, result)
// strconv.ParseInt: parsing "測試": invalid syntax
input = "35.661777,測試"
input = "35.661777 測試"
result, empty = convertLocation(input)
assert.Equal(t, true, empty)
assert.True(t, empty)
assert.Equal(t, Location{}, result)
input = "35.661777,139.704051"
input = "35.661777 139.704051"
result, empty = convertLocation(input)
assert.Equal(t, false, empty)
assert.False(t, empty)
assert.Equal(t, Location{
Latitude: float64(35.661777),
Longitude: float64(139.704051),
}, result)
input = "35.661777,139.704051,title"
input = "35.661777 139.704051 title"
result, empty = convertLocation(input)
assert.Equal(t, false, empty)
assert.False(t, empty)
assert.Equal(t, Location{
Title: "title",
Address: "",
@@ -201,10 +361,10 @@ func TestConvertLocation(t *testing.T) {
Longitude: float64(139.704051),
}, result)
input = "35.661777,139.704051,title,address"
input = "35.661777 139.704051 title address"
result, empty = convertLocation(input)
assert.Equal(t, false, empty)
assert.False(t, empty)
assert.Equal(t, Location{
Title: "title",
Address: "address",
@@ -212,3 +372,201 @@ func TestConvertLocation(t *testing.T) {
Longitude: float64(139.704051),
}, result)
}
func TestHTMLMessage(t *testing.T) {
skipIfNoTelegramSecrets(t)
plugin := Plugin{
Repo: Repo{
Name: "go-hello",
Namespace: "appleboy",
},
Commit: Commit{
Sha: "e7c4f0a63ceeb42a39ac7806f7b51f3f0d204fd2",
Author: "Bo-Yi Wu",
Branch: "master",
Message: "test",
},
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")},
Message: `
Test HTML Format
<a href='https://google.com'>Google .com 1</a>
<a href='https://google.com'>Google .com 2</a>
<a href='https://google.com'>Google .com 3</a>
`,
Format: formatHTML,
},
}
assert.NoError(t, plugin.Exec())
plugin.Config.MessageFile = "tests/message_html.txt"
assert.NoError(t, plugin.Exec())
}
func TestMessageFile(t *testing.T) {
skipIfNoTelegramSecrets(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",
Started: time.Now().Unix(),
Finished: time.Now().Add(180 * time.Second).Unix(),
},
Config: Config{
Token: os.Getenv("TELEGRAM_TOKEN"),
To: []string{os.Getenv("TELEGRAM_TO")},
MessageFile: "tests/message.txt",
},
}
err := plugin.Exec()
assert.NoError(t, err)
}
func TestTemplateVars(t *testing.T) {
skipIfNoTelegramSecrets(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",
Started: time.Now().Unix(),
Finished: time.Now().Add(180 * time.Second).Unix(),
},
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.NoError(t, err)
}
func TestTemplateVarsFile(t *testing.T) {
skipIfNoTelegramSecrets(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",
TemplateVarsFile: "tests/vars.json",
},
}
err := plugin.Exec()
assert.NoError(t, err)
}
func TestProxySendMessage(t *testing.T) {
skipIfNoTelegramSecrets(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.NoError(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(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.NoError(t, err)
}
+5
View File
@@ -0,0 +1,5 @@
Sample message loaded from file.
Commit msg: {{commit.message}}
duration: {{duration build.started build.finished}}
+5
View File
@@ -0,0 +1,5 @@
Test HTML Format from file
<a href='https://google.com'>Google .com 1</a>
<a href='https://google.com'>Google .com 2</a>
<a href='https://google.com'>Google .com 3</a>
<a href='https://google.com'>Google .com 4</a>
+8
View File
@@ -0,0 +1,8 @@
Sample message template loaded from file.
*Environ:* {{tpl.env}}
*Version:* {{tpl.version}}
Commit msg: {{commit.message}}
duration: {{duration build.started build.finished}}
+1
View File
@@ -0,0 +1 @@
{"env":"testing","version":"1.2.0-SNAPSHOT"}