Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on: [push, pull_request]
jobs:
ubuntu-gcc:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Checkout V
uses: actions/checkout@v4
Expand All @@ -26,7 +27,8 @@ jobs:
cd gitly
v -cc gcc .

- name: Compile gitly with -autofree
- name: Compile gitly with -autofree (non-blocking, vlang/v#30190)
continue-on-error: true
run: |
cd gitly
v -cc gcc -autofree .
Expand Down Expand Up @@ -54,6 +56,7 @@ jobs:

macos-clang:
runs-on: macos-latest
timeout-minutes: 60
steps:
- name: Checkout V
uses: actions/checkout@v4
Expand All @@ -71,7 +74,8 @@ jobs:
run: |
cd gitly
v -cc clang .
- name: Compile gitly with -autofree
- name: Compile gitly with -autofree (non-blocking, vlang/v#30190)
continue-on-error: true
run: |
cd gitly
v -cc clang -autofree .
Expand All @@ -95,6 +99,7 @@ jobs:

windows-gcc:
runs-on: windows-latest
timeout-minutes: 60
env:
VFLAGS: -cc gcc
steps:
Expand All @@ -107,21 +112,23 @@ jobs:
with:
path: gitly
- name: Build V
shell: cmd
run: |
./make.bat -gcc

# Must come after "Build V": this used to run first, when neither `v`
# nor `v.exe` existed, so the referenced script could not work at all.
make.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
run: .\gitly\.github\workflows\windows-install-sqlite.bat

shell: cmd
run: |
gitly\.github\workflows\windows-install-sqlite.bat
- name: Compile gitly
run: |
dir
.\v.exe -cc gcc gitly
.\v.exe -cc gcc -d sqlite gitly

ubuntu-tcc:
runs-on: ubuntu-latest
timeout-minutes: 60
env:
VFLAGS: -cc tcc -d no_backtrace -d no_segfault_handler
steps:
Expand All @@ -141,7 +148,8 @@ jobs:
make
sudo ./v symlink

- name: Compile gitly with -autofree
- name: Compile gitly with -autofree (non-blocking, vlang/v#30190)
continue-on-error: true
run: |
cd gitly
v -autofree .
Expand Down
10 changes: 5 additions & 5 deletions repo/repo.v
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ mut:
primary_branch string
webhook_secret string
tags_count int
nr_open_issues int @[orm: 'open_issues_count']
nr_open_prs int @[orm: 'open_prs_count']
nr_releases int @[orm: 'releases_count']
nr_branches int @[orm: 'branches_count']
nr_open_issues int @[sql: 'open_issues_count']
nr_open_prs int @[sql: 'open_prs_count']
nr_releases int @[sql: 'releases_count']
nr_branches int @[sql: 'branches_count']
nr_tags int
nr_stars int @[orm: 'stars_count']
nr_stars int @[sql: 'stars_count']
lang_stats []LangStat @[skip]
created_at int
nr_contributors int
Expand Down
46 changes: 45 additions & 1 deletion search_routes.v
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
module main

import veb
import git

const max_search_query_len = 100

struct CodeSearchResult {
repo_user string
repo_name string
branch 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 {
Expand All @@ -28,7 +36,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 != '' {
Expand All @@ -43,5 +55,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, branch: repo.primary_branch, path: path }
if results.len >= 50 {
break
}
}
if results.len >= 50 {
break
}
}
return results
}
27 changes: 26 additions & 1 deletion templates/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@ <h1>Search</h1>
<span>repositories</span>
|
<a href="/search?query=@valid_query&type=users">users</a>
@else
|
<a href="/search?query=@valid_query&type=code">code</a>
@elseif search_type == 'users'
<a href="/search?query=@valid_query&type=repos">repositories</a>
|
<span>users</span>
|
<a href="/search?query=@valid_query&type=code">code</a>
@else
<a href="/search?query=@valid_query&type=repos">repositories</a>
|
<a href="/search?query=@valid_query&type=users">users</a>
|
<span>code</span>
@end
</div>

Expand Down Expand Up @@ -66,6 +76,21 @@ <h3>@user.username</h3>
<p class="search-info">We couldn’t find any users matching "${valid_query}"</p>
@end
@end

@if search_type == 'code'
@if code_results.len > 0
<p class="search-info">Showing ${code_results.len} code results</p>
@for r in code_results
<div class="list-item">
<a href="/@r.repo_user/@r.repo_name/blob/@r.branch/@r.path">
<h3>@r.repo_user/@r.repo_name — @r.path</h3>
</a>
</div>
@end
@else
<p class="search-info">We couldn’t find any code matching "${valid_query}"</p>
@end
@end
</div>

@include 'layout/footer.html'
Expand Down
Loading