diff --git a/src/github.com/matrix-org/go-neb/goneb.go b/src/github.com/matrix-org/go-neb/goneb.go index 0d7c611..062970b 100644 --- a/src/github.com/matrix-org/go-neb/goneb.go +++ b/src/github.com/matrix-org/go-neb/goneb.go @@ -6,6 +6,7 @@ import ( "github.com/matrix-org/go-neb/database" "github.com/matrix-org/go-neb/server" _ "github.com/matrix-org/go-neb/services/echo" + _ "github.com/matrix-org/go-neb/services/github" _ "github.com/mattn/go-sqlite3" "net/http" _ "net/http/pprof" 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 new file mode 100644 index 0000000..8c20fab --- /dev/null +++ b/src/github.com/matrix-org/go-neb/services/github/github.go @@ -0,0 +1,52 @@ +package services + +import ( + "github.com/matrix-org/go-neb/database" + "github.com/matrix-org/go-neb/matrix" + "github.com/matrix-org/go-neb/plugin" + "regexp" + "strings" +) + +type githubService struct { + id string + UserID string + Rooms []string +} + +func (s *githubService) ServiceUserID() string { return s.UserID } +func (s *githubService) ServiceID() string { return s.id } +func (s *githubService) ServiceType() string { return "github" } +func (s *githubService) RoomIDs() []string { return s.Rooms } +func (s *githubService) Plugin(roomID string) plugin.Plugin { + return plugin.Plugin{ + Commands: []plugin.Command{ + plugin.Command{ + Path: []string{"github"}, + Command: func(roomID, userID string, args []string) (interface{}, error) { + return &matrix.TextMessage{"m.notice", strings.Join(args, " ")}, nil + }, + }, + }, + Expansions: []plugin.Expansion{ + plugin.Expansion{ + // E.g. owner/repo#11 (issue/PR numbers) + Regexp: regexp.MustCompile("[A-z0-9-_]+/[A-z0-9-_]+#[0-9]+"), + Expand: func(roomID, matchingText string) interface{} { + // get the issue/PR number + repoAndNum := strings.Split(matchingText, "#") + return &matrix.TextMessage{ + "m.notice", + "Repo: " + repoAndNum[0] + " Num: " + repoAndNum[1], + } + }, + }, + }, + } +} + +func init() { + database.RegisterService(func(serviceID string) database.Service { + return &githubService{id: serviceID} + }) +}