1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

Add author filtering to commit view

This commit introduces a new feature to the commit view, allowing users
to filter commits based on the author's name or email address. Similar
to the existing path filtering functionality, accessible through <c-s>,
this feature allows users to filter the commit history by the currently
selected commit's author if the commit view is focused, or by typing in
the author's name or email address.

This feature adds an entry to the filtering menu, to provide users with
a familiar and intuitive experience
This commit is contained in:
Tristan Déplantes
2024-01-21 22:55:26 -05:00
committed by Stefan Haller
parent 329b434915
commit 503422a72e
22 changed files with 292 additions and 27 deletions

View File

@ -0,0 +1,70 @@
package filter_by_author
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var SelectAuthor = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Filter commits using the currently highlighted commit's author when the commit view is active",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {
config.AppState.GitLogShowGraph = "never"
},
SetupRepo: func(shell *Shell) {
commonSetup(shell)
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
SelectedLineIdx(0).
Press(keys.Universal.FilteringMenu)
t.ExpectPopup().Menu().
Title(Equals("Filtering")).
Select(Contains("Filter by 'Paul Oberstein <paul.oberstein@email.com>'")).
Confirm()
t.Views().Commits().
IsFocused().
Lines(
Contains("commit 7"),
Contains("commit 6"),
Contains("commit 5"),
Contains("commit 4"),
Contains("commit 3"),
Contains("commit 2"),
Contains("commit 1"),
Contains("commit 0"),
)
t.Views().Information().Content(Contains("Filtering by 'Paul Oberstein <paul.oberstein@email.com>'"))
t.Views().Commits().
Press(keys.Universal.FilteringMenu)
t.ExpectPopup().Menu().
Title(Equals("Filtering")).
Select(Contains("Stop filtering")).
Confirm()
t.Views().Commits().
IsFocused().
NavigateToLine(Contains("SK commit 0")).
Press(keys.Universal.FilteringMenu)
t.ExpectPopup().Menu().
Title(Equals("Filtering")).
Select(Contains("Filter by 'Siegfried Kircheis <siegfried.kircheis@email.com>'")).
Confirm()
t.Views().Commits().
IsFocused().
Lines(
Contains("commit 0"),
)
t.Views().Information().Content(Contains("Filtering by 'Siegfried Kircheis <siegfried.kircheis@email.com>'"))
},
})

View File

@ -0,0 +1,30 @@
package filter_by_author
import (
"fmt"
"strings"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
type AuthorInfo struct {
name string
numberOfCommits int
}
func commonSetup(shell *Shell) {
authors := []AuthorInfo{{"Yang Wen-li", 3}, {"Siegfried Kircheis", 1}, {"Paul Oberstein", 8}}
totalCommits := 0
repoStartDaysAgo := 100
for _, authorInfo := range authors {
for i := 0; i < authorInfo.numberOfCommits; i++ {
authorEmail := strings.ToLower(strings.ReplaceAll(authorInfo.name, " ", ".")) + "@email.com"
commitMessage := fmt.Sprintf("commit %d", i)
shell.SetAuthor(authorInfo.name, authorEmail)
shell.EmptyCommitDaysAgo(commitMessage, repoStartDaysAgo-totalCommits)
totalCommits++
}
}
}

View File

@ -0,0 +1,66 @@
package filter_by_author
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var TypeAuthor = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Filter commits by author using the typed in author",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {
},
SetupRepo: func(shell *Shell) {
commonSetup(shell)
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Status().
Focus().
Press(keys.Universal.FilteringMenu)
t.ExpectPopup().Menu().
Title(Equals("Filtering")).
Select(Contains("Enter author to filter by")).
Confirm()
t.ExpectPopup().Prompt().
Title(Equals("Enter author:")).
Type("Yang").
SuggestionLines(Equals("Yang Wen-li <yang.wen-li@email.com>")).
ConfirmFirstSuggestion()
t.Views().Commits().
IsFocused().
Lines(
Contains("commit 2"),
Contains("commit 1"),
Contains("commit 0"),
)
t.Views().Information().Content(Contains("Filtering by 'Yang Wen-li <yang.wen-li@email.com>'"))
t.Views().Status().
Focus().
Press(keys.Universal.FilteringMenu)
t.ExpectPopup().Menu().
Title(Equals("Filtering")).
Select(Contains("Enter author to filter by")).
Confirm()
t.ExpectPopup().Prompt().
Title(Equals("Enter author:")).
Type("Siegfried").
SuggestionLines(Equals("Siegfried Kircheis <siegfried.kircheis@email.com>")).
ConfirmFirstSuggestion()
t.Views().Commits().
IsFocused().
Lines(
Contains("commit 0"),
)
t.Views().Information().Content(Contains("Filtering by 'Siegfried Kircheis <siegfried.kircheis@email.com>'"))
},
})

View File

@ -15,6 +15,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/integration/tests/diff"
"github.com/jesseduffield/lazygit/pkg/integration/tests/file"
"github.com/jesseduffield/lazygit/pkg/integration/tests/filter_and_search"
"github.com/jesseduffield/lazygit/pkg/integration/tests/filter_by_author"
"github.com/jesseduffield/lazygit/pkg/integration/tests/filter_by_path"
"github.com/jesseduffield/lazygit/pkg/integration/tests/interactive_rebase"
"github.com/jesseduffield/lazygit/pkg/integration/tests/misc"
@ -149,6 +150,8 @@ var tests = []*components.IntegrationTest{
filter_and_search.NestedFilter,
filter_and_search.NestedFilterTransient,
filter_and_search.NewSearch,
filter_by_author.SelectAuthor,
filter_by_author.TypeAuthor,
filter_by_path.CliArg,
filter_by_path.SelectFile,
filter_by_path.TypeFile,