From bed64285555e6c9bf5ebf34b7538e1da67e926b2 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 12 May 2026 17:52:55 +0300 Subject: [PATCH] all: vfmt --- ci/ci_status.v | 8 +++-- cli.v | 3 +- repo/branch.v | 5 ++-- repo/branch_routes.v | 3 +- repo/repo.v | 3 +- repo/tag.v | 3 +- static/assets/version | 2 +- tests/first_run.v | 68 ++++++++++++++++++++++++++++--------------- user/user_routes.v | 8 ++--- utils.v | 10 +++---- 10 files changed, 66 insertions(+), 47 deletions(-) diff --git a/ci/ci_status.v b/ci/ci_status.v index 1595e09..0839ec1 100644 --- a/ci/ci_status.v +++ b/ci/ci_status.v @@ -41,7 +41,7 @@ fn (s CiStatusEnum) icon() string { } struct CiStatus { - id int @[primary; sql: serial] + id int @[primary; sql: serial] repo_id int commit_hash string branch string @@ -97,7 +97,8 @@ fn (mut app App) add_ci_status(ci CiStatus) ! { fn (mut app App) update_ci_status(repo_id int, commit_hash string, status CiStatusEnum) ! { updated := int(time.now().unix()) sql app.db { - update CiStatus set status = status, updated_at = updated where repo_id == repo_id && commit_hash == commit_hash + update CiStatus set status = status, updated_at = updated where repo_id == repo_id + && commit_hash == commit_hash }! } @@ -119,7 +120,8 @@ fn (mut app App) upsert_ci_status(repo_id int, commit_hash string, branch string id := existing.id updated := int(time.now().unix()) sql app.db { - update CiStatus set status = status, ci_run_id = ci_run_id, updated_at = updated where id == id + update CiStatus set status = status, ci_run_id = ci_run_id, updated_at = updated + where id == id }! } diff --git a/cli.v b/cli.v index fa27ae0..05e4a95 100644 --- a/cli.v +++ b/cli.v @@ -15,8 +15,7 @@ pub fn (mut app App) command_fetcher() ! { match args[0] { 'adduser' { if args.len > 4 { - app.register_user(args[1], args[2], args[3], args[4..], false, - false)! + app.register_user(args[1], args[2], args[3], args[4..], false, false)! println('Added user ${args[1]}') } else { error('Not enough arguments (3 required but only ${args.len} given)') diff --git a/repo/branch.v b/repo/branch.v index 38ec4cc..a35a10d 100644 --- a/repo/branch.v +++ b/repo/branch.v @@ -26,7 +26,8 @@ fn (mut app App) fetch_branches(repo Repo) ! { fn (mut app App) fetch_branch(repo Repo, branch_name string) ! { last_commit_hash := repo.get_last_branch_commit_hash(branch_name) - branch_data := repo.git('log ${branch_name} -1 --pretty="%aE${log_field_separator}%cD" ${last_commit_hash}') + branch_data := + repo.git('log ${branch_name} -1 --pretty="%aE${log_field_separator}%cD" ${last_commit_hash}') log_parts := branch_data.split(log_field_separator) author_email := log_parts[0] @@ -68,7 +69,7 @@ fn (mut app App) create_branch_or_update(repository_id int, branch_name string, date: date } - app.debug("inserting branch: ${new_branch}") + app.debug('inserting branch: ${new_branch}') sql app.db { insert new_branch into Branch diff --git a/repo/branch_routes.v b/repo/branch_routes.v index 41e246d..5a9202f 100644 --- a/repo/branch_routes.v +++ b/repo/branch_routes.v @@ -5,8 +5,7 @@ import api @['/api/v1/:user/:repo_name/branches/count'] fn (mut app App) handle_branch_count(username string, repo_name string) veb.Result { - has_access := app.has_user_repo_read_access_by_repo_name(ctx, ctx.user.id, username, - repo_name) + has_access := app.has_user_repo_read_access_by_repo_name(ctx, ctx.user.id, username, repo_name) if !has_access { return ctx.json_error('Not found') diff --git a/repo/repo.v b/repo/repo.v index 833cca0..fa7864a 100644 --- a/repo/repo.v +++ b/repo/repo.v @@ -646,8 +646,7 @@ fn (r &Repo) parse_top_file_line(line string, branch string) ?File { } fn (r &Repo) top_files(branch string, limit int) []File { - git_result := git.Git.exec_in_dir(r.git_dir, ['ls-tree', '-r', '--full-name', '--long', - branch]) + git_result := git.Git.exec_in_dir(r.git_dir, ['ls-tree', '-r', '--full-name', '--long', branch]) if git_result.exit_code != 0 { eprintln('git ls-tree top files error: ${git_result.output}') return []File{} diff --git a/repo/tag.v b/repo/tag.v index 892b373..73e54c0 100644 --- a/repo/tag.v +++ b/repo/tag.v @@ -16,7 +16,8 @@ mut: } fn (mut app App) fetch_tags(repo Repo) ! { - tags_output := repo.git('tag --format="%(refname:lstrip=2)${log_field_separator}%(objectname)${log_field_separator}%(subject)${log_field_separator}%(authoremail)${log_field_separator}%(creatordate:rfc)"') + tags_output := + repo.git('tag --format="%(refname:lstrip=2)${log_field_separator}%(objectname)${log_field_separator}%(subject)${log_field_separator}%(authoremail)${log_field_separator}%(creatordate:rfc)"') for tag_output in tags_output.split_into_lines() { tag_parts := tag_output.split(log_field_separator) diff --git a/static/assets/version b/static/assets/version index 6ed80cd..8522f42 100644 --- a/static/assets/version +++ b/static/assets/version @@ -1 +1 @@ -9f790cd \ No newline at end of file +259c97a \ No newline at end of file diff --git a/tests/first_run.v b/tests/first_run.v index 32dfcb2..428a006 100644 --- a/tests/first_run.v +++ b/tests/first_run.v @@ -67,7 +67,7 @@ fn main() { test_blob_page(test_username, repo_name, test_github_repo_primary_branch, 'examples/hello.v') // test_refs_page(test_username, repo_name) // test_api_branches_count(test_username, repo_name) - ilog("all tests passed!") + ilog('all tests passed!') after()! } @@ -178,9 +178,8 @@ fn test_index_page() { // returns headers and token fn register_user(username string, password string, email string) !(http.Header, string) { - response := http.post(prepare_url('register'), 'username=${username}&password=${password}&email=${email}&no_redirect=1') or { - return err - } + response := http.post(prepare_url('register'), + 'username=${username}&password=${password}&email=${email}&no_redirect=1') or { return err } mut token := '' for val in response.header.values(.set_cookie) { @@ -208,28 +207,36 @@ fn test_user_page(username string) { fn test_repo_page(username string, repo_name string) { ilog('Testing the new repo /${username}/${repo_name} page is up') - repo_page_result := http.get(prepare_url("${username}/${repo_name}")) or { exit_with_message(err.str()) } + repo_page_result := http.get(prepare_url('${username}/${repo_name}')) or { + exit_with_message(err.str()) + } assert repo_page_result.status_code == 200 } fn test_branch_page(username string, repo_name string, branch_name string) { ilog('Testing the new branch /${username}/${repo_name}/tree/${branch_name} page is up') - branch_page_result := http.get(prepare_url("${username}/${repo_name}/tree/${branch_name}")) or { exit_with_message(err.str()) } + branch_page_result := http.get(prepare_url('${username}/${repo_name}/tree/${branch_name}')) or { + exit_with_message(err.str()) + } assert branch_page_result.status_code == 200 } fn test_repos_page(username string) { ilog('Testing the new repos /${username}/repos page is up') - repos_page_result := http.get(prepare_url("${username}/repos")) or { exit_with_message(err.str()) } + repos_page_result := http.get(prepare_url('${username}/repos')) or { + exit_with_message(err.str()) + } assert repos_page_result.status_code == 200 } fn test_contributors_page(username string, repo_name string) { ilog('Testing the new contributors /${username}/${repo_name}/contributors page is up') - contributors_page_result := http.get(prepare_url("${username}/${repo_name}/contributors")) or { exit_with_message(err.str()) } + contributors_page_result := http.get(prepare_url('${username}/${repo_name}/contributors')) or { + exit_with_message(err.str()) + } assert contributors_page_result.status_code == 200 } @@ -237,21 +244,27 @@ fn test_contributors_page(username string, repo_name string) { fn test_commits_page(username string, repo_name string, branch_name string) { ilog('Testing the new commits /${username}/${repo_name}/${branch_name}/commits/1 page is up') // Doesn't work with commits/[no 1] - commits_page_result := http.get(prepare_url("${username}/${repo_name}/${branch_name}/commits/1")) or { exit_with_message(err.str()) } + commits_page_result := http.get(prepare_url('${username}/${repo_name}/${branch_name}/commits/1')) or { + exit_with_message(err.str()) + } assert commits_page_result.status_code == 200 } fn test_branches_page(username string, repo_name string) { ilog('Testing the new branches /${username}/${repo_name}/branches page is up') - branches_page_result := http.get(prepare_url("${username}/${repo_name}/branches")) or { exit_with_message(err.str()) } + branches_page_result := http.get(prepare_url('${username}/${repo_name}/branches')) or { + exit_with_message(err.str()) + } assert branches_page_result.status_code == 200 } fn test_api_branches_count(username string, repo_name string) { ilog('Testing if api/v1/${username}/${repo_name}/branches/count works') - api_branches_count_result := http.get(prepare_url("api/v1/${username}/${repo_name}/branches/count")) or { exit_with_message(err.str()) } + api_branches_count_result := http.get(prepare_url('api/v1/${username}/${repo_name}/branches/count')) or { + exit_with_message(err.str()) + } // api_branches_count_result := http.fetch( // method: .get // url: prepare_url("api/v1/${username}/${repo_name}/branches/count") @@ -267,48 +280,57 @@ fn test_api_branches_count(username string, repo_name string) { fn test_refs_page(username string, repo_name string) { ilog('Testing the new refs /${username}/${repo_name}/info/refs page is up') - refs_page_result := http.get(prepare_url("${username}/${repo_name}/info/refs")) or { exit_with_message(err.str()) } + refs_page_result := http.get(prepare_url('${username}/${repo_name}/info/refs')) or { + exit_with_message(err.str()) + } assert refs_page_result.status_code == 200 } fn test_oauth_page() { ilog('Testing the new oauth /oauth page is up') - oauth_page_result := http.get(prepare_url("oauth")) or { exit_with_message(err.str()) } + oauth_page_result := http.get(prepare_url('oauth')) or { exit_with_message(err.str()) } assert oauth_page_result.status_code == 200 } fn test_repo_tree(username string, repo_name string, branch_name string, path string) { ilog('Testing the new tree /${username}/${repo_name}/tree/${branch_name}/${path} page is up') - repo_tree_result := http.get(prepare_url("${username}/${repo_name}/tree/${branch_name}/${path}")) or { exit_with_message(err.str()) } + repo_tree_result := http.get(prepare_url('${username}/${repo_name}/tree/${branch_name}/${path}')) or { + exit_with_message(err.str()) + } assert repo_tree_result.status_code == 200 } + // fn test_issues_page(username string) { // test_endpoint_page("${username}/issues", 'issues') // } fn test_stars_page(username string) { - ilog("Testing the new stars /${username}/stars page is up") - stars_page_result := http.get(prepare_url("${username}/stars")) or { exit_with_message(err.str()) } + ilog('Testing the new stars /${username}/stars page is up') + stars_page_result := http.get(prepare_url('${username}/stars')) or { + exit_with_message(err.str()) + } assert stars_page_result.status_code == 200 } fn test_settings_page(username string) { ilog('Testing the new settings /${username}/settings page is up') - settings_page_result := http.get(prepare_url("${username}/settings")) or { exit_with_message(err.str()) } + settings_page_result := http.get(prepare_url('${username}/settings')) or { + exit_with_message(err.str()) + } assert settings_page_result.status_code == 200 } fn test_blob_page(username string, repo_name string, branch_name string, path string) { - url := "${username}/${repo_name}/blob/${branch_name}/${path}" + url := '${username}/${repo_name}/blob/${branch_name}/${path}' ilog('Testing the new blob /${url} page is up') blob_page_result := http.fetch( - method: .get - url: prepare_url(url) + method: .get + url: prepare_url(url) ) or { exit_with_message(err.str()) } assert blob_page_result.status_code == 200 @@ -316,12 +338,12 @@ fn test_blob_page(username string, repo_name string, branch_name string, path st } fn test_repo_settings_page(username string, repo_name string) { - test_endpoint_page("${username}/${repo_name}/settings", 'settings') + test_endpoint_page('${username}/${repo_name}/settings', 'settings') } fn test_endpoint_page(endpoint string, pagename string) { - ilog('Testing the new ${pagename} /${endpoint} page is up') - endpoint_result := http.get(prepare_url("${endpoint}")) or { exit_with_message(err.str()) } + ilog('Testing the new ${pagename} /${endpoint} page is up') + endpoint_result := http.get(prepare_url('${endpoint}')) or { exit_with_message(err.str()) } assert endpoint_result.status_code == 200 } diff --git a/user/user_routes.v b/user/user_routes.v index 4c0f3f7..db2d9d3 100644 --- a/user/user_routes.v +++ b/user/user_routes.v @@ -160,9 +160,8 @@ pub fn (mut app App) handle_update_user_settings(mut ctx Context, username strin } fn (mut app App) rename_user_directory(old_name string, new_name string) { - os.mv('${app.config.repo_storage_path}/${old_name}', '${app.config.repo_storage_path}/${new_name}') or { - panic(err) - } + os.mv('${app.config.repo_storage_path}/${old_name}', + '${app.config.repo_storage_path}/${new_name}') or { panic(err) } } pub fn (mut app App) register(mut ctx Context) veb.Result { @@ -238,8 +237,7 @@ pub fn (mut app App) handle_register(mut ctx Context, username string, email str } // TODO: refactor - is_registered := app.register_user(username, hashed_password, salt, [email], false, - no_users) or { + is_registered := app.register_user(username, hashed_password, salt, [email], false, no_users) or { ctx.error('Failed to register') return app.register(mut ctx) } diff --git a/utils.v b/utils.v index 995a594..daf6b7d 100644 --- a/utils.v +++ b/utils.v @@ -58,13 +58,11 @@ fn check_last_page(total int, offset int, per_page int) bool { } const is_dev = true - + fn css2(s string) veb.RawHtml { if is_dev { - return '' - } - else { - return '' + return '' + } else { + return '' } } - -- 2.39.5