Compare commits

...

30 Commits

Author SHA1 Message Date
lddsb 526b8eec46 docs: update README for at mobiles 2021-07-02 23:13:05 +08:00
lddsb 8729ae05b4 feat: add at mobiles tpl 2021-07-02 23:01:24 +08:00
dependabot[bot] cec9f81f52 build(deps): bump github.com/lddsb/dingtalk-webhook from 0.0.4 to 0.0.5
Bumps [github.com/lddsb/dingtalk-webhook](https://github.com/lddsb/dingtalk-webhook) from 0.0.4 to 0.0.5.
- [Release notes](https://github.com/lddsb/dingtalk-webhook/releases)
- [Commits](https://github.com/lddsb/dingtalk-webhook/compare/v0.0.4...v0.0.5)

---
updated-dependencies:
- dependency-name: github.com/lddsb/dingtalk-webhook
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-07-02 22:01:57 +08:00
dependabot-preview[bot] 428577470d Upgrade to GitHub-native Dependabot 2021-06-26 23:30:42 +08:00
lddsb 7c8a85bcc4 fix: release.yaml go-version error 2020-12-19 15:53:16 +08:00
lddsb ecf4f89e0a feat: use goreleaser for release tool 2020-12-19 15:39:10 +08:00
lddsb e7ef2de488 feat: support custom started at and finished at 2020-12-19 11:59:45 +08:00
lddsb acd708ada3 docs: update readme and changelog for 1.2.5 2020-12-16 17:48:07 +08:00
lddsb 5bcf803346 fix: docker image tags missing 2020-12-16 14:58:38 +08:00
lddsb 1b219624cd feat: GitHub Actions for build and push docker image 2020-12-16 14:14:51 +08:00
lddsb d409acce48 feat: use os.Getenv() read environment variables for tpl 2020-12-16 11:58:09 +08:00
dependabot-preview[bot] 2e94325c0e Bump github.com/urfave/cli from 1.22.4 to 1.22.5 (#27)
Bumps [github.com/urfave/cli](https://github.com/urfave/cli) from 1.22.4 to 1.22.5.
- [Release notes](https://github.com/urfave/cli/releases)
- [Changelog](https://github.com/urfave/cli/blob/master/docs/CHANGELOG.md)
- [Commits](https://github.com/urfave/cli/compare/v1.22.4...v1.22.5)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-11-28 13:36:40 +08:00
lddsb 1622a2beaa perf: update readme and changelog 2020-04-29 18:40:45 +08:00
dependabot-preview[bot] d2ab02e29c Bump github.com/urfave/cli from 1.22.3 to 1.22.4 (#23)
Bumps [github.com/urfave/cli](https://github.com/urfave/cli) from 1.22.3 to 1.22.4.
- [Release notes](https://github.com/urfave/cli/releases)
- [Changelog](https://github.com/urfave/cli/blob/master/docs/CHANGELOG.md)
- [Commits](https://github.com/urfave/cli/compare/v1.22.3...v1.22.4)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-04-29 11:09:42 +08:00
lddsb d0284b2434 Merge tag 'v1.2.4'
patch for k8s missing env
2020-04-29 11:08:21 +08:00
lddsb c8bc5d889d fix: patch for k8s missing env 2020-04-29 10:59:46 +08:00
Dee Luo d4dc439671 Create CHANGELOG.md 2020-03-10 22:43:40 +08:00
dependabot-preview[bot] 8d0434b308 Bump github.com/urfave/cli from 1.22.2 to 1.22.3 (#20)
Bumps [github.com/urfave/cli](https://github.com/urfave/cli) from 1.22.2 to 1.22.3.
- [Release notes](https://github.com/urfave/cli/releases)
- [Changelog](https://github.com/urfave/cli/blob/master/docs/CHANGELOG.md)
- [Commits](https://github.com/urfave/cli/compare/v1.22.2...v1.22.3)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-03-10 18:13:02 +08:00
Dee Luo 8aafd04b82 fix: default image cdn url (#17) 2020-01-20 11:51:20 +08:00
lddsb a651a73cbd fix: default image cdn url 2020-01-20 11:36:34 +08:00
Dee Luo 7c68447d1d feat: support sign (#13) 2019-12-02 18:07:13 +08:00
Dee Luo 183999881b Merge pull request #12 from lddsb/dependabot/go_modules/github.com/lddsb/dingtalk-webhook-0.0.2
Bump github.com/lddsb/dingtalk-webhook from 0.0.1 to 0.0.2
2019-11-30 15:07:55 +08:00
dependabot-preview[bot] 4c52115e2a Bump github.com/lddsb/dingtalk-webhook from 0.0.1 to 0.0.2
Bumps [github.com/lddsb/dingtalk-webhook](https://github.com/lddsb/dingtalk-webhook) from 0.0.1 to 0.0.2.
- [Release notes](https://github.com/lddsb/dingtalk-webhook/releases)
- [Commits](https://github.com/lddsb/dingtalk-webhook/compare/v0.0.1...0.0.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-11-30 02:41:16 +00:00
lddsb fb601a0d6c feat: add dependabot badge 2019-11-26 08:55:49 +08:00
Dee Luo 8bd745becf Merge pull request #10 from lddsb/dependabot/go_modules/github.com/urfave/cli-1.22.2
Bump github.com/urfave/cli from 1.20.0 to 1.22.2
2019-11-26 08:43:38 +08:00
dependabot-preview[bot] e9aea90aac Bump github.com/urfave/cli from 1.20.0 to 1.22.2
Bumps [github.com/urfave/cli](https://github.com/urfave/cli) from 1.20.0 to 1.22.2.
- [Release notes](https://github.com/urfave/cli/releases)
- [Changelog](https://github.com/urfave/cli/blob/master/docs/CHANGELOG.md)
- [Commits](https://github.com/urfave/cli/compare/v1.20.0...v1.22.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-11-26 00:40:21 +00:00
Dee Luo c77b865a43 fix: read me adjustment 2019-11-25 23:19:23 +08:00
Dee Luo fbfbec3bde Merge pull request #9 from lddsb/feature/readme-zh
feat: add readme_zh
2019-11-25 23:03:10 +08:00
lddsb 30c2324f4e feat: add readme_zh 2019-11-25 22:49:34 +08:00
Dee Luo 11d34af11a Merge pull request #6 from lddsb/bugfix/tips-title-support
add tips title option, and add exit code for exception
2019-11-07 22:04:09 +08:00
16 changed files with 633 additions and 55 deletions
+8
View File
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: gomod
directory: "/"
schedule:
interval: daily
time: "10:00"
open-pull-requests-limit: 10
+55
View File
@@ -0,0 +1,55 @@
name: Publish to DockerHub and Github Package
on:
push:
tags:
- "v*"
jobs:
dockerhub:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Repo metadata
id: repo
uses: actions/github-script@v3
with:
script: |
const repo = await github.repos.get(context.repo)
return repo.data
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=lddsb/drone-dingtalk-message
GITHUB_IMAGE=ghcr.io/lddsb/drone-dingtalk-message
VERSION=${GITHUB_REF#refs/tags/v}
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
MINOR=${VERSION%.*}
MAJOR=${MINOR%.*}
TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest"
TAGS="$TAGS,${GITHUB_IMAGE}:${VERSION},${GITHUB_IMAGE}:${MINOR},${GITHUB_IMAGE}:${MAJOR},${GITHUB_IMAGE}:latest"
fi
echo ::set-output name=tags::${TAGS}
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Register
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.prep.outputs.tags }}
+25
View File
@@ -0,0 +1,25 @@
name: Publish release
on:
push:
tags:
- "v*"
jobs:
release:
name: publish release, upload asset
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15.6
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.CR_PAT }}
+3 -1
View File
@@ -2,4 +2,6 @@ dive.log
drone-dingtalk-message
.idea
vendor
coverage.txt
coverage.txt
coverage.out
env.list
+49
View File
@@ -0,0 +1,49 @@
env:
- GO111MODULE=on
before:
hooks:
- go mod download
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows
goarch:
- 386
- amd64
- arm
- arm64
mod_timestamp: '{{ .CommitTimestamp }}'
binary: dingtalk-message
flags:
- -trimpath
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{ .CommitDate }} -X main.builtBy=goreleaser
checksum:
name_template: '{{ .ProjectName }}_checksums.txt'
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
- Merge pull request
- Merge branch
- go mod tidy
archives:
- name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
format_overrides:
- goos: windows
format: zip
files:
- README.md
- LICENSE
- tpls/*
+72
View File
@@ -0,0 +1,72 @@
# Changelog
## [Unreleased]
## [1.2.5] - 2020-12-16
### Added:
* The TPL can use environment variables.
* Debug mode.
* Use GitHub Actions for automation.
## [1.2.4] - 2020-04-28
### Fixed:
* kubernetes runner missing env, [details](https://docs.drone.io/runner/kubernetes/overview)
## [1.2.3] - 2020-01-20
### Fixed:
* CDN url of default image.
## [1.2.2] - 2019-12-07
### Added:
* Support DingTalk `sign secret`, please see the [README](README.md) for instructions.
## [1.2.1] - 2019-11-07
### Added:
* Support customize message tips title by `tips_title` option.
## [1.2.0] - 2019-09-24
### Added:
* Support custom TPL.
## [1.1.4] - 2020-04-28
### Fixed:
* kubernetes runner missing env, [details](https://docs.drone.io/runner/kubernetes/overview)
## [1.1.3] - 2020-01-20
### Fixed:
* CDN url of default image.
## [1.1.2] - 2019-11-07
### Added:
* Support customize message tips title by `tips_title` option.
## [1.1.1] - 2019-09-24
### Added:
* Support full token url as `token`.
## [1.1.0] - 2019-03-09
### Added:
* Package management tools migrate from dep to go mod, 1.0.x version stopped supporting new features.
## [1.0.2] - 2020-01-20
### Fixed:
* CDN url of default image.
## [1.0.1] - 2019-03-09
### Added:
* Auto publish image to DockerHub.
[Unreleased]: https://github.com/lddsb/drone-dingtalk-message/compare/v1.2.5...HEAD
[1.2.5]: https://github.com/lddsb/drone-dingtalk-message/compare/v1.2.4...v1.2.5
[1.2.4]: https://github.com/lddsb/drone-dingtalk-message/compare/v1.2.3...v1.2.4
[1.2.3]: https://github.com/lddsb/drone-dingtalk-message/compare/v1.2.2...v1.2.3
[1.2.2]: https://github.com/lddsb/drone-dingtalk-message/compare/v1.2.1...v1.2.2
[1.2.1]: https://github.com/lddsb/drone-dingtalk-message/compare/v1.2.0...v1.2.1
[1.2.0]: https://github.com/lddsb/drone-dingtalk-message/compare/v1.1.0...v1.2.0
[1.1.4]: https://github.com/lddsb/drone-dingtalk-message/compare/v1.1.3...v1.1.4
[1.1.3]: https://github.com/lddsb/drone-dingtalk-message/compare/v1.1.2...v1.1.3
[1.1.2]: https://github.com/lddsb/drone-dingtalk-message/compare/v1.1.1...v1.1.2
[1.1.1]: https://github.com/lddsb/drone-dingtalk-message/compare/v1.1.0...v1.1.1
[1.1.0]: https://github.com/lddsb/drone-dingtalk-message/compare/v1.0.0...v1.1.0
[1.0.2]: https://github.com/lddsb/drone-dingtalk-message/compare/v1.0.1...v1.0.2
[1.0.1]: https://github.com/lddsb/drone-dingtalk-message/compare/v1.0.0...v1.0.1
+1 -1
View File
@@ -6,6 +6,6 @@ RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux go build -a -o drone-dingtalk .
FROM alpine:latest
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
COPY --from=builder /app/drone-dingtalk /bin
COPY --from=builder /app/tpls /app/tpls
COPY --from=builder /app/tpls /app/drone/dingtalk/message/tpls
ENTRYPOINT ["/bin/drone-dingtalk"]
+46 -10
View File
@@ -1,7 +1,20 @@
# Drone CI DingTalk Message Plugin
[![Docker Cloud Build Status](https://img.shields.io/docker/cloud/build/lddsb/drone-dingtalk-message)](https://hub.docker.com/r/lddsb/drone-dingtalk-message) [![Go Report Card](https://goreportcard.com/badge/github.com/lddsb/drone-dingtalk-message)](https://goreportcard.com/report/github.com/lddsb/drone-dingtalk-message) [![codecov](https://codecov.io/gh/lddsb/drone-dingtalk-message/branch/master/graph/badge.svg)](https://codecov.io/gh/lddsb/drone-dingtalk-message) [![LICENSE: MIT](https://img.shields.io/github/license/lddsb/drone-dingtalk-message.svg?style=flat-square)](LICENSE)
[![GitHub Actions](https://github.com/lddsb/drone-dingtalk-message/workflows/Publish%20to%20DockerHub%20and%20Github%20Package/badge.svg)](https://github.com/lddsb/drone-dingtalk-message/actions?query=workflow%3A%22Publish+to+DockerHub+and+Github+Package%22) [![Go Report Card](https://goreportcard.com/badge/github.com/lddsb/drone-dingtalk-message)](https://goreportcard.com/report/github.com/lddsb/drone-dingtalk-message) [![codecov](https://codecov.io/gh/lddsb/drone-dingtalk-message/branch/master/graph/badge.svg)](https://codecov.io/gh/lddsb/drone-dingtalk-message) [![Dependabot](https://api.dependabot.com/badges/status?host=github&repo=lddsb/drone-dingtalk-message&identifier=159822771)](https://app.dependabot.com/accounts/lddsb/repos/159822771) [![LICENSE: MIT](https://img.shields.io/github/license/lddsb/drone-dingtalk-message.svg?style=flat-square)](LICENSE)
[中文说明](README_ZH.md)
<!-- toc -->
- [Drone CI Plugin Config](#drone-ci-plugin-config)
- [Plugin Parameter Reference](#plugin-parameter-reference)
- [TPL](#tpl)
- [Screen Shot](#screen-shot)
- [Development](#development)
- [Todo](#todo)
- [Kubernetes Users](#kubernetes-users)
<!-- tocstop -->
just support `text`, `markdown` and `link` type now
### Drone CI Plugin Config
`0.8.x`
```yaml
@@ -13,11 +26,8 @@ pipeline:
type: markdown
```
`1.0.x`
`1.x`
```yaml
kind: pipeline
name: default
steps:
...
- name: notification
@@ -25,7 +35,8 @@ steps:
settings:
token: your-groupbot-token
type: markdown
secret: your-secret-for-generate-sign
debug: true
```
### Plugin Parameter Reference
@@ -37,9 +48,16 @@ String. Access token for group bot. (you can get the access token when you add a
String. Message type, plan support text, markdown, link and action card, but due to time issue, it's only support `markdown` and `text` now, and you can get the best experience by use markdown.
`secret`
String. Secret for generate sign.
`tpl`
String. Your custom `tpl`, it can be a local path or a remote http link.
String. Your custom `tpl`, it can be a local path, or a remote http link.
`debug`
Boolean. Debug mode.
`tips_title`
@@ -73,7 +91,7 @@ String. You can customize the [TPL_REPO_SHORT_NAME] by this configuration item.
String. You can customize the [TPL_REPO_FULL_NAME] by this configuration item.
`tpl_build_status_sucdess`
`tpl_build_status_success`
String. You can customize the [TPL_BUILD_STATUS] (when status=`success`) by this configuration item.
@@ -81,12 +99,17 @@ String. You can customize the [TPL_BUILD_STATUS] (when status=`success`) by this
String. You can customize the [TPL_BUILD_STATUS] (when status=`failure`) by this configuration item.
`msg_at_mobiles`
String. You want at's phone number in the group, if you need at multi phone numbers, you can use `,` to separate. (if you use markdown type, you need define the at content in your tpl file)
### TPL
> `tpl` won't work with message type `link` !!!
That's a good news, we support `tpl` now.This is a example for `markdown` message:
That's a good news, we support `tpl` now.This is an example for `markdown` message:
# [TPL_REPO_FULL_NAME] build [TPL_BUILD_STATUS], takes [TPL_BUILD_CONSUMING]s
@mobile1 @mobile2
[TPL_COMMIT_MSG]
[TPL_COMMIT_SHA]([TPL_COMMIT_LINK])
@@ -165,4 +188,17 @@ $ ./drone-dingtalk-message -h
```
### Todo
It's sad, just support `text`, `markdown` and `link` type now.
- implement all message type
- i18N
- batch send
- retry(e.g., network error, etc.)
### Kubernetes Users
Attention kubernetes users, [CHANGELOG](CHANGELOG.md#124---2020-04-28).It's the available versions:
- `1.1`(always latest for `1.1.x`)
- `>=1.1.4`
- `1.2`(always latest for `1.2.x`)
- `>=1.2.4`
- latest(always latest)
+207
View File
@@ -0,0 +1,207 @@
# Drone CI的钉钉群组机器人通知插件
[![GitHub Actions](https://github.com/lddsb/drone-dingtalk-message/workflows/Publish%20to%20DockerHub%20and%20Github%20Package/badge.svg)](https://github.com/lddsb/drone-dingtalk-message/actions?query=workflow%3A%22Publish+to+DockerHub+and+Github+Package%22) [![Go Report Card](https://goreportcard.com/badge/github.com/lddsb/drone-dingtalk-message)](https://goreportcard.com/report/github.com/lddsb/drone-dingtalk-message) [![codecov](https://codecov.io/gh/lddsb/drone-dingtalk-message/branch/master/graph/badge.svg)](https://codecov.io/gh/lddsb/drone-dingtalk-message) [![Dependabot](https://api.dependabot.com/badges/status?host=github&repo=lddsb/drone-dingtalk-message&identifier=159822771)](https://app.dependabot.com/accounts/lddsb/repos/159822771) [![LICENSE: MIT](https://img.shields.io/github/license/lddsb/drone-dingtalk-message.svg?style=flat-square)](LICENSE)
<!-- toc -->
- [怎么使用本插件](#%E6%80%8E%E4%B9%88%E4%BD%BF%E7%94%A8%E6%9C%AC%E6%8F%92%E4%BB%B6)
- [插件参数](#%E6%8F%92%E4%BB%B6%E5%8F%82%E6%95%B0)
- [模版](#%E6%A8%A1%E7%89%88)
- [截图展示](#%E6%88%AA%E5%9B%BE%E5%B1%95%E7%A4%BA)
- [贡献代码](#%E8%B4%A1%E7%8C%AE%E4%BB%A3%E7%A0%81)
- [未来计划](#%E6%9C%AA%E6%9D%A5%E8%AE%A1%E5%88%92)
- [Kubernetes 用户请注意](#kubernetes-%E7%94%A8%E6%88%B7%E8%AF%B7%E6%B3%A8%E6%84%8F)
<!-- tocstop -->
### 怎么使用本插件
添加一个`step`到你的`.drone.yml`中,下面是例子:
`0.8.x`
```yaml
pipeline:
...
notification:
image: lddsb/drone-dingtalk-message
token: your-group-bot-token
type: markdown
```
`1.x`
```yaml
steps:
...
- name: notification
image: lddsb/drone-dingtalk-message
settings:
token: your-groupbot-token
type: markdown
secret: your-secret-for-generate-sign
debug: true
```
### 插件参数
`token`(必须)
你可以通过加入和创建一个群组来添加钉钉自定义机器人,添加自定义机器人完成后即可获得所需要的`access token`
`type`(必须)
消息类型,因个人能力有限,目前仅支持`markdown``text`,其中,使用`markdown`可以获得最好的体验。
`secret`
如果你设置了`加签`,可以把你的`加签`密钥填入此项完成`加签`操作。
`tpl`
你可以通过该字段来自定义你的消息模版。该字段可以是一个本地路径也可以是一个远程的URL。
`debug`
通过该值可以打开`debug`模式,打印所有环境变量。
`tips_title`
你可以通过该字段自定义钉钉机器人的消息通知提醒标题。(注意,不是消息内容的标题,是收到钉钉机器人发的消息后,会有一个外显的标题)
`success_color`
你可以通过该字段自定义打包成功的颜色。比如:`008000`
`failure_color`
你可以通过该字段自定义打包失败的颜色。比如:`FF0000`
`success_pic`
你可以通过该字段自定义打包成功的图片。
`failure_pic`
字符串,你可以通过该字段自定义打包失败的图片。
`tpl_commit_branch_name`
你可以通过该字段自定义分支的名称,可以在模版中通过[TPL_COMMIT_BRANCH]来使用该值。
`tpl_repo_short_name`
你可以通过该字段自定义仓库的名字,可以在模版中通过[TPL_REPO_SHORT_NAME]来使用该值。
`tpl_repo_full_name`
你可以通过该字段自定义仓库的全名(包含组织名称),可以在模版中通过[TPL_REPO_FULL_NAME]来使用该值。
`tpl_build_status_success`
你可以通过该字段自定义运行成功状态的值,可以在模版中通过[TPL_BUILD_STATUS]来使用该值。(仅当前方`step`运行结果为成功时该值会生效)
`tpl_build_status_failure`
你可以通过该字段自定义运行失败状态的值,可以在模版中通过[TPL_BUILD_STATUS]来使用该值。(仅当前方`step`运行结果为失败时该值会生效)
`msg_at_mobiles`
你需要@的群成员的手机号,多个时用英文逗号(`,`)分隔。如过你使用的是 `markdown` 类型的消息,则需要在 `tpl` 文件中加入 `@手机号` 的内容。
### 模版
> `tpl` 对 `link` 类型的消息并不支持 !!!
感天动地,我们终于支持自定义模版了!下面是一个`markdown`的自定义模版例子:
# [TPL_REPO_FULL_NAME] build [TPL_BUILD_STATUS], takes [TPL_BUILD_CONSUMING]s
@mobile1 @mobile2
[TPL_COMMIT_MSG]
[TPL_COMMIT_SHA]([TPL_COMMIT_LINK])
[[TPL_AUTHOR_NAME]([TPL_AUTHOR_EMAIL])](mailto:[TPL_AUTHOR_EMAIL])
[Click To The Build Detail Page [TPL_STATUS_EMOTICON)]]([TPL_BUILD_LINK])
`mobile1``mobile2` 应该为钉钉对应的手机号码,可以放在自己想要放的位置。
你可以写自己喜欢的模版,终于不用再对默认模版发愁啦!并且模版的语法非常简单!比较可惜的是目前支持的变量还比较少,下面是当前支持的变量的列表:
| Variable | Value |
| :-------------------: | :-------------------------------------------------: |
| [TPL_REPO_SHORT_NAME] | 当前仓库的名称,比如本仓库 `drone-dingtalk-message` |
| [TPL_REPO_FULL_NAME] | 当前仓库的名称,比如本仓库 `lddsb/drone-dingtalk-message` |
| [TPL_REPO_GROUP_NAME] | 当前仓库的组织名称,比如本仓库 `lddsb` |
| [TPL_REPO_OWNER_NAME] | 当前仓库拥有者的名称 |
| [TPL_REPO_REMOTE_URL] | 当前仓库的远程地址 |
| [TPL_BUILD_STATUS] | 当前编译的状态(比如, success, failure) |
| [TPL_BUILD_LINK] | 当前编译的链接 |
| [TPL_BUILD_EVENT] | 触发当前编译的动作(比如, push, pull request等) |
| [TPL_BUILD_CONSUMING] | 当前编译耗时,单位秒 |
| [TPL_COMMIT_SHA] | 当前提交的sha |
| [TPL_COMMIT_REF] | 当前提交的ref(比如, refs/heads/master等) |
| [TPL_COMMIT_LINK] | 当前提交的远程地址 |
| [TPL_COMMIT_BRANCH] | 当前分之名称(比如, dev, master等) |
| [TPL_COMMIT_MSG] | 当前提交的信息 |
| [TPL_AUTHOR_NAME] | 当前提交作者名称 |
| [TPL_AUTHOR_EMAIL] | 当前提交作者邮箱地址 |
| [TPL_AUTHOR_USERNAME] | 当前提交作者的用户名 |
| [TPL_AUTHOR_AVATAR] | 当前提交作者的头像 |
| [TPL_STATUS_PIC] | 根据编译状态显示不同的图片 |
| [TPL_STATUS_COLOR] | 根据编译状态显示不同的颜色 |
| [TPL_STATUS_EMOTICON] | 根据编译状态显示不同的表情,比如 `:)` `:(` |
### 截图展示
- 发送成功(Drone Web
![send-success](https://i.imgur.com/cECppkW.jpg)
- 忘记填写Access TokenDrone Web
![missing-access-token](https://i.imgur.com/Su7iiyw.jpg)
- 忘记填写消息类型或者不支持的消息类型
![message-type-error](https://i.imgur.com/qtJ4DsA.jpg)
- 默认的`markdown`消息
![markdown-message-default](https://i.imgur.com/Bl7cT1y.jpg)
- 带颜色和链接的`markdown`消息
![markdown-massage-customize](https://i.imgur.com/pzdFzIw.jpg)
- 带颜色、链接和图片的`markdown`消息
![markdown-massage-customize](https://i.imgur.com/xFrCTZp.jpg)
### 贡献代码
本项目使用了`go mod`来管理依赖,因此要编译本项目相当简单。
- 先把项目代码拷贝到本地
```shell
$ git clone https://github.com/lddsb/drone-dingtalk-message.git /path/to/you/want
```
- 然后直接执行编译即可
```shell
$ cd /path/to/you/want && GO111MODULE=on go build .
```
- 跑个`help`
```shell
$ ./drone-dingtalk-message -h
```
### 未来计划
目前仅支持 `text`, `markdown` 以及 `link` 类型的消息,建议使用`markdown`类型。
- 实现更多的消息类型
- i18N国际化直接翻译环境变量
- 批量发送给多个群机器人
- 失败重试机制
### Kubernetes 用户请注意
因为`Drone CI` [官方缺陷](https://docs.drone.io/runner/kubernetes/overview) ,所以较早版本将无法正常获取到需要用到的变量,会导致部分功能异常。为了能正常使用,所以请使用以下版本:
- `1.1`(总会是`1.1.x`的最新版本)
- `>=1.1.4`
- `1.2`(总会是`1.2.x`的最新版本)
- `>=1.2.4`
+2 -2
View File
@@ -4,6 +4,6 @@ go 1.12
require (
github.com/joho/godotenv v1.3.0
github.com/lddsb/dingtalk-webhook v0.0.1
github.com/urfave/cli v1.20.0
github.com/lddsb/dingtalk-webhook v0.0.5
github.com/urfave/cli v1.22.5
)
+15 -4
View File
@@ -1,6 +1,17 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/lddsb/dingtalk-webhook v0.0.1 h1:l4FdTMaRaHnrYfByALukFWK0ru9Rttl0dANg13/SnTI=
github.com/lddsb/dingtalk-webhook v0.0.1/go.mod h1:5E+/sOBb6m+3ztqnZl4danEY3I5FeIwb12v12s9osbw=
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/lddsb/dingtalk-webhook v0.0.5 h1:EOSXvcpN4IC7fXSAheI3OLJwwOGEPlGDV7xje1fQuJo=
github.com/lddsb/dingtalk-webhook v0.0.5/go.mod h1:dwNU75Sog87wJXAFcY5mDFM7eW4hIdX7bNemrN92pH0=
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/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU=
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+58 -17
View File
@@ -4,19 +4,21 @@ import (
"fmt"
"log"
"os"
"time"
_ "github.com/joho/godotenv/autoload"
"github.com/joho/godotenv"
"github.com/urfave/cli"
)
// Version of cli
var Version = "0.1.1202"
var Version = "0.2.1219"
func main() {
app := cli.NewApp()
app.Name = "Drone Dingtalk Message Plugin"
app.Usage = "Sending message to Dingtalk group by robot using webhook"
app.Copyright = "© 2018 Dee Luo"
app.Name = "Drone DingTalk Message Plugin"
app.Usage = "Sending message to DingTalk group by robot using WebHook"
year := time.Now().Year()
app.Copyright = fmt.Sprintf("© 2018-%d Dee Luo", year)
app.Authors = []cli.Author{
{
Name: "Dee Luo",
@@ -27,7 +29,7 @@ func main() {
app.Version = Version
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "config.debug",
Name: "config.debug,debug",
Usage: "debug mode",
EnvVar: "PLUGIN_DEBUG",
},
@@ -38,22 +40,27 @@ func main() {
},
cli.StringFlag{
Name: "config.token,access_token,token",
Usage: "dingtalk webhook access token",
Usage: "DingTalk webhook access token",
EnvVar: "PLUGIN_ACCESS_TOKEN,PLUGIN_TOKEN",
},
cli.StringFlag{
Name: "config.message.type,message_type",
Usage: "dingtalk message type, like text, markdown, action card, link and feed card...",
Name: "config.secret,secret",
Usage: "DingTalk WebHook secret for generate sign",
EnvVar: "PLUGIN_SECRET",
},
cli.StringFlag{
Name: "config.message.type,message_type,type",
Usage: "DingTalk message type, like text, markdown, action card, link and feed card...",
EnvVar: "PLUGIN_MSG_TYPE,PLUGIN_TYPE,PLUGIN_MESSAGE_TYPE",
},
cli.StringFlag{
Name: "config.message.at.all",
Name: "config.message.at.all,at.all",
Usage: "at all in a message(only text and markdown type message can at)",
EnvVar: "PLUGIN_MSG_AT_ALL",
},
cli.StringFlag{
Name: "config.message.at.mobiles",
Usage: "at someone in a dingtalk group need this guy bind's mobile",
Name: "config.message.at.mobiles,mobiles",
Usage: "at someone in a DingTalk group need this guy bind's mobile",
EnvVar: "PLUGIN_MSG_AT_MOBILES",
},
cli.StringFlag{
@@ -127,6 +134,16 @@ func main() {
Usage: "provider the owner of the repository",
EnvVar: "DRONE_REPO_OWNER",
},
cli.Uint64Flag{
Name: "stage.started",
Usage: "stage started ",
EnvVar: "DRONE_STAGE_STARTED",
},
cli.Uint64Flag{
Name: "stage.finished",
Usage: "stage finished",
EnvVar: "DRONE_STAGE_FINISHED",
},
cli.StringFlag{
Name: "build.status",
Usage: "build status",
@@ -143,12 +160,12 @@ func main() {
Usage: "build event",
EnvVar: "DRONE_BUILD_EVENT",
},
cli.StringFlag{
cli.Uint64Flag{
Name: "build.started",
Usage: "build started",
EnvVar: "DRONE_BUILD_STARTED",
},
cli.StringFlag{
cli.Uint64Flag{
Name: "build.finished",
Usage: "build finished",
EnvVar: "DRONE_BUILD_FINISHED",
@@ -184,7 +201,7 @@ func main() {
EnvVar: "FAILURE_COLOR,PLUGIN_FAILURE_COLOR",
},
cli.StringFlag{
Name: "custom.tpl",
Name: "custom.tpl,tpl",
Usage: "custom tpl",
EnvVar: "PLUGIN_TPL,PLUGIN_CUSTOM_TPL",
},
@@ -203,6 +220,21 @@ func main() {
Usage: "tpl custom commit branch name",
EnvVar: "PLUGIN_TPL_COMMIT_BRANCH_NAME,TPL_COMMIT_BRANCH_NAME",
},
cli.StringFlag{
Name: "custom.started,started",
Usage: "started custom env name, eg., BUILD_STARTED",
EnvVar: "PLUGIN_CUSTOM_STARTED",
},
cli.StringFlag{
Name: "custom.finished,finished",
Usage: "finished custom env name, eg., BUILD_FINISHED",
EnvVar: "PLUGIN_CUSTOM_FINISHED",
},
}
// kubernetes runner patch
if _, err := os.Stat("/run/drone/env"); err == nil {
godotenv.Overload("/run/drone/env")
}
if err := app.Run(os.Args); nil != err {
@@ -227,8 +259,8 @@ func run(c *cli.Context) {
Status: c.String("build.status"),
Link: c.String("build.link"),
Event: c.String("build.event"),
StartAt: c.Int64("build.started"),
FinishedAt: c.Int64("build.finished"),
StartAt: c.Uint64("build.started"),
FinishedAt: c.Uint64("build.finished"),
},
Commit: Commit{
Sha: c.String("commit.sha"),
@@ -242,10 +274,15 @@ func run(c *cli.Context) {
Username: c.String("commit.author.username"),
},
},
Stage: Stage{
StartedAt: c.Uint64("stage.started"),
FinishedAt: c.Uint64("stage.finished"),
},
},
// custom config
Config: Config{
AccessToken: c.String("config.token"),
Secret: c.String("config.secret"),
IsAtALL: c.Bool("config.message.at.all"),
MsgType: c.String("config.message.type"),
Mobiles: c.String("config.message.at.mobiles"),
@@ -262,6 +299,10 @@ func run(c *cli.Context) {
FailureColor: c.String("custom.color.failure"),
},
Tpl: c.String("custom.tpl"),
Consuming: Consuming{
StartedEnv: c.String("custom.started"),
FinishedEnv: c.String("custom.finished"),
},
},
Tpl: Tpl{
Repo: TplRepo{
+68 -16
View File
@@ -9,6 +9,7 @@ import (
"net/url"
"os"
"regexp"
"strconv"
"strings"
webhook "github.com/lddsb/dingtalk-webhook"
@@ -29,8 +30,8 @@ type (
Status string // providers the current build status
Link string // providers the current build link
Event string // trigger event
StartAt int64 // build start at ( unix timestamp )
FinishedAt int64 // build finish at ( unix timestamp )
StartAt uint64 // build start at ( unix timestamp )
FinishedAt uint64 // build finish at ( unix timestamp )
}
// Commit commit info
@@ -43,6 +44,12 @@ type (
Author CommitAuthor
}
// Stage drone stage env
Stage struct {
StartedAt uint64
FinishedAt uint64
}
// CommitAuthor commit author info
CommitAuthor struct {
Avatar string // providers the author avatar for the current commit
@@ -56,12 +63,14 @@ type (
Repo Repo
Build Build
Commit Commit
Stage Stage
}
// Config plugin private config
Config struct {
Debug bool
AccessToken string
Secret string
IsAtALL bool
Mobiles string
Username string
@@ -103,42 +112,61 @@ type (
Message MessageConfig
}
// Custom user custom env
Custom struct {
Tpl string
Color Color
Pic Pic
Tpl string
Color Color
Pic Pic
Consuming Consuming
}
// Tpl TPL base
Tpl struct {
Repo TplRepo
Commit TplCommit
Build TplBuild
}
// TplRepo TPL repo
TplRepo struct {
FullName string
ShortName string
}
// TplCommit TPL commit
TplCommit struct {
Branch string
}
// TplBuild TPL build
TplBuild struct {
Status Status
}
// Status status
Status struct {
Success string
Failure string
}
// Consuming custom consuming env
Consuming struct {
StartedEnv string
FinishedEnv string
}
)
// Exec execute webhook
// Exec execute WebHook
func (p *Plugin) Exec() error {
if p.Config.Debug {
for _, e := range os.Environ() {
log.Println(e)
}
}
var err error
if 0 == len(p.Config.AccessToken) {
msg := "missing dingtalk access token"
if "" == p.Config.AccessToken {
msg := "missing DingTalk access token"
return errors.New(msg)
}
@@ -151,15 +179,21 @@ func (p *Plugin) Exec() error {
p.Config.TipsTitle = "you have a new message"
}
newWebhook := webhook.NewWebHook(p.Config.AccessToken)
newWebHook := webhook.NewWebHook(p.Config.AccessToken)
// add sign
if "" != p.Config.Secret {
newWebHook.Secret = p.Config.Secret
}
mobiles := strings.Split(p.Config.Mobiles, ",")
switch strings.ToLower(p.Config.MsgType) {
case "markdown":
err = newWebhook.SendMarkdownMsg(p.Config.TipsTitle, tpl, p.Config.IsAtALL, mobiles...)
err = newWebHook.SendMarkdownMsg(p.Config.TipsTitle, tpl, p.Config.IsAtALL, mobiles...)
case "text":
err = newWebhook.SendTextMsg(tpl, p.Config.IsAtALL, mobiles...)
err = newWebHook.SendTextMsg(tpl, p.Config.IsAtALL, mobiles...)
case "link":
err = newWebhook.SendLinkMsg(p.Drone.Build.Status, tpl, p.Drone.Commit.Author.Avatar, p.Drone.Build.Link)
err = newWebHook.SendLinkMsg(p.Drone.Build.Status, tpl, p.Drone.Commit.Author.Avatar, p.Drone.Build.Link)
default:
msg := "not support message type"
err = errors.New(msg)
@@ -187,7 +221,7 @@ func fileExists(filePath string) bool {
// getTpl get tpl from local file or remote file
func (p *Plugin) getTpl() (tpl string, err error) {
//var tpl string
tplDir := "/app/tpls"
tplDir := "/app/drone/dingtalk/message/tpls"
if "" == p.Custom.Tpl {
p.Custom.Tpl = fmt.Sprintf("%s/%s.tpl", tplDir, strings.ToLower(p.Config.MsgType))
}
@@ -242,6 +276,11 @@ func (p *Plugin) fillTpl(tpl string) string {
reg := regexp.MustCompile(`\[([^\[\]]*)]`)
match := reg.FindAllStringSubmatch(tpl, -1)
for _, m := range match {
// from environment
if envStr := os.Getenv(m[1]); envStr != "" {
tpl = strings.ReplaceAll(tpl, m[0], envStr)
}
// check if the keyword is legal
if _, ok := envs[m[1]]; ok {
// replace keyword
@@ -271,7 +310,20 @@ func (p *Plugin) getEnvs() map[string]interface{} {
envs["TPL_BUILD_STATUS"] = p.getStatus()
envs["TPL_BUILD_LINK"] = p.Drone.Build.Link
envs["TPL_BUILD_EVENT"] = p.Drone.Build.Event
envs["TPL_BUILD_CONSUMING"] = fmt.Sprintf("%v", p.Drone.Build.FinishedAt-p.Drone.Build.StartAt)
var consuming uint64
// custom consuming env
if p.Custom.Consuming.FinishedEnv != "" && p.Custom.Consuming.StartedEnv != "" {
finishedAt, _ := strconv.ParseUint(os.Getenv(p.Custom.Consuming.FinishedEnv), 10, 64)
startedAt, _ := strconv.ParseUint(os.Getenv(p.Custom.Consuming.StartedEnv), 10, 64)
consuming = finishedAt - startedAt
} else {
consuming = p.Drone.Build.FinishedAt - p.Drone.Build.StartAt
if consuming == 0 {
consuming = p.Drone.Stage.FinishedAt - p.Drone.Stage.StartedAt
}
}
envs["TPL_BUILD_CONSUMING"] = fmt.Sprintf("%v", consuming)
envs["TPL_COMMIT_SHA"] = p.Drone.Commit.Sha
envs["TPL_COMMIT_REF"] = p.Drone.Commit.Ref
@@ -338,12 +390,12 @@ func (p *Plugin) getEmoticon() string {
func (p *Plugin) getPicURL() string {
pics := make(map[string]string)
// success picture url
pics["success"] = "https://ws4.sinaimg.cn/large/006tNc79gy1fz05g5a7utj30he0bfjry.jpg"
pics["success"] = "https://wx1.sinaimg.cn/large/006tNc79gy1fz05g5a7utj30he0bfjry.jpg"
if p.Custom.Pic.SuccessPicURL != "" {
pics["success"] = p.Custom.Pic.SuccessPicURL
}
// failure picture url
pics["failure"] = "https://ws1.sinaimg.cn/large/006tNc79gy1fz0b4fghpnj30hd0bdmxn.jpg"
pics["failure"] = "https://wx1.sinaimg.cn/large/006tNc79gy1fz0b4fghpnj30hd0bdmxn.jpg"
if p.Custom.Pic.FailurePicURL != "" {
pics["failure"] = p.Custom.Pic.FailurePicURL
}
+9
View File
@@ -0,0 +1,9 @@
### **[CI_PROJECT_TITLE]**'s **[CI_COMMIT_BRANCH]** build **[TPL_BUILD_STATUS]**
Message: [CI_COMMIT_MESSAGE]
Detail: [[CI_COMMIT_SHA]]([CI_PROJECT_URL]/commit/[CI_COMMIT_SHA])
Author: [[GITLAB_USER_NAME]([GITLAB_USER_EMAIL])](mailto:[GITLAB_USER_EMAIL])
[Click To The Build Detail Page [TPL_STATUS_EMOTICON]]([CI_PIPELINE_URL])
+4 -4
View File
@@ -1,9 +1,9 @@
### [TPL_REPO_SHORT_NAME] build [TPL_BUILD_STATUS] (`takes [TPL_BUILD_CONSUMING]s`)
[TPL_COMMIT_MSG]
Message: [TPL_COMMIT_MSG]
[[TPL_COMMIT_SHA]]([TPL_COMMIT_LINK])
Detail: [[TPL_COMMIT_SHA]]([TPL_COMMIT_LINK])
[[TPL_AUTHOR_NAME]([TPL_AUTHOR_EMAIL])](mailto:[TPL_AUTHOR_EMAIL])
Author: [[TPL_AUTHOR_NAME]([TPL_AUTHOR_EMAIL])](mailto:[TPL_AUTHOR_EMAIL])
[Click To The Build Detail Page [TPL_STATUS_EMOTICON]]([TPL_BUILD_LINK])
[Click To The Build Detail Page [TPL_STATUS_EMOTICON]]([TPL_BUILD_LINK])
+11
View File
@@ -0,0 +1,11 @@
### [TPL_REPO_SHORT_NAME] build [TPL_BUILD_STATUS] (`takes [TPL_BUILD_CONSUMING]s`)
@mobile1 @mobile2
Message: [TPL_COMMIT_MSG]
Detail: [[TPL_COMMIT_SHA]]([TPL_COMMIT_LINK])
Author: [[TPL_AUTHOR_NAME]([TPL_AUTHOR_EMAIL])](mailto:[TPL_AUTHOR_EMAIL])
[Click To The Build Detail Page [TPL_STATUS_EMOTICON]]([TPL_BUILD_LINK])