Browse Source

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.
pull/27/head
Kegan Dougal 8 years ago
parent
commit
5bccd52190
  1. 27
      src/github.com/matrix-org/go-neb/matrix/types.go
  2. 8
      src/github.com/matrix-org/go-neb/services/github/github.go

27
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)
}

8
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 {

Loading…
Cancel
Save