Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes root commit reference #24

Merged
merged 1 commit into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 28 additions & 14 deletions internal/pkg/gitclient/gitclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,33 +59,47 @@ func (gc *GitClient) GetTags() ([]*Ref, error) {
return tags, err
}

func (gc *GitClient) GetFirstCommit() (*Ref, error) {
commitObjectss, err := gc.repo.CommitObjects()
func (gc *GitClient) GetLogs(reverse bool) ([]*Ref, error) {
logOpts := git.LogOptions{
Order: git.LogOrderCommitterTime,
}

logsRefs, err := gc.repo.Log(&logOpts)
if err != nil {
return nil, err
}

commits := []*object.Commit{}
err = commitObjectss.ForEach(func(commit *object.Commit) error {
commits = append(commits, commit)
return nil
})
logs := []*Ref{}
err = logsRefs.ForEach(func(c *object.Commit) error {
logs = append(logs, &Ref{
Sha: c.Hash.String(),
Name: c.Hash.String(),
Date: c.Committer.When,
})

sort.Slice(commits, func(i, j int) bool {
return commits[i].Committer.When.Before(commits[j].Committer.When)
return nil
})

if err != nil {
return nil, err
}

ref := &Ref{
Sha: commits[0].Hash.String(),
Name: commits[0].Hash.String(), // Set Name to the commit hash because it is the first commit and doesn't have a name
Date: commits[0].Committer.When,
if reverse {
sort.Slice(logs, func(i, j int) bool {
return logs[i].Date.Before(logs[j].Date)
})
}

return logs, nil
}

func (gc *GitClient) GetFirstCommit() (*Ref, error) {
logs, err := gc.GetLogs(true)
if err != nil {
return nil, err
}

return ref, nil
return logs[0], nil
}

func NewGitClient() (*GitClient, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/writer/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func Write(changeLog *changelog.ChangeLogProperties) error {
var tmplSrc = `# Changelog

All notable changes to this project will be documented in this file.
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org).
{{range .Tags}}
Expand Down