├── .dockerignore ├── .drone.yml ├── .github ├── issue_template.md ├── pull_request_template.md └── settings.yml ├── .gitignore ├── LICENSE ├── README.md ├── docker ├── Dockerfile.linux.amd64 ├── Dockerfile.linux.arm64 ├── Dockerfile.windows.1809 ├── Dockerfile.windows.ltsc2022 └── manifest.tmpl ├── go.mod ├── go.sum ├── main.go ├── memes ├── README.md ├── archer_fail.jpg ├── grumpy_cat_deploy_fail.jpg ├── grumpy_cat_fail.jpg ├── homer_deploy_fail.jpg ├── kittens_fail.jpg ├── morpheus_deploy_fail.jpg ├── professor_success.jpg └── success_kid_deploy_success.jpg └── plugin.go /.dockerignore: -------------------------------------------------------------------------------- 1 | * 2 | !release/ 3 | -------------------------------------------------------------------------------- /.drone.yml: -------------------------------------------------------------------------------- 1 | --- 2 | kind: pipeline 3 | name: testing 4 | type: vm 5 | 6 | platform: 7 | os: linux 8 | arch: amd64 9 | pool: 10 | use: ubuntu 11 | 12 | steps: 13 | - name: vet 14 | pull: always 15 | image: golang:1.19 16 | commands: 17 | - go vet ./... 18 | environment: 19 | GO111MODULE: on 20 | volumes: 21 | - name: gopath 22 | path: /go 23 | 24 | - name: test 25 | pull: always 26 | image: golang:1.19 27 | commands: 28 | - go test -cover ./... 29 | environment: 30 | GO111MODULE: on 31 | volumes: 32 | - name: gopath 33 | path: /go 34 | 35 | volumes: 36 | - name: gopath 37 | temp: {} 38 | 39 | trigger: 40 | ref: 41 | - refs/heads/master 42 | - "refs/tags/**" 43 | - "refs/pull/**" 44 | 45 | --- 46 | kind: pipeline 47 | name: linux-amd64 48 | type: vm 49 | 50 | platform: 51 | os: linux 52 | arch: amd64 53 | pool: 54 | use: ubuntu 55 | 56 | steps: 57 | - name: build-push 58 | pull: always 59 | image: golang:1.19 60 | commands: 61 | - 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/linux/amd64/drone-slack-blame' 62 | environment: 63 | CGO_ENABLED: 0 64 | GO111MODULE: on 65 | when: 66 | event: 67 | exclude: 68 | - tag 69 | 70 | - name: build-tag 71 | pull: always 72 | image: golang:1.19 73 | commands: 74 | - 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/linux/amd64/drone-slack-blame' 75 | environment: 76 | CGO_ENABLED: 0 77 | GO111MODULE: on 78 | when: 79 | event: 80 | - tag 81 | 82 | - name: executable 83 | pull: always 84 | image: golang:1.19 85 | commands: 86 | - ./release/linux/amd64/drone-slack-blame --help 87 | 88 | - name: publish 89 | pull: always 90 | image: plugins/docker:linux-amd64 91 | settings: 92 | auto_tag: true 93 | auto_tag_suffix: linux-amd64 94 | daemon_off: false 95 | dockerfile: docker/Dockerfile.linux.amd64 96 | password: 97 | from_secret: docker_password 98 | repo: plugins/slack-blame 99 | username: 100 | from_secret: docker_username 101 | when: 102 | ref: 103 | - refs/heads/master 104 | - refs/tags/** 105 | 106 | trigger: 107 | ref: 108 | - refs/heads/master 109 | - "refs/tags/**" 110 | - "refs/pull/**" 111 | 112 | depends_on: 113 | - testing 114 | 115 | --- 116 | kind: pipeline 117 | name: linux-arm64 118 | type: vm 119 | 120 | platform: 121 | os: linux 122 | arch: arm64 123 | pool: 124 | use: ubuntu_arm64 125 | 126 | steps: 127 | - name: build-push 128 | pull: always 129 | image: golang:1.19 130 | commands: 131 | - 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/linux/arm64/drone-slack-blame' 132 | environment: 133 | CGO_ENABLED: 0 134 | GO111MODULE: on 135 | when: 136 | event: 137 | exclude: 138 | - tag 139 | 140 | - name: build-tag 141 | pull: always 142 | image: golang:1.19 143 | commands: 144 | - 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/linux/arm64/drone-slack-blame' 145 | environment: 146 | CGO_ENABLED: 0 147 | GO111MODULE: on 148 | when: 149 | event: 150 | - tag 151 | 152 | - name: executable 153 | pull: always 154 | image: golang:1.19 155 | commands: 156 | - ./release/linux/arm64/drone-slack-blame --help 157 | 158 | - name: publish 159 | pull: always 160 | image: plugins/docker:linux-arm64 161 | settings: 162 | auto_tag: true 163 | auto_tag_suffix: linux-arm64 164 | daemon_off: false 165 | dockerfile: docker/Dockerfile.linux.arm64 166 | password: 167 | from_secret: docker_password 168 | repo: plugins/slack-blame 169 | username: 170 | from_secret: docker_username 171 | when: 172 | ref: 173 | - refs/heads/master 174 | - refs/tags/** 175 | 176 | trigger: 177 | ref: 178 | - refs/heads/master 179 | - "refs/tags/**" 180 | - "refs/pull/**" 181 | 182 | depends_on: 183 | - testing 184 | 185 | --- 186 | kind: pipeline 187 | type: vm 188 | name: windows-1809 189 | 190 | platform: 191 | os: windows 192 | arch: amd64 193 | 194 | pool: 195 | use: windows 196 | 197 | steps: 198 | - name: environment 199 | image: golang:1.19 200 | pull: always 201 | environment: 202 | CGO_ENABLED: "0" 203 | commands: 204 | - go version 205 | - go env 206 | - name: build 207 | image: golang:1.19 208 | environment: 209 | CGO_ENABLED: "0" 210 | commands: 211 | - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/windows/amd64/drone-slack-blame.exe . 212 | - name: docker 213 | image: plugins/docker 214 | settings: 215 | dockerfile: docker/Dockerfile.windows.1809 216 | repo: plugins/slack-blame 217 | username: 218 | from_secret: docker_username 219 | password: 220 | from_secret: docker_password 221 | auto_tag: true 222 | auto_tag_suffix: windows-1809-amd64 223 | daemon_off: true 224 | purge: false 225 | when: 226 | ref: 227 | - refs/heads/master 228 | - refs/tags/** 229 | depends_on: 230 | - testing 231 | trigger: 232 | ref: 233 | - refs/heads/master 234 | - refs/tags/** 235 | - refs/pull/** 236 | 237 | --- 238 | kind: pipeline 239 | type: vm 240 | name: windows-ltsc2022 241 | 242 | platform: 243 | os: windows 244 | arch: amd64 245 | 246 | pool: 247 | use: windows-2022 248 | 249 | steps: 250 | - name: environment 251 | image: golang:1.19 252 | pull: always 253 | environment: 254 | CGO_ENABLED: "0" 255 | commands: 256 | - go version 257 | - go env 258 | - name: build 259 | image: golang:1.19 260 | environment: 261 | CGO_ENABLED: "0" 262 | commands: 263 | - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/windows/amd64/drone-slack-blame.exe . 264 | - name: docker 265 | image: plugins/docker 266 | settings: 267 | dockerfile: docker/Dockerfile.windows.ltsc2022 268 | repo: plugins/slack-blame 269 | username: 270 | from_secret: docker_username 271 | password: 272 | from_secret: docker_password 273 | auto_tag: true 274 | auto_tag_suffix: windows-ltsc2022-amd64 275 | daemon_off: true 276 | purge: false 277 | when: 278 | ref: 279 | - refs/heads/master 280 | - refs/tags/** 281 | depends_on: 282 | - testing 283 | trigger: 284 | ref: 285 | - refs/heads/master 286 | - refs/tags/** 287 | - refs/pull/** 288 | 289 | --- 290 | kind: pipeline 291 | name: notifications 292 | type: vm 293 | 294 | platform: 295 | os: linux 296 | arch: amd64 297 | pool: 298 | use: ubuntu 299 | 300 | steps: 301 | - name: manifest 302 | pull: always 303 | image: plugins/manifest 304 | settings: 305 | auto_tag: true 306 | ignore_missing: true 307 | password: 308 | from_secret: docker_password 309 | spec: docker/manifest.tmpl 310 | username: 311 | from_secret: docker_username 312 | 313 | trigger: 314 | ref: 315 | - refs/heads/master 316 | - "refs/tags/**" 317 | 318 | depends_on: 319 | - linux-amd64 320 | - linux-arm64 321 | - windows-1809 322 | - windows-ltsc2022 323 | -------------------------------------------------------------------------------- /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drone-plugins/drone-slack-blame/4207428a5c023c6ebadcabe286ac77baf444383d/.github/pull_request_template.md -------------------------------------------------------------------------------- /.github/settings.yml: -------------------------------------------------------------------------------- 1 | repository: 2 | name: drone-slack-blame 3 | description: Drone plugin to send build status blames via Slack 4 | homepage: http://plugins.drone.io/drone-plugins/drone-slack-blame 5 | topics: drone, drone-plugin 6 | 7 | private: false 8 | has_issues: true 9 | has_wiki: false 10 | has_downloads: false 11 | 12 | default_branch: master 13 | 14 | allow_squash_merge: true 15 | allow_merge_commit: true 16 | allow_rebase_merge: true 17 | 18 | labels: 19 | - name: bug 20 | color: d73a4a 21 | description: Something isn't working 22 | - name: duplicate 23 | color: cfd3d7 24 | description: This issue or pull request already exists 25 | - name: enhancement 26 | color: a2eeef 27 | description: New feature or request 28 | - name: good first issue 29 | color: 7057ff 30 | description: Good for newcomers 31 | - name: help wanted 32 | color: 008672 33 | description: Extra attention is needed 34 | - name: invalid 35 | color: e4e669 36 | description: This doesn't seem right 37 | - name: question 38 | color: d876e3 39 | description: Further information is requested 40 | - name: renovate 41 | color: e99695 42 | description: Automated action from Renovate 43 | - name: wontfix 44 | color: ffffff 45 | description: This will not be worked on 46 | 47 | teams: 48 | - name: Admins 49 | permission: admin 50 | - name: Captain 51 | permission: admin 52 | - name: Maintainers 53 | permission: push 54 | 55 | branches: 56 | - name: master 57 | protection: 58 | required_pull_request_reviews: 59 | required_approving_review_count: 1 60 | dismiss_stale_reviews: false 61 | require_code_owner_reviews: false 62 | dismissal_restrictions: 63 | teams: 64 | - Admins 65 | - Captain 66 | required_status_checks: 67 | strict: true 68 | contexts: 69 | - continuous-integration/drone/pr 70 | enforce_admins: false 71 | restrictions: 72 | users: [] 73 | teams: [] 74 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | 26 | release/ 27 | vendor/ 28 | 29 | coverage.out 30 | drone-slack-blame 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # drone-slack-blame 2 | 3 | [![Build Status](http://cloud.drone.io/api/badges/drone-plugins/drone-slack-blame/status.svg)](http://cloud.drone.io/drone-plugins/drone-slack-blame) 4 | [![Gitter chat](https://badges.gitter.im/drone/drone.png)](https://gitter.im/drone/drone) 5 | [![Join the discussion at https://discourse.drone.io](https://img.shields.io/badge/discourse-forum-orange.svg)](https://discourse.drone.io) 6 | [![Drone questions at https://stackoverflow.com](https://img.shields.io/badge/drone-stackoverflow-orange.svg)](https://stackoverflow.com/questions/tagged/drone.io) 7 | [![](https://images.microbadger.com/badges/image/plugins/slack-blame.svg)](https://microbadger.com/images/plugins/slack-blame "Get your own image badge on microbadger.com") 8 | [![Go Doc](https://godoc.org/github.com/drone-plugins/drone-slack-blame?status.svg)](http://godoc.org/github.com/drone-plugins/drone-slack-blame) 9 | [![Go Report](https://goreportcard.com/badge/github.com/drone-plugins/drone-slack-blame)](https://goreportcard.com/report/github.com/drone-plugins/drone-slack-blame) 10 | 11 | Drone plugin to send build status blames via Slack. For the usage information and a listing of the available options please take a look at [the docs](http://plugins.drone.io/drone-plugins/drone-slack-blame/). 12 | 13 | ## Build 14 | 15 | Build the binary with the following command: 16 | 17 | ```console 18 | export GOOS=linux 19 | export GOARCH=amd64 20 | export CGO_ENABLED=0 21 | export GO111MODULE=on 22 | 23 | go build -v -a -tags netgo -o release/linux/amd64/drone-slack-blame 24 | ``` 25 | 26 | ## Docker 27 | 28 | Build the Docker image with the following command: 29 | 30 | ```console 31 | docker build \ 32 | --label org.label-schema.build-date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \ 33 | --label org.label-schema.vcs-ref=$(git rev-parse --short HEAD) \ 34 | --file docker/Dockerfile.linux.amd64 --tag plugins/slack-blame . 35 | ``` 36 | 37 | ## Usage 38 | 39 | ```console 40 | docker run --rm \ 41 | -e PLUGIN_TOKEN=xxxxx \ 42 | -e PLUGIN_CHANNEL=dev \ 43 | -e PLUGIN_SUCCESS_USERNAME="Happy Keanu (on behalf of Drone)" \ 44 | -e PLUGIN_SUCCESS_ICON=":happy_keanu:" \ 45 | -e PLUGIN_SUCCESS_MESSAGE="The build is fixed!" \ 46 | -e PLUGIN_SUCCESS_IMAGE_ATTACHMENTS="http://i.imgur.com/TP4PIxc.jpg" \ 47 | -e PLUGIN_FAILURE_USERNAME="Sad Keanu (on behalf of Drone)" \ 48 | -e PLUGIN_FAILURE_ICON=":sad_keanu:" \ 49 | -e PLUGIN_FAILURE_MESSAGE="The build is broken!" \ 50 | -e PLUGIN_FAILURE_IMAGE_ATTACHMENTS="http://cdn.meme.am/instances/51000361.jpg" \ 51 | -v $(pwd):$(pwd) \ 52 | -w $(pwd) \ 53 | plugins/slack-blame 54 | ``` 55 | -------------------------------------------------------------------------------- /docker/Dockerfile.linux.amd64: -------------------------------------------------------------------------------- 1 | FROM plugins/base:multiarch 2 | 3 | LABEL maintainer="Drone.IO Community " \ 4 | org.label-schema.name="Drone Slack Blame" \ 5 | org.label-schema.vendor="Drone.IO Community" \ 6 | org.label-schema.schema-version="1.0" 7 | 8 | ADD release/linux/amd64/drone-slack-blame /bin/ 9 | ENTRYPOINT ["/bin/drone-slack-blame"] 10 | -------------------------------------------------------------------------------- /docker/Dockerfile.linux.arm64: -------------------------------------------------------------------------------- 1 | FROM plugins/base:multiarch 2 | 3 | LABEL maintainer="Drone.IO Community " \ 4 | org.label-schema.name="Drone Slack Blame" \ 5 | org.label-schema.vendor="Drone.IO Community" \ 6 | org.label-schema.schema-version="1.0" 7 | 8 | ADD release/linux/arm64/drone-slack-blame /bin/ 9 | ENTRYPOINT ["/bin/drone-slack-blame"] 10 | -------------------------------------------------------------------------------- /docker/Dockerfile.windows.1809: -------------------------------------------------------------------------------- 1 | # escape=` 2 | FROM plugins/base:windows-1809-amd64@sha256:61095306fa56d51adc841f2b0f93f511efb5792d12f2549bb2eb1cbce02c1f05 3 | 4 | LABEL maintainer="Drone.IO Community " ` 5 | org.label-schema.name="Drone Slack Blame" ` 6 | org.label-schema.vendor="Drone.IO Community" ` 7 | org.label-schema.schema-version="1.0" 8 | 9 | ADD release/windows/amd64/drone-slack-blame.exe C:/bin/drone-slack-blame.exe 10 | ENTRYPOINT [ "C:\\bin\\drone-slack-blame.exe" ] 11 | -------------------------------------------------------------------------------- /docker/Dockerfile.windows.ltsc2022: -------------------------------------------------------------------------------- 1 | # escape=` 2 | FROM plugins/base:windows-ltsc2022-amd64@sha256:0f90d5bceb432f1ee6f93cf44eed6a38c322834edd55df8a6648c9e6f15131f4 3 | 4 | LABEL maintainer="Drone.IO Community " ` 5 | org.label-schema.name="Drone Slack Blame" ` 6 | org.label-schema.vendor="Drone.IO Community" ` 7 | org.label-schema.schema-version="1.0" 8 | 9 | ADD release/windows/amd64/drone-slack-blame.exe C:/bin/drone-slack-blame.exe 10 | ENTRYPOINT [ "C:\\bin\\drone-slack-blame.exe" ] 11 | -------------------------------------------------------------------------------- /docker/manifest.tmpl: -------------------------------------------------------------------------------- 1 | image: plugins/slack-blame:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}} 2 | {{#if build.tags}} 3 | tags: 4 | {{#each build.tags}} 5 | - {{this}} 6 | {{/each}} 7 | {{/if}} 8 | manifests: 9 | - 10 | image: plugins/slack-blame:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64 11 | platform: 12 | architecture: amd64 13 | os: linux 14 | - 15 | image: plugins/slack-blame:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64 16 | platform: 17 | architecture: arm64 18 | os: linux 19 | variant: v8 20 | - 21 | image: plugins/slack-blame:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1803-amd64 22 | platform: 23 | architecture: amd64 24 | os: windows 25 | version: 1803 26 | - 27 | image: plugins/slack-blame:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809-amd64 28 | platform: 29 | architecture: amd64 30 | os: windows 31 | version: 1809 32 | - 33 | image: plugins/slack-blame:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1803-amd64 34 | platform: 35 | architecture: amd64 36 | os: windows 37 | version: 1803 -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/drone-plugins/drone-slack-blame 2 | 3 | require ( 4 | github.com/drone/drone-template-lib v1.0.0 5 | github.com/nlopes/slack v0.6.0 6 | github.com/pkg/errors v0.9.1 7 | github.com/sirupsen/logrus v1.9.0 8 | github.com/urfave/cli v1.22.10 9 | ) 10 | 11 | require ( 12 | bou.ke/monkey v1.0.1 // indirect 13 | github.com/Masterminds/goutils v1.1.0 // indirect 14 | github.com/Masterminds/semver v1.4.2 // indirect 15 | github.com/Masterminds/sprig v2.20.0+incompatible // indirect 16 | github.com/aymerick/raymond v2.0.2+incompatible // indirect 17 | github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect 18 | github.com/google/uuid v1.1.1 // indirect 19 | github.com/gorilla/websocket v1.4.1 // indirect 20 | github.com/huandu/xstrings v1.2.0 // indirect 21 | github.com/imdario/mergo v0.3.7 // indirect 22 | github.com/russross/blackfriday/v2 v2.0.1 // indirect 23 | github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect 24 | github.com/tkuchiki/faketime v0.1.1 // indirect 25 | golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 // indirect 26 | golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect 27 | ) 28 | 29 | go 1.19 30 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | bou.ke/monkey v1.0.1 h1:zEMLInw9xvNakzUUPjfS4Ds6jYPqCFx3m7bRmG5NH2U= 2 | bou.ke/monkey v1.0.1/go.mod h1:FgHuK96Rv2Nlf+0u1OOVDpCMdsWyOFmeeketDHE7LIg= 3 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 4 | github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg= 5 | github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= 6 | github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITgsTc= 7 | github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= 8 | github.com/Masterminds/sprig v2.18.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o= 9 | github.com/Masterminds/sprig v2.20.0+incompatible h1:dJTKKuUkYW3RMFdQFXPU/s6hg10RgctmTjRcbZ98Ap8= 10 | github.com/Masterminds/sprig v2.20.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o= 11 | github.com/aymerick/raymond v2.0.2+incompatible h1:VEp3GpgdAnv9B2GFyTvqgcKvY+mfKMjPOA3SbKLtnU0= 12 | github.com/aymerick/raymond v2.0.2+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= 13 | github.com/bouk/monkey v1.0.0/go.mod h1:PG/63f4XEUlVyW1ttIeOJmJhhe1+t9EC/je3eTjvFhE= 14 | github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= 15 | github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 16 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 17 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 18 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 19 | github.com/drone/drone-template-lib v1.0.0 h1:PNBBfUhifRnrPCoWBlTitk3jipXdv8u8WLbIf7h7j00= 20 | github.com/drone/drone-template-lib v1.0.0/go.mod h1:Hqy1tgqPH5mtbFOZmow19l4jOkZvp+WZ00cB4W3MJhg= 21 | github.com/google/uuid v1.1.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 22 | github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= 23 | github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 24 | github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= 25 | github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= 26 | github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= 27 | github.com/huandu/xstrings v1.2.0 h1:yPeWdRnmynF7p+lLYz0H2tthW9lqhMJrQV/U7yy4wX0= 28 | github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4= 29 | github.com/imdario/mergo v0.3.7 h1:Y+UAYTZ7gDEuOfhxKWy+dvb5dRQ6rJjFSdX2HZY1/gI= 30 | github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= 31 | github.com/nlopes/slack v0.6.0 h1:jt0jxVQGhssx1Ib7naAOZEZcGdtIhTzkP0nopK0AsRA= 32 | github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= 33 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 34 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 35 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 36 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 37 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 38 | github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= 39 | github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 40 | github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= 41 | github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= 42 | github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= 43 | github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= 44 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 45 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 46 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 47 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 48 | github.com/tkuchiki/faketime v0.0.0-20170607100027-a4500a4f4643/go.mod h1:RXY/TXAwGGL36IKDjrHFMcjpUrEiyWSEtLhFPw3UWF0= 49 | github.com/tkuchiki/faketime v0.1.1 h1:UZjBlktFAi23wo+jWuHuNoHUpLnB0j/5B62bl5nCPls= 50 | github.com/tkuchiki/faketime v0.1.1/go.mod h1:RXY/TXAwGGL36IKDjrHFMcjpUrEiyWSEtLhFPw3UWF0= 51 | github.com/urfave/cli v1.22.10 h1:p8Fspmz3iTctJstry1PYS3HVdllxnEzTEsgIgtxTrCk= 52 | github.com/urfave/cli v1.22.10/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= 53 | golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 54 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 55 | golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 h1:Gv7RPwsi3eZ2Fgewe3CBsuOebPwO27PoXzRpJPsvSSM= 56 | golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 57 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 58 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 59 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 60 | golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= 61 | golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 62 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 63 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 64 | gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= 65 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 66 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 67 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 68 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | 6 | "github.com/pkg/errors" 7 | "github.com/sirupsen/logrus" 8 | "github.com/urfave/cli" 9 | ) 10 | 11 | var ( 12 | version = "unknown" 13 | ) 14 | 15 | func main() { 16 | app := cli.NewApp() 17 | app.Name = "slack blame plugin" 18 | app.Usage = "slack blame plugin" 19 | app.Action = run 20 | app.Version = version 21 | app.Flags = []cli.Flag{ 22 | cli.StringFlag{ 23 | Name: "token", 24 | Usage: "slack access token", 25 | EnvVar: "PLUGIN_TOKEN,SLACK_TOKEN", 26 | }, 27 | cli.StringFlag{ 28 | Name: "channel", 29 | Usage: "slack channel", 30 | EnvVar: "PLUGIN_CHANNEL", 31 | }, 32 | cli.StringFlag{ 33 | Name: "mapping", 34 | Usage: "mapping of authors to slack users", 35 | EnvVar: "PLUGIN_MAPPING", 36 | }, 37 | cli.StringFlag{ 38 | Name: "success_username", 39 | Usage: "username for successful builds", 40 | Value: "drone", 41 | EnvVar: "PLUGIN_SUCCESS_USERNAME", 42 | }, 43 | cli.StringFlag{ 44 | Name: "success_icon", 45 | Usage: "icon for successful builds", 46 | Value: ":drone:", 47 | EnvVar: "PLUGIN_SUCCESS_ICON", 48 | }, 49 | cli.StringFlag{ 50 | Name: "success_template", 51 | Usage: "template for successful builds", 52 | EnvVar: "PLUGIN_SUCCESS_TEMPLATE", 53 | }, 54 | cli.StringSliceFlag{ 55 | Name: "success_image_attachments", 56 | Usage: "image attachments for successful builds", 57 | EnvVar: "PLUGIN_SUCCESS_IMAGE_ATTACHMENTS", 58 | }, 59 | cli.StringFlag{ 60 | Name: "failure_username", 61 | Usage: "username for failed builds", 62 | Value: "drone", 63 | EnvVar: "PLUGIN_FAILURE_USERNAME", 64 | }, 65 | cli.StringFlag{ 66 | Name: "failure_icon", 67 | Usage: "icon for failed builds", 68 | Value: ":drone:", 69 | EnvVar: "PLUGIN_FAILURE_ICON", 70 | }, 71 | cli.StringFlag{ 72 | Name: "failure_template", 73 | Usage: "template for failed builds", 74 | EnvVar: "PLUGIN_FAILURE_TEMPLATE", 75 | }, 76 | cli.StringSliceFlag{ 77 | Name: "failure_image_attachments", 78 | Usage: "image attachments for failed builds", 79 | EnvVar: "PLUGIN_FAILURE_IMAGE_ATTACHMENTS", 80 | }, 81 | cli.StringFlag{ 82 | Name: "repo.fullname", 83 | Usage: "repository full name", 84 | EnvVar: "DRONE_REPO", 85 | }, 86 | cli.StringFlag{ 87 | Name: "repo.owner", 88 | Usage: "repository owner", 89 | EnvVar: "DRONE_REPO_OWNER", 90 | }, 91 | cli.StringFlag{ 92 | Name: "repo.name", 93 | Usage: "repository name", 94 | EnvVar: "DRONE_REPO_NAME", 95 | }, 96 | cli.StringFlag{ 97 | Name: "repo.link", 98 | Usage: "repository link", 99 | EnvVar: "DRONE_REPO_LINK", 100 | }, 101 | cli.StringFlag{ 102 | Name: "commit.sha", 103 | Usage: "git commit sha", 104 | EnvVar: "DRONE_COMMIT_SHA", 105 | }, 106 | cli.StringFlag{ 107 | Name: "commit.ref", 108 | Value: "refs/heads/master", 109 | Usage: "git commit ref", 110 | EnvVar: "DRONE_COMMIT_REF", 111 | }, 112 | cli.StringFlag{ 113 | Name: "commit.branch", 114 | Value: "master", 115 | Usage: "git commit branch", 116 | EnvVar: "DRONE_COMMIT_BRANCH", 117 | }, 118 | cli.StringFlag{ 119 | Name: "commit.message", 120 | Usage: "git commit message", 121 | EnvVar: "DRONE_COMMIT_MESSAGE", 122 | }, 123 | cli.StringFlag{ 124 | Name: "commit.link", 125 | Usage: "git commit link", 126 | EnvVar: "DRONE_COMMIT_LINK", 127 | }, 128 | cli.StringFlag{ 129 | Name: "commit.author.name", 130 | Usage: "git author name", 131 | EnvVar: "DRONE_COMMIT_AUTHOR", 132 | }, 133 | cli.StringFlag{ 134 | Name: "commit.author.email", 135 | Usage: "git author email", 136 | EnvVar: "DRONE_COMMIT_AUTHOR_EMAIL", 137 | }, 138 | cli.StringFlag{ 139 | Name: "build.event", 140 | Value: "push", 141 | Usage: "build event", 142 | EnvVar: "DRONE_BUILD_EVENT", 143 | }, 144 | cli.IntFlag{ 145 | Name: "build.number", 146 | Usage: "build number", 147 | EnvVar: "DRONE_BUILD_NUMBER", 148 | }, 149 | cli.StringFlag{ 150 | Name: "build.status", 151 | Usage: "build status", 152 | Value: "success", 153 | EnvVar: "DRONE_BUILD_STATUS", 154 | }, 155 | cli.StringFlag{ 156 | Name: "build.link", 157 | Usage: "build link", 158 | EnvVar: "DRONE_BUILD_LINK", 159 | }, 160 | cli.StringFlag{ 161 | Name: "build.deploy", 162 | Usage: "build deployment target", 163 | EnvVar: "DRONE_DEPLOY_TO", 164 | }, 165 | cli.IntFlag{ 166 | Name: "prev.build.number", 167 | Usage: "previous build number", 168 | EnvVar: "DRONE_PREV_BUILD_NUMBER", 169 | }, 170 | cli.StringFlag{ 171 | Name: "prev.build.status", 172 | Usage: "previous build status", 173 | EnvVar: "DRONE_PREV_BUILD_STATUS", 174 | }, 175 | cli.StringFlag{ 176 | Name: "prev.commit.sha", 177 | Usage: "previous build sha", 178 | EnvVar: "DRONE_PREV_COMMIT_SHA", 179 | }, 180 | } 181 | 182 | if err := app.Run(os.Args); err != nil { 183 | logrus.Fatal(err) 184 | } 185 | } 186 | 187 | func run(c *cli.Context) error { 188 | plugin := Plugin{ 189 | Repo: Repo{ 190 | FullName: c.String("repo.fullname"), 191 | Owner: c.String("repo.owner"), 192 | Name: c.String("repo.name"), 193 | Link: c.String("repo.link"), 194 | }, 195 | Build: Build{ 196 | Commit: c.String("commit.sha"), 197 | Branch: c.String("commit.branch"), 198 | Ref: c.String("commit.ref"), 199 | Link: c.String("commit.link"), 200 | Message: c.String("commit.message"), 201 | Author: c.String("commit.author.name"), 202 | Email: c.String("commit.author.email"), 203 | Number: c.Int("build.number"), 204 | Status: c.String("build.status"), 205 | Event: c.String("build.event"), 206 | Deploy: c.String("build.deploy"), 207 | BuildLink: c.String("build.link"), 208 | }, 209 | BuildLast: Build{ 210 | Number: c.Int("prev.build.number"), 211 | Status: c.String("prev.build.status"), 212 | Commit: c.String("prev.commit.sha"), 213 | }, 214 | Config: Config{ 215 | Token: c.String("token"), 216 | Channel: c.String("channel"), 217 | Mapping: c.String("mapping"), 218 | Success: MessageOptions{ 219 | Username: c.String("success_username"), 220 | Icon: c.String("success_icon"), 221 | Template: c.String("success_template"), 222 | ImageAttachments: c.StringSlice("success_image_attachments"), 223 | }, 224 | Failure: MessageOptions{ 225 | Username: c.String("failure_username"), 226 | Icon: c.String("failure_icon"), 227 | Template: c.String("failure_template"), 228 | ImageAttachments: c.StringSlice("failure_image_attachments"), 229 | }, 230 | }, 231 | } 232 | 233 | if plugin.Config.Token == "" { 234 | return errors.New("Missing authentication token") 235 | } 236 | 237 | return plugin.Exec() 238 | } 239 | -------------------------------------------------------------------------------- /memes/README.md: -------------------------------------------------------------------------------- 1 | # A collection of memes for build events 2 | 3 | Add the links to your .drone.yml configuration for slack blame to use. 4 | 5 | ```yaml 6 | notify: 7 | slack_blame: 8 | success: 9 | image_attachments: 10 | - ADD ATTACHMENTS HERE 11 | failure: 12 | image_attachments: 13 | - ADD ATTACHMENTS HERE 14 | ``` 15 | 16 | Pull requests accepted for new images! 17 | 18 | ## Success 19 | 20 | ![Professor](professor_success.jpg) 21 | 22 | `https://raw.githubusercontent.com/drone-plugins/drone-slack-blame/master/memes/professor_success.jpg` 23 | 24 | ## Failure 25 | 26 | ![Archer](archer_fail.jpg) 27 | 28 | `https://raw.githubusercontent.com/drone-plugins/drone-slack-blame/master/memes/archer_fail.jpg` 29 | 30 | ![Grumpy Cat](grumpy_cat_fail.jpg) 31 | 32 | `https://raw.githubusercontent.com/drone-plugins/drone-slack-blame/master/memes/grumpy_cat_fail.jpg` 33 | 34 | ![Kittens](kittens_fail.jpg) 35 | 36 | `https://raw.githubusercontent.com/drone-plugins/drone-slack-blame/master/memes/kittens_fail.jpg` 37 | 38 | ## Success Deploy 39 | 40 | ![Success Kid](success_kid_deploy_success.jpg) 41 | 42 | `https://raw.githubusercontent.com/drone-plugins/drone-slack-blame/master/memes/success_kid_deploy_success.jpg` 43 | 44 | ## Failure Deploy 45 | 46 | ![Grumpy Cat](grumpy_cat_deploy_fail.jpg) 47 | 48 | `https://raw.githubusercontent.com/drone-plugins/drone-slack-blame/master/memes/grumpy_cat_deploy_fail.jpg` 49 | 50 | ![Homer](homer_deploy_fail.jpg) 51 | 52 | `https://raw.githubusercontent.com/drone-plugins/drone-slack-blame/master/memes/homer_deploy_fail.jpg` 53 | 54 | ![Morpheus](morpheus_deploy_fail.jpg) 55 | 56 | `https://raw.githubusercontent.com/drone-plugins/drone-slack-blame/master/memes/morpheus_deploy_fail.jpg` 57 | -------------------------------------------------------------------------------- /memes/archer_fail.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drone-plugins/drone-slack-blame/4207428a5c023c6ebadcabe286ac77baf444383d/memes/archer_fail.jpg -------------------------------------------------------------------------------- /memes/grumpy_cat_deploy_fail.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drone-plugins/drone-slack-blame/4207428a5c023c6ebadcabe286ac77baf444383d/memes/grumpy_cat_deploy_fail.jpg -------------------------------------------------------------------------------- /memes/grumpy_cat_fail.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drone-plugins/drone-slack-blame/4207428a5c023c6ebadcabe286ac77baf444383d/memes/grumpy_cat_fail.jpg -------------------------------------------------------------------------------- /memes/homer_deploy_fail.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drone-plugins/drone-slack-blame/4207428a5c023c6ebadcabe286ac77baf444383d/memes/homer_deploy_fail.jpg -------------------------------------------------------------------------------- /memes/kittens_fail.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drone-plugins/drone-slack-blame/4207428a5c023c6ebadcabe286ac77baf444383d/memes/kittens_fail.jpg -------------------------------------------------------------------------------- /memes/morpheus_deploy_fail.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drone-plugins/drone-slack-blame/4207428a5c023c6ebadcabe286ac77baf444383d/memes/morpheus_deploy_fail.jpg -------------------------------------------------------------------------------- /memes/professor_success.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drone-plugins/drone-slack-blame/4207428a5c023c6ebadcabe286ac77baf444383d/memes/professor_success.jpg -------------------------------------------------------------------------------- /memes/success_kid_deploy_success.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drone-plugins/drone-slack-blame/4207428a5c023c6ebadcabe286ac77baf444383d/memes/success_kid_deploy_success.jpg -------------------------------------------------------------------------------- /plugin.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "io/ioutil" 7 | "math/rand" 8 | "net/http" 9 | "net/url" 10 | "os" 11 | "strings" 12 | "time" 13 | 14 | "github.com/drone/drone-template-lib/template" 15 | "github.com/nlopes/slack" 16 | "github.com/pkg/errors" 17 | "github.com/sirupsen/logrus" 18 | ) 19 | 20 | type ( 21 | // MessageOptions contains the slack message. 22 | MessageOptions struct { 23 | Icon string 24 | Username string 25 | Template string 26 | ImageAttachments []string 27 | } 28 | 29 | // Repo information. 30 | Repo struct { 31 | FullName string 32 | Owner string 33 | Name string 34 | Link string 35 | } 36 | 37 | // Build information. 38 | Build struct { 39 | Commit string 40 | Branch string 41 | Ref string 42 | Link string 43 | Message string 44 | Author string 45 | Email string 46 | Number int 47 | Status string 48 | Event string 49 | Deploy string 50 | BuildLink string 51 | } 52 | 53 | // Config for the plugin. 54 | Config struct { 55 | Token string 56 | Channel string 57 | Mapping string 58 | Success MessageOptions 59 | Failure MessageOptions 60 | } 61 | 62 | // Plugin values. 63 | Plugin struct { 64 | Repo Repo 65 | Build Build 66 | BuildLast Build 67 | Config Config 68 | User *slack.User 69 | } 70 | 71 | // searchFunc determines how to search for a slack user. 72 | searchFunc func(*slack.User, string) bool 73 | ) 74 | 75 | // Exec executes the plugin. 76 | func (p Plugin) Exec() error { 77 | // create the API 78 | api := slack.New(p.Config.Token) 79 | 80 | // verify the connection 81 | authResponse, err := api.AuthTest() 82 | 83 | if err != nil { 84 | return errors.Wrap(err, "failed to test auth") 85 | } 86 | 87 | logrus.WithFields(logrus.Fields{ 88 | "team": authResponse.Team, 89 | "user": authResponse.User, 90 | }).Info("Successfully authenticated with Slack API") 91 | 92 | // get the user 93 | p.User, _ = p.findSlackUser(api) 94 | 95 | // get the associated @ string 96 | messageOptions := p.createMessage() 97 | var userAt string 98 | 99 | if p.User != nil { 100 | userAt = fmt.Sprintf("@%s", p.User.Name) 101 | 102 | _, _, err := api.PostMessage(userAt, messageOptions) 103 | 104 | if err == nil { 105 | logrus.WithFields(logrus.Fields{ 106 | "username": p.User.Name, 107 | }).Info("Notified user") 108 | } else { 109 | logrus.WithFields(logrus.Fields{ 110 | "username": p.User.Name, 111 | }).Error("Could not notify user") 112 | } 113 | } else { 114 | userAt = p.Build.Author 115 | logrus.WithFields(logrus.Fields{ 116 | "author": userAt, 117 | }).Error("Could not find author") 118 | } 119 | 120 | if p.Config.Channel != "" { 121 | if !strings.HasPrefix(p.Config.Channel, "#") { 122 | p.Config.Channel = "#" + p.Config.Channel 123 | } 124 | _, _, err := api.PostMessage(p.Config.Channel, messageOptions) 125 | 126 | if err == nil { 127 | logrus.WithFields(logrus.Fields{ 128 | "channel": p.Config.Channel, 129 | }).Info("Channel notified") 130 | } else { 131 | logrus.WithFields(logrus.Fields{ 132 | "channel": p.Config.Channel, 133 | }).Error("Unable to notify channel") 134 | } 135 | } 136 | 137 | return nil 138 | } 139 | 140 | // createMessage generates the message to post to Slack. 141 | func (p Plugin) createMessage() slack.MsgOption { 142 | // This is currently deprecated 143 | var messageOptions MessageOptions 144 | var color string 145 | var messageTitle string 146 | 147 | // Determine if the build was a success 148 | if p.Build.Status == "success" { 149 | messageOptions = p.Config.Success 150 | color = "good" 151 | messageTitle = "Build succeeded" 152 | } else { 153 | messageOptions = p.Config.Failure 154 | color = "danger" 155 | messageTitle = "Build failed" 156 | } 157 | 158 | // setup the message 159 | messageParams := slack.PostMessageParameters{ 160 | Username: messageOptions.Username, 161 | } 162 | 163 | if strings.HasPrefix(messageOptions.Icon, "http") { 164 | logrus.Info("Icon is a URL") 165 | messageParams.IconURL = messageOptions.Icon 166 | } else { 167 | logrus.Info("Icon is an emoji") 168 | messageParams.IconEmoji = messageOptions.Icon 169 | } 170 | 171 | messageText, err := template.Render(messageOptions.Template, &p) 172 | 173 | if err != nil { 174 | logrus.Error("Could not parse template") 175 | } 176 | 177 | // create the attachment 178 | attachment := slack.Attachment{ 179 | Color: color, 180 | Text: messageText, 181 | Title: messageTitle, 182 | TitleLink: p.Build.Link, 183 | } 184 | 185 | // Add image if any are provided 186 | imageCount := len(messageOptions.ImageAttachments) 187 | 188 | if imageCount > 0 { 189 | logrus.WithFields(logrus.Fields{ 190 | "count": imageCount, 191 | }).Info("Choosing from images") 192 | rand.Seed(time.Now().UTC().UnixNano()) 193 | attachment.ImageURL = messageOptions.ImageAttachments[rand.Intn(imageCount)] 194 | } 195 | 196 | return slack.MsgOptionCompose( 197 | slack.MsgOptionPostMessageParameters(messageParams), 198 | slack.MsgOptionAttachments(attachment), 199 | ) 200 | } 201 | 202 | // findSlackUser uses the slack API to find the user who made the commit that 203 | // is being built. 204 | func (p Plugin) findSlackUser(api *slack.Client) (*slack.User, error) { 205 | // get the mapping 206 | mapping := userMapping(p.Config.Mapping) 207 | 208 | // determine the search function to use 209 | var search searchFunc 210 | var find string 211 | 212 | if val, ok := mapping[p.Build.Email]; ok { 213 | logrus.WithFields(logrus.Fields{ 214 | "username": val, 215 | }).Info("Searching for user by name, using build.email as key") 216 | search = checkUsername 217 | find = val 218 | } else if val, ok := mapping[p.Build.Author]; ok { 219 | logrus.WithFields(logrus.Fields{ 220 | "username": val, 221 | }).Info("Searching for user by name, using build.author as key") 222 | search = checkUsername 223 | find = val 224 | } else { 225 | logrus.WithFields(logrus.Fields{ 226 | "email": p.Build.Email, 227 | }).Info("Searching for user by email") 228 | search = checkEmail 229 | find = p.Build.Email 230 | } 231 | 232 | if len(find) == 0 { 233 | return nil, errors.New("No user to search for") 234 | } 235 | 236 | // search for the user 237 | users, err := api.GetUsers() 238 | 239 | if err != nil { 240 | return nil, errors.Wrap(err, "failed to query users") 241 | } 242 | 243 | var blameUser *slack.User 244 | 245 | for _, user := range users { 246 | if search(&user, find) { 247 | logrus.WithFields(logrus.Fields{ 248 | "username": user.Name, 249 | "email": user.Profile.Email, 250 | }).Info("Found user") 251 | 252 | blameUser = &user 253 | break 254 | } else { 255 | logrus.WithFields(logrus.Fields{ 256 | "username": user.Name, 257 | "email": user.Profile.Email, 258 | }).Debug("User") 259 | } 260 | } 261 | 262 | return blameUser, nil 263 | } 264 | 265 | // userMapping gets the user mapping file. 266 | func userMapping(value string) map[string]string { 267 | mapping := []byte(contents(value)) 268 | 269 | // turn into a map 270 | values := map[string]string{} 271 | err := json.Unmarshal(mapping, &values) 272 | 273 | if err != nil { 274 | if len(mapping) != 0 { 275 | logrus.WithFields(logrus.Fields{ 276 | "mapping": value, 277 | "error": err, 278 | }).Error("Could not parse mapping") 279 | } 280 | 281 | values = make(map[string]string) 282 | } 283 | 284 | return values 285 | } 286 | 287 | // contents gets the value referenced either in a local filem, a URL or the 288 | // string value itself. 289 | func contents(s string) string { 290 | if _, err := os.Stat(s); err == nil { 291 | o, _ := ioutil.ReadFile(s) 292 | return os.ExpandEnv(string(o)) 293 | } 294 | if _, err := url.Parse(s); err == nil { 295 | resp, err := http.Get(s) 296 | if err != nil { 297 | return s 298 | } 299 | defer resp.Body.Close() 300 | o, _ := ioutil.ReadAll(resp.Body) 301 | return os.ExpandEnv(string(o)) 302 | } 303 | return os.ExpandEnv(s) 304 | } 305 | 306 | // checkEmail sees if the email is used by the user. 307 | func checkEmail(user *slack.User, email string) bool { 308 | return strings.EqualFold(user.Profile.Email, email) 309 | } 310 | 311 | // checkUsername sees if the username is the same as the user. 312 | func checkUsername(user *slack.User, name string) bool { 313 | return user.Profile.DisplayName == name || user.RealName == name 314 | } 315 | --------------------------------------------------------------------------------