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")
|
ErrEmptyCommit = errors.New("empty commit")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Commit represens conventional commit
|
||||||
type Commit struct {
|
type Commit struct {
|
||||||
// Commit as is
|
// Commit as is
|
||||||
RawHeader string
|
RawHeader string
|
||||||
|
@ -27,6 +28,7 @@ type Commit struct {
|
||||||
Scope string
|
Scope string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewCommit return conventional commit from git commit
|
||||||
func NewCommit(c git.Commit) (result Commit, err error) {
|
func NewCommit(c git.Commit) (result Commit, err error) {
|
||||||
// Preprocess
|
// Preprocess
|
||||||
message := strings.TrimSpace(c.Message)
|
message := strings.TrimSpace(c.Message)
|
||||||
|
|
|
@ -2,10 +2,12 @@ package git
|
||||||
|
|
||||||
import "github.com/go-git/go-git/v5/plumbing/object"
|
import "github.com/go-git/go-git/v5/plumbing/object"
|
||||||
|
|
||||||
|
// Commit stores all git-commit information
|
||||||
type Commit struct {
|
type Commit struct {
|
||||||
Message string
|
Message string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert from git-commit
|
||||||
func newCommit(commit *object.Commit) Commit {
|
func newCommit(commit *object.Commit) Commit {
|
||||||
return Commit{
|
return Commit{
|
||||||
Message: commit.Message,
|
Message: commit.Message,
|
||||||
|
|
|
@ -15,6 +15,7 @@ const (
|
||||||
defaultCommitCount = 10
|
defaultCommitCount = 10
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Repository is an abstraction for git-repository
|
||||||
type Repository interface {
|
type Repository interface {
|
||||||
Log(fromRev, toRev string) ([]Commit, error)
|
Log(fromRev, toRev string) ([]Commit, error)
|
||||||
}
|
}
|
||||||
|
@ -25,6 +26,7 @@ type repo struct {
|
||||||
|
|
||||||
type stopFn func(*object.Commit) error
|
type stopFn func(*object.Commit) error
|
||||||
|
|
||||||
|
// NewRepository return Repository from path
|
||||||
func NewRepository(path string) (Repository, error) {
|
func NewRepository(path string) (Repository, error) {
|
||||||
r, err := git.PlainOpen(path)
|
r, err := git.PlainOpen(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -36,7 +38,7 @@ func NewRepository(path string) (Repository, error) {
|
||||||
}, nil
|
}, 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) {
|
func (r *repo) Log(fromRev, toRev string) ([]Commit, error) {
|
||||||
if fromRev == "" {
|
if fromRev == "" {
|
||||||
fromRev = head
|
fromRev = head
|
||||||
|
|
|
@ -2,6 +2,7 @@ package markdown
|
||||||
|
|
||||||
import "strings"
|
import "strings"
|
||||||
|
|
||||||
|
// Generate return string which represents all markdown nodes
|
||||||
func Generate(bases []Node) string {
|
func Generate(bases []Node) string {
|
||||||
lines := make([]string, len(bases))
|
lines := make([]string, len(bases))
|
||||||
for i, base := range bases {
|
for i, base := range bases {
|
||||||
|
|
|
@ -6,6 +6,7 @@ const (
|
||||||
defaultBaseLen = 10
|
defaultBaseLen = 10
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Parse return all markdown nodes from lines
|
||||||
func Parse(lines []string) []Node {
|
func Parse(lines []string) []Node {
|
||||||
bases := make([]Node, 0, defaultBaseLen)
|
bases := make([]Node, 0, defaultBaseLen)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue