Skip to content

Commit

Permalink
feat(Commit): Rename commit.Info to commit.Commit and relocate the st…
Browse files Browse the repository at this point in the history
…ruct inside the commit pkg
  • Loading branch information
HRemonen committed Oct 28, 2023
1 parent 15d5a08 commit 358c4ca
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 43 deletions.
2 changes: 1 addition & 1 deletion cmd/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ var commitCmd = &cobra.Command{
}
}

commitInfo := commit.Info{
commitInfo := commit.Commit{
CommitType: commitType,
CommitScope: commitScope,
CommitDescription: commitDescription,
Expand Down
41 changes: 26 additions & 15 deletions pkg/commit/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ import (
"strings"
)

type Commit struct {

Check warning on line 17 in pkg/commit/commit.go

View workflow job for this annotation

GitHub Actions / lint

exported: exported type Commit should have comment or be unexported (revive)
CommitType string
CommitScope string
CommitDescription string
CommitBody string
IsCoAuthored bool
CoAuthors []string
IsBreakingChange bool
BreakingChangeDescription string
}

// getStringsFromTerminalOutput takes the os/exec functions returned byte array
// and transforms the bytes into an array of lines
func getStagedFilesFromTerminalOutput(output []byte) []string {
Expand Down Expand Up @@ -48,38 +59,38 @@ func GetStagedFiles() ([]string, error) {
}

// CreateCommitMessage creates a commit message in the Conventional Commits format.
func createCommitMessage(commitInfo Info) string {
func createCommitMessage(commit Commit) string {
var commitMessage string
commitMessage = commitInfo.CommitType
commitMessage = commit.CommitType

if commitInfo.CommitScope != "" {
commitMessage += "(" + commitInfo.CommitScope + ")"
if commit.CommitScope != "" {
commitMessage += "(" + commit.CommitScope + ")"
}

if commitInfo.IsBreakingChange {
if commit.IsBreakingChange {
commitMessage += "!"
}

commitMessage += ": " + commitInfo.CommitDescription
commitMessage += ": " + commit.CommitDescription

if commitInfo.CommitBody != "" {
commitMessage += "\n\n" + commitInfo.CommitBody
if commit.CommitBody != "" {
commitMessage += "\n\n" + commit.CommitBody
}

// TODO: ADD configurable option for adding [skip ci] to commit message on docs commits
/* if commitInfo.CommitType == "docs" {
/* if commit.CommitType == "docs" {
commitMessage += "\n"
commitMessage += "\n[skip ci]"
} */

if commitInfo.IsBreakingChange {
if commit.IsBreakingChange {
commitMessage += "\n"
commitMessage += "\nBREAKING CHANGE: " + commitInfo.BreakingChangeDescription
commitMessage += "\nBREAKING CHANGE: " + commit.BreakingChangeDescription
}

if commitInfo.IsCoAuthored {
if commit.IsCoAuthored {
commitMessage += "\n"
for _, coauth := range commitInfo.CoAuthors {
for _, coauth := range commit.CoAuthors {
commitMessage += "\nCo-authored-by: " + coauth
}
}
Expand All @@ -88,8 +99,8 @@ func createCommitMessage(commitInfo Info) string {
}

// CreateGitCommit creates a Git commit with the given message and files.
func CreateGitCommit(commitInfo Info, files []string) error {
commitMessage := createCommitMessage(commitInfo)
func CreateGitCommit(commit Commit, files []string) error {
commitMessage := createCommitMessage(commit)

commitArgs := append([]string{"commit", "-m", commitMessage}, files...)

Expand Down
27 changes: 0 additions & 27 deletions pkg/commit/info.go

This file was deleted.

0 comments on commit 358c4ca

Please sign in to comment.