diff --git a/model/commit.go b/model/commit.go index 4163b12..a9a4f83 100644 --- a/model/commit.go +++ b/model/commit.go @@ -41,6 +41,13 @@ func (c *Commit) getQuestion() []*survey.Question { VimMode: true, }, Validate: survey.Required, + }, { + Name: "scope", + Prompt: &survey.Input{ + Message: "Enter commit type scope", + Help: "Scope should represent the scope of commit type", + }, + Validate: survey.MaxLength(8), }, { Name: "title", Prompt: &survey.Input{ @@ -55,10 +62,9 @@ func (c *Commit) getQuestion() []*survey.Question { return err }, }, { - Name: "message", - Prompt: &survey.Multiline{ - Message: "Enter commit message", - Help: "Message will represent everything that commit have done", + Name: "hasMessage", + Prompt: &survey.Confirm{ + Message: "Do you have commit message?", }, }, } @@ -84,7 +90,16 @@ func (c *Commit) Commit(key string, option CommitOption) { } manager.StartResultManager().Save("", survey.Ask(qs, &answers)).IfNoError(func() { + if answers.HasMessage { + messageQuestion := &survey.Multiline{ + Message: "Enter commit message", + Help: "Message will represent everything that commit have done", + } + survey.AskOne(messageQuestion, &answers.Message, nil) + } + om.Log.ToDebug("commit type", answers.GetType()) + om.Log.ToDebug("commit scope", answers.Scope) om.Log.ToDebug("commit title", answers.Title) om.Log.ToDebug("commit message", answers.Message) diff --git a/model/commit_message.go b/model/commit_message.go index 8e67ab9..b5a7cd6 100644 --- a/model/commit_message.go +++ b/model/commit_message.go @@ -7,9 +7,11 @@ import ( // CommitMessage is the commit message for save in commit. type CommitMessage struct { - Type string - Title string - Message string + Type string + Scope string + Title string + HasMessage bool + Message string } // GetType will try to format the key to right way. @@ -24,8 +26,12 @@ func (c *CommitMessage) GetType() string { } func (c *CommitMessage) GetMessage() string { + if c.Scope != "" { + c.Scope = "(" + c.Scope + ")" + } + if c.Message == "" { - return fmt.Sprintf("[%s] %s", c.GetType(), c.Title) + return fmt.Sprintf("%s%s: %s", c.GetType(), c.Scope, c.Title) } - return fmt.Sprintf("[%s] %s\n%s", c.GetType(), c.Title, c.Message) + return fmt.Sprintf("%s%s: %s\n\n%s", c.GetType(), c.Scope, c.Title, c.Message) }