Skip to content

Commit d45a460

Browse files
senthilhnsOmpragashmindzaurus
authored
Support for slackUserIdFromEmail slackUserIdsFromCommitters commands (#175)
* adding slack file send * added all file send params * adding slack file upload * adding test files * modifed plugin tests to check for request body similar to previous cases * adding output env vars * updating slack file upload instructions * handling filename arg is empty case * Update plugin.go done Co-authored-by: OP (oppenheimer) <[email protected]> * not creating any tmp files if DRONE_OUTPUT not set * Update README.md * Update README.md * Update plugin.go * Update README.md * adding get slack id from email functionality * getting all slack ids of commiters from git * updating arm64 docker file * added windows git command for getting commiters * Updating usage for get slack id support in README.MD * test update for commiter log * adding git commit id ranges for getting commiter ids * adding HEAD and sha commit ranges, HEAD and number sha commit ranges * Updating usage from Get the Slack IDs of all committers * getting old and new commit ids from HEAD^ and HEAD * making slack id of commiters to json string * adding email len == 0 check and returning error * taking csv list for getSlackid from emails * testing message sending to user * sending dm same as channel msg * added fmt prints * changing fmt.Print to log.Print * removing bash git command with go git package * removing git bash install from linux docker files * adding test functions * removing debug print * adding test cases for no commiters, slack lookup failure, rate limit failure * Update plugin.go Co-authored-by: OP (oppenheimer) <[email protected]> * Update plugin.go Co-authored-by: OP (oppenheimer) <[email protected]> * Update plugin.go Co-authored-by: OP (oppenheimer) <[email protected]> * Update plugin.go Co-authored-by: OP (oppenheimer) <[email protected]> * adding time package --------- Co-authored-by: OP (oppenheimer) <[email protected]> Co-authored-by: Senthil Kumar T <[email protected]>
1 parent fc548f3 commit d45a460

File tree

8 files changed

+587
-31
lines changed

8 files changed

+587
-31
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,49 @@ Make sure to replace `your_access_token` with your actual Slack access token and
8888
If you provide an access token, it will use the Slack API to send the message.
8989

9090

91+
### Get Slack Id of a user from a Email ID
92+
```bash
93+
docker run --network host --rm \
94+
-e PLUGIN_ACCESS_TOKEN=your_access_token \
95+
96+
plugins/slack
97+
```
98+
Output will be stored in the FOUND_SLACK_ID environment variable
99+
Make sure to replace `your_access_token` with your actual Slack access token and adjust
100+
101+
### Get the Slack IDs of all committers from a git repo with two commit ids as commit Ids
102+
```bash
103+
docker run --network host --rm \
104+
-e PLUGIN_ACCESS_TOKEN=your_access_token \
105+
-e PLUGIN_COMMITTER_LIST_GIT_PATH=/harness \
106+
-e PLUGIN_RECENT_COMMIT_ID=7fd1a60b01f91b314f59955a4e4d4e80d8edf11d \
107+
-e PLUGIN_OLD_COMMIT_ID=7fd1a60b01f91b314f59955a4e4d4e80d8edf11d \
108+
plugins/slack
109+
```
110+
111+
### Get the Slack IDs of all committers from a git repo with HEAD and a commit id
112+
```bash
113+
docker run --network host --rm \
114+
-e PLUGIN_ACCESS_TOKEN=your_access_token \
115+
-e PLUGIN_COMMITTER_LIST_GIT_PATH=/harness \
116+
-e PLUGIN_RECENT_COMMIT_ID=HEAD \
117+
-e PLUGIN_OLD_COMMIT_ID=7fd1a60b01f91b314f59955a4e4d4e80d8edf11d \
118+
plugins/slack
119+
```
120+
121+
### Get the Slack IDs of all committers from a git repo with HEAD and a number of commits behind HEAD
122+
```bash
123+
docker run --network host --rm \
124+
-e PLUGIN_ACCESS_TOKEN=your_access_token \
125+
-e PLUGIN_COMMITTER_LIST_GIT_PATH=/harness \
126+
-e PLUGIN_RECENT_COMMIT_ID=HEAD \
127+
-e PLUGIN_OLD_COMMIT_ID=5 \
128+
plugins/slack
129+
```
130+
131+
Output will be stored in the COMMITTER_SLACK_ID_LIST environment variable as comma separated values.
132+
Make sure to replace `your_access_token` with your actual Slack access token and adjust.
133+
91134
## Release Preparation
92135

93136
Run the changelog generator.

docker/Dockerfile.linux.amd64

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM plugins/base:multiarch
1+
FROM alpine:3.20
22

33
LABEL maintainer="Drone.IO Community <[email protected]>" \
44
org.label-schema.name="Drone Slack" \

docker/Dockerfile.linux.arm64

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM plugins/base:multiarch
1+
FROM alpine:3.20
22

33
LABEL maintainer="Drone.IO Community <[email protected]>" \
44
org.label-schema.name="Drone Slack" \

go.mod

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,45 @@ go 1.20
44

55
require (
66
github.com/drone/drone-template-lib v1.0.0
7+
github.com/go-git/go-git/v5 v5.12.0
78
github.com/joho/godotenv v1.5.1
89
github.com/slack-go/slack v0.15.0
910
github.com/urfave/cli v1.22.14
1011
gotest.tools/v3 v3.5.1
1112
)
1213

1314
require (
15+
dario.cat/mergo v1.0.0 // indirect
1416
github.com/Masterminds/goutils v1.1.0 // indirect
1517
github.com/Masterminds/semver v1.4.2 // indirect
1618
github.com/Masterminds/sprig v2.18.0+incompatible // indirect
19+
github.com/Microsoft/go-winio v0.6.1 // indirect
20+
github.com/ProtonMail/go-crypto v1.0.0 // indirect
1721
github.com/aymerick/raymond v2.0.2+incompatible // indirect
22+
github.com/cloudflare/circl v1.3.7 // indirect
1823
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
19-
github.com/google/go-cmp v0.5.9 // indirect
24+
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
25+
github.com/emirpasic/gods v1.18.1 // indirect
26+
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
27+
github.com/go-git/go-billy/v5 v5.5.0 // indirect
28+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
29+
github.com/google/go-cmp v0.6.0 // indirect
2030
github.com/google/uuid v1.1.0 // indirect
2131
github.com/gorilla/websocket v1.5.3 // indirect
2232
github.com/huandu/xstrings v1.2.0 // indirect
2333
github.com/imdario/mergo v0.3.7 // indirect
24-
github.com/pkg/errors v0.8.0 // indirect
34+
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
35+
github.com/kevinburke/ssh_config v1.2.0 // indirect
36+
github.com/pjbgf/sha1cd v0.3.0 // indirect
37+
github.com/pkg/errors v0.9.1 // indirect
2538
github.com/russross/blackfriday/v2 v2.1.0 // indirect
26-
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
39+
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
40+
github.com/skeema/knownhosts v1.2.2 // indirect
41+
github.com/xanzy/ssh-agent v0.3.3 // indirect
42+
golang.org/x/crypto v0.21.0 // indirect
43+
golang.org/x/mod v0.12.0 // indirect
44+
golang.org/x/net v0.22.0 // indirect
45+
golang.org/x/sys v0.18.0 // indirect
46+
golang.org/x/tools v0.13.0 // indirect
47+
gopkg.in/warnings.v0 v0.1.2 // indirect
2748
)

go.sum

Lines changed: 117 additions & 8 deletions
Large diffs are not rendered by default.

main.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ package main
33
import (
44
"errors"
55
"fmt"
6-
"log"
7-
"os"
8-
96
"github.com/joho/godotenv"
107
"github.com/urfave/cli"
8+
"log"
9+
"os"
1110
)
1211

1312
var (
@@ -16,6 +15,7 @@ var (
1615
)
1716

1817
func main() {
18+
1919
app := cli.NewApp()
2020
app.Name = "slack plugin"
2121
app.Usage = "slack plugin"
@@ -239,6 +239,21 @@ func main() {
239239
Usage: "fail build on error",
240240
EnvVar: "PLUGIN_FAIL_ON_ERROR",
241241
},
242+
cli.StringFlag{
243+
Name: "slack_id_of",
244+
Usage: "slack id required for the user email id",
245+
EnvVar: "PLUGIN_SLACK_USER_EMAIL_ID",
246+
},
247+
cli.StringFlag{
248+
Name: "committer_list_git_path",
249+
Usage: "git repo path holding the committers email id to fetch slack IDs from",
250+
EnvVar: "PLUGIN_GIT_REPO_PATH",
251+
},
252+
cli.BoolFlag{
253+
Name: "plugin_committer_slack_id",
254+
Usage: "flag to enable fetching slack IDs from the committers list",
255+
EnvVar: "PLUGIN_COMMITTERS_SLACK_ID",
256+
},
242257
}
243258

244259
if _, err := os.Stat("/run/drone/env"); err == nil {
@@ -299,11 +314,14 @@ func run(c *cli.Context) error {
299314
CustomTemplate: c.String("custom.template"),
300315
Message: c.String("message"),
301316
// File upload attributes
302-
FilePath: c.String("filepath"),
303-
FileName: c.String("filename"),
304-
Title: c.String("title"),
305-
InitialComment: c.String("initial_comment"),
306-
FailOnError: c.Bool("fail_on_error"),
317+
FilePath: c.String("filepath"),
318+
FileName: c.String("filename"),
319+
Title: c.String("title"),
320+
InitialComment: c.String("initial_comment"),
321+
FailOnError: c.Bool("fail_on_error"),
322+
SlackIdOf: c.String("slack_id_of"),
323+
CommitterListGitPath: c.String("committer_list_git_path"),
324+
CommitterSlackId: c.Bool("plugin_committer_slack_id"),
307325
},
308326
}
309327

0 commit comments

Comments
 (0)