@@ -19,8 +19,8 @@ func init() {
1919 commitCmd .PersistentFlags ().StringP ("file" , "f" , ".git/COMMIT_EDITMSG" , "commit message file" )
2020 commitCmd .PersistentFlags ().StringP ("model" , "m" , "gpt-3.5-turbo" , "openai model" )
2121 commitCmd .PersistentFlags ().StringP ("lang" , "l" , "en" , "summarizing language uses English by default" )
22- _ = viper .BindPFlag ("openai .model" , commitCmd .PersistentFlags ().Lookup ("model" ))
23- _ = viper .BindPFlag ("output .lang" , commitCmd .PersistentFlags ().Lookup ("lang" ))
22+ _ = viper .BindPFlag ("commit .model" , commitCmd .PersistentFlags ().Lookup ("model" ))
23+ _ = viper .BindPFlag ("commit .lang" , commitCmd .PersistentFlags ().Lookup ("lang" ))
2424 _ = viper .BindPFlag ("output.file" , commitCmd .PersistentFlags ().Lookup ("file" ))
2525}
2626
@@ -42,6 +42,10 @@ var commitCmd = &cobra.Command{
4242
4343 color .Green ("Summarize the commit message use " + viper .GetString ("openai.model" ) + " model" )
4444
45+ if prompt .GetLanguage (viper .GetString ("commit.lang" )) != prompt .DefaultLanguage {
46+ viper .Set ("output.lang" , viper .GetString ("commit.lang" ))
47+ }
48+
4549 client , err := openai .New (
4650 viper .GetString ("openai.api_key" ),
4751 viper .GetString ("openai.model" ),
@@ -52,7 +56,6 @@ var commitCmd = &cobra.Command{
5256 return err
5357 }
5458
55- // Get summarize comment from diff datas
5659 out , err := util .GetTemplate (
5760 prompt .SummarizeFileDiffTemplate ,
5861 util.Data {
@@ -63,6 +66,7 @@ var commitCmd = &cobra.Command{
6366 return err
6467 }
6568
69+ // Get summarize comment from diff datas
6670 color .Cyan ("We are trying to summarize a git diff" )
6771 summarizeDiff , err := client .Completion (cmd .Context (), out )
6872 if err != nil {
@@ -79,6 +83,7 @@ var commitCmd = &cobra.Command{
7983 return err
8084 }
8185
86+ // Get summarize title from diff datas
8287 color .Cyan ("We are trying to summarize a title for pull request" )
8388 summarizeTitle , err := client .Completion (cmd .Context (), out )
8489 if err != nil {
@@ -98,6 +103,7 @@ var commitCmd = &cobra.Command{
98103 return err
99104 }
100105
106+ // translate a git commit message
101107 color .Cyan ("We are trying to translate a git commit message to " + prompt .GetLanguage (viper .GetString ("output.lang" )) + "language" )
102108 summarize , err := client .Completion (cmd .Context (), out )
103109 if err != nil {
@@ -107,10 +113,14 @@ var commitCmd = &cobra.Command{
107113 } else {
108114 message = strings .TrimSpace (summarizeTitle ) + "\n \n " + strings .TrimSpace (summarizeDiff )
109115 }
116+
117+ // Output commit summary data from AI
110118 color .Yellow ("================Commit Summary====================" )
111119 color .Yellow ("\n " + message + "\n \n " )
112120 color .Yellow ("==================================================" )
113121 color .Cyan ("Write the commit message to " + viper .GetString ("output.file" ) + " file" )
122+
123+ // write commit message to git staging file
114124 err = os .WriteFile (viper .GetString ("output.file" ), []byte (message ), 0o644 )
115125 if err != nil {
116126 return err
0 commit comments