Skip to content

Commit

Permalink
chore: fix compilation with latest V, fuck the experimental half bake…
Browse files Browse the repository at this point in the history
…d contexts
  • Loading branch information
spytheman committed Nov 18, 2024
1 parent 75a3cf7 commit cbd3199
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 110 deletions.
12 changes: 6 additions & 6 deletions highlight/java.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module highlight

fn init_java() Lang {
return Lang{
name: 'Java'
name: 'Java'
lang_extensions: ['java']
line_comments: '//'
mline_comments: ['/*', '*/']
string_start: ['"', "'"]
color: '#f1e05a'
keywords: [
line_comments: '//'
mline_comments: ['/*', '*/']
string_start: ['"', "'"]
color: '#f1e05a'
keywords: [
'abstract',
'continue',
'for',
Expand Down
8 changes: 4 additions & 4 deletions src/admin_routes.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const admin_users_per_page = 30
// TODO move to admin controller

@['/admin/settings']
pub fn (mut app App) admin_settings() veb.Result {
pub fn (mut app App) admin_settings(mut ctx Context) veb.Result {
if !ctx.is_admin() {
return ctx.redirect_to_index()
}
Expand Down Expand Up @@ -42,12 +42,12 @@ pub fn (mut app App) handle_admin_edit_user(user_id string) veb.Result {
}

@['/admin/users']
pub fn (mut app App) admin_users_default() veb.Result {
return app.admin_users(0)
pub fn (mut app App) admin_users_default(mut ctx Context) veb.Result {
return app.admin_users(mut ctx, 0)
}

@['/admin/users/:page']
pub fn (mut app App) admin_users(page int) veb.Result {
pub fn (mut app App) admin_users(mut ctx Context, page int) veb.Result {
if !ctx.is_admin() {
return ctx.redirect_to_index()
}
Expand Down
4 changes: 2 additions & 2 deletions src/comment.v
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ pub fn (mut app App) handle_add_comment(username string, repo_name string) veb.R
is_issue_id_empty := validation.is_string_empty(issue_id)
if is_text_empty || is_issue_id_empty || !ctx.logged_in {
ctx.error('Issue comment is not valid')
return app.issue(username, repo_name, issue_id)
return app.issue(mut ctx, username, repo_name, issue_id)
}
app.add_issue_comment(ctx.user.id, issue_id.int(), text) or {
ctx.error('There was an error while inserting the comment')
return app.issue(username, repo_name, issue_id)
return app.issue(mut ctx, username, repo_name, issue_id)
}
// TODO: count comments
app.increment_issue_comments(issue_id.int()) or { app.info(err.str()) }
Expand Down
6 changes: 3 additions & 3 deletions src/feed_routes.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ module main
import veb

@['/:username/feed']
pub fn (mut app App) user_feed_default(username string) veb.Result {
return app.user_feed(username, 0)
pub fn (mut app App) user_feed_default(mut ctx Context, username string) veb.Result {
return app.user_feed(mut ctx, username, 0)
}

@['/:username/feed/:page']
pub fn (mut app App) user_feed(username string, page int) veb.Result {
pub fn (mut app App) user_feed(mut ctx Context, username string, page int) veb.Result {
exists, user := app.check_username(username)

if !exists || ctx.user.username != user.username {
Expand Down
4 changes: 2 additions & 2 deletions src/gitly.v
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ pub fn (mut app App) init_server() {
}

pub fn (mut app App) before_request(mut ctx Context) {
ctx.logged_in = app.is_logged_in()
ctx.logged_in = app.is_logged_in(mut ctx)

app.load_settings()

if ctx.logged_in {
ctx.user = app.get_user_from_cookies() or {
ctx.user = app.get_user_from_cookies(ctx) or {
ctx.logged_in = false
User{}
}
Expand Down
16 changes: 8 additions & 8 deletions src/issue_routes.v
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ pub fn (mut app App) new_issue(username string, repo_name string) veb.Result {
}

@['/:username/issues']
pub fn (mut app App) handle_get_user_issues(username string) veb.Result {
return app.user_issues(username, 0)
pub fn (mut app App) handle_get_user_issues(mut ctx Context, username string) veb.Result {
return app.user_issues(mut ctx, username, 0)
}

@['/:username/:repo_name/issues'; post]
pub fn (mut app App) handle_add_repo_issue(username string, repo_name string) veb.Result {
pub fn (mut app App) handle_add_repo_issue(mut ctx Context, username string, repo_name string) veb.Result {
// TODO: use captcha instead of user restrictions
if !ctx.logged_in || (ctx.logged_in && ctx.user.posts_count >= posts_per_day) {
return ctx.redirect_to_index()
Expand All @@ -68,12 +68,12 @@ pub fn (mut app App) handle_add_repo_issue(username string, repo_name string) ve
}

@['/:username/:repo_name/issues']
pub fn (mut app App) handle_get_repo_issues(username string, repo_name string) veb.Result {
return app.issues(username, repo_name, 0)
pub fn (mut app App) handle_get_repo_issues(mut ctx Context, username string, repo_name string) veb.Result {
return app.issues(mut ctx, username, repo_name, 0)
}

@['/:username/:repo_name/issues/:page']
pub fn (mut app App) issues(username string, repo_name string, page int) veb.Result {
pub fn (mut app App) issues(mut ctx Context, username string, repo_name string, page int) veb.Result {
repo := app.find_repo_by_name_and_username(repo_name, username) or { return ctx.not_found() }
mut issues_with_users := []IssueWithUser{}
for issue in app.find_repo_issues_as_page(repo.id, page) {
Expand Down Expand Up @@ -105,7 +105,7 @@ pub fn (mut app App) issues(username string, repo_name string, page int) veb.Res
}

@['/:username/:repo_name/issue/:id']
pub fn (mut app App) issue(username string, repo_name string, id string) veb.Result {
pub fn (mut app App) issue(mut ctx Context, username string, repo_name string, id string) veb.Result {
repo := app.find_repo_by_name_and_username(repo_name, username) or { return ctx.not_found() }
issue := app.find_issue_by_id(id.int()) or { return ctx.not_found() }
issue_author := app.get_user_by_id(issue.author_id) or { return ctx.not_found() }
Expand All @@ -121,7 +121,7 @@ pub fn (mut app App) issue(username string, repo_name string, id string) veb.Res
}

@['/:username/issues/:page']
pub fn (mut app App) user_issues(username string, page int) veb.Result {
pub fn (mut app App) user_issues(mut ctx Context, username string, page int) veb.Result {
if !ctx.logged_in {
return ctx.not_found()
}
Expand Down
6 changes: 5 additions & 1 deletion src/main.v
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import os
import veb

const http_port = os.getenv_opt('GITLY_PORT') or { '8080' }.int()
const http_port = get_port()

fn get_port() int {
return os.getenv_opt('GITLY_PORT') or { '8080' }.int()
}

fn main() {
if os.args.contains('ci_run') {
Expand Down
6 changes: 3 additions & 3 deletions src/release_routes.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import time
const releases_per_page = 20

@['/:username/:repo_name/releases']
pub fn (mut app App) releases_default(username string, repo_name string) veb.Result {
return app.releases(username, repo_name, 0)
pub fn (mut app App) releases_default(mut ctx Context, username string, repo_name string) veb.Result {
return app.releases(mut ctx, username, repo_name, 0)
}

@['/:username/:repo_name/releases/:page']
pub fn (mut app App) releases(username string, repo_name string, page int) veb.Result {
pub fn (mut app App) releases(mut ctx Context, username string, repo_name string, page int) veb.Result {
repo := app.find_repo_by_name_and_username(repo_name, username) or { return ctx.not_found() }

repo_id := repo.id
Expand Down
62 changes: 31 additions & 31 deletions src/repo_routes.v
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn (mut app App) handle_repo_delete(username string, repo_name string) veb.R
spawn app.delete_repository(repo.id, repo.git_dir, repo.name)
} else {
ctx.error('Verification failed')
return app.repo_settings(username, repo_name, mut ctx)
return app.repo_settings(mut ctx, username, repo_name)
}

return ctx.redirect_to_index()
Expand All @@ -106,64 +106,64 @@ pub fn (mut app App) handle_repo_move(username string, repo_name string, dest st
if dest != '' && verify == '${username}/${repo_name}' {
dest_user := app.get_user_by_username(dest) or {
ctx.error('Unknown user ${dest}')
return app.repo_settings(username, repo_name, mut ctx)
return app.repo_settings(mut ctx, username, repo_name)
}

if app.user_has_repo(dest_user.id, repo.name) {
ctx.error('User already owns repo ${repo.name}')
return app.repo_settings(username, repo_name, mut ctx)
return app.repo_settings(mut ctx, username, repo_name)
}

if app.get_count_user_repos(dest_user.id) >= max_user_repos {
ctx.error('User already reached the repo limit')
return app.repo_settings(username, repo_name, mut ctx)
return app.repo_settings(mut ctx, username, repo_name)
}

app.move_repo_to_user(repo.id, dest_user.id, dest_user.username) or {
ctx.error('There was an error while moving the repo')
return app.repo_settings(username, repo_name, mut ctx)
return app.repo_settings(mut ctx, username, repo_name)
}

return ctx.redirect('/${dest_user.username}/${repo.name}')
} else {
ctx.error('Verification failed')

return app.repo_settings(username, repo_name, mut ctx)
return app.repo_settings(mut ctx, username, repo_name)
}

return ctx.redirect_to_index()
}

@['/:username/:repo_name']
pub fn (mut app App) handle_tree(username string, repo_name string) veb.Result {
pub fn (mut app App) handle_tree(mut ctx Context, username string, repo_name string) veb.Result {
println('handle tree()')
match repo_name {
'repos' {
return app.user_repos(username, mut ctx)
return app.user_repos(mut ctx, username)
}
'issues' {
return app.handle_get_user_issues(username, mut ctx)
return app.handle_get_user_issues(mut ctx, username)
}
'settings' {
return app.user_settings(username)
return app.user_settings(mut ctx, username)
}
else {}
}

repo := app.find_repo_by_name_and_username(repo_name, username) or { return ctx.not_found() }

return app.tree(username, repo_name, repo.primary_branch, '')
return app.tree(mut ctx, username, repo_name, repo.primary_branch, '')
}

@['/:username/:repo_name/tree/:branch_name']
pub fn (mut app App) handle_branch_tree(username string, repo_name string, branch_name string) veb.Result {
pub fn (mut app App) handle_branch_tree(mut ctx Context, username string, repo_name string, branch_name string) veb.Result {
app.find_repo_by_name_and_username(repo_name, username) or { return ctx.not_found() }

return app.tree(username, repo_name, branch_name, '')
return app.tree(mut ctx, username, repo_name, branch_name, '')
}

@['/:username/:repo_name/update']
pub fn (mut app App) handle_repo_update(username string, repo_name string) veb.Result {
pub fn (mut app App) handle_repo_update(mut ctx Context, username string, repo_name string) veb.Result {
mut repo := app.find_repo_by_name_and_username(repo_name, username) or {
return ctx.not_found()
}
Expand All @@ -185,7 +185,7 @@ pub fn (mut app App) new() veb.Result {
}

@['/new'; post]
pub fn (mut app App) handle_new_repo(name string, clone_url string, description string, no_redirect string) veb.Result {
pub fn (mut app App) handle_new_repo(mut ctx Context, name string, clone_url string, description string, no_redirect string) veb.Result {
mut valid_clone_url := clone_url
is_clone_url_empty := validation.is_string_empty(clone_url)
is_public := ctx.form['repo_visibility'] == 'public'
Expand All @@ -194,24 +194,24 @@ pub fn (mut app App) handle_new_repo(name string, clone_url string, description
}
if !ctx.is_admin() && app.get_count_user_repos(ctx.user.id) >= max_user_repos {
ctx.error('You have reached the limit for the number of repositories')
return app.new()
return app.new(mut ctx)
}
if name.len > max_repo_name_len {
ctx.error('The repository name is too long (should be fewer than ${max_repo_name_len} characters)')
return app.new()
return app.new(mut ctx)
}
if _ := app.find_repo_by_name_and_username(name, ctx.user.username) {
ctx.error('A repository with the name "${name}" already exists')
return app.new()
return app.new(mut ctx)
}
if name.contains(' ') {
ctx.error('Repository name cannot contain spaces')
return app.new()
return app.new(mut ctx)
}
is_repo_name_valid := validation.is_repository_name_valid(name)
if !is_repo_name_valid {
ctx.error('The repository name is not valid')
return app.new()
return app.new(mut ctx)
}
has_clone_url_https_prefix := clone_url.starts_with('https://')
if !is_clone_url_empty {
Expand All @@ -221,7 +221,7 @@ pub fn (mut app App) handle_new_repo(name string, clone_url string, description
is_git_repo := git.check_git_repo_url(valid_clone_url)
if !is_git_repo {
ctx.error('The repository URL does not contain any git repository or the server does not respond')
return app.new()
return app.new(mut ctx)
}
}
repo_path := os.join_path(app.config.repo_storage_path, ctx.user.username, name)
Expand Down Expand Up @@ -249,7 +249,7 @@ pub fn (mut app App) handle_new_repo(name string, clone_url string, description
}
app.add_repo(new_repo) or {
ctx.error('There was an error while adding the repo')
return app.new()
return app.new(mut ctx)
}
new_repo2 := app.find_repo_by_name_and_user_id(new_repo.name, ctx.user.id) or {
app.info('Repo was not inserted')
Expand All @@ -259,15 +259,15 @@ pub fn (mut app App) handle_new_repo(name string, clone_url string, description
primary_branch := git.get_repository_primary_branch(repo_path)
app.update_repo_primary_branch(repo_id, primary_branch) or {
ctx.error('There was an error while adding the repo')
return app.new()
return app.new(mut ctx)
}
app.find_repo_by_id(repo_id) or { return app.new() }
app.find_repo_by_id(repo_id) or { return app.new(mut ctx) }
// Update only cloned repositories
/*
if !is_clone_url_empty {
app.update_repo_from_fs(mut new_repo) or {
ctx.error('There was an error while cloning the repo')
return app.new()
return app.new(mut ctx)
}
}
*/
Expand All @@ -289,7 +289,7 @@ pub fn (mut app App) foo(mut new_repo Repo) {
}

@['/:username/:repo_name/tree/:branch_name/:path...']
pub fn (mut app App) tree(username string, repo_name string, branch_name string, path string) veb.Result {
pub fn (mut app App) tree(mut ctx Context, username string, repo_name string, branch_name string, path string) veb.Result {
mut repo := app.find_repo_by_name_and_username(repo_name, username) or {
return ctx.not_found()
}
Expand Down Expand Up @@ -431,7 +431,7 @@ pub fn (mut app App) tree(username string, repo_name string, branch_name string,
}

@['/api/v1/repos/:repo_id/star'; 'post']
pub fn (mut app App) handle_api_repo_star(repo_id_str string) veb.Result {
pub fn (mut app App) handle_api_repo_star(mut ctx Context, repo_id_str string) veb.Result {
repo_id := repo_id_str.int()

has_access := app.has_user_repo_read_access(ctx, ctx.user.id, repo_id)
Expand All @@ -450,7 +450,7 @@ pub fn (mut app App) handle_api_repo_star(repo_id_str string) veb.Result {
}

@['/api/v1/repos/:repo_id/watch'; 'post']
pub fn (mut app App) handle_api_repo_watch(repo_id_str string) veb.Result {
pub fn (mut app App) handle_api_repo_watch(mut ctx Context, repo_id_str string) veb.Result {
repo_id := repo_id_str.int()

has_access := app.has_user_repo_read_access(ctx, ctx.user.id, repo_id)
Expand All @@ -469,7 +469,7 @@ pub fn (mut app App) handle_api_repo_watch(repo_id_str string) veb.Result {
}

@['/:username/:repo_name/contributors']
pub fn (mut app App) contributors(username string, repo_name string) veb.Result {
pub fn (mut app App) contributors(mut ctx Context, username string, repo_name string) veb.Result {
repo := app.find_repo_by_name_and_username(repo_name, username) or { return ctx.not_found() }

contributors := app.find_repo_registered_contributor(repo.id)
Expand All @@ -478,7 +478,7 @@ pub fn (mut app App) contributors(username string, repo_name string) veb.Result
}

@['/:username/:repo_name/blob/:branch_name/:path...']
pub fn (mut app App) blob(username string, repo_name string, branch_name string, path string) veb.Result {
pub fn (mut app App) blob(mut ctx Context, username string, repo_name string, branch_name string, path string) veb.Result {
repo := app.find_repo_by_name_and_username(repo_name, username) or { return ctx.not_found() }

mut path_parts := path.split('/')
Expand All @@ -505,7 +505,7 @@ pub fn (mut app App) blob(username string, repo_name string, branch_name string,
}

@['/:user/:repository/raw/:branch_name/:path...']
pub fn (mut app App) handle_raw(username string, repo_name string, branch_name string, path string) veb.Result {
pub fn (mut app App) handle_raw(mut ctx Context, username string, repo_name string, branch_name string, path string) veb.Result {
user := app.get_user_by_username(username) or { return ctx.not_found() }
repo := app.find_repo_by_name_and_user_id(repo_name, user.id) or { return ctx.not_found() }

Expand Down
Loading

0 comments on commit cbd3199

Please sign in to comment.