Skip to content

Commit

Permalink
✨ Add configuration to set sign-off
Browse files Browse the repository at this point in the history
Allow setting the default state for sign-off of commits.

Identified a problem with reseting the footer model which was not
changing the signoff to the default value. By fixing this issue, there
is no need to use the toggle signoff method within the footer model.
  • Loading branch information
mikelorant committed Jan 25, 2023
1 parent 78c7f77 commit f765d56
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ view:
# Default: below
emojiSelector: below

commit:
# Enable author sign-off for commits.
# Values: true, false
# Default: false
signoff: false

authors:
# List of extra authors.
- name: John Doe
Expand Down
13 changes: 10 additions & 3 deletions internal/ui/footer/footer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ type Model struct {
}

func New(state *commit.State) Model {
if len(state.Repository.Users) == 0 {
state.Repository.Users = []repository.User{{}}
authors := concatSlice(state.Repository.Users, state.Config.Authors)

if len(authors) == 0 {
authors = []repository.User{{}}
}

return Model{
Author: state.Repository.Users[0],
Author: authors[0],
}
}

Expand Down Expand Up @@ -68,3 +70,8 @@ func (m Model) signoff() string {
func ToModel(m tea.Model, c tea.Cmd) (Model, tea.Cmd) {
return m.(Model), c
}

func concatSlice[T any](first []T, second []T) []T {
n := len(first)
return append(first[:n:n], second...)
}
32 changes: 32 additions & 0 deletions internal/ui/testdata/config_signoff_off.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
commit 1 (HEAD -> master)
author: John Doe <[email protected]>
date: Sat Jan 1 01:00:00 2022 +0000

┌────┐ ┌─────────────────────────────────────────────────────────────┐
│ │ │ placeholder │ 0/50
└────┘ └─────────────────────────────────────────────────────────────┘

┌──────────────────────────────────────────────────────────────────────────┐
│? Choose an emoji: ● │
│❯ 🎨 - Improve structure / format of the code. │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└──────────────────────────────────────────────────────────────────────────┘

┌──────────────────────────────────────────────────────────────────────────┐
│ placeholder │
│ ~ │
│ ~ │
│ ~ │
│ ~ │
│ ~ │
└──────────────────────────────────────────────────────────────────────────┘

Alt + <enter> Commit <s> Sign-off </> Help Summary <tab>
Ctrl + <c> Cancel Author <tab> + Shift
32 changes: 32 additions & 0 deletions internal/ui/testdata/config_signoff_on.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
commit 1 (HEAD -> master)
author: John Doe <[email protected]>
date: Sat Jan 1 01:00:00 2022 +0000

┌────┐ ┌─────────────────────────────────────────────────────────────┐
│ │ │ placeholder │ 0/50
└────┘ └─────────────────────────────────────────────────────────────┘

┌──────────────────────────────────────────────────────────────────────────┐
│? Choose an emoji: ● │
│❯ 🎨 - Improve structure / format of the code. │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└──────────────────────────────────────────────────────────────────────────┘

┌──────────────────────────────────────────────────────────────────────────┐
│ placeholder │
│ ~ │
│ ~ │
│ ~ │
└──────────────────────────────────────────────────────────────────────────┘

Signed-off-by: John Doe <[email protected]>

Alt + <enter> Commit <s> Sign-off </> Help Summary <tab>
Ctrl + <c> Cancel Author <tab> + Shift
3 changes: 2 additions & 1 deletion internal/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (m *Model) Configure(state *commit.State) {
}

m.defaultFocus(state.Config)
m.signoff = state.Config.Commit.Signoff
}

func (m Model) Start() (*commit.Request, error) {
Expand Down Expand Up @@ -227,7 +228,6 @@ func (m Model) onKeyPress(msg tea.KeyMsg) keyResponse {
return keyResponse{model: m, cmd: tea.Quit, end: true}
case "alt+s":
m.signoff = !m.signoff
m.models.footer.ToggleSignoff()

return keyResponse{model: m, end: false, nilMsg: true}
case "alt+t":
Expand Down Expand Up @@ -276,6 +276,7 @@ func (m Model) resetModels() Model {
m.models.body.Blur()
m.models.body.Height = bodyDefaultHeight
m.models.footer.Author = m.models.info.Author
m.models.footer.Signoff = m.signoff
m.models.help.Blur()

return m
Expand Down
24 changes: 24 additions & 0 deletions internal/ui/ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,30 @@ func TestModel(t *testing.T) {
},
},
},
{
name: "config_signoff_off",
args: args{
state: func(s *commit.State) {
s.Config.Commit.Signoff = false
},
model: func(m ui.Model) ui.Model {
m, _ = ToModel(m.Update(nil))
return m
},
},
},
{
name: "config_signoff_on",
args: args{
state: func(s *commit.State) {
s.Config.Commit.Signoff = true
},
model: func(m ui.Model) ui.Model {
m, _ = ToModel(m.Update(nil))
return m
},
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit f765d56

Please sign in to comment.