From 9e36e173e0f948d6222cbc5e37e2df3d9cd2d1d5 Mon Sep 17 00:00:00 2001 From: metif12 Date: Tue, 10 Nov 2026 10:48:54 +0330 Subject: [PATCH 1/3] feat: revert a commit (Phase 3) --- commit/commit_routes.v | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/commit/commit_routes.v b/commit/commit_routes.v index 35564987..9086581d 100644 --- a/commit/commit_routes.v +++ b/commit/commit_routes.v @@ -4,6 +4,7 @@ import veb import time import api import git +import os @['/api/v1/:user/:repo_name/:branch_name/commits/count'] fn (mut app App) handle_commits_count(mut ctx Context, username string, repo_name string, branch_name string) veb.Result { @@ -32,7 +33,7 @@ fn (mut app App) handle_commits_count(mut ctx Context, username string, repo_nam // app.debug("${branch} ${count}" ) return ctx.json(api.ApiCommitCount{ success: true - result: count + result: count }) } @@ -140,3 +141,35 @@ pub fn (mut app App) commit(mut ctx Context, username string, repo_name string, return $veb.html() } + +@['/:username/:repo_name/revert/:hash'; post] +pub fn (mut app App) handle_revert_commit(mut ctx Context, username string, repo_name string, hash string) veb.Result { + repo := app.find_repo_by_name_and_username(repo_name, username) or { return ctx.not_found() } + if !app.can_admin_repo(ctx, repo) { + return ctx.not_found() + } + branch := ctx.form['branch'] or { repo.primary_branch } + if !is_safe_ref(branch) || !is_valid_commit_hash(hash) { + ctx.error('Invalid branch or commit') + return ctx.redirect('///-/commits/') + } + worktree := os.join_path(os.temp_dir(), 'gitly_revert_') + os.mkdir_all(worktree) or { + ctx.error('Failed to create worktree: ') + return ctx.redirect('///-/commits/') + } + defer { os.rmdir_all(worktree) or {} } + add_res := git.Git.exec_in_dir(repo.git_dir, ['worktree', 'add', '--force', worktree, branch]) + if add_res.exit_code != 0 { + ctx.error('Failed to prepare worktree: ') + return ctx.redirect('///-/commits/') + } + revert_res := git.Git.exec_in_dir(worktree, ['revert', '--no-edit', hash]) + remove_res := git.Git.exec_in_dir(repo.git_dir, ['worktree', 'remove', '--force', worktree]) + if revert_res.exit_code != 0 { + ctx.error('Revert failed: ') + return ctx.redirect('///-/commits/') + } + _ = remove_res + return ctx.redirect('///-/commits/') +} From 99c3ede46b1eb1b969d8362e50aa2bee5a19c4cf Mon Sep 17 00:00:00 2001 From: metif12 Date: Thu, 12 Nov 2026 16:38:59 +0330 Subject: [PATCH 2/3] fix: revert redirects and unique worktree --- commit/commit_routes.v | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/commit/commit_routes.v b/commit/commit_routes.v index 9086581d..83cf9faa 100644 --- a/commit/commit_routes.v +++ b/commit/commit_routes.v @@ -151,25 +151,25 @@ pub fn (mut app App) handle_revert_commit(mut ctx Context, username string, repo branch := ctx.form['branch'] or { repo.primary_branch } if !is_safe_ref(branch) || !is_valid_commit_hash(hash) { ctx.error('Invalid branch or commit') - return ctx.redirect('///-/commits/') + return ctx.redirect('/${username}/${repo_name}/-/commits/${branch}') } - worktree := os.join_path(os.temp_dir(), 'gitly_revert_') + worktree := os.join_path(os.temp_dir(), 'gitly_revert_${os.getpid()}_${time.now().unix_nano()}') os.mkdir_all(worktree) or { ctx.error('Failed to create worktree: ') - return ctx.redirect('///-/commits/') + return ctx.redirect('/${username}/${repo_name}/-/commits/${branch}') } defer { os.rmdir_all(worktree) or {} } add_res := git.Git.exec_in_dir(repo.git_dir, ['worktree', 'add', '--force', worktree, branch]) if add_res.exit_code != 0 { ctx.error('Failed to prepare worktree: ') - return ctx.redirect('///-/commits/') + return ctx.redirect('/${username}/${repo_name}/-/commits/${branch}') } revert_res := git.Git.exec_in_dir(worktree, ['revert', '--no-edit', hash]) remove_res := git.Git.exec_in_dir(repo.git_dir, ['worktree', 'remove', '--force', worktree]) if revert_res.exit_code != 0 { ctx.error('Revert failed: ') - return ctx.redirect('///-/commits/') + return ctx.redirect('/${username}/${repo_name}/-/commits/${branch}') } _ = remove_res - return ctx.redirect('///-/commits/') + return ctx.redirect('/${username}/${repo_name}/-/commits/${branch}') } From 21dea101833041c773bb01457a594cb8f42fc6af 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('