Skip to content

Commit cbd3199

Browse files
committed
chore: fix compilation with latest V, fuck the experimental half baked contexts
1 parent 75a3cf7 commit cbd3199

14 files changed

+114
-110
lines changed

highlight/java.v

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ module highlight
33

44
fn init_java() Lang {
55
return Lang{
6-
name: 'Java'
6+
name: 'Java'
77
lang_extensions: ['java']
8-
line_comments: '//'
9-
mline_comments: ['/*', '*/']
10-
string_start: ['"', "'"]
11-
color: '#f1e05a'
12-
keywords: [
8+
line_comments: '//'
9+
mline_comments: ['/*', '*/']
10+
string_start: ['"', "'"]
11+
color: '#f1e05a'
12+
keywords: [
1313
'abstract',
1414
'continue',
1515
'for',

src/admin_routes.v

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const admin_users_per_page = 30
77
// TODO move to admin controller
88

99
@['/admin/settings']
10-
pub fn (mut app App) admin_settings() veb.Result {
10+
pub fn (mut app App) admin_settings(mut ctx Context) veb.Result {
1111
if !ctx.is_admin() {
1212
return ctx.redirect_to_index()
1313
}
@@ -42,12 +42,12 @@ pub fn (mut app App) handle_admin_edit_user(user_id string) veb.Result {
4242
}
4343

4444
@['/admin/users']
45-
pub fn (mut app App) admin_users_default() veb.Result {
46-
return app.admin_users(0)
45+
pub fn (mut app App) admin_users_default(mut ctx Context) veb.Result {
46+
return app.admin_users(mut ctx, 0)
4747
}
4848

4949
@['/admin/users/:page']
50-
pub fn (mut app App) admin_users(page int) veb.Result {
50+
pub fn (mut app App) admin_users(mut ctx Context, page int) veb.Result {
5151
if !ctx.is_admin() {
5252
return ctx.redirect_to_index()
5353
}

src/comment.v

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ pub fn (mut app App) handle_add_comment(username string, repo_name string) veb.R
2424
is_issue_id_empty := validation.is_string_empty(issue_id)
2525
if is_text_empty || is_issue_id_empty || !ctx.logged_in {
2626
ctx.error('Issue comment is not valid')
27-
return app.issue(username, repo_name, issue_id)
27+
return app.issue(mut ctx, username, repo_name, issue_id)
2828
}
2929
app.add_issue_comment(ctx.user.id, issue_id.int(), text) or {
3030
ctx.error('There was an error while inserting the comment')
31-
return app.issue(username, repo_name, issue_id)
31+
return app.issue(mut ctx, username, repo_name, issue_id)
3232
}
3333
// TODO: count comments
3434
app.increment_issue_comments(issue_id.int()) or { app.info(err.str()) }

src/feed_routes.v

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ module main
33
import veb
44

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

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

1414
if !exists || ctx.user.username != user.username {

src/gitly.v

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,12 @@ pub fn (mut app App) init_server() {
128128
}
129129

130130
pub fn (mut app App) before_request(mut ctx Context) {
131-
ctx.logged_in = app.is_logged_in()
131+
ctx.logged_in = app.is_logged_in(mut ctx)
132132

133133
app.load_settings()
134134

135135
if ctx.logged_in {
136-
ctx.user = app.get_user_from_cookies() or {
136+
ctx.user = app.get_user_from_cookies(ctx) or {
137137
ctx.logged_in = false
138138
User{}
139139
}

src/issue_routes.v

+8-8
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ pub fn (mut app App) new_issue(username string, repo_name string) veb.Result {
3939
}
4040

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

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

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

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

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

123123
@['/:username/issues/:page']
124-
pub fn (mut app App) user_issues(username string, page int) veb.Result {
124+
pub fn (mut app App) user_issues(mut ctx Context, username string, page int) veb.Result {
125125
if !ctx.logged_in {
126126
return ctx.not_found()
127127
}

src/main.v

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import os
22
import veb
33

4-
const http_port = os.getenv_opt('GITLY_PORT') or { '8080' }.int()
4+
const http_port = get_port()
5+
6+
fn get_port() int {
7+
return os.getenv_opt('GITLY_PORT') or { '8080' }.int()
8+
}
59

610
fn main() {
711
if os.args.contains('ci_run') {

src/release_routes.v

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import time
66
const releases_per_page = 20
77

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

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

1717
repo_id := repo.id

src/repo_routes.v

+31-31
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub fn (mut app App) handle_repo_delete(username string, repo_name string) veb.R
8686
spawn app.delete_repository(repo.id, repo.git_dir, repo.name)
8787
} else {
8888
ctx.error('Verification failed')
89-
return app.repo_settings(username, repo_name, mut ctx)
89+
return app.repo_settings(mut ctx, username, repo_name)
9090
}
9191

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

112112
if app.user_has_repo(dest_user.id, repo.name) {
113113
ctx.error('User already owns repo ${repo.name}')
114-
return app.repo_settings(username, repo_name, mut ctx)
114+
return app.repo_settings(mut ctx, username, repo_name)
115115
}
116116

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

122122
app.move_repo_to_user(repo.id, dest_user.id, dest_user.username) or {
123123
ctx.error('There was an error while moving the repo')
124-
return app.repo_settings(username, repo_name, mut ctx)
124+
return app.repo_settings(mut ctx, username, repo_name)
125125
}
126126

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

131-
return app.repo_settings(username, repo_name, mut ctx)
131+
return app.repo_settings(mut ctx, username, repo_name)
132132
}
133133

134134
return ctx.redirect_to_index()
135135
}
136136

137137
@['/:username/:repo_name']
138-
pub fn (mut app App) handle_tree(username string, repo_name string) veb.Result {
138+
pub fn (mut app App) handle_tree(mut ctx Context, username string, repo_name string) veb.Result {
139139
println('handle tree()')
140140
match repo_name {
141141
'repos' {
142-
return app.user_repos(username, mut ctx)
142+
return app.user_repos(mut ctx, username)
143143
}
144144
'issues' {
145-
return app.handle_get_user_issues(username, mut ctx)
145+
return app.handle_get_user_issues(mut ctx, username)
146146
}
147147
'settings' {
148-
return app.user_settings(username)
148+
return app.user_settings(mut ctx, username)
149149
}
150150
else {}
151151
}
152152

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

155-
return app.tree(username, repo_name, repo.primary_branch, '')
155+
return app.tree(mut ctx, username, repo_name, repo.primary_branch, '')
156156
}
157157

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

162-
return app.tree(username, repo_name, branch_name, '')
162+
return app.tree(mut ctx, username, repo_name, branch_name, '')
163163
}
164164

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

187187
@['/new'; post]
188-
pub fn (mut app App) handle_new_repo(name string, clone_url string, description string, no_redirect string) veb.Result {
188+
pub fn (mut app App) handle_new_repo(mut ctx Context, name string, clone_url string, description string, no_redirect string) veb.Result {
189189
mut valid_clone_url := clone_url
190190
is_clone_url_empty := validation.is_string_empty(clone_url)
191191
is_public := ctx.form['repo_visibility'] == 'public'
@@ -194,24 +194,24 @@ pub fn (mut app App) handle_new_repo(name string, clone_url string, description
194194
}
195195
if !ctx.is_admin() && app.get_count_user_repos(ctx.user.id) >= max_user_repos {
196196
ctx.error('You have reached the limit for the number of repositories')
197-
return app.new()
197+
return app.new(mut ctx)
198198
}
199199
if name.len > max_repo_name_len {
200200
ctx.error('The repository name is too long (should be fewer than ${max_repo_name_len} characters)')
201-
return app.new()
201+
return app.new(mut ctx)
202202
}
203203
if _ := app.find_repo_by_name_and_username(name, ctx.user.username) {
204204
ctx.error('A repository with the name "${name}" already exists')
205-
return app.new()
205+
return app.new(mut ctx)
206206
}
207207
if name.contains(' ') {
208208
ctx.error('Repository name cannot contain spaces')
209-
return app.new()
209+
return app.new(mut ctx)
210210
}
211211
is_repo_name_valid := validation.is_repository_name_valid(name)
212212
if !is_repo_name_valid {
213213
ctx.error('The repository name is not valid')
214-
return app.new()
214+
return app.new(mut ctx)
215215
}
216216
has_clone_url_https_prefix := clone_url.starts_with('https://')
217217
if !is_clone_url_empty {
@@ -221,7 +221,7 @@ pub fn (mut app App) handle_new_repo(name string, clone_url string, description
221221
is_git_repo := git.check_git_repo_url(valid_clone_url)
222222
if !is_git_repo {
223223
ctx.error('The repository URL does not contain any git repository or the server does not respond')
224-
return app.new()
224+
return app.new(mut ctx)
225225
}
226226
}
227227
repo_path := os.join_path(app.config.repo_storage_path, ctx.user.username, name)
@@ -249,7 +249,7 @@ pub fn (mut app App) handle_new_repo(name string, clone_url string, description
249249
}
250250
app.add_repo(new_repo) or {
251251
ctx.error('There was an error while adding the repo')
252-
return app.new()
252+
return app.new(mut ctx)
253253
}
254254
new_repo2 := app.find_repo_by_name_and_user_id(new_repo.name, ctx.user.id) or {
255255
app.info('Repo was not inserted')
@@ -259,15 +259,15 @@ pub fn (mut app App) handle_new_repo(name string, clone_url string, description
259259
primary_branch := git.get_repository_primary_branch(repo_path)
260260
app.update_repo_primary_branch(repo_id, primary_branch) or {
261261
ctx.error('There was an error while adding the repo')
262-
return app.new()
262+
return app.new(mut ctx)
263263
}
264-
app.find_repo_by_id(repo_id) or { return app.new() }
264+
app.find_repo_by_id(repo_id) or { return app.new(mut ctx) }
265265
// Update only cloned repositories
266266
/*
267267
if !is_clone_url_empty {
268268
app.update_repo_from_fs(mut new_repo) or {
269269
ctx.error('There was an error while cloning the repo')
270-
return app.new()
270+
return app.new(mut ctx)
271271
}
272272
}
273273
*/
@@ -289,7 +289,7 @@ pub fn (mut app App) foo(mut new_repo Repo) {
289289
}
290290

291291
@['/:username/:repo_name/tree/:branch_name/:path...']
292-
pub fn (mut app App) tree(username string, repo_name string, branch_name string, path string) veb.Result {
292+
pub fn (mut app App) tree(mut ctx Context, username string, repo_name string, branch_name string, path string) veb.Result {
293293
mut repo := app.find_repo_by_name_and_username(repo_name, username) or {
294294
return ctx.not_found()
295295
}
@@ -431,7 +431,7 @@ pub fn (mut app App) tree(username string, repo_name string, branch_name string,
431431
}
432432

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)