Skip to content

Commit cb1c390

Browse files
committed
Initial import
0 parents  commit cb1c390

File tree

8 files changed

+169
-0
lines changed

8 files changed

+169
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.swp
2+
*~
3+
/drone-plugin-matrix
4+
/vendor

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# vim: set ft=dockerfile:
2+
FROM alpine:3.6
3+
# Author with no obligation to maintain
4+
MAINTAINER Paul Tötterman <[email protected]>
5+
6+
RUN apk --no-cache add ca-certificates
7+
ADD drone-plugin-matrix /
8+
ENTRYPOINT /drone-plugin-matrix

Gopkg.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
# Gopkg.toml example
3+
#
4+
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
5+
# for detailed Gopkg.toml documentation.
6+
#
7+
# required = ["github.com/user/thing/cmd/thing"]
8+
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
9+
#
10+
# [[constraint]]
11+
# name = "github.com/user/project"
12+
# version = "1.0.0"
13+
#
14+
# [[constraint]]
15+
# name = "github.com/user/project2"
16+
# branch = "dev"
17+
# source = "github.com/myfork/project2"
18+
#
19+
# [[override]]
20+
# name = "github.com/x/y"
21+
# version = "2.4.0"
22+
23+
24+
[[constraint]]
25+
branch = "master"
26+
name = "github.com/matrix-org/gomatrix"

LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright (c) 2017, Paul Tötterman <[email protected]>
2+
3+
Permission to use, copy, modify, and/or distribute this software for any
4+
purpose with or without fee is hereby granted, provided that the above
5+
copyright notice and this permission notice appear in all copies.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.PHONY: build
2+
build: drone-plugin-matrix
3+
4+
drone-plugin-matrix: main.go
5+
CGO_ENABLED=0 go build -ldflags '-s -w'
6+
7+
.PHONY: docker
8+
docker: drone-plugin-matrix
9+
docker build -t drone-plugin-matrix .
10+
11+
.PHONY: clean
12+
clean:
13+
rm -f drone-plugin-matrix

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# drone-plugin-matrix
2+
3+
[Drone](https://drone.io/) notifications to [Matrix](https://matrix.org/)
4+
5+
Usage:
6+
7+
```yaml
8+
matrix:
9+
image: ptman/drone-plugin-matrix
10+
homeserver: https://matrix.org
11+
roomid: '!0123456789abcdef:matrix.org' # room has to already be joined
12+
username: ourbot # either username
13+
password: *account-password* # and password
14+
userid: @ourbot:matrix.org # or userid
15+
accesstoken: 0123456789abcdef # and accesstoken
16+
secrets: # and a better idea
17+
- source: matrix_username # is to not store
18+
target: plugin_username # credentials in the git repo
19+
- source: matrix_password # but instead use drone
20+
target: plugin_password # secret management
21+
```
22+
23+
## License
24+
25+
ISC

main.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (c) 2017 Paul Tötterman <[email protected]>. All rights reserved.
2+
3+
package main
4+
5+
import (
6+
"fmt"
7+
"log"
8+
"os"
9+
10+
"github.com/matrix-org/gomatrix"
11+
)
12+
13+
func main() {
14+
homeServer := os.Getenv("PLUGIN_HOMESERVER")
15+
userName := os.Getenv("PLUGIN_USERNAME")
16+
password := os.Getenv("PLUGIN_PASSWORD")
17+
18+
userID := os.Getenv("PLUGIN_USERID")
19+
accessToken := os.Getenv("PLUGIN_ACCESSTOKEN")
20+
21+
roomID := os.Getenv("PLUGIN_ROOMID")
22+
message := os.Getenv("PLUGIN_MESSAGE")
23+
24+
repoOwner := os.Getenv("DRONE_REPO_OWNER")
25+
repoName := os.Getenv("DRONE_REPO_NAME")
26+
27+
buildStatus := os.Getenv("DRONE_BUILD_STATUS")
28+
buildLink := os.Getenv("DRONE_BUILD_LINK")
29+
buildBranch := os.Getenv("DRONE_BRANCH")
30+
buildAuthor := os.Getenv("DRONE_COMMIT_AUTHOR")
31+
buildCommit := os.Getenv("DRONE_COMMIT")
32+
33+
m, err := gomatrix.NewClient(homeServer, userID, accessToken)
34+
if err != nil {
35+
log.Fatal(err)
36+
}
37+
38+
if userID == "" || accessToken == "" {
39+
r, err := m.Login(&gomatrix.ReqLogin{
40+
Type: "m.login.password",
41+
User: userName,
42+
Password: password,
43+
InitialDeviceDisplayName: "Drone",
44+
})
45+
if err != nil {
46+
log.Fatal(err)
47+
}
48+
m.SetCredentials(r.UserID, r.AccessToken)
49+
}
50+
51+
if message == "" {
52+
message = fmt.Sprintf("Build %s <%s> %s/%s#%s (%s) by %s",
53+
buildStatus,
54+
buildLink,
55+
repoOwner,
56+
repoName,
57+
buildCommit[:8],
58+
buildBranch,
59+
buildAuthor)
60+
}
61+
62+
if _, err := m.SendNotice(roomID, message); err != nil {
63+
log.Fatal(err)
64+
}
65+
}

0 commit comments

Comments
 (0)