mirror of
https://github.com/lddsb/drone-dingtalk-message.git
synced 2026-07-16 16:11:11 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f931e70cc7 |
+37
-11
@@ -9,7 +9,7 @@ steps:
|
|||||||
commands:
|
commands:
|
||||||
- make vet
|
- make vet
|
||||||
environment:
|
environment:
|
||||||
GO111MODULE: "on"
|
GO111MODULE: on
|
||||||
volumes:
|
volumes:
|
||||||
- name: gopath
|
- name: gopath
|
||||||
path: /go
|
path: /go
|
||||||
@@ -21,7 +21,7 @@ steps:
|
|||||||
- make test
|
- make test
|
||||||
- make coverage
|
- make coverage
|
||||||
environment:
|
environment:
|
||||||
GO111MODULE: "on"
|
GO111MODULE: on
|
||||||
volumes:
|
volumes:
|
||||||
- name: gopath
|
- name: gopath
|
||||||
path: /go
|
path: /go
|
||||||
@@ -37,13 +37,9 @@ volumes:
|
|||||||
- name: gopath
|
- name: gopath
|
||||||
temp: {}
|
temp: {}
|
||||||
|
|
||||||
trigger:
|
|
||||||
event:
|
|
||||||
- pull_request
|
|
||||||
|
|
||||||
---
|
---
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
name: dryrun
|
name: build
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: build
|
- name: build
|
||||||
@@ -53,7 +49,13 @@ steps:
|
|||||||
- go build -a -o drone-dingtalk-message .
|
- go build -a -o drone-dingtalk-message .
|
||||||
environment:
|
environment:
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
GO111MODULE: "on"
|
GO111MODULE: on
|
||||||
|
|
||||||
|
- name: executable
|
||||||
|
pull: always
|
||||||
|
image: golang
|
||||||
|
commands:
|
||||||
|
- ./drone-dingtalk-message -h
|
||||||
|
|
||||||
- name: dryrun
|
- name: dryrun
|
||||||
pull: always
|
pull: always
|
||||||
@@ -61,15 +63,39 @@ steps:
|
|||||||
settings:
|
settings:
|
||||||
cache_from: lddsb/drone-dingtalk-message
|
cache_from: lddsb/drone-dingtalk-message
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
dry_run: true
|
dryrun: true
|
||||||
repo: lddsb/drone-dingtalk-message
|
repo: lddsb/drone-dingtalk-message
|
||||||
tags:
|
tags:
|
||||||
- latest
|
- latest
|
||||||
- 1.0.0
|
- 1.0.0
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- pull_request
|
||||||
|
|
||||||
|
- name: publish
|
||||||
|
pull: always
|
||||||
|
image: plugins/docker
|
||||||
|
settings:
|
||||||
|
repo: lddsb/drone-dingtalk-message
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
tags:
|
||||||
|
- latest
|
||||||
|
- 1.0.0
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
password:
|
||||||
|
from_secret: docker_password
|
||||||
|
when:
|
||||||
|
status:
|
||||||
|
- success
|
||||||
|
event:
|
||||||
|
- tag
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
event:
|
ref:
|
||||||
- pull_request
|
- refs/heads/master
|
||||||
|
- 'refs/pull/**'
|
||||||
|
- 'refs/tags/**'
|
||||||
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- testing
|
- testing
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
[*.y*ml]
|
|
||||||
indent_size = 2
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
version: 2
|
|
||||||
updates:
|
|
||||||
- package-ecosystem: gomod
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: daily
|
|
||||||
time: "10:00"
|
|
||||||
open-pull-requests-limit: 10
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
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 }}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
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 }}
|
|
||||||
+1
-3
@@ -2,6 +2,4 @@ dive.log
|
|||||||
drone-dingtalk-message
|
drone-dingtalk-message
|
||||||
.idea
|
.idea
|
||||||
vendor
|
vendor
|
||||||
coverage.txt
|
coverage.txt
|
||||||
coverage.out
|
|
||||||
env.list
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
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/*
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
# 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
|
|
||||||
+11
-5
@@ -1,11 +1,17 @@
|
|||||||
FROM golang AS builder
|
FROM golang AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux go build -a -o drone-dingtalk .
|
ENV GO111MODULE on
|
||||||
|
ENV CGO_ENABLED 0
|
||||||
|
ENV GOOS linux
|
||||||
|
RUN 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 && \
|
||||||
COPY --from=builder /app/drone-dingtalk /bin
|
apk add \
|
||||||
COPY --from=builder /app/tpls /app/drone/dingtalk/message/tpls
|
ca-certificates && \
|
||||||
|
rm -rf /var/cache/apk/*
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/drone-dingtalk"]
|
COPY --from=builder /app/drone-dingtalk /bin/
|
||||||
|
ENTRYPOINT ["/bin/drone-dingtalk"]
|
||||||
@@ -1,61 +1,30 @@
|
|||||||
# Drone CI DingTalk Message Plugin
|
# Drone CI DingTalk Message Plugin
|
||||||
[](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)
|
[](https://drone.lddsb.com/lddsb/drone-dingtalk-message) [](https://goreportcard.com/report/github.com/lddsb/drone-dingtalk-message) [](https://codecov.io/gh/lddsb/drone-dingtalk-message) [](https://codebeat.co/projects/github-com-lddsb-drone-dingtalk-message-master) [](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 -->
|
|
||||||
|
|
||||||
### 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.x`
|
`1.0.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
|
|
||||||
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
|
||||||
@@ -67,103 +36,34 @@ 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.
|
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`
|
`message_color`(when `type=markdown`)
|
||||||
|
|
||||||
String. Secret for generate sign.
|
Boolean value. This option can change the title and commit message color if turn on.
|
||||||
|
|
||||||
`tpl`
|
`success_color`(when `message_color=true`)
|
||||||
|
|
||||||
String. Your custom `tpl`, it can be a local path, or a remote http link.
|
|
||||||
|
|
||||||
`debug`
|
|
||||||
Boolean. Debug mode.
|
|
||||||
|
|
||||||
`tips_title`
|
|
||||||
|
|
||||||
String. You can customize the title for the message tips, just work when message type is markdown.
|
|
||||||
|
|
||||||
`success_color`
|
|
||||||
|
|
||||||
String. You can customize the color for the `build success` message by this option, you should input a hex color, example: `008000`.
|
String. You can customize the color for the `build success` message by this option, you should input a hex color, example: `008000`.
|
||||||
|
|
||||||
`failure_color`
|
`failure_color`(when `message_color=true`)
|
||||||
|
|
||||||
String. You can customize the color for the `build success` message by this option, you should input a hex color, example: `FF0000`.
|
String. You can customize the color for the `build success` message by this option, you should input a hex color, example: `FF0000`.
|
||||||
|
|
||||||
`success_pic`
|
`sha_link`(when `type=markdown`)
|
||||||
|
|
||||||
|
Boolean value. This option can link the sha to your source page when it turn on.
|
||||||
|
|
||||||
|
`message_pic`(when `type=markdown`)
|
||||||
|
|
||||||
|
Boolean value. If this option turn on, it will embed a image into the message.
|
||||||
|
|
||||||
|
`success_pic`(when `message_pic=true`)
|
||||||
|
|
||||||
String. You can customize the picture for the `build success` message by this option.
|
String. You can customize the picture for the `build success` message by this option.
|
||||||
|
|
||||||
`failure_pic`
|
`failure_pic`(when `message_pic=true`)
|
||||||
|
|
||||||
String. You can customize the picture for the `build failure` message by this option.
|
String. You can customize the picture for the `build failure` message by this option.
|
||||||
|
|
||||||
`tpl_commit_branch_name`
|
|
||||||
|
|
||||||
String. You can customize the [TPL_COMMIT_BRANCH] by this configuration item.
|
|
||||||
|
|
||||||
`tpl_repo_short_name`
|
|
||||||
|
|
||||||
String. You can customize the [TPL_REPO_SHORT_NAME] by this configuration item.
|
|
||||||
|
|
||||||
`tpl_repo_full_name`
|
|
||||||
|
|
||||||
String. You can customize the [TPL_REPO_FULL_NAME] by this configuration item.
|
|
||||||
|
|
||||||
`tpl_build_status_success`
|
|
||||||
|
|
||||||
String. You can customize the [TPL_BUILD_STATUS] (when status=`success`) by this configuration item.
|
|
||||||
|
|
||||||
`tpl_build_status_failure`
|
|
||||||
|
|
||||||
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 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])
|
|
||||||
|
|
||||||
[[TPL_AUTHOR_NAME]([TPL_AUTHOR_EMAIL])](mailto:[TPL_AUTHOR_EMAIL])
|
|
||||||
|
|
||||||
[Click To The Build Detail Page [TPL_STATUS_EMOTICON)]]([TPL_BUILD_LINK])
|
|
||||||
You can write your own `tpl` what you want. The syntax of `tpl` is very simple, you can fill `tpl` with preset variables. It's a list of currently supported preset variables:
|
|
||||||
|
|
||||||
| Variable | Value |
|
|
||||||
| :-------------------: | :-------------------------------------------------: |
|
|
||||||
| [TPL_REPO_SHORT_NAME] | current repo name(bare name) |
|
|
||||||
| [TPL_REPO_FULL_NAME] | the full name(with group name) of current repo |
|
|
||||||
| [TPL_REPO_GROUP_NAME] | the group name of current repo |
|
|
||||||
| [TPL_REPO_OWNER_NAME] | the owner name of current repo |
|
|
||||||
| [TPL_REPO_REMOTE_URL] | the remote url of current repo |
|
|
||||||
| [TPL_BUILD_STATUS] | current build status(e.g., success, failure) |
|
|
||||||
| [TPL_BUILD_LINK] | current build link |
|
|
||||||
| [TPL_BUILD_EVENT] | current build event(e.g., push, pull request, etc.) |
|
|
||||||
| [TPL_BUILD_CONSUMING] | current build consuming, second |
|
|
||||||
| [TPL_COMMIT_SHA] | current commit sha |
|
|
||||||
| [TPL_COMMIT_REF] | current commit ref(e.g., refs/heads/master, etc.) |
|
|
||||||
| [TPL_COMMIT_LINK] | current commit remote url link |
|
|
||||||
| [TPL_COMMIT_BRANCH] | current branch name(e.g., dev, etc) |
|
|
||||||
| [TPL_COMMIT_MSG] | current commit message |
|
|
||||||
| [TPL_AUTHOR_NAME] | current commit author name |
|
|
||||||
| [TPL_AUTHOR_EMAIL] | current commit author email |
|
|
||||||
| [TPL_AUTHOR_USERNAME] | current commit author username |
|
|
||||||
| [TPL_AUTHOR_AVATAR] | current commit author avatar |
|
|
||||||
| [TPL_STATUS_PIC] | custom pic for build status |
|
|
||||||
| [TPL_STATUS_COLOR] | custom color for build status |
|
|
||||||
| [TPL_STATUS_EMOTICON] | custom emoticon for build status |
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Screen Shot
|
### Screen Shot
|
||||||
- Send Success
|
- Send Success
|
||||||
|
|
||||||
@@ -189,35 +89,28 @@ You can write your own `tpl` what you want. The syntax of `tpl` is very simple,
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
### Todo
|
||||||
|
|
||||||
|
- Multi-Type
|
||||||
|
- Multi-Lang
|
||||||
|
- More User Customization
|
||||||
|
|
||||||
|
|
||||||
### Development
|
### Development
|
||||||
We use `go mod` to manage dependencies, so it's easy to build.
|
|
||||||
|
|
||||||
- get this repo
|
- First get this repo
|
||||||
```shell
|
```shell
|
||||||
$ git clone https://github.com/lddsb/drone-dingtalk-message.git /path/to/you/want
|
go get github.com/lddsb/drone-dingtalk-message
|
||||||
|
```
|
||||||
|
- get dependent lib
|
||||||
|
```shell
|
||||||
|
dep ensure
|
||||||
```
|
```
|
||||||
- build
|
- build
|
||||||
```shell
|
```shell
|
||||||
$ cd /path/to/you/want && GO111MODULE=on go build .
|
cd $GOPATH/src/github.com/lddsb/drone-dingtalk-message && go build .
|
||||||
```
|
```
|
||||||
- run
|
- run
|
||||||
```shell
|
```shell
|
||||||
$ ./drone-dingtalk-message -h
|
./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)
|
|
||||||
-226
@@ -1,226 +0,0 @@
|
|||||||
# Drone CI的钉钉群组机器人通知插件
|
|
||||||
[](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 -->
|
|
||||||
|
|
||||||
### 怎么使用本插件
|
|
||||||
添加一个`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
|
|
||||||
```
|
|
||||||
|
|
||||||
`命令行版本`
|
|
||||||
```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 文件的位置(绝对路径)
|
|
||||||
```
|
|
||||||
|
|
||||||
### 插件参数
|
|
||||||
`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)
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
- 忘记填写Access Token(Drone Web)
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
- 忘记填写消息类型或者不支持的消息类型
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
- 默认的`markdown`消息
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
- 带颜色和链接的`markdown`消息
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
- 带颜色、链接和图片的`markdown`消息
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
### 贡献代码
|
|
||||||
本项目使用了`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`
|
|
||||||
@@ -3,7 +3,7 @@ module github.com/lddsb/drone-dingtalk-message
|
|||||||
go 1.12
|
go 1.12
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.3.0
|
||||||
github.com/lddsb/dingtalk-webhook v0.0.5
|
github.com/lddsb/dingtalk-webhook v0.0.1
|
||||||
github.com/urfave/cli v1.22.15
|
github.com/urfave/cli v1.20.0
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,31 +1,6 @@
|
|||||||
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
|
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
github.com/lddsb/dingtalk-webhook v0.0.1 h1:l4FdTMaRaHnrYfByALukFWK0ru9Rttl0dANg13/SnTI=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/lddsb/dingtalk-webhook v0.0.1/go.mod h1:5E+/sOBb6m+3ztqnZl4danEY3I5FeIwb12v12s9osbw=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||||
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/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
|
||||||
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/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.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/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,21 +4,19 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
_ "github.com/joho/godotenv/autoload"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version of cli
|
// Version of cli
|
||||||
var Version = "0.2.1219"
|
var Version = "0.1.1202"
|
||||||
|
|
||||||
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"
|
||||||
year := time.Now().Year()
|
app.Copyright = "© 2018 Dee Luo"
|
||||||
app.Copyright = fmt.Sprintf("© 2018-%d Dee Luo", year)
|
|
||||||
app.Authors = []cli.Author{
|
app.Authors = []cli.Author{
|
||||||
{
|
{
|
||||||
Name: "Dee Luo",
|
Name: "Dee Luo",
|
||||||
@@ -29,45 +27,36 @@ func main() {
|
|||||||
app.Version = Version
|
app.Version = Version
|
||||||
app.Flags = []cli.Flag{
|
app.Flags = []cli.Flag{
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "config.debug,debug",
|
Name: "config.debug",
|
||||||
Usage: "debug mode",
|
Usage: "debug mode",
|
||||||
EnvVar: "PLUGIN_DEBUG",
|
EnvVar: "PLUGIN_DEBUG",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
|
||||||
Name: "config.tips.title",
|
|
||||||
Usage: "customize the tips title",
|
|
||||||
EnvVar: "PLUGIN_TIPS_TITLE",
|
|
||||||
},
|
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "config.token,access_token,token",
|
Name: "config.token,access_token,token",
|
||||||
Usage: "DingTalk webhook access token",
|
Usage: "dingtalk webhook access token",
|
||||||
EnvVar: "PLUGIN_ACCESS_TOKEN,PLUGIN_TOKEN",
|
EnvVar: "PLUGIN_ACCESS_TOKEN,PLUGIN_TOKEN",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "config.secret,secret",
|
Name: "config.lang",
|
||||||
Usage: "DingTalk WebHook secret for generate sign",
|
Value: "zh_CN",
|
||||||
EnvVar: "PLUGIN_SECRET",
|
Usage: "the lang display (zh_CN or en_US, zh_CN is default)",
|
||||||
|
EnvVar: "PLUGIN_LANG",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "config.message.type,message_type,type",
|
Name: "config.message.type,message_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,at.all",
|
Name: "config.message.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,mobiles",
|
Name: "config.message.at.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",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
|
||||||
Name: "commit.author.username",
|
|
||||||
Usage: "providers the author username for the current commit",
|
|
||||||
EnvVar: "DRONE_COMMIT_AUTHOR",
|
|
||||||
},
|
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "commit.author.avatar",
|
Name: "commit.author.avatar",
|
||||||
Usage: "providers the author avatar url for the current commit",
|
Usage: "providers the author avatar url for the current commit",
|
||||||
@@ -105,45 +94,10 @@ func main() {
|
|||||||
EnvVar: "DRONE_COMMIT_SHA",
|
EnvVar: "DRONE_COMMIT_SHA",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "commit.ref",
|
Name: "repo.fullname",
|
||||||
Usage: "provider the commit ref for the current build",
|
|
||||||
EnvVar: "DRONE_COMMIT_REF",
|
|
||||||
},
|
|
||||||
cli.StringFlag{
|
|
||||||
Name: "repo.full.name",
|
|
||||||
Usage: "providers the full name of the repository",
|
Usage: "providers the full name of the repository",
|
||||||
EnvVar: "DRONE_REPO",
|
EnvVar: "DRONE_REPO",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
|
||||||
Name: "repo.name",
|
|
||||||
Usage: "provider the name of the repository",
|
|
||||||
EnvVar: "DRONE_REPO_NAME",
|
|
||||||
},
|
|
||||||
cli.StringFlag{
|
|
||||||
Name: "repo.group",
|
|
||||||
Usage: "provider the group of the repository",
|
|
||||||
EnvVar: "DRONE_REPO_NAMESPACE",
|
|
||||||
},
|
|
||||||
cli.StringFlag{
|
|
||||||
Name: "repo.remote.url",
|
|
||||||
Usage: "provider the remote url of the repository",
|
|
||||||
EnvVar: "DRONE_REMOTE_URL",
|
|
||||||
},
|
|
||||||
cli.StringFlag{
|
|
||||||
Name: "repo.owner",
|
|
||||||
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{
|
cli.StringFlag{
|
||||||
Name: "build.status",
|
Name: "build.status",
|
||||||
Usage: "build status",
|
Usage: "build status",
|
||||||
@@ -156,85 +110,40 @@ func main() {
|
|||||||
EnvVar: "DRONE_BUILD_LINK",
|
EnvVar: "DRONE_BUILD_LINK",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "build.event",
|
Name: "config.success.pic.url",
|
||||||
Usage: "build event",
|
Usage: "config success picture url",
|
||||||
EnvVar: "DRONE_BUILD_EVENT",
|
|
||||||
},
|
|
||||||
cli.Uint64Flag{
|
|
||||||
Name: "build.started",
|
|
||||||
Usage: "build started",
|
|
||||||
EnvVar: "DRONE_BUILD_STARTED",
|
|
||||||
},
|
|
||||||
cli.Uint64Flag{
|
|
||||||
Name: "build.finished",
|
|
||||||
Usage: "build finished",
|
|
||||||
EnvVar: "DRONE_BUILD_FINISHED",
|
|
||||||
},
|
|
||||||
cli.StringFlag{
|
|
||||||
Name: "tpl.build.status.success",
|
|
||||||
Usage: "tpl.build status for replace success",
|
|
||||||
EnvVar: "TPL_BUILD_STATUS_SUCCESS, PLUGIN_TPL_BUILD_STATUS_SUCCESS",
|
|
||||||
},
|
|
||||||
cli.StringFlag{
|
|
||||||
Name: "tpl.build.status.failure",
|
|
||||||
Usage: "tpl.build status for replace failure",
|
|
||||||
EnvVar: "TPL_BUILD_STATUS_FAILURE, PLUGIN_TPL_BUILD_STATUS_FAILURE",
|
|
||||||
},
|
|
||||||
cli.StringFlag{
|
|
||||||
Name: "custom.pic.url.success",
|
|
||||||
Usage: "custom success picture url",
|
|
||||||
EnvVar: "SUCCESS_PICTURE_URL,PLUGIN_SUCCESS_PIC",
|
EnvVar: "SUCCESS_PICTURE_URL,PLUGIN_SUCCESS_PIC",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "custom.pic.url.failure",
|
Name: "config.failure.pic.url",
|
||||||
Usage: "custom failure picture url",
|
Usage: "config failure picture url",
|
||||||
EnvVar: "FAILURE_PICTURE_URL,PLUGIN_FAILURE_PIC",
|
EnvVar: "FAILURE_PICTURE_URL,PLUGIN_FAILURE_PIC",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "custom.color.success",
|
Name: "config.success.color",
|
||||||
Usage: "custom success color for title in markdown",
|
Usage: "config success color for title in markdown",
|
||||||
EnvVar: "SUCCESS_COLOR,PLUGIN_SUCCESS_COLOR",
|
EnvVar: "SUCCESS_COLOR,PLUGIN_SUCCESS_COLOR",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "custom.color.failure",
|
Name: "config.failure.color",
|
||||||
Usage: "custom failure color for title in markdown",
|
Usage: "config failure color for title in markdown",
|
||||||
EnvVar: "FAILURE_COLOR,PLUGIN_FAILURE_COLOR",
|
EnvVar: "FAILURE_COLOR,PLUGIN_FAILURE_COLOR",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.BoolFlag{
|
||||||
Name: "custom.tpl,tpl",
|
Name: "config.message.color",
|
||||||
Usage: "custom tpl",
|
Usage: "configure the message with color or not",
|
||||||
EnvVar: "PLUGIN_TPL,PLUGIN_CUSTOM_TPL",
|
EnvVar: "PLUGIN_COLOR,PLUGIN_MESSAGE_COLOR",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.BoolFlag{
|
||||||
Name: "tpl.repo.full.name",
|
Name: "config.message.pic",
|
||||||
Usage: "tpl custom repo full name",
|
Usage: "configure the message with picture or not",
|
||||||
EnvVar: "PLUGIN_TPL_REPO_FULL_NAME,TPL_REPO_FULL_NAME",
|
EnvVar: "PLUGIN_PIC,PLUGIN_MESSAGE_PIC",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.BoolFlag{
|
||||||
Name: "tpl.repo.short.name",
|
Name: "config.message.sha.link",
|
||||||
Usage: "tpl custom repo short name",
|
Usage: "link sha source page or not",
|
||||||
EnvVar: "PLUGIN_TPL_REPO_SHORT_NAME,TPL_REPO_SHORT_NAME",
|
EnvVar: "PLUGIN_SHA_LINK,PLUGIN_MESSAGE_SHA_LINK",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
|
||||||
Name: "tpl.commit.branch.name",
|
|
||||||
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 {
|
if err := app.Run(os.Args); nil != err {
|
||||||
@@ -248,81 +157,54 @@ func run(c *cli.Context) {
|
|||||||
Drone: Drone{
|
Drone: Drone{
|
||||||
// repo info
|
// repo info
|
||||||
Repo: Repo{
|
Repo: Repo{
|
||||||
ShortName: c.String("repo.name"),
|
FullName: c.String("repo.fullname"),
|
||||||
GroupName: c.String("repo.group"),
|
|
||||||
OwnerName: c.String("repo.owner"),
|
|
||||||
RemoteURL: c.String("repo.remote.url"),
|
|
||||||
FullName: c.String("repo.full.name"),
|
|
||||||
},
|
},
|
||||||
// build info
|
// build info
|
||||||
Build: Build{
|
Build: Build{
|
||||||
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"),
|
|
||||||
StartAt: c.Uint64("build.started"),
|
|
||||||
FinishedAt: c.Uint64("build.finished"),
|
|
||||||
},
|
},
|
||||||
Commit: Commit{
|
Commit: Commit{
|
||||||
Sha: c.String("commit.sha"),
|
Sha: c.String("commit.sha"),
|
||||||
Branch: c.String("commit.branch"),
|
Branch: c.String("commit.branch"),
|
||||||
Message: c.String("commit.message"),
|
Message: c.String("commit.message"),
|
||||||
Link: c.String("commit.link"),
|
Link: c.String("commit.link"),
|
||||||
Author: CommitAuthor{
|
Authors: struct {
|
||||||
Avatar: c.String("commit.author.avatar"),
|
Avatar string
|
||||||
Email: c.String("commit.author.email"),
|
Email string
|
||||||
Name: c.String("commit.author.name"),
|
Name string
|
||||||
Username: c.String("commit.author.username"),
|
}{
|
||||||
|
Avatar: c.String("commit.author.avatar"),
|
||||||
|
Email: c.String("commit.author.email"),
|
||||||
|
Name: c.String("commit.author.name"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Stage: Stage{
|
|
||||||
StartedAt: c.Uint64("stage.started"),
|
|
||||||
FinishedAt: c.Uint64("stage.finished"),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
// custom config
|
// custom config
|
||||||
Config: Config{
|
Config: Config{
|
||||||
AccessToken: c.String("config.token"),
|
AccessToken: c.String("config.token"),
|
||||||
Secret: c.String("config.secret"),
|
//Lang: c.String("config.lang"),
|
||||||
IsAtALL: c.Bool("config.message.at.all"),
|
IsAtALL: c.Bool("config.message.at.all"),
|
||||||
MsgType: c.String("config.message.type"),
|
MsgType: c.String("config.message.type"),
|
||||||
Mobiles: c.String("config.message.at.mobiles"),
|
Mobiles: c.String("config.message.at.mobiles"),
|
||||||
Debug: c.Bool("config.debug"),
|
Debug: c.Bool("config.debug"),
|
||||||
TipsTitle: c.String("config.tips.title"),
|
|
||||||
},
|
},
|
||||||
Custom: Custom{
|
Extra: Extra{
|
||||||
Pic: Pic{
|
Pic: ExtraPic{
|
||||||
SuccessPicURL: c.String("custom.pic.url.success"),
|
WithPic: c.Bool("config.message.pic"),
|
||||||
FailurePicURL: c.String("custom.pic.url.failure"),
|
SuccessPicURL: c.String("config.success.pic.url"),
|
||||||
|
FailurePicURL: c.String("config.failure.pic.url"),
|
||||||
},
|
},
|
||||||
Color: Color{
|
Color: ExtraColor{
|
||||||
SuccessColor: c.String("custom.color.success"),
|
SuccessColor: c.String("config.success.color"),
|
||||||
FailureColor: c.String("custom.color.failure"),
|
FailureColor: c.String("config.failure.color"),
|
||||||
},
|
WithColor: c.Bool("config.message.color"),
|
||||||
Tpl: c.String("custom.tpl"),
|
|
||||||
Consuming: Consuming{
|
|
||||||
StartedEnv: c.String("custom.started"),
|
|
||||||
FinishedEnv: c.String("custom.finished"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Tpl: Tpl{
|
|
||||||
Repo: TplRepo{
|
|
||||||
FullName: c.String("tpl.repo.full.name"),
|
|
||||||
ShortName: c.String("tpl.repo.short.name"),
|
|
||||||
},
|
|
||||||
Commit: TplCommit{
|
|
||||||
Branch: c.String("tpl.commit.branch.name"),
|
|
||||||
},
|
|
||||||
Build: TplBuild{
|
|
||||||
Status: Status{
|
|
||||||
Success: c.String("tpl.build.status.success"),
|
|
||||||
Failure: c.String("tpl.build.status.failure"),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
LinkSha: c.Bool("config.message.sha.link"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := plugin.Exec(); nil != err {
|
if err := plugin.Exec(); nil != err {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,87 +3,63 @@ package main
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
|
||||||
"net/url"
|
|
||||||
"os"
|
|
||||||
"regexp"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
webhook "github.com/lddsb/dingtalk-webhook"
|
webhook "github.com/lddsb/dingtalk-webhook"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// Repo repo base info
|
// Repo `repo base info`
|
||||||
Repo struct {
|
Repo struct {
|
||||||
ShortName string // short name
|
FullName string // repository full name
|
||||||
GroupName string // group name
|
|
||||||
FullName string // repository full name
|
|
||||||
OwnerName string // repo owner
|
|
||||||
RemoteURL string // repo remote url
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build info
|
// Build `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
|
|
||||||
StartAt uint64 // build start at ( unix timestamp )
|
|
||||||
FinishedAt uint64 // build finish at ( unix timestamp )
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit info
|
// Commit `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)
|
||||||
Message string // providers the commit message for the current build
|
Message string // providers the commit message for the current build
|
||||||
Sha string // providers the commit sha for the current build
|
Sha string // providers the commit sha for the current build
|
||||||
Ref string // commit ref
|
Authors CommitAuthors
|
||||||
Author CommitAuthor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stage drone stage env
|
// CommitAuthors `commit author info`
|
||||||
Stage struct {
|
CommitAuthors struct {
|
||||||
StartedAt uint64
|
Avatar string // providers the author avatar for the current commit
|
||||||
FinishedAt uint64
|
Email string // providers the author email for the current commit
|
||||||
|
Name string // providers the author name for the current commit
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommitAuthor commit author info
|
// Drone `drone info`
|
||||||
CommitAuthor struct {
|
|
||||||
Avatar string // providers the author avatar for the current commit
|
|
||||||
Email string // providers the author email for the current commit
|
|
||||||
Name string // providers the author name for the current commit
|
|
||||||
Username string // the author username for the current commit
|
|
||||||
}
|
|
||||||
|
|
||||||
// Drone drone info
|
|
||||||
Drone struct {
|
Drone struct {
|
||||||
Repo Repo
|
Repo Repo
|
||||||
Build Build
|
Build Build
|
||||||
Commit Commit
|
Commit Commit
|
||||||
Stage Stage
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config plugin private config
|
// Config `plugin private config`
|
||||||
Config struct {
|
Config struct {
|
||||||
Debug bool
|
Debug bool
|
||||||
AccessToken string
|
AccessToken string
|
||||||
Secret string
|
|
||||||
IsAtALL bool
|
IsAtALL bool
|
||||||
Mobiles string
|
Mobiles string
|
||||||
Username string
|
Username string
|
||||||
MsgType string
|
MsgType string
|
||||||
TipsTitle string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MessageConfig DingTalk message struct
|
// MessageConfig `DingTalk message struct`
|
||||||
MessageConfig struct {
|
MessageConfig struct {
|
||||||
ActionCard ActionCard
|
ActionCard ActionCard
|
||||||
}
|
}
|
||||||
|
|
||||||
// ActionCard action card message struct
|
// ActionCard `action card message struct`
|
||||||
ActionCard struct {
|
ActionCard struct {
|
||||||
LinkUrls string
|
LinkUrls string
|
||||||
LinkTitles string
|
LinkTitles string
|
||||||
@@ -91,109 +67,56 @@ type (
|
|||||||
BtnOrientation bool
|
BtnOrientation bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pic extra config for pic
|
// Extra `extra variables`
|
||||||
Pic struct {
|
Extra struct {
|
||||||
|
Color ExtraColor
|
||||||
|
Pic ExtraPic
|
||||||
|
LinkSha bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExtraPic `extra config for pic`
|
||||||
|
ExtraPic struct {
|
||||||
|
WithPic bool
|
||||||
SuccessPicURL string
|
SuccessPicURL string
|
||||||
FailurePicURL string
|
FailurePicURL string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Color extra config for color
|
// ExtraColor `extra config for color`
|
||||||
Color struct {
|
ExtraColor struct {
|
||||||
|
WithColor bool
|
||||||
SuccessColor string
|
SuccessColor string
|
||||||
FailureColor string
|
FailureColor string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plugin plugin all config
|
// Plugin `plugin all config`
|
||||||
Plugin struct {
|
Plugin struct {
|
||||||
Tpl Tpl
|
Drone Drone
|
||||||
Drone Drone
|
Config Config
|
||||||
Config Config
|
Extra Extra
|
||||||
Custom Custom
|
|
||||||
Message MessageConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
// Custom user custom env
|
|
||||||
Custom struct {
|
|
||||||
Tpl string
|
|
||||||
Color Color
|
|
||||||
Pic Pic
|
|
||||||
Consuming Consuming
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 {
|
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 0 == len(p.Config.AccessToken) {
|
||||||
msg := "missing DingTalk access token"
|
msg := "missing dingtalk access token"
|
||||||
return errors.New(msg)
|
return errors.New(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
tpl, err := p.getMessage()
|
if 6 > len(p.Drone.Commit.Sha) {
|
||||||
if err != nil {
|
return errors.New("commit sha cannot short than 6")
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if p.Config.TipsTitle == "" {
|
|
||||||
p.Config.TipsTitle = "you have a new message"
|
|
||||||
}
|
|
||||||
|
|
||||||
newWebHook := webhook.NewWebHook(p.Config.AccessToken)
|
|
||||||
|
|
||||||
// add sign
|
|
||||||
if "" != p.Config.Secret {
|
|
||||||
newWebHook.Secret = p.Config.Secret
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newWebhook := webhook.NewWebHook(p.Config.AccessToken)
|
||||||
mobiles := strings.Split(p.Config.Mobiles, ",")
|
mobiles := strings.Split(p.Config.Mobiles, ",")
|
||||||
switch strings.ToLower(p.Config.MsgType) {
|
switch strings.ToLower(p.Config.MsgType) {
|
||||||
case "markdown":
|
case "markdown":
|
||||||
err = newWebHook.SendMarkdownMsg(p.Config.TipsTitle, tpl, p.Config.IsAtALL, mobiles...)
|
err = newWebhook.SendMarkdownMsg("You have a new message...", p.baseTpl(), p.Config.IsAtALL, mobiles...)
|
||||||
case "text":
|
case "text":
|
||||||
err = newWebHook.SendTextMsg(tpl, p.Config.IsAtALL, mobiles...)
|
err = newWebhook.SendTextMsg(p.baseTpl(), p.Config.IsAtALL, mobiles...)
|
||||||
case "link":
|
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, p.baseTpl(), p.Drone.Commit.Authors.Avatar, p.Drone.Build.Link)
|
||||||
default:
|
default:
|
||||||
msg := "not support message type"
|
msg := "not support message type"
|
||||||
err = errors.New(msg)
|
err = errors.New(msg)
|
||||||
@@ -206,174 +129,90 @@ func (p *Plugin) Exec() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// fileExists check file is exists
|
// markdownTpl `output the tpl of markdown`
|
||||||
func fileExists(filePath string) bool {
|
func (p *Plugin) markdownTpl() string {
|
||||||
_, err := os.Stat(filePath)
|
var tpl string
|
||||||
if err != nil {
|
|
||||||
if os.IsExist(err) {
|
// title
|
||||||
return true
|
title := fmt.Sprintf(" %s *Branch Build %s*",
|
||||||
}
|
strings.Title(p.Drone.Commit.Branch),
|
||||||
return false
|
strings.Title(p.Drone.Build.Status))
|
||||||
|
// with color on title
|
||||||
|
if p.Extra.Color.WithColor {
|
||||||
|
title = fmt.Sprintf("<font color=%s>%s</font>", p.getColor(), title)
|
||||||
}
|
}
|
||||||
return true
|
|
||||||
|
tpl = fmt.Sprintf("# %s \n", title)
|
||||||
|
|
||||||
|
// with pic
|
||||||
|
if p.Extra.Pic.WithPic {
|
||||||
|
tpl += fmt.Sprintf("\n\n",
|
||||||
|
p.Drone.Build.Status,
|
||||||
|
p.getPicURL())
|
||||||
|
}
|
||||||
|
|
||||||
|
// commit message
|
||||||
|
commitMsg := fmt.Sprintf("%s", p.Drone.Commit.Message)
|
||||||
|
if p.Extra.Color.WithColor {
|
||||||
|
commitMsg = fmt.Sprintf("<font color=%s>%s</font>", p.getColor(), commitMsg)
|
||||||
|
}
|
||||||
|
tpl += commitMsg + "\n\n"
|
||||||
|
|
||||||
|
// sha info
|
||||||
|
commitSha := p.Drone.Commit.Sha
|
||||||
|
if p.Extra.LinkSha {
|
||||||
|
commitSha = fmt.Sprintf("[Click To %s Commit Detail Page](%s)", commitSha[:6], p.Drone.Commit.Link)
|
||||||
|
}
|
||||||
|
tpl += commitSha + "\n\n"
|
||||||
|
|
||||||
|
// author info
|
||||||
|
authorInfo := fmt.Sprintf("`%s(%s)`", p.Drone.Commit.Authors.Name, p.Drone.Commit.Authors.Email)
|
||||||
|
tpl += authorInfo + "\n\n"
|
||||||
|
|
||||||
|
// build detail link
|
||||||
|
buildDetail := fmt.Sprintf("[Click To The Build Detail Page %s](%s)",
|
||||||
|
p.getEmoticon(),
|
||||||
|
p.Drone.Build.Link)
|
||||||
|
tpl += buildDetail
|
||||||
|
return tpl
|
||||||
}
|
}
|
||||||
|
|
||||||
// getTpl get tpl from local file or remote file
|
func (p *Plugin) baseTpl() string {
|
||||||
func (p *Plugin) getTpl() (tpl string, err error) {
|
tpl := ""
|
||||||
//var tpl string
|
switch strings.ToLower(p.Config.MsgType) {
|
||||||
tplDir := "/app/drone/dingtalk/message/tpls"
|
case "markdown":
|
||||||
if "" == p.Custom.Tpl {
|
tpl = p.markdownTpl()
|
||||||
p.Custom.Tpl = fmt.Sprintf("%s/%s.tpl", tplDir, strings.ToLower(p.Config.MsgType))
|
case "text":
|
||||||
}
|
tpl = fmt.Sprintf(`[%s] %s
|
||||||
|
%s (%s)
|
||||||
|
@%s
|
||||||
|
%s (%s)
|
||||||
|
`,
|
||||||
|
p.Drone.Build.Status,
|
||||||
|
strings.TrimSpace(p.Drone.Commit.Message),
|
||||||
|
p.Drone.Repo.FullName,
|
||||||
|
p.Drone.Commit.Branch,
|
||||||
|
p.Drone.Commit.Sha,
|
||||||
|
p.Drone.Commit.Authors.Name,
|
||||||
|
p.Drone.Commit.Authors.Email)
|
||||||
|
case "link":
|
||||||
|
tpl = fmt.Sprintf(`%s(%s) @%s %s(%s)`,
|
||||||
|
p.Drone.Repo.FullName,
|
||||||
|
p.Drone.Commit.Branch,
|
||||||
|
p.Drone.Commit.Sha[:6],
|
||||||
|
p.Drone.Commit.Authors.Name,
|
||||||
|
p.Drone.Commit.Authors.Email)
|
||||||
|
case "actionCard":
|
||||||
|
// coming soon
|
||||||
|
|
||||||
u, err := url.Parse(p.Custom.Tpl)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
if u.Scheme != "" {
|
|
||||||
resp, err := http.Get(p.Custom.Tpl)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
// check response
|
|
||||||
if u.Path != resp.Request.URL.Path {
|
|
||||||
return "", errors.New("cannot get tpl from url")
|
|
||||||
}
|
|
||||||
|
|
||||||
// defer close
|
|
||||||
defer func() {
|
|
||||||
_ = resp.Body.Close()
|
|
||||||
}()
|
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
tpl = string(body)
|
|
||||||
} else {
|
|
||||||
if !fileExists(p.Custom.Tpl) {
|
|
||||||
// it must be a tpl stream
|
|
||||||
return p.Custom.Tpl, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
tplStr, err := ioutil.ReadFile(p.Custom.Tpl)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
tpl = string(tplStr)
|
|
||||||
}
|
|
||||||
|
|
||||||
return tpl, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// fillTpl fill the tpl by valid keyword
|
|
||||||
func (p *Plugin) fillTpl(tpl string) string {
|
|
||||||
envs := p.getEnvs()
|
|
||||||
// replace regex
|
|
||||||
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
|
|
||||||
tpl = strings.ReplaceAll(tpl, m[0], envs[m[1]].(string))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return tpl
|
return tpl
|
||||||
}
|
}
|
||||||
|
|
||||||
// getEnvs get available envs
|
/**
|
||||||
func (p *Plugin) getEnvs() map[string]interface{} {
|
get emoticon
|
||||||
var envs map[string]interface{}
|
*/
|
||||||
envs = make(map[string]interface{})
|
|
||||||
envs["TPL_REPO_FULL_NAME"] = p.Drone.Repo.FullName
|
|
||||||
if p.Tpl.Repo.FullName != "" {
|
|
||||||
envs["TPL_REPO_FULL_NAME"] = p.Tpl.Repo.FullName
|
|
||||||
}
|
|
||||||
envs["TPL_REPO_SHORT_NAME"] = p.Drone.Repo.ShortName
|
|
||||||
if p.Tpl.Repo.ShortName != "" {
|
|
||||||
envs["TPL_REPO_SHORT_NAME"] = p.Tpl.Repo.ShortName
|
|
||||||
}
|
|
||||||
envs["TPL_REPO_GROUP_NAME"] = p.Drone.Repo.GroupName
|
|
||||||
envs["TPL_REPO_OWNER_NAME"] = p.Drone.Repo.OwnerName
|
|
||||||
envs["TPL_REPO_REMOTE_URL"] = p.Drone.Repo.RemoteURL
|
|
||||||
|
|
||||||
envs["TPL_BUILD_STATUS"] = p.getStatus()
|
|
||||||
envs["TPL_BUILD_LINK"] = p.Drone.Build.Link
|
|
||||||
envs["TPL_BUILD_EVENT"] = p.Drone.Build.Event
|
|
||||||
|
|
||||||
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
|
|
||||||
envs["TPL_COMMIT_LINK"] = p.Drone.Commit.Link
|
|
||||||
envs["TPL_COMMIT_MSG"] = p.Drone.Commit.Message
|
|
||||||
envs["TPL_COMMIT_BRANCH"] = p.Drone.Commit.Branch
|
|
||||||
if p.Tpl.Commit.Branch != "" {
|
|
||||||
envs["TPL_COMMIT_BRANCH"] = p.Tpl.Commit.Branch
|
|
||||||
}
|
|
||||||
|
|
||||||
envs["TPL_AUTHOR_NAME"] = p.Drone.Commit.Author.Name
|
|
||||||
envs["TPL_AUTHOR_USERNAME"] = p.Drone.Commit.Author.Username
|
|
||||||
envs["TPL_AUTHOR_EMAIL"] = p.Drone.Commit.Author.Email
|
|
||||||
envs["TPL_AUTHOR_AVATAR"] = p.Drone.Commit.Author.Avatar
|
|
||||||
|
|
||||||
envs["TPL_STATUS_PIC"] = p.getPicURL()
|
|
||||||
envs["TPL_STATUS_COLOR"] = p.getColor()
|
|
||||||
envs["TPL_STATUS_EMOTICON"] = p.getEmoticon()
|
|
||||||
|
|
||||||
return envs
|
|
||||||
}
|
|
||||||
|
|
||||||
// getMessage get message tpl
|
|
||||||
func (p *Plugin) getMessage() (tpl string, err error) {
|
|
||||||
tpl, err = p.getTpl()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return p.fillTpl(tpl), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// getStatus
|
|
||||||
func (p *Plugin) getStatus() string {
|
|
||||||
if p.Drone.Build.Status == "success" {
|
|
||||||
if p.Tpl.Build.Status.Success != "" {
|
|
||||||
return p.Tpl.Build.Status.Success
|
|
||||||
}
|
|
||||||
|
|
||||||
return p.Drone.Build.Status
|
|
||||||
}
|
|
||||||
|
|
||||||
if p.Tpl.Build.Status.Failure != "" {
|
|
||||||
return p.Tpl.Build.Status.Failure
|
|
||||||
}
|
|
||||||
|
|
||||||
return p.Drone.Build.Status
|
|
||||||
}
|
|
||||||
|
|
||||||
// get emoticon
|
|
||||||
func (p *Plugin) getEmoticon() string {
|
func (p *Plugin) getEmoticon() string {
|
||||||
emoticons := make(map[string]string)
|
emoticons := make(map[string]string)
|
||||||
emoticons["success"] = ":)"
|
emoticons["success"] = ":)"
|
||||||
@@ -387,47 +226,44 @@ func (p *Plugin) getEmoticon() string {
|
|||||||
return ":("
|
return ":("
|
||||||
}
|
}
|
||||||
|
|
||||||
// get picture url
|
/**
|
||||||
|
get picture url
|
||||||
|
*/
|
||||||
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://wx1.sinaimg.cn/large/006tNc79gy1fz05g5a7utj30he0bfjry.jpg"
|
pics["success"] = "https://ws4.sinaimg.cn/large/006tNc79gy1fz05g5a7utj30he0bfjry.jpg"
|
||||||
if p.Custom.Pic.SuccessPicURL != "" {
|
if p.Extra.Pic.SuccessPicURL != "" {
|
||||||
pics["success"] = p.Custom.Pic.SuccessPicURL
|
pics["success"] = p.Extra.Pic.SuccessPicURL
|
||||||
}
|
}
|
||||||
// failure picture url
|
// failure picture url
|
||||||
pics["failure"] = "https://wx1.sinaimg.cn/large/006tNc79gy1fz0b4fghpnj30hd0bdmxn.jpg"
|
pics["failure"] = "https://ws1.sinaimg.cn/large/006tNc79gy1fz0b4fghpnj30hd0bdmxn.jpg"
|
||||||
if p.Custom.Pic.FailurePicURL != "" {
|
if p.Extra.Pic.FailurePicURL != "" {
|
||||||
pics["failure"] = p.Custom.Pic.FailurePicURL
|
pics["failure"] = p.Extra.Pic.FailurePicURL
|
||||||
}
|
}
|
||||||
|
|
||||||
picURL, ok := pics[p.Drone.Build.Status]
|
url, ok := pics[p.Drone.Build.Status]
|
||||||
if ok {
|
if ok {
|
||||||
return picURL
|
return url
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// get color for message title
|
/**
|
||||||
|
get color for message title
|
||||||
|
*/
|
||||||
func (p *Plugin) getColor() string {
|
func (p *Plugin) getColor() string {
|
||||||
colors := make(map[string]string)
|
colors := make(map[string]string)
|
||||||
// success color
|
// success color
|
||||||
colors["success"] = "#008000"
|
colors["success"] = "#008000"
|
||||||
if p.Custom.Color.SuccessColor != "" {
|
if p.Extra.Color.SuccessColor != "" {
|
||||||
if p.Custom.Color.SuccessColor[0] != '#' {
|
colors["success"] = "#" + p.Extra.Color.SuccessColor
|
||||||
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.Extra.Color.FailureColor != "" {
|
||||||
if p.Custom.Color.FailureColor[0] != '#' {
|
colors["failure"] = "#" + p.Extra.Color.FailureColor
|
||||||
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]
|
||||||
|
|||||||
+14
-16
@@ -12,45 +12,43 @@ func TestPlugin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
p.Config.AccessToken = "example-access-token"
|
p.Config.AccessToken = "example-access-token"
|
||||||
p.Custom.Tpl = "tpls/markdown.tpl"
|
err = p.Exec()
|
||||||
|
if nil == err {
|
||||||
|
t.Error("commit sha length error should be catch!")
|
||||||
|
}
|
||||||
|
|
||||||
|
p.Drone.Commit.Sha = "53729847dfksj"
|
||||||
err = p.Exec()
|
err = p.Exec()
|
||||||
if nil == err {
|
if nil == err {
|
||||||
t.Error("not support message type error should be catch!")
|
t.Error("not support message type error should be catch!")
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Config.MsgType = "link"
|
|
||||||
err = p.Exec()
|
|
||||||
if nil == err {
|
|
||||||
t.Error("access token invalid error should be catch!")
|
|
||||||
}
|
|
||||||
|
|
||||||
p.Custom.Tpl = "https://aaa.com"
|
|
||||||
p.Config.MsgType = "text"
|
p.Config.MsgType = "text"
|
||||||
err = p.Exec()
|
err = p.Exec()
|
||||||
if nil == err {
|
if nil == err {
|
||||||
t.Error("access token invalid error should be catch!")
|
t.Error("access token invalid error should be catch!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
p.Custom.Tpl = ""
|
|
||||||
p.Config.MsgType = "link"
|
p.Config.MsgType = "link"
|
||||||
err = p.Exec()
|
err = p.Exec()
|
||||||
if nil == err {
|
if nil == err {
|
||||||
t.Error("access token invalid error should be catch!")
|
t.Error("access token invalid error should be catch!")
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Custom.Color.FailureColor = "#555555"
|
p.Extra.Color.WithColor = true
|
||||||
p.Custom.Color.SuccessColor = "#222222"
|
p.Extra.Color.FailureColor = "#555555"
|
||||||
p.Custom.Pic.FailurePicURL = "https://www.baidu.com"
|
p.Extra.Color.SuccessColor = "#222222"
|
||||||
p.Custom.Pic.SuccessPicURL = "https://www.baidu.com"
|
p.Extra.Pic.WithPic = true
|
||||||
|
p.Extra.Pic.FailurePicURL = "https://www.baidu.com"
|
||||||
|
p.Extra.Pic.SuccessPicURL = "https://www.baidu.com"
|
||||||
|
p.Extra.LinkSha = true
|
||||||
|
// p.Drone.Build.Status = "failure"
|
||||||
p.Config.MsgType = "markdown"
|
p.Config.MsgType = "markdown"
|
||||||
p.Custom.Tpl = "tpls/markdown.tpl"
|
|
||||||
err = p.Exec()
|
err = p.Exec()
|
||||||
if nil == err {
|
if nil == err {
|
||||||
t.Error("access token invalid error should be catch!")
|
t.Error("access token invalid error should be catch!")
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Custom.Tpl = "https://gist.githubusercontent.com/lddsb/87065e73678dcf56cd222a3c2f1f32b0/raw/fce9fb28b2c8c768eb93df5598beee8c98cba610/md.tpl"
|
|
||||||
p.Drone.Build.Status = "failure"
|
p.Drone.Build.Status = "failure"
|
||||||
err = p.Exec()
|
err = p.Exec()
|
||||||
if nil == err {
|
if nil == err {
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
### **[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])
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
### [TPL_REPO_SHORT_NAME] build [TPL_BUILD_STATUS] (`takes [TPL_BUILD_CONSUMING]s`)
|
|
||||||
|
|
||||||
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])
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
### [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])
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
[TPL_REPO_NAME] build [TPL_BUILD_STATUS] (takes [TPL_BUILD_CONSUMING]s)
|
|
||||||
[TPL_COMMIT_MSG]
|
|
||||||
[TPL_COMMIT_SHA] ([TPL_COMMIT_LINK])
|
|
||||||
[TPL_AUTHOR_NAME] ([TPL_AUTHOR_EMAIL])
|
|
||||||
Click To The Build Detail Page [TPL_STATUS_EMOTICON] ([TPL_BUILD_LINK])
|
|
||||||
Reference in New Issue
Block a user