From 5bccd5219050298e8cb633e3c9563c0e6d1d98b4 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 15 Aug 2016 10:38:09 +0100 Subject: [PATCH] Add StarterLink as a field to the Github Service config Use it verbatim in the responses to !commands when the caller has not authed with Github. --- .../matrix-org/go-neb/matrix/types.go | 27 +++++++++++++++++++ .../go-neb/services/github/github.go | 8 +++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/github.com/matrix-org/go-neb/matrix/types.go b/src/github.com/matrix-org/go-neb/matrix/types.go index 0db9054..900b16a 100644 --- a/src/github.com/matrix-org/go-neb/matrix/types.go +++ b/src/github.com/matrix-org/go-neb/matrix/types.go @@ -1,6 +1,7 @@ package matrix import ( + "encoding/json" "html" "regexp" ) @@ -114,3 +115,29 @@ func GetHTMLMessage(msgtype, htmlText string) HTMLMessage { FormattedBody: htmlText, } } + +// StarterLinkMessage represents a message with a starter_link custom data. +type StarterLinkMessage struct { + Body string + Link string +} + +// MarshalJSON converts this message into actual event content JSON. +func (m StarterLinkMessage) MarshalJSON() ([]byte, error) { + var data map[string]string + + if m.Link != "" { + data = map[string]string{ + "org.matrix.neb.starter_link": m.Link, + } + } + + msg := struct { + MsgType string `json:"msgtype"` + Body string `json:"body"` + Data map[string]string `json:"data,omitempty"` + }{ + "m.notice", m.Body, data, + } + return json.Marshal(msg) +} diff --git a/src/github.com/matrix-org/go-neb/services/github/github.go b/src/github.com/matrix-org/go-neb/services/github/github.go index 4fc9dd4..75bc820 100644 --- a/src/github.com/matrix-org/go-neb/services/github/github.go +++ b/src/github.com/matrix-org/go-neb/services/github/github.go @@ -28,6 +28,7 @@ type githubService struct { ClientUserID string RealmID string SecretToken string + StarterLink string Rooms map[string]struct { // room_id => {} Repos map[string]struct { // owner/repo => { events: ["push","issue","pull_request"] } Events []string @@ -49,9 +50,10 @@ func (s *githubService) RoomIDs() []string { func (s *githubService) cmdGithubCreate(roomID, userID string, args []string) (interface{}, error) { cli := s.githubClientFor(userID, false) if cli == nil { - // TODO: send starter link - return &matrix.TextMessage{"m.notice", - userID + " : You have not linked your Github account."}, nil + return matrix.StarterLinkMessage{ + Body: "You need to OAuth with Github before you can create issues.", + Link: s.StarterLink, + }, nil } if len(args) < 2 {