Skip to content

Commit d090b37

Browse files
committed
Add more doc in the code
1 parent 3f5bde9 commit d090b37

File tree

5 files changed

+27
-4
lines changed

5 files changed

+27
-4
lines changed

pkg/branch/branch.go

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ const _replacementCharacter = "-"
1111

1212
var _regexp = regexp.MustCompile("[^A-Za-z0-9.]+")
1313

14+
// GenerateName generates a new branch name off of the identifier and title specified.
15+
// Both the identifier and title must not be blank.
16+
// Leading hyphens (prefix and suffix) are removed from the name returned.
1417
func GenerateName(id string, title string) (string, error) {
1518
if id == "" || strings.TrimSpace(id) == "" {
1619
return "", errors.New("id must not be blank")

pkg/branch/doc.go

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package branch allows to perform operations like generating a new branch name
2+
package branch

pkg/issue/doc.go

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package issue allows to query on issues against the remote issue provider
2+
package issue

pkg/issue/github.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,33 @@ import (
88
"strconv"
99
)
1010

11+
// GHIssueFinder is a struct type that implements the issue.Finder interface
1112
type GHIssueFinder struct{}
1213

14+
// This provides a compile-safe way of making sure GHIssueFinder implements the issue.Finder interface
15+
var _ Finder = GHIssueFinder{}
16+
17+
// _GhIssueInfo is a struct used to unmarshal GitHub API responses.
18+
// It needs to be exported but is not intended to be used directly.
1319
type _GhIssueInfo struct {
14-
Number int `json:"number"`
15-
Title string `json:"title"`
20+
// Number is the GitHub issue number
21+
Number int `json:"number"`
22+
// Title is the GitHub issue title
23+
Title string `json:"title"`
1624
}
1725

26+
// NewGHIssueFinder returns a new object of type GHIssueFinder
1827
func NewGHIssueFinder() *GHIssueFinder {
1928
return &GHIssueFinder{}
2029
}
2130

31+
// FindById allows to retrieve an issue given its identifier.
32+
// It optionally writes any relevant warnings or messages to eventually output into the io.Writer object specified.
2233
func (g GHIssueFinder) FindById(w io.Writer, repo string, id string) (Info, error) {
2334
args := []string{"issue", "view", id, "--json", "number,title"}
2435
if repo != "" {
2536
args = append(args, "-R", repo)
2637
}
27-
var issueInfo _GhIssueInfo
2838
stdOut, stdErr, err := gh.Exec(args...)
2939
if err != nil {
3040
return Info{}, err
@@ -33,6 +43,7 @@ func (g GHIssueFinder) FindById(w io.Writer, repo string, id string) (Info, erro
3343
//goland:noinspection GoUnhandledErrorResult
3444
fmt.Fprintln(w, stdErrStr)
3545
}
46+
var issueInfo _GhIssueInfo
3647
err = json.Unmarshal(stdOut.Bytes(), &issueInfo)
3748
return Info{
3849
Id: strconv.Itoa(issueInfo.Number),

pkg/issue/issue.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ package issue
22

33
import "io"
44

5+
// Info is a generic struct representing a given issue
56
type Info struct {
67
Id string
78
Title string
89
}
910

11+
// Finder is the interface used to manipulate issues
1012
type Finder interface {
11-
FindById(w io.Writer, repo string, issue string) (Info, error)
13+
14+
// FindById allows to retrieve an issue given its identifier.
15+
// It optionally writes any relevant warnings or messages to eventually output into the io.Writer object specified.
16+
FindById(w io.Writer, repo string, id string) (Info, error)
1217
}

0 commit comments

Comments
 (0)