Skip to content

Commit

Permalink
feat: adds a new flag to specify github commits URL
Browse files Browse the repository at this point in the history
  • Loading branch information
joselitofilho committed Apr 6, 2024
1 parent 7545ffc commit b3c8782
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion cmd/go-conventional-commits/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ func main() {
Default: "",
Help: "The base project link that we will concatenate the task ID. For example: https://myproject.domain.com/board/",
})
commitsURL := parser.String("", "commitsURL", &argparse.Options{
Required: false,
Default: "",
Help: "The base commit URL that we will concatenate the commit hash. For example: https://github.com/user/project/commit/",
})
repoPath := parser.String("p", "path", &argparse.Options{
Required: false,
Default: ".",
Expand All @@ -62,7 +67,7 @@ func main() {
log.Fatalln(err)
}

changeLogs := transformers.TransformChangeLogs(transformers.TransformMessages(commits), *projectLink)
changeLogs := transformers.TransformChangeLogs(transformers.TransformMessages(commits, *commitsURL), *projectLink)

codeCoverageValue := buildCoverageValue(*repoPath, *coverageCmd)

Expand Down
4 changes: 2 additions & 2 deletions internal/transformers/transformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ func TransformChangeLogs(messages []string, projectLink string) changelogs.Chang
}

// TransformChangeLog takes a commits message and parses it into a slice of string
func TransformMessages(commits []*gitlog.Commit) []string {
func TransformMessages(commits []*gitlog.Commit, commitsURL string) []string {
messages := make([]string, 0, len(commits))

for _, commit := range commits {
hash := ""
if commit.Hash != nil && len(commit.Hash.Short) > 0 {
hash = " #" + commit.Hash.Short
hash = " #" + commitsURL + commit.Hash.Short
}

message := commit.Subject + hash + "\n\n" + commit.Body
Expand Down
4 changes: 2 additions & 2 deletions internal/transformers/transformers_messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ func TestTransforms_Messages(t *testing.T) {
Subject: "feat: added a new feature",
Body: "Refs #GCC-123",
}}
messages := transformers.TransformMessages(commits)
require.Equal(t, []string{"feat: added a new feature #f4f7dec\n\nRefs #GCC-123"}, messages)
messages := transformers.TransformMessages(commits, "https://url/commits/")
require.Equal(t, []string{"feat: added a new feature #https://url/commits/f4f7dec\n\nRefs #GCC-123"}, messages)
}

0 comments on commit b3c8782

Please sign in to comment.