From becdf338105cdd7a5dc7d93b778ed8366d60429f Mon Sep 17 00:00:00 2001 From: metif12 Date: Tue, 10 Nov 2026 10:42:10 +0330 Subject: [PATCH 1/3] feat: in-repo code search (Phase 2) --- search_routes.v | 45 ++++++++++++++++++++++++++++++++++++++++++- templates/search.html | 27 +++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/search_routes.v b/search_routes.v index a943b89a..82f1bb9d 100644 --- a/search_routes.v +++ b/search_routes.v @@ -1,9 +1,16 @@ module main import veb +import git const max_search_query_len = 100 +struct CodeSearchResult { + repo_user string + repo_name string + path string +} + // Preserve international project and user names while preventing callers from // turning the search box into an unbounded SQL LIKE wildcard query. fn normalize_search_query(query string) string { @@ -28,7 +35,11 @@ fn normalize_search_query(query string) string { pub fn (mut app App) search() veb.Result { query := (ctx.query['query'] or { '' }).trim_space() requested_type := ctx.query['type'] or { 'repos' } - search_type := if requested_type in ['repos', 'users'] { requested_type } else { 'repos' } + search_type := if requested_type in ['repos', 'users', 'code'] { + requested_type + } else { + 'repos' + } valid_query := normalize_search_query(query) repos := if search_type == 'repos' && valid_query != '' { @@ -43,5 +54,37 @@ pub fn (mut app App) search() veb.Result { []User{} } + mut code_results := []CodeSearchResult{} + if search_type == 'code' && valid_query != '' { + code_results = app.search_code(valid_query) + } + return $veb.html() } + +fn (mut app App) search_code(query string) []CodeSearchResult { + mut results := []CodeSearchResult{} + repos := sql app.db { + select from Repo where is_public == true limit 20 + } or { []Repo{} } + for repo in repos { + res := git.Git.exec_in_dir(repo.git_dir, ['grep', '-l', '-I', query, repo.primary_branch]) + if res.exit_code != 0 { + continue + } + for line in res.output.split_into_lines() { + path := line.trim_space() + if path == '' { + continue + } + results << CodeSearchResult{ repo_user: repo.user_name, repo_name: repo.name, path: path } + if results.len >= 50 { + break + } + } + if results.len >= 50 { + break + } + } + return results +} diff --git a/templates/search.html b/templates/search.html index 61f6c18e..ce74462d 100644 --- a/templates/search.html +++ b/templates/search.html @@ -15,10 +15,20 @@

Search

repositories | users - @else + | + code + @elseif search_type == 'users' repositories | users + | + code + @else + repositories + | + users + | + code @end @@ -66,6 +76,21 @@

@user.username

We couldn’t find any users matching "${valid_query}"

@end @end + + @if search_type == 'code' + @if code_results.len > 0 +

Showing ${code_results.len} code results

+ @for r in code_results +
+ +

@r.repo_user/@r.repo_name — @r.path

+
+
+ @end + @else +

We couldn’t find any code matching "${valid_query}"

+ @end + @end @include 'layout/footer.html' From 5083a9c6249a5ebfbf9b164e419d766c953dc024 Mon Sep 17 00:00:00 2001 From: metif12 Date: Thu, 12 Nov 2026 16:40:23 +0330 Subject: [PATCH 2/3] fix: code search links include branch --- search_routes.v | 3 ++- templates/search.html | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/search_routes.v b/search_routes.v index 82f1bb9d..d05d26a7 100644 --- a/search_routes.v +++ b/search_routes.v @@ -8,6 +8,7 @@ const max_search_query_len = 100 struct CodeSearchResult { repo_user string repo_name string + branch string path string } @@ -77,7 +78,7 @@ fn (mut app App) search_code(query string) []CodeSearchResult { if path == '' { continue } - results << CodeSearchResult{ repo_user: repo.user_name, repo_name: repo.name, path: path } + results << CodeSearchResult{ repo_user: repo.user_name, repo_name: repo.name, branch: repo.primary_branch, path: path } if results.len >= 50 { break } diff --git a/templates/search.html b/templates/search.html index ce74462d..1388acab 100644 --- a/templates/search.html +++ b/templates/search.html @@ -82,7 +82,7 @@

@user.username

Showing ${code_results.len} code results

@for r in code_results From d1da2469d028585141711ad2262be0690b6063bd Mon Sep 17 00:00:00 2001 From: metif12 Date: Fri, 13 Nov 2026 11:58:39 +0330 Subject: [PATCH 3/3] fix: make CI green (windows makev, markdown shadowing, search column) - windows: make.bat no longer exists in vlang/v, use makev.bat - highlight/markdown_test.v: rename const markdown to xss_markdown_sample to avoid shadowing import markdown (V checker now errors on markdown.to_html call in highlight/markdown.v when test const shadows the module) - repo/repo.v: order by stars_count (actual column via @[sql:]) not nr_stars (field name), fixing no such column error in search_repos Verified: - v -d sqlite test highlight/markdown_test.v -> 1 passed - v -cc gcc -d sqlite test search_test.v -> 1 passed (tcc lacks openssl, gcc used as in CI) --- .github/workflows/ci.yml | 2 +- highlight/markdown_test.v | 4 ++-- repo/repo.v | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 197487fb..00c1f1e7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -114,7 +114,7 @@ jobs: - name: Build V shell: cmd run: | - make.bat -gcc + makev.bat -gcc # Must run after "Build V": the script shells out to `v.exe`, which # does not exist until V is built. - name: Install SQLite diff --git a/highlight/markdown_test.v b/highlight/markdown_test.v index c5823681..8406cb46 100644 --- a/highlight/markdown_test.v +++ b/highlight/markdown_test.v @@ -1,9 +1,9 @@ module highlight -const markdown = ' test' +const xss_markdown_sample = ' test' fn test_convert_markdown_to_html() { - rendered := convert_markdown_to_html(markdown) + rendered := convert_markdown_to_html(xss_markdown_sample) assert !rendered.contains('