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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 34 additions & 1 deletion commit/commit_routes.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
})
}

Expand Down Expand Up @@ -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('/${username}/${repo_name}/-/commits/${branch}')
}
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('/${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('/${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('/${username}/${repo_name}/-/commits/${branch}')
}
_ = remove_res
return ctx.redirect('/${username}/${repo_name}/-/commits/${branch}')
}
4 changes: 2 additions & 2 deletions highlight/markdown_test.v
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module highlight

const markdown = '<script> alert(true) </script> <!-- comment -->test'
const xss_markdown_sample = '<script> alert(true) </script> <!-- comment -->test'

fn test_convert_markdown_to_html() {
rendered := convert_markdown_to_html(markdown)
rendered := convert_markdown_to_html(xss_markdown_sample)
assert !rendered.contains('<script>')
assert rendered.contains('&lt;script&gt;')
assert rendered.contains('test</p>')
Expand Down
2 changes: 1 addition & 1 deletion repo/repo.v
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ fn (mut app App) search_public_repos(query string) []Repo {
// unrelated users.
fn (mut app App) search_repos(query string, user_id int) []Repo {
pattern := sql_like_pattern(query)
repo_rows := db_exec_values(mut app.db, 'select id from ${sql_table('Repo')} where is_deleted is false and (\n\t\t\tlower(name) like lower(${pattern}) or lower(user_name) like lower(${pattern}) or lower(description) like lower(${pattern})\n\t\t) order by nr_stars desc, name asc limit ${search_candidate_limit}') or {
repo_rows := db_exec_values(mut app.db, 'select id from ${sql_table('Repo')} where is_deleted is false and (\n\t\t\tlower(name) like lower(${pattern}) or lower(user_name) like lower(${pattern}) or lower(description) like lower(${pattern})\n\t\t) order by stars_count desc, name asc limit ${search_candidate_limit}') or {
app.warn('Repository search failed: ${err}')
return []
}
Expand Down
Loading