Skip to content

Commit 2337d79

Browse files
authored
feat: Add support for conventional commits and templates (#10)
- Add support for conventional commits - Add a new template for conventional commits - Update the `prompt.go` file to include the new template - Remove the `ignoreLists` field from the `Command` struct in `git.go` fix #9
1 parent 03b4770 commit 2337d79

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

cmd/commit.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,25 @@ var commitCmd = &cobra.Command{
9999
return err
100100
}
101101

102+
// support conventional commits
103+
out, err = util.GetTemplate(
104+
prompt.ConventionalCommitTemplate,
105+
util.Data{
106+
"summary_points": summarizeDiff,
107+
},
108+
)
109+
if err != nil {
110+
return err
111+
}
112+
conventionalCommitPrefix, err := client.Completion(cmd.Context(), out)
113+
if err != nil {
114+
return err
115+
}
116+
117+
if conventionalCommitPrefix != "" {
118+
summarizeTitle = conventionalCommitPrefix + ": " + summarizeTitle
119+
}
120+
102121
if prompt.GetLanguage(viper.GetString("output.lang")) != prompt.DefaultLanguage {
103122
out, err = util.GetTemplate(
104123
prompt.TranslationTemplate,

git/git.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ var excludeFromDiff = []string{
1414
"go.sum",
1515
}
1616

17-
type Command struct {
18-
ignoreLists []string
19-
}
17+
type Command struct{}
2018

2119
func (c *Command) excludeFiles() []string {
2220
newFileLists := []string{}

prompt/prompt.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import (
1111
var files embed.FS
1212

1313
const (
14-
SummarizeFileDiffTemplate = "summarize_file_diff.tmpl"
15-
SummarizeTitleTemplate = "summarize_title.tmpl"
16-
TranslationTemplate = "translation.tmpl"
14+
SummarizeFileDiffTemplate = "summarize_file_diff.tmpl"
15+
SummarizeTitleTemplate = "summarize_title.tmpl"
16+
ConventionalCommitTemplate = "conventional_commit.tmpl"
17+
TranslationTemplate = "translation.tmpl"
1718
)
1819

1920
func init() {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
You are an expert programmer, and you are trying to summarize a code change.
2+
You went over every file that was changed in it.
3+
For some of these files changes where too big and were omitted in the files diff summary.
4+
Determine the best label for the commit.
5+
6+
Here are the labels you can choose from:
7+
8+
- build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
9+
- chore: Updating libraries, copyrights or other repo setting, includes updating dependencies.
10+
- ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, GitHub Actions)
11+
- docs: Non-code changes, such as fixing typos or adding new documentation
12+
- feat: a commit of the type feat introduces a new feature to the codebase
13+
- fix: A commit of the type fix patches a bug in your codebase
14+
- perf: A code change that improves performance
15+
- refactor: A code change that neither fixes a bug nor adds a feature
16+
- style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
17+
- test: Adding missing tests or correcting existing tests
18+
19+
20+
THE FILE SUMMARIES:
21+
###
22+
{{ .summary_points }}
23+
###
24+
25+
The label best describing this change:

0 commit comments

Comments
 (0)