docs: documenting export methods (#6)
* docs(git): explain Commit and Repository * docs(git): better comment for Log method * docs(markdown): add comment for Generate and Parse method * docs(convention): add comment for conventional commit Co-authored-by: Tran Hau <ngtranhau@gmail.com>main
parent
fa1c13eec3
commit
3a201be3ec
|
@ -19,6 +19,7 @@ var (
|
|||
ErrEmptyCommit = errors.New("empty commit")
|
||||
)
|
||||
|
||||
// Commit represens conventional commit
|
||||
type Commit struct {
|
||||
// Commit as is
|
||||
RawHeader string
|
||||
|
@ -27,6 +28,7 @@ type Commit struct {
|
|||
Scope string
|
||||
}
|
||||
|
||||
// NewCommit return conventional commit from git commit
|
||||
func NewCommit(c git.Commit) (result Commit, err error) {
|
||||
// Preprocess
|
||||
message := strings.TrimSpace(c.Message)
|
||||
|
|
|
@ -2,10 +2,12 @@ package git
|
|||
|
||||
import "github.com/go-git/go-git/v5/plumbing/object"
|
||||
|
||||
// Commit stores all git-commit information
|
||||
type Commit struct {
|
||||
Message string
|
||||
}
|
||||
|
||||
// Convert from git-commit
|
||||
func newCommit(commit *object.Commit) Commit {
|
||||
return Commit{
|
||||
Message: commit.Message,
|
||||
|
|
|
@ -15,6 +15,7 @@ const (
|
|||
defaultCommitCount = 10
|
||||
)
|
||||
|
||||
// Repository is an abstraction for git-repository
|
||||
type Repository interface {
|
||||
Log(fromRev, toRev string) ([]Commit, error)
|
||||
}
|
||||
|
@ -25,6 +26,7 @@ type repo struct {
|
|||
|
||||
type stopFn func(*object.Commit) error
|
||||
|
||||
// NewRepository return Repository from path
|
||||
func NewRepository(path string) (Repository, error) {
|
||||
r, err := git.PlainOpen(path)
|
||||
if err != nil {
|
||||
|
@ -36,7 +38,7 @@ func NewRepository(path string) (Repository, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
// Get all commits between <from revision> and <to revision>
|
||||
// Log return all commits between <from revision> and <to revision>
|
||||
func (r *repo) Log(fromRev, toRev string) ([]Commit, error) {
|
||||
if fromRev == "" {
|
||||
fromRev = head
|
||||
|
|
|
@ -2,6 +2,7 @@ package markdown
|
|||
|
||||
import "strings"
|
||||
|
||||
// Generate return string which represents all markdown nodes
|
||||
func Generate(bases []Node) string {
|
||||
lines := make([]string, len(bases))
|
||||
for i, base := range bases {
|
||||
|
|
|
@ -6,6 +6,7 @@ const (
|
|||
defaultBaseLen = 10
|
||||
)
|
||||
|
||||
// Parse return all markdown nodes from lines
|
||||
func Parse(lines []string) []Node {
|
||||
bases := make([]Node, 0, defaultBaseLen)
|
||||
|
||||
|
|
Loading…
Reference in New Issue