mirror of
https://github.com/lddsb/drone-dingtalk-message.git
synced 2026-06-14 05:13:05 +08:00
Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4db9815ece | |||
| eed2f0fae1 | |||
| ca944a4a26 | |||
| 07310794cb | |||
| a165a28c60 | |||
| 43222b966a | |||
| 530b471503 | |||
| 3a0957f479 | |||
| c9a57df515 | |||
| d0a4fc64e4 | |||
| 526b8eec46 | |||
| 8729ae05b4 | |||
| cec9f81f52 | |||
| 428577470d | |||
| 7c8a85bcc4 | |||
| ecf4f89e0a | |||
| e7ef2de488 | |||
| acd708ada3 | |||
| 5bcf803346 | |||
| 1b219624cd | |||
| d409acce48 | |||
| 2e94325c0e | |||
| 1622a2beaa | |||
| d2ab02e29c | |||
| d0284b2434 | |||
| c8bc5d889d | |||
| d4dc439671 | |||
| 8d0434b308 | |||
| 8aafd04b82 | |||
| a651a73cbd |
@@ -0,0 +1,8 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: gomod
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: daily
|
||||||
|
time: "10:00"
|
||||||
|
open-pull-requests-limit: 10
|
||||||
@@ -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 }}
|
||||||
@@ -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@v4
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: stable
|
||||||
|
- name: Run GoReleaser
|
||||||
|
uses: goreleaser/goreleaser-action@v5
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
args: release --clean
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.CR_PAT }}
|
||||||
@@ -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 }}_
|
||||||
|
{{- title .Os }}_
|
||||||
|
{{- if eq .Arch "amd64" }}x86_64
|
||||||
|
{{- else if eq .Arch "386" }}i386
|
||||||
|
{{- else }}{{ .Arch }}{{ end }}
|
||||||
|
{{- if .Arm }}v{{ .Arm }}{{ end -}}
|
||||||
|
format_overrides:
|
||||||
|
- goos: windows
|
||||||
|
format: zip
|
||||||
|
files:
|
||||||
|
- README.md
|
||||||
|
- LICENSE
|
||||||
|
- tpls/*
|
||||||
@@ -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
@@ -6,6 +6,6 @@ RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux go build -a -o drone-dingtalk .
|
|||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
|
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
|
||||||
COPY --from=builder /app/drone-dingtalk /bin
|
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"]
|
ENTRYPOINT ["/bin/drone-dingtalk"]
|
||||||
|
|||||||
@@ -1,34 +1,61 @@
|
|||||||
# Drone CI DingTalk Message Plugin
|
# Drone CI DingTalk Message Plugin
|
||||||
[](https://hub.docker.com/r/lddsb/drone-dingtalk-message) [](https://goreportcard.com/report/github.com/lddsb/drone-dingtalk-message) [](https://codecov.io/gh/lddsb/drone-dingtalk-message) [](https://app.dependabot.com/accounts/lddsb/repos/159822771) [](LICENSE)
|
[](https://github.com/lddsb/drone-dingtalk-message/actions?query=workflow%3A%22Publish+to+DockerHub+and+Github+Package%22) [](https://goreportcard.com/report/github.com/lddsb/drone-dingtalk-message) [](https://codecov.io/gh/lddsb/drone-dingtalk-message) [](https://app.dependabot.com/accounts/lddsb/repos/159822771) [](LICENSE)
|
||||||
|
|
||||||
[中文说明](README_ZH.md)
|
[中文说明](README_ZH.md)
|
||||||
|
|
||||||
just support `text`, `markdown` and `link` type now
|
<!-- 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 -->
|
||||||
|
|
||||||
### Drone CI Plugin Config
|
### Drone CI Plugin Config
|
||||||
`0.8.x`
|
`0.8.x`
|
||||||
```yaml
|
```yaml
|
||||||
pipeline:
|
pipeline:
|
||||||
...
|
#...
|
||||||
notification:
|
notification:
|
||||||
image: lddsb/drone-dingtalk-message
|
image: lddsb/drone-dingtalk-message
|
||||||
token: your-group-bot-token
|
token: your-group-bot-token
|
||||||
type: markdown
|
type: markdown
|
||||||
```
|
```
|
||||||
|
|
||||||
`1.0.x`
|
`1.x`
|
||||||
```yaml
|
```yaml
|
||||||
kind: pipeline
|
|
||||||
name: default
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
...
|
#...
|
||||||
- name: notification
|
- name: notification
|
||||||
image: lddsb/drone-dingtalk-message
|
image: lddsb/drone-dingtalk-message
|
||||||
settings:
|
settings:
|
||||||
token: your-groupbot-token
|
token: your-groupbot-token
|
||||||
type: markdown
|
type: markdown
|
||||||
secret: your-secret-for-generate-sign
|
secret: your-secret-for-generate-sign
|
||||||
|
debug: true
|
||||||
|
```
|
||||||
|
|
||||||
|
`Use the "exec" type`
|
||||||
|
```yaml
|
||||||
|
kind: pipeline
|
||||||
|
type: exec
|
||||||
|
|
||||||
|
steps:
|
||||||
|
...
|
||||||
|
|
||||||
|
- name: notification
|
||||||
|
environment: # Using environment to pass parameters
|
||||||
|
PLUGIN_TOKEN:
|
||||||
|
from_secret: dingtalk_token
|
||||||
|
PLUGIN_TYPE: markdown
|
||||||
|
PLUGIN_DEBUG: false
|
||||||
|
PLUGIN_TPL: /data/drone/dingtalk/tpls/markdown.tpl # The actual location (absolute path) of the tpl.
|
||||||
|
commands:
|
||||||
|
- /data/drone/dingtalk/dingtalk-message # Location of the "dingtalk-message" file (absolute path)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Plugin Parameter Reference
|
### Plugin Parameter Reference
|
||||||
@@ -46,7 +73,10 @@ String. Secret for generate sign.
|
|||||||
|
|
||||||
`tpl`
|
`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`
|
`tips_title`
|
||||||
|
|
||||||
@@ -88,12 +118,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.
|
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
|
||||||
> `tpl` won't work with message type `link` !!!
|
> `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
|
# [TPL_REPO_FULL_NAME] build [TPL_BUILD_STATUS], takes [TPL_BUILD_CONSUMING]s
|
||||||
|
@mobile1 @mobile2
|
||||||
[TPL_COMMIT_MSG]
|
[TPL_COMMIT_MSG]
|
||||||
|
|
||||||
[TPL_COMMIT_SHA]([TPL_COMMIT_LINK])
|
[TPL_COMMIT_SHA]([TPL_COMMIT_LINK])
|
||||||
@@ -171,5 +206,18 @@ $ cd /path/to/you/want && GO111MODULE=on go build .
|
|||||||
$ ./drone-dingtalk-message -h
|
$ ./drone-dingtalk-message -h
|
||||||
```
|
```
|
||||||
|
|
||||||
### Todo
|
### TODO
|
||||||
|
It's sad, just support `text`, `markdown` and `link` type now.
|
||||||
- implement all message type
|
- 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)
|
||||||
|
|||||||
+80
-30
@@ -1,9 +1,21 @@
|
|||||||
# Drone CI的钉钉群组机器人通知插件
|
# Drone CI的钉钉群组机器人通知插件
|
||||||
[](https://hub.docker.com/r/lddsb/drone-dingtalk-message) [](https://goreportcard.com/report/github.com/lddsb/drone-dingtalk-message) [](https://codecov.io/gh/lddsb/drone-dingtalk-message) [](https://app.dependabot.com/accounts/lddsb/repos/159822771) [](LICENSE)
|
[](https://github.com/lddsb/drone-dingtalk-message/actions?query=workflow%3A%22Publish+to+DockerHub+and+Github+Package%22) [](https://goreportcard.com/report/github.com/lddsb/drone-dingtalk-message) [](https://codecov.io/gh/lddsb/drone-dingtalk-message) [](https://app.dependabot.com/accounts/lddsb/repos/159822771) [](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 -->
|
||||||
|
|
||||||
目前仅支持 `text`, `markdown` 以及 `link` 类型的消息,建议使用`markdown`类型。
|
|
||||||
### 怎么使用本插件
|
### 怎么使用本插件
|
||||||
添加一个`step`到你的`.drone.yml`中,下面是简单的例子:
|
添加一个`step`到你的`.drone.yml`中,下面是例子:
|
||||||
|
|
||||||
`0.8.x`
|
`0.8.x`
|
||||||
```yaml
|
```yaml
|
||||||
@@ -15,11 +27,8 @@ pipeline:
|
|||||||
type: markdown
|
type: markdown
|
||||||
```
|
```
|
||||||
|
|
||||||
`1.0.x`
|
`1.x`
|
||||||
```yaml
|
```yaml
|
||||||
kind: pipeline
|
|
||||||
name: default
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
...
|
...
|
||||||
- name: notification
|
- name: notification
|
||||||
@@ -28,7 +37,26 @@ steps:
|
|||||||
token: your-groupbot-token
|
token: your-groupbot-token
|
||||||
type: markdown
|
type: markdown
|
||||||
secret: your-secret-for-generate-sign
|
secret: your-secret-for-generate-sign
|
||||||
|
debug: true
|
||||||
|
```
|
||||||
|
|
||||||
|
`命令行版本`
|
||||||
|
```yaml
|
||||||
|
kind: pipeline
|
||||||
|
type: exec
|
||||||
|
|
||||||
|
steps:
|
||||||
|
...
|
||||||
|
|
||||||
|
- name: 通知
|
||||||
|
environment: # 使用 environment 传递参数
|
||||||
|
PLUGIN_TOKEN:
|
||||||
|
from_secret: dingtalk_token
|
||||||
|
PLUGIN_TYPE: markdown
|
||||||
|
PLUGIN_DEBUG: false
|
||||||
|
PLUGIN_TPL: /data/drone/dingtalk/tpls/markdown.tpl # tpl 的实际位置(绝对路径)
|
||||||
|
commands:
|
||||||
|
- /data/drone/dingtalk/dingtalk-message # dingtalk-message 文件的位置(绝对路径)
|
||||||
```
|
```
|
||||||
|
|
||||||
### 插件参数
|
### 插件参数
|
||||||
@@ -48,6 +76,10 @@ steps:
|
|||||||
|
|
||||||
你可以通过该字段来自定义你的消息模版。该字段可以是一个本地路径也可以是一个远程的URL。
|
你可以通过该字段来自定义你的消息模版。该字段可以是一个本地路径也可以是一个远程的URL。
|
||||||
|
|
||||||
|
`debug`
|
||||||
|
|
||||||
|
通过该值可以打开`debug`模式,打印所有环境变量。
|
||||||
|
|
||||||
`tips_title`
|
`tips_title`
|
||||||
|
|
||||||
你可以通过该字段自定义钉钉机器人的消息通知提醒标题。(注意,不是消息内容的标题,是收到钉钉机器人发的消息后,会有一个外显的标题)
|
你可以通过该字段自定义钉钉机器人的消息通知提醒标题。(注意,不是消息内容的标题,是收到钉钉机器人发的消息后,会有一个外显的标题)
|
||||||
@@ -88,12 +120,17 @@ steps:
|
|||||||
|
|
||||||
你可以通过该字段自定义运行失败状态的值,可以在模版中通过[TPL_BUILD_STATUS]来使用该值。(仅当前方`step`运行结果为失败时该值会生效)
|
你可以通过该字段自定义运行失败状态的值,可以在模版中通过[TPL_BUILD_STATUS]来使用该值。(仅当前方`step`运行结果为失败时该值会生效)
|
||||||
|
|
||||||
|
`msg_at_mobiles`
|
||||||
|
|
||||||
|
你需要@的群成员的手机号,多个时用英文逗号(`,`)分隔。如过你使用的是 `markdown` 类型的消息,则需要在 `tpl` 文件中加入 `@手机号` 的内容。
|
||||||
|
|
||||||
### 模版
|
### 模版
|
||||||
> `tpl` 对 `link` 类型的消息并不支持 !!!
|
> `tpl` 对 `link` 类型的消息并不支持 !!!
|
||||||
|
|
||||||
感天动地,我们终于支持自定义模版了!下面是一个`markdown`的自定义模版例子:
|
感天动地,我们终于支持自定义模版了!下面是一个`markdown`的自定义模版例子:
|
||||||
|
|
||||||
# [TPL_REPO_FULL_NAME] build [TPL_BUILD_STATUS], takes [TPL_BUILD_CONSUMING]s
|
# [TPL_REPO_FULL_NAME] build [TPL_BUILD_STATUS], takes [TPL_BUILD_CONSUMING]s
|
||||||
|
@mobile1 @mobile2
|
||||||
[TPL_COMMIT_MSG]
|
[TPL_COMMIT_MSG]
|
||||||
|
|
||||||
[TPL_COMMIT_SHA]([TPL_COMMIT_LINK])
|
[TPL_COMMIT_SHA]([TPL_COMMIT_LINK])
|
||||||
@@ -102,31 +139,33 @@ steps:
|
|||||||
|
|
||||||
[Click To The Build Detail Page [TPL_STATUS_EMOTICON)]]([TPL_BUILD_LINK])
|
[Click To The Build Detail Page [TPL_STATUS_EMOTICON)]]([TPL_BUILD_LINK])
|
||||||
|
|
||||||
你可以写自己喜欢的模版,终于不用再对着默认模版发愁啦!并且模版的语法非常简单!比较可惜的是目前支持的变量还比较少,下面是当前支持的变量的列表:
|
`mobile1` 和 `mobile2` 应该为钉钉对应的手机号码,可以放在自己想要放的位置。
|
||||||
|
|
||||||
|
你可以写自己喜欢的模版,终于不用再对默认模版发愁啦!并且模版的语法非常简单!比较可惜的是目前支持的变量还比较少,下面是当前支持的变量的列表:
|
||||||
|
|
||||||
| Variable | Value |
|
| Variable | Value |
|
||||||
| :-------------------: | :-------------------------------------------------: |
|
| :-------------------: | :-------------------------------------------------: |
|
||||||
| [TPL_REPO_SHORT_NAME] | current repo name(bare name) |
|
| [TPL_REPO_SHORT_NAME] | 当前仓库的名称,比如本仓库 `drone-dingtalk-message` |
|
||||||
| [TPL_REPO_FULL_NAME] | the full name(with group name) of current repo |
|
| [TPL_REPO_FULL_NAME] | 当前仓库的名称,比如本仓库 `lddsb/drone-dingtalk-message` |
|
||||||
| [TPL_REPO_GROUP_NAME] | the group name of current repo |
|
| [TPL_REPO_GROUP_NAME] | 当前仓库的组织名称,比如本仓库 `lddsb` |
|
||||||
| [TPL_REPO_OWNER_NAME] | the owner name of current repo |
|
| [TPL_REPO_OWNER_NAME] | 当前仓库拥有者的名称 |
|
||||||
| [TPL_REPO_REMOTE_URL] | the remote url of current repo |
|
| [TPL_REPO_REMOTE_URL] | 当前仓库的远程地址 |
|
||||||
| [TPL_BUILD_STATUS] | current build status(e.g., success, failure) |
|
| [TPL_BUILD_STATUS] | 当前编译的状态(比如, success, failure) |
|
||||||
| [TPL_BUILD_LINK] | current build link |
|
| [TPL_BUILD_LINK] | 当前编译的链接 |
|
||||||
| [TPL_BUILD_EVENT] | current build event(e.g., push, pull request, etc.) |
|
| [TPL_BUILD_EVENT] | 触发当前编译的动作(比如, push, pull request等) |
|
||||||
| [TPL_BUILD_CONSUMING] | current build consuming, second |
|
| [TPL_BUILD_CONSUMING] | 当前编译耗时,单位秒 |
|
||||||
| [TPL_COMMIT_SHA] | current commit sha |
|
| [TPL_COMMIT_SHA] | 当前提交的sha |
|
||||||
| [TPL_COMMIT_REF] | current commit ref(e.g., refs/heads/master, etc.) |
|
| [TPL_COMMIT_REF] | 当前提交的ref(比如, refs/heads/master等) |
|
||||||
| [TPL_COMMIT_LINK] | current commit remote url link |
|
| [TPL_COMMIT_LINK] | 当前提交的远程地址 |
|
||||||
| [TPL_COMMIT_BRANCH] | current branch name(e.g., dev, etc) |
|
| [TPL_COMMIT_BRANCH] | 当前分之名称(比如, dev, master等) |
|
||||||
| [TPL_COMMIT_MSG] | current commit message |
|
| [TPL_COMMIT_MSG] | 当前提交的信息 |
|
||||||
| [TPL_AUTHOR_NAME] | current commit author name |
|
| [TPL_AUTHOR_NAME] | 当前提交作者名称 |
|
||||||
| [TPL_AUTHOR_EMAIL] | current commit author email |
|
| [TPL_AUTHOR_EMAIL] | 当前提交作者邮箱地址 |
|
||||||
| [TPL_AUTHOR_USERNAME] | current commit author username |
|
| [TPL_AUTHOR_USERNAME] | 当前提交作者的用户名 |
|
||||||
| [TPL_AUTHOR_AVATAR] | current commit author avatar |
|
| [TPL_AUTHOR_AVATAR] | 当前提交作者的头像 |
|
||||||
| [TPL_STATUS_PIC] | custom pic for build status |
|
| [TPL_STATUS_PIC] | 根据编译状态显示不同的图片 |
|
||||||
| [TPL_STATUS_COLOR] | custom color for build status |
|
| [TPL_STATUS_COLOR] | 根据编译状态显示不同的颜色 |
|
||||||
| [TPL_STATUS_EMOTICON] | custom emoticon for build status |
|
| [TPL_STATUS_EMOTICON] | 根据编译状态显示不同的表情,比如 `:)` `:(` |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -172,5 +211,16 @@ $ cd /path/to/you/want && GO111MODULE=on go build .
|
|||||||
$ ./drone-dingtalk-message -h
|
$ ./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`
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ module github.com/lddsb/drone-dingtalk-message
|
|||||||
go 1.12
|
go 1.12
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/joho/godotenv v1.3.0
|
github.com/joho/godotenv v1.5.1
|
||||||
github.com/lddsb/dingtalk-webhook v0.0.4
|
github.com/lddsb/dingtalk-webhook v0.0.5
|
||||||
github.com/urfave/cli v1.22.2
|
github.com/urfave/cli v1.22.15
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,17 +1,31 @@
|
|||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
|
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||||
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/lddsb/dingtalk-webhook v0.0.4 h1:gAJFy66L2gZ5j6kDrHRoz/zQFaNamcObtetNonq76RA=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/lddsb/dingtalk-webhook v0.0.4/go.mod h1:dwNU75Sog87wJXAFcY5mDFM7eW4hIdX7bNemrN92pH0=
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
|
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 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
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.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo=
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||||
|
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/urfave/cli v1.22.15 h1:nuqt+pdC/KqswQKhETJjo7pvn/k4xMUxgW6liI7XpnM=
|
||||||
|
github.com/urfave/cli v1.22.15/go.mod h1:wSan1hmo5zeyLGBjRJbzRTNk8gwoYa2B9n4q9dmRIc0=
|
||||||
|
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/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=
|
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=
|
||||||
|
|||||||
@@ -4,19 +4,21 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
_ "github.com/joho/godotenv/autoload"
|
"github.com/joho/godotenv"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version of cli
|
// Version of cli
|
||||||
var Version = "0.2.1130"
|
var Version = "0.2.1219"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.Name = "Drone DingTalk Message Plugin"
|
app.Name = "Drone DingTalk Message Plugin"
|
||||||
app.Usage = "Sending message to DingTalk group by robot using WebHook"
|
app.Usage = "Sending message to DingTalk group by robot using WebHook"
|
||||||
app.Copyright = "© 2018 Dee Luo"
|
year := time.Now().Year()
|
||||||
|
app.Copyright = fmt.Sprintf("© 2018-%d Dee Luo", year)
|
||||||
app.Authors = []cli.Author{
|
app.Authors = []cli.Author{
|
||||||
{
|
{
|
||||||
Name: "Dee Luo",
|
Name: "Dee Luo",
|
||||||
@@ -27,7 +29,7 @@ func main() {
|
|||||||
app.Version = Version
|
app.Version = Version
|
||||||
app.Flags = []cli.Flag{
|
app.Flags = []cli.Flag{
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "config.debug",
|
Name: "config.debug,debug",
|
||||||
Usage: "debug mode",
|
Usage: "debug mode",
|
||||||
EnvVar: "PLUGIN_DEBUG",
|
EnvVar: "PLUGIN_DEBUG",
|
||||||
},
|
},
|
||||||
@@ -47,17 +49,17 @@ func main() {
|
|||||||
EnvVar: "PLUGIN_SECRET",
|
EnvVar: "PLUGIN_SECRET",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "config.message.type,message_type",
|
Name: "config.message.type,message_type,type",
|
||||||
Usage: "DingTalk message type, like text, markdown, action card, link and feed card...",
|
Usage: "DingTalk message type, like text, markdown, action card, link and feed card...",
|
||||||
EnvVar: "PLUGIN_MSG_TYPE,PLUGIN_TYPE,PLUGIN_MESSAGE_TYPE",
|
EnvVar: "PLUGIN_MSG_TYPE,PLUGIN_TYPE,PLUGIN_MESSAGE_TYPE",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
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)",
|
Usage: "at all in a message(only text and markdown type message can at)",
|
||||||
EnvVar: "PLUGIN_MSG_AT_ALL",
|
EnvVar: "PLUGIN_MSG_AT_ALL",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "config.message.at.mobiles",
|
Name: "config.message.at.mobiles,mobiles",
|
||||||
Usage: "at someone in a DingTalk group need this guy bind's mobile",
|
Usage: "at someone in a DingTalk group need this guy bind's mobile",
|
||||||
EnvVar: "PLUGIN_MSG_AT_MOBILES",
|
EnvVar: "PLUGIN_MSG_AT_MOBILES",
|
||||||
},
|
},
|
||||||
@@ -132,6 +134,16 @@ func main() {
|
|||||||
Usage: "provider the owner of the repository",
|
Usage: "provider the owner of the repository",
|
||||||
EnvVar: "DRONE_REPO_OWNER",
|
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{
|
cli.StringFlag{
|
||||||
Name: "build.status",
|
Name: "build.status",
|
||||||
Usage: "build status",
|
Usage: "build status",
|
||||||
@@ -148,12 +160,12 @@ func main() {
|
|||||||
Usage: "build event",
|
Usage: "build event",
|
||||||
EnvVar: "DRONE_BUILD_EVENT",
|
EnvVar: "DRONE_BUILD_EVENT",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.Uint64Flag{
|
||||||
Name: "build.started",
|
Name: "build.started",
|
||||||
Usage: "build started",
|
Usage: "build started",
|
||||||
EnvVar: "DRONE_BUILD_STARTED",
|
EnvVar: "DRONE_BUILD_STARTED",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.Uint64Flag{
|
||||||
Name: "build.finished",
|
Name: "build.finished",
|
||||||
Usage: "build finished",
|
Usage: "build finished",
|
||||||
EnvVar: "DRONE_BUILD_FINISHED",
|
EnvVar: "DRONE_BUILD_FINISHED",
|
||||||
@@ -189,7 +201,7 @@ func main() {
|
|||||||
EnvVar: "FAILURE_COLOR,PLUGIN_FAILURE_COLOR",
|
EnvVar: "FAILURE_COLOR,PLUGIN_FAILURE_COLOR",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "custom.tpl",
|
Name: "custom.tpl,tpl",
|
||||||
Usage: "custom tpl",
|
Usage: "custom tpl",
|
||||||
EnvVar: "PLUGIN_TPL,PLUGIN_CUSTOM_TPL",
|
EnvVar: "PLUGIN_TPL,PLUGIN_CUSTOM_TPL",
|
||||||
},
|
},
|
||||||
@@ -208,6 +220,21 @@ func main() {
|
|||||||
Usage: "tpl custom commit branch name",
|
Usage: "tpl custom commit branch name",
|
||||||
EnvVar: "PLUGIN_TPL_COMMIT_BRANCH_NAME,TPL_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 {
|
if err := app.Run(os.Args); nil != err {
|
||||||
@@ -232,8 +259,8 @@ func run(c *cli.Context) {
|
|||||||
Status: c.String("build.status"),
|
Status: c.String("build.status"),
|
||||||
Link: c.String("build.link"),
|
Link: c.String("build.link"),
|
||||||
Event: c.String("build.event"),
|
Event: c.String("build.event"),
|
||||||
StartAt: c.Int64("build.started"),
|
StartAt: c.Uint64("build.started"),
|
||||||
FinishedAt: c.Int64("build.finished"),
|
FinishedAt: c.Uint64("build.finished"),
|
||||||
},
|
},
|
||||||
Commit: Commit{
|
Commit: Commit{
|
||||||
Sha: c.String("commit.sha"),
|
Sha: c.String("commit.sha"),
|
||||||
@@ -247,6 +274,10 @@ func run(c *cli.Context) {
|
|||||||
Username: c.String("commit.author.username"),
|
Username: c.String("commit.author.username"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Stage: Stage{
|
||||||
|
StartedAt: c.Uint64("stage.started"),
|
||||||
|
FinishedAt: c.Uint64("stage.finished"),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
// custom config
|
// custom config
|
||||||
Config: Config{
|
Config: Config{
|
||||||
@@ -268,6 +299,10 @@ func run(c *cli.Context) {
|
|||||||
FailureColor: c.String("custom.color.failure"),
|
FailureColor: c.String("custom.color.failure"),
|
||||||
},
|
},
|
||||||
Tpl: c.String("custom.tpl"),
|
Tpl: c.String("custom.tpl"),
|
||||||
|
Consuming: Consuming{
|
||||||
|
StartedEnv: c.String("custom.started"),
|
||||||
|
FinishedEnv: c.String("custom.finished"),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Tpl: Tpl{
|
Tpl: Tpl{
|
||||||
Repo: TplRepo{
|
Repo: TplRepo{
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
webhook "github.com/lddsb/dingtalk-webhook"
|
webhook "github.com/lddsb/dingtalk-webhook"
|
||||||
@@ -24,16 +25,16 @@ type (
|
|||||||
RemoteURL string // repo remote url
|
RemoteURL string // repo remote url
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build build info
|
// Build info
|
||||||
Build struct {
|
Build struct {
|
||||||
Status string // providers the current build status
|
Status string // providers the current build status
|
||||||
Link string // providers the current build link
|
Link string // providers the current build link
|
||||||
Event string // trigger event
|
Event string // trigger event
|
||||||
StartAt int64 // build start at ( unix timestamp )
|
StartAt uint64 // build start at ( unix timestamp )
|
||||||
FinishedAt int64 // build finish at ( unix timestamp )
|
FinishedAt uint64 // build finish at ( unix timestamp )
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit commit info
|
// Commit info
|
||||||
Commit struct {
|
Commit struct {
|
||||||
Branch string // providers the branch for the current commit
|
Branch string // providers the branch for the current commit
|
||||||
Link string // providers the http link to the current commit in the remote source code management system(e.g.GitHub)
|
Link string // providers the http link to the current commit in the remote source code management system(e.g.GitHub)
|
||||||
@@ -43,6 +44,12 @@ type (
|
|||||||
Author CommitAuthor
|
Author CommitAuthor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stage drone stage env
|
||||||
|
Stage struct {
|
||||||
|
StartedAt uint64
|
||||||
|
FinishedAt uint64
|
||||||
|
}
|
||||||
|
|
||||||
// CommitAuthor commit author info
|
// CommitAuthor commit author info
|
||||||
CommitAuthor struct {
|
CommitAuthor struct {
|
||||||
Avatar string // providers the author avatar for the current commit
|
Avatar string // providers the author avatar for the current commit
|
||||||
@@ -56,6 +63,7 @@ type (
|
|||||||
Repo Repo
|
Repo Repo
|
||||||
Build Build
|
Build Build
|
||||||
Commit Commit
|
Commit Commit
|
||||||
|
Stage Stage
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config plugin private config
|
// Config plugin private config
|
||||||
@@ -104,39 +112,58 @@ type (
|
|||||||
Message MessageConfig
|
Message MessageConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Custom user custom env
|
||||||
Custom struct {
|
Custom struct {
|
||||||
Tpl string
|
Tpl string
|
||||||
Color Color
|
Color Color
|
||||||
Pic Pic
|
Pic Pic
|
||||||
|
Consuming Consuming
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tpl base
|
||||||
Tpl struct {
|
Tpl struct {
|
||||||
Repo TplRepo
|
Repo TplRepo
|
||||||
Commit TplCommit
|
Commit TplCommit
|
||||||
Build TplBuild
|
Build TplBuild
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TplRepo TPL repo
|
||||||
TplRepo struct {
|
TplRepo struct {
|
||||||
FullName string
|
FullName string
|
||||||
ShortName string
|
ShortName string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TplCommit TPL commit
|
||||||
TplCommit struct {
|
TplCommit struct {
|
||||||
Branch string
|
Branch string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TplBuild TPL build
|
||||||
TplBuild struct {
|
TplBuild struct {
|
||||||
Status Status
|
Status Status
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Status status
|
||||||
Status struct {
|
Status struct {
|
||||||
Success string
|
Success string
|
||||||
Failure string
|
Failure string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Consuming custom consuming env
|
||||||
|
Consuming struct {
|
||||||
|
StartedEnv string
|
||||||
|
FinishedEnv string
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Exec execute WebHook
|
// Exec execute WebHook
|
||||||
func (p *Plugin) Exec() error {
|
func (p *Plugin) Exec() error {
|
||||||
|
if p.Config.Debug {
|
||||||
|
for _, e := range os.Environ() {
|
||||||
|
log.Println(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if "" == p.Config.AccessToken {
|
if "" == p.Config.AccessToken {
|
||||||
msg := "missing DingTalk access token"
|
msg := "missing DingTalk access token"
|
||||||
@@ -194,7 +221,7 @@ func fileExists(filePath string) bool {
|
|||||||
// getTpl get tpl from local file or remote file
|
// getTpl get tpl from local file or remote file
|
||||||
func (p *Plugin) getTpl() (tpl string, err error) {
|
func (p *Plugin) getTpl() (tpl string, err error) {
|
||||||
//var tpl string
|
//var tpl string
|
||||||
tplDir := "/app/tpls"
|
tplDir := "/app/drone/dingtalk/message/tpls"
|
||||||
if "" == p.Custom.Tpl {
|
if "" == p.Custom.Tpl {
|
||||||
p.Custom.Tpl = fmt.Sprintf("%s/%s.tpl", tplDir, strings.ToLower(p.Config.MsgType))
|
p.Custom.Tpl = fmt.Sprintf("%s/%s.tpl", tplDir, strings.ToLower(p.Config.MsgType))
|
||||||
}
|
}
|
||||||
@@ -228,7 +255,8 @@ func (p *Plugin) getTpl() (tpl string, err error) {
|
|||||||
tpl = string(body)
|
tpl = string(body)
|
||||||
} else {
|
} else {
|
||||||
if !fileExists(p.Custom.Tpl) {
|
if !fileExists(p.Custom.Tpl) {
|
||||||
return "", errors.New("tpl file not exists")
|
// it must be a tpl stream
|
||||||
|
return p.Custom.Tpl, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
tplStr, err := ioutil.ReadFile(p.Custom.Tpl)
|
tplStr, err := ioutil.ReadFile(p.Custom.Tpl)
|
||||||
@@ -249,6 +277,11 @@ func (p *Plugin) fillTpl(tpl string) string {
|
|||||||
reg := regexp.MustCompile(`\[([^\[\]]*)]`)
|
reg := regexp.MustCompile(`\[([^\[\]]*)]`)
|
||||||
match := reg.FindAllStringSubmatch(tpl, -1)
|
match := reg.FindAllStringSubmatch(tpl, -1)
|
||||||
for _, m := range match {
|
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
|
// check if the keyword is legal
|
||||||
if _, ok := envs[m[1]]; ok {
|
if _, ok := envs[m[1]]; ok {
|
||||||
// replace keyword
|
// replace keyword
|
||||||
@@ -278,7 +311,20 @@ func (p *Plugin) getEnvs() map[string]interface{} {
|
|||||||
envs["TPL_BUILD_STATUS"] = p.getStatus()
|
envs["TPL_BUILD_STATUS"] = p.getStatus()
|
||||||
envs["TPL_BUILD_LINK"] = p.Drone.Build.Link
|
envs["TPL_BUILD_LINK"] = p.Drone.Build.Link
|
||||||
envs["TPL_BUILD_EVENT"] = p.Drone.Build.Event
|
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_SHA"] = p.Drone.Commit.Sha
|
||||||
envs["TPL_COMMIT_REF"] = p.Drone.Commit.Ref
|
envs["TPL_COMMIT_REF"] = p.Drone.Commit.Ref
|
||||||
@@ -345,12 +391,12 @@ func (p *Plugin) getEmoticon() string {
|
|||||||
func (p *Plugin) getPicURL() string {
|
func (p *Plugin) getPicURL() string {
|
||||||
pics := make(map[string]string)
|
pics := make(map[string]string)
|
||||||
// success picture url
|
// 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 != "" {
|
if p.Custom.Pic.SuccessPicURL != "" {
|
||||||
pics["success"] = p.Custom.Pic.SuccessPicURL
|
pics["success"] = p.Custom.Pic.SuccessPicURL
|
||||||
}
|
}
|
||||||
// failure picture url
|
// 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 != "" {
|
if p.Custom.Pic.FailurePicURL != "" {
|
||||||
pics["failure"] = p.Custom.Pic.FailurePicURL
|
pics["failure"] = p.Custom.Pic.FailurePicURL
|
||||||
}
|
}
|
||||||
@@ -369,13 +415,19 @@ func (p *Plugin) getColor() string {
|
|||||||
// success color
|
// success color
|
||||||
colors["success"] = "#008000"
|
colors["success"] = "#008000"
|
||||||
if p.Custom.Color.SuccessColor != "" {
|
if p.Custom.Color.SuccessColor != "" {
|
||||||
colors["success"] = "#" + p.Custom.Color.SuccessColor
|
if p.Custom.Color.SuccessColor[0] != '#' {
|
||||||
|
p.Custom.Color.SuccessColor = "#" + p.Custom.Color.SuccessColor
|
||||||
|
}
|
||||||
|
colors["success"] = p.Custom.Color.SuccessColor
|
||||||
}
|
}
|
||||||
|
|
||||||
// failure color
|
// failure color
|
||||||
colors["failure"] = "#FF0000"
|
colors["failure"] = "#FF0000"
|
||||||
if p.Custom.Color.FailureColor != "" {
|
if p.Custom.Color.FailureColor != "" {
|
||||||
colors["failure"] = "#" + p.Custom.Color.FailureColor
|
if p.Custom.Color.FailureColor[0] != '#' {
|
||||||
|
p.Custom.Color.FailureColor = "#" + p.Custom.Color.FailureColor
|
||||||
|
}
|
||||||
|
colors["failure"] = p.Custom.Color.FailureColor
|
||||||
}
|
}
|
||||||
|
|
||||||
color, ok := colors[p.Drone.Build.Status]
|
color, ok := colors[p.Drone.Build.Status]
|
||||||
|
|||||||
@@ -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])
|
||||||
+3
-3
@@ -1,9 +1,9 @@
|
|||||||
### [TPL_REPO_SHORT_NAME] build [TPL_BUILD_STATUS] (`takes [TPL_BUILD_CONSUMING]s`)
|
### [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])
|
||||||
@@ -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])
|
||||||
Reference in New Issue
Block a user