Browse Source

Implement `!github create owner/repo title`

pull/12/head
Kegan Dougal 9 years ago
parent
commit
8beb8fda7f
  1. 34
      src/github.com/matrix-org/go-neb/services/github/github.go

34
src/github.com/matrix-org/go-neb/services/github/github.go

@ -51,7 +51,39 @@ func (s *githubService) Plugin(roomID string) plugin.Plugin {
return &matrix.TextMessage{"m.notice",
userID + " : You have not linked your Github account."}, nil
}
return &matrix.TextMessage{"m.notice", strings.Join(args, " ")}, nil
if len(args) < 2 {
return &matrix.TextMessage{"m.notice",
`Usage: !github create owner/repo "issue title" "description"`}, nil
}
var (
ownerRepo string
title *string
desc *string
)
ownerRepo = args[0]
if len(args) == 2 {
title = &args[1]
} else if len(args) == 3 {
title = &args[1]
desc = &args[2]
} else { // > 3 args is probably a title without quote marks
joinedTitle := strings.Join(args[1:], " ")
title = &joinedTitle
}
o := strings.Split(ownerRepo, "/")
issue, res, err := cli.Issues.Create(o[0], o[1], &github.IssueRequest{
Title: title,
Body: desc,
})
if err != nil {
log.WithField("err", err).Print("Failed to create issue")
return nil, fmt.Errorf("Failed to create issue. HTTP %d", res.StatusCode)
}
return matrix.TextMessage{"m.notice", fmt.Sprintf("Created issue: %s", *issue.HTMLURL)}, nil
},
},
},

Loading…
Cancel
Save