[FEAT] support searching non default branches/tags when using git-grep (#3654)
resolves https://codeberg.org/forgejo/forgejo/pulls/3639#issuecomment-1806676 and https://codeberg.org/forgejo/forgejo/pulls/3513#issuecomment-1794990 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3654 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Shiny Nematoda <snematoda.751k2@aleeas.com> Co-committed-by: Shiny Nematoda <snematoda.751k2@aleeas.com>
This commit is contained in:
parent
9b4452fd7b
commit
b6ca8abcfd
9 changed files with 101 additions and 26 deletions
|
@ -12,6 +12,7 @@ import (
|
|||
code_indexer "code.gitea.io/gitea/modules/indexer/code"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"code.gitea.io/gitea/routers"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
|
@ -38,6 +39,7 @@ func TestSearchRepoNoIndexer(t *testing.T) {
|
|||
func testSearchRepo(t *testing.T, indexer bool) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
defer test.MockVariableValue(&setting.Indexer.RepoIndexerEnabled, indexer)()
|
||||
defer test.MockVariableValue(&testWebRoutes, routers.NormalRoutes())()
|
||||
|
||||
repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user2", "repo1")
|
||||
assert.NoError(t, err)
|
||||
|
@ -48,6 +50,13 @@ func testSearchRepo(t *testing.T, indexer bool) {
|
|||
|
||||
testSearch(t, "/user2/repo1/search?q=Description&page=1", []string{"README.md"}, indexer)
|
||||
|
||||
req := NewRequest(t, "HEAD", "/user2/repo1/search/branch/"+repo.DefaultBranch)
|
||||
if indexer {
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
} else {
|
||||
MakeRequest(t, req, http.StatusOK)
|
||||
}
|
||||
|
||||
defer test.MockVariableValue(&setting.Indexer.IncludePatterns, setting.IndexerGlobFromString("**.txt"))()
|
||||
defer test.MockVariableValue(&setting.Indexer.ExcludePatterns, setting.IndexerGlobFromString("**/y/**"))()
|
||||
|
||||
|
|
|
@ -190,10 +190,7 @@ func TestViewRepoWithSymlinks(t *testing.T) {
|
|||
|
||||
// TestViewAsRepoAdmin tests PR #2167
|
||||
func TestViewAsRepoAdmin(t *testing.T) {
|
||||
for user, expectedNoDescription := range map[string]bool{
|
||||
"user2": true,
|
||||
"user4": false,
|
||||
} {
|
||||
for _, user := range []string{"user2", "user4"} {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
session := loginUser(t, user)
|
||||
|
@ -206,7 +203,7 @@ func TestViewAsRepoAdmin(t *testing.T) {
|
|||
repoTopics := htmlDoc.doc.Find("#repo-topics").Children()
|
||||
repoSummary := htmlDoc.doc.Find(".repository-summary").Children()
|
||||
|
||||
assert.Equal(t, expectedNoDescription, noDescription.HasClass("no-description"))
|
||||
assert.True(t, noDescription.HasClass("no-description"))
|
||||
assert.True(t, repoTopics.HasClass("repo-topic"))
|
||||
assert.True(t, repoSummary.HasClass("repository-menu"))
|
||||
}
|
||||
|
@ -995,3 +992,33 @@ func TestViewRepoOpenWith(t *testing.T) {
|
|||
testOpenWith([]string{"test://"})
|
||||
})
|
||||
}
|
||||
|
||||
func TestRepoCodeSearchForm(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
testSearchForm := func(t *testing.T, indexer bool) {
|
||||
defer test.MockVariableValue(&setting.Indexer.RepoIndexerEnabled, indexer)()
|
||||
req := NewRequest(t, "GET", "/user2/repo1/src/branch/master")
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
action, exists := htmlDoc.doc.Find("form[data-test-tag=codesearch]").Attr("action")
|
||||
assert.True(t, exists)
|
||||
|
||||
branchSubURL := "/branch/master"
|
||||
|
||||
if indexer {
|
||||
assert.NotContains(t, action, branchSubURL)
|
||||
} else {
|
||||
assert.Contains(t, action, branchSubURL)
|
||||
}
|
||||
}
|
||||
|
||||
t.Run("indexer disabled", func(t *testing.T) {
|
||||
testSearchForm(t, false)
|
||||
})
|
||||
|
||||
t.Run("indexer enabled", func(t *testing.T) {
|
||||
testSearchForm(t, true)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue