0
0
mirror of https://github.com/thegeeklab/wp-matrix.git synced 2024-11-22 00:30:41 +00:00

Initial import

This commit is contained in:
Paul Tötterman 2017-10-31 20:58:23 +02:00
commit cb1c390141
8 changed files with 169 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*.swp
*~
/drone-plugin-matrix
/vendor

8
Dockerfile Normal file
View File

@ -0,0 +1,8 @@
# vim: set ft=dockerfile:
FROM alpine:3.6
# Author with no obligation to maintain
MAINTAINER Paul Tötterman <paul.totterman@gmail.com>
RUN apk --no-cache add ca-certificates
ADD drone-plugin-matrix /
ENTRYPOINT /drone-plugin-matrix

15
Gopkg.lock generated Normal file
View File

@ -0,0 +1,15 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
branch = "master"
name = "github.com/matrix-org/gomatrix"
packages = ["."]
revision = "a7fc80c8060c2544fe5d4dae465b584f8e9b4e27"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "d631b7f46070377e77e160dda36075f4421695f6149e974427eafc8458012b3c"
solver-name = "gps-cdcl"
solver-version = 1

26
Gopkg.toml Normal file
View File

@ -0,0 +1,26 @@
# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
[[constraint]]
branch = "master"
name = "github.com/matrix-org/gomatrix"

13
LICENSE Normal file
View File

@ -0,0 +1,13 @@
Copyright (c) 2017, Paul Tötterman <ptman@iki.fi>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

13
Makefile Normal file
View File

@ -0,0 +1,13 @@
.PHONY: build
build: drone-plugin-matrix
drone-plugin-matrix: main.go
CGO_ENABLED=0 go build -ldflags '-s -w'
.PHONY: docker
docker: drone-plugin-matrix
docker build -t drone-plugin-matrix .
.PHONY: clean
clean:
rm -f drone-plugin-matrix

25
README.md Normal file
View File

@ -0,0 +1,25 @@
# drone-plugin-matrix
[Drone](https://drone.io/) notifications to [Matrix](https://matrix.org/)
Usage:
```yaml
matrix:
image: ptman/drone-plugin-matrix
homeserver: https://matrix.org
roomid: '!0123456789abcdef:matrix.org' # room has to already be joined
username: ourbot # either username
password: *account-password* # and password
userid: @ourbot:matrix.org # or userid
accesstoken: 0123456789abcdef # and accesstoken
secrets: # and a better idea
- source: matrix_username # is to not store
target: plugin_username # credentials in the git repo
- source: matrix_password # but instead use drone
target: plugin_password # secret management
```
## License
ISC

65
main.go Normal file
View File

@ -0,0 +1,65 @@
// Copyright (c) 2017 Paul Tötterman <ptman@iki.fi>. All rights reserved.
package main
import (
"fmt"
"log"
"os"
"github.com/matrix-org/gomatrix"
)
func main() {
homeServer := os.Getenv("PLUGIN_HOMESERVER")
userName := os.Getenv("PLUGIN_USERNAME")
password := os.Getenv("PLUGIN_PASSWORD")
userID := os.Getenv("PLUGIN_USERID")
accessToken := os.Getenv("PLUGIN_ACCESSTOKEN")
roomID := os.Getenv("PLUGIN_ROOMID")
message := os.Getenv("PLUGIN_MESSAGE")
repoOwner := os.Getenv("DRONE_REPO_OWNER")
repoName := os.Getenv("DRONE_REPO_NAME")
buildStatus := os.Getenv("DRONE_BUILD_STATUS")
buildLink := os.Getenv("DRONE_BUILD_LINK")
buildBranch := os.Getenv("DRONE_BRANCH")
buildAuthor := os.Getenv("DRONE_COMMIT_AUTHOR")
buildCommit := os.Getenv("DRONE_COMMIT")
m, err := gomatrix.NewClient(homeServer, userID, accessToken)
if err != nil {
log.Fatal(err)
}
if userID == "" || accessToken == "" {
r, err := m.Login(&gomatrix.ReqLogin{
Type: "m.login.password",
User: userName,
Password: password,
InitialDeviceDisplayName: "Drone",
})
if err != nil {
log.Fatal(err)
}
m.SetCredentials(r.UserID, r.AccessToken)
}
if message == "" {
message = fmt.Sprintf("Build %s <%s> %s/%s#%s (%s) by %s",
buildStatus,
buildLink,
repoOwner,
repoName,
buildCommit[:8],
buildBranch,
buildAuthor)
}
if _, err := m.SendNotice(roomID, message); err != nil {
log.Fatal(err)
}
}