|
|
@ -45,17 +45,22 @@ func (s *githubService) RoomIDs() []string { |
|
|
|
} |
|
|
|
return keys |
|
|
|
} |
|
|
|
func (s *githubService) Plugin(roomID string) plugin.Plugin { |
|
|
|
return plugin.Plugin{ |
|
|
|
Commands: []plugin.Command{ |
|
|
|
plugin.Command{ |
|
|
|
Path: []string{"github", "create"}, |
|
|
|
Command: func(roomID, userID string, args []string) (interface{}, error) { |
|
|
|
|
|
|
|
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 |
|
|
|
r, err := database.GetServiceDB().LoadAuthRealm(s.RealmID) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
ghRealm, ok := r.(*realms.GithubRealm) |
|
|
|
if !ok { |
|
|
|
return nil, fmt.Errorf("Failed to cast realm %s into a GithubRealm", s.RealmID) |
|
|
|
} |
|
|
|
return matrix.StarterLinkMessage{ |
|
|
|
Body: "You need to OAuth with Github before you can create issues.", |
|
|
|
Link: ghRealm.StarterLink, |
|
|
|
}, nil |
|
|
|
} |
|
|
|
|
|
|
|
if len(args) < 2 { |
|
|
@ -95,13 +100,9 @@ func (s *githubService) Plugin(roomID string) plugin.Plugin { |
|
|
|
} |
|
|
|
|
|
|
|
return matrix.TextMessage{"m.notice", fmt.Sprintf("Created issue: %s", *issue.HTMLURL)}, nil |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
Expansions: []plugin.Expansion{ |
|
|
|
plugin.Expansion{ |
|
|
|
Regexp: ownerRepoIssueRegex, |
|
|
|
Expand: func(roomID, userID, matchingText string) interface{} { |
|
|
|
} |
|
|
|
|
|
|
|
func (s *githubService) expandIssue(roomID, userID, matchingText string) interface{} { |
|
|
|
cli := s.githubClientFor(userID, true) |
|
|
|
owner, repo, num, err := ownerRepoNumberFromText(matchingText) |
|
|
|
if err != nil { |
|
|
@ -124,6 +125,23 @@ func (s *githubService) Plugin(roomID string) plugin.Plugin { |
|
|
|
"m.notice", |
|
|
|
fmt.Sprintf("%s : %s", *i.HTMLURL, *i.Title), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func (s *githubService) Plugin(roomID string) plugin.Plugin { |
|
|
|
return plugin.Plugin{ |
|
|
|
Commands: []plugin.Command{ |
|
|
|
plugin.Command{ |
|
|
|
Path: []string{"github", "create"}, |
|
|
|
Command: func(roomID, userID string, args []string) (interface{}, error) { |
|
|
|
return s.cmdGithubCreate(roomID, userID, args) |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
Expansions: []plugin.Expansion{ |
|
|
|
plugin.Expansion{ |
|
|
|
Regexp: ownerRepoIssueRegex, |
|
|
|
Expand: func(roomID, userID, matchingText string) interface{} { |
|
|
|
return s.expandIssue(roomID, userID, matchingText) |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|