Skip to content

Commit

Permalink
feat(ui-prompt): add scope to commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamontat Chantrachirathumrong committed Feb 5, 2019
1 parent 5b9be10 commit a58aa0c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
23 changes: 19 additions & 4 deletions model/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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?",
},
},
}
Expand All @@ -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)

Expand Down
16 changes: 11 additions & 5 deletions model/commit_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
}

0 comments on commit a58aa0c

Please sign in to comment.