Skip to content

Commit

Permalink
Merge pull request #4 from lddsb/feature/msg-tpl
Browse files Browse the repository at this point in the history
complete tpl feature
  • Loading branch information
lddsb authored Sep 20, 2019
2 parents 8d080c3 + 9cb8a9b commit 8164de1
Show file tree
Hide file tree
Showing 10 changed files with 455 additions and 221 deletions.
6 changes: 1 addition & 5 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,11 @@ steps:
settings:
cache_from: lddsb/drone-dingtalk-message
dockerfile: Dockerfile
dryrun: true
dry_run: true
repo: lddsb/drone-dingtalk-message
tags:
- latest
- 1.0.0
name:
from_secret: docker_username
password:
from_secret: docker_password

trigger:
event:
Expand Down
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
FROM golang
FROM golang AS builder
WORKDIR /app
COPY . .
RUN GO111MODULE=on go build -o drone-dingtalk-message .
RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux go build -a -o drone-dingtalk .

FROM alpine:latest
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
COPY --from=0 /app/drone-dingtalk-message /bin
ENTRYPOINT ["/bin/drone-dingtalk-message"]
COPY --from=builder /app/drone-dingtalk /bin
COPY --from=builder /app/tpls /app/tpls

ENTRYPOINT ["/bin/drone-dingtalk"]
87 changes: 69 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Drone CI DingTalk Message Plugin
[![Docker Cloud Build Status](https://img.shields.io/docker/cloud/build/lddsb/drone-dingtalk-message)](https://hub.docker.com/r/lddsb/drone-dingtalk-message) [![Go Report Card](https://goreportcard.com/badge/github.com/lddsb/drone-dingtalk-message)](https://goreportcard.com/report/github.com/lddsb/drone-dingtalk-message) [![codecov](https://codecov.io/gh/lddsb/drone-dingtalk-message/branch/master/graph/badge.svg)](https://codecov.io/gh/lddsb/drone-dingtalk-message) [![LICENSE: MIT](https://img.shields.io/github/license/lddsb/drone-dingtalk-message.svg?style=flat-square)](LICENSE)

just support `text`, `markdown` and `link` type now
### Drone CI Plugin Config
`0.8.x`
```yaml
Expand Down Expand Up @@ -36,33 +37,86 @@ 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.

`message_color`(when `type=markdown`)
`tpl`

Boolean value. This option can change the title and commit message color if turn on.
String. Your custom `tpl`, it can be a local path or a remote http link.

`success_color`(when `message_color=true`)
`success_color`

String. You can customize the color for the `build success` message by this option, you should input a hex color, example: `008000`.

`failure_color`(when `message_color=true`)
`failure_color`

String. You can customize the color for the `build success` message by this option, you should input a hex color, example: `FF0000`.

`sha_link`(when `type=markdown`)
`success_pic`

Boolean value. This option can link the sha to your source page when it turn on.
String. You can customize the picture for the `build success` message by this option.

`message_pic`(when `type=markdown`)
`failure_pic`

Boolean value. If this option turn on, it will embed a image into the message.
String. You can customize the picture for the `build failure` message by this option.

`success_pic`(when `message_pic=true`)
`tpl_commit_branch_name`

String. You can customize the picture for the `build success` message by this option.
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_sucdess`

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.

### TPL
> `tpl` won't work with message type `link` !!!

That's a good news, we support `tpl` now.This is a example for `markdown` message:

# [TPL_REPO_FULL_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])](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 |

`failure_pic`(when `message_pic=true`)

String. You can customize the picture for the `build failure` message by this option.

### Screen Shot
- Send Success
Expand All @@ -89,12 +143,6 @@ String. You can customize the picture for the `build failure` message by this op

![markdown-massage-customize](https://i.imgur.com/xFrCTZp.jpg)

### Todo

- Multi-Type
- Multi-Lang
- More User Customization


### Development
We use `go mod` to manage dependencies, so it's easy to build.
Expand All @@ -111,3 +159,6 @@ $ cd /path/to/you/want && GO111MODULE=on go build .
```shell
$ ./drone-dingtalk-message -h
```

### Todo
- implement all message type
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ go 1.12

require (
github.com/joho/godotenv v1.3.0
github.com/lddsb/dingtalk-webhook v0.0.0-20190307231412-b4abe34b5fa9
github.com/lddsb/dingtalk-webhook v0.0.1
github.com/urfave/cli v1.20.0
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/lddsb/dingtalk-webhook v0.0.0-20190307231412-b4abe34b5fa9 h1:ZeUdCEbcT0+l10jTSyjU9+18ZbDTz6TdkH6yGiCd9dQ=
github.com/lddsb/dingtalk-webhook v0.0.0-20190307231412-b4abe34b5fa9/go.mod h1:5E+/sOBb6m+3ztqnZl4danEY3I5FeIwb12v12s9osbw=
github.com/lddsb/dingtalk-webhook v0.0.1 h1:l4FdTMaRaHnrYfByALukFWK0ru9Rttl0dANg13/SnTI=
github.com/lddsb/dingtalk-webhook v0.0.1/go.mod h1:5E+/sOBb6m+3ztqnZl4danEY3I5FeIwb12v12s9osbw=
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
Loading

0 comments on commit 8164de1

Please sign in to comment.