Browse Source

Add very noddy github service. Add owner/repo#11 expander.

kegan/github
Kegan Dougal 8 years ago
parent
commit
7f0af81330
  1. 1
      src/github.com/matrix-org/go-neb/goneb.go
  2. 52
      src/github.com/matrix-org/go-neb/services/github/github.go

1
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"

52
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}
})
}
Loading…
Cancel
Save