/
ghb.go
49 lines (40 loc) · 1.22 KB
/
ghb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package cmd
import (
"fmt"
"io"
"strings"
"github.com/google/go-github/github"
)
type ghb struct {
c gitHubAPIDoer
}
func newGHB() *ghb {
cl := newGitHubClient()
return &ghb{c: cl}
}
func (g *ghb) createRepo(org string, repo *github.Repository) (*github.Repository, *github.Response, error) {
return g.c.createRepo(org, repo)
}
func (g *ghb) createIssue(repoName string, labels []string) (*github.Issue, *github.Response, error) {
// var issue *github.IssueRequest にしてはいけない。
// issue.Labels が nil pointer dereference になる。
var issue github.IssueRequest
lines, err := g.c.issueLineFromEditor(repoName)
if err != nil {
return nil, nil, err
}
if len(lines) == 1 {
issue.Title = github.String(lines[0])
} else {
issue.Title, issue.Body =
github.String(lines[0]), github.String(strings.Join(lines[1:], "\n"))
}
issue.Labels = &labels
return g.c.createIssue(repoName, &issue)
}
func (g *ghb) printGitClone(out io.Writer, repo *github.Repository) {
fmt.Fprintf(out, "git clone %s\n", strings.Trim(github.Stringify(repo.GitURL), `"`))
}
func (g *ghb) printIssueNum(out io.Writer, issue *github.Issue) {
fmt.Fprintln(out, "Issue num:", strings.Trim(github.Stringify(issue.Number), `"`))
}