|
|
@ -14,7 +14,7 @@ import ( |
|
|
|
|
|
|
|
// Matches alphanumeric then a /, then more alphanumeric then a #, then a number.
|
|
|
|
// E.g. owner/repo#11 (issue/PR numbers) - Captured groups for owner/repo/number
|
|
|
|
const ownerRepoIssueRegex = "([A-z0-9-_]+)/([A-z0-9-_]+)#([0-9]+)" |
|
|
|
var ownerRepoIssueRegex = regexp.MustCompile("([A-z0-9-_]+)/([A-z0-9-_]+)#([0-9]+)") |
|
|
|
|
|
|
|
type githubService struct { |
|
|
|
id string |
|
|
@ -31,7 +31,7 @@ func (s *githubService) Plugin(roomID string) plugin.Plugin { |
|
|
|
Commands: []plugin.Command{}, |
|
|
|
Expansions: []plugin.Expansion{ |
|
|
|
plugin.Expansion{ |
|
|
|
Regexp: regexp.MustCompile(ownerRepoIssueRegex), |
|
|
|
Regexp: ownerRepoIssueRegex, |
|
|
|
Expand: func(roomID, matchingText string) interface{} { |
|
|
|
cli := githubClient("") |
|
|
|
owner, repo, num, err := ownerRepoNumberFromText(matchingText) |
|
|
@ -78,10 +78,8 @@ func githubClient(token string) *github.Client { |
|
|
|
// ownerRepoNumberFromText parses a GH issue string that looks like 'owner/repo#11'
|
|
|
|
// into its constituient parts. Returns: owner, repo, issue#.
|
|
|
|
func ownerRepoNumberFromText(ownerRepoNumberText string) (string, string, int, error) { |
|
|
|
// TODO: cache this?
|
|
|
|
re := regexp.MustCompile(ownerRepoIssueRegex) |
|
|
|
// [full_string, owner, repo, issue_number]
|
|
|
|
groups := re.FindStringSubmatch(ownerRepoNumberText) |
|
|
|
groups := ownerRepoIssueRegex.FindStringSubmatch(ownerRepoNumberText) |
|
|
|
if len(groups) != 4 { |
|
|
|
return "", "", 0, fmt.Errorf("No match found for '%s'", ownerRepoNumberText) |
|
|
|
} |
|
|
|