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
sudo pacman -Syu 2021-03-29 20:57:06 +07:00 committed by GitHub
parent fa1c13eec3
commit 3a201be3ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 1 deletions

View File

@ -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)

View File

@ -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,

View File

@ -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

View File

@ -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 {

View File

@ -6,6 +6,7 @@ const (
defaultBaseLen = 10
)
// Parse return all markdown nodes from lines
func Parse(lines []string) []Node {
bases := make([]Node, 0, defaultBaseLen)