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
4 changes: 2 additions & 2 deletions admin/admin_routes.v
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn (mut app App) admin_settings(mut ctx Context) veb.Result {
}

@['/admin/settings'; post]
pub fn (mut app App) handle_admin_update_settings(oauth_client_id string, oauth_client_secret string) veb.Result {
pub fn (mut app App) handle_admin_update_settings(mut ctx Context, oauth_client_id string, oauth_client_secret string) veb.Result {
if !ctx.is_admin() {
return ctx.redirect_to_index()
}
Expand All @@ -34,7 +34,7 @@ pub fn (mut app App) handle_admin_update_settings(oauth_client_id string, oauth_
}

@['/admin/users/:user'; post]
pub fn (mut app App) handle_admin_edit_user(user_id string) veb.Result {
pub fn (mut app App) handle_admin_edit_user(mut ctx Context, user_id string) veb.Result {
if !ctx.is_admin() {
return ctx.redirect_to_index()
}
Expand Down
8 changes: 4 additions & 4 deletions ci/ci_routes.v
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fn (mut app App) verify_ci_callback_signature(ctx &Context, body string) bool {

// GET /:username/:repo_name/ci - CI runs list page
@['/:username/:repo_name/ci']
pub fn (mut app App) ci_runs(username string, repo_name string) veb.Result {
pub fn (mut app App) ci_runs(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() }

if !app.can_read_repo(ctx, repo) {
Expand Down Expand Up @@ -141,7 +141,7 @@ pub fn (mut app App) ci_runs(username string, repo_name string) veb.Result {

// GET /:username/:repo_name/ci/:run_id_str - CI run detail page
@['/:username/:repo_name/ci/:run_id_str']
pub fn (mut app App) ci_run_detail(username string, repo_name string, run_id_str string) veb.Result {
pub fn (mut app App) ci_run_detail(mut ctx Context, username string, repo_name string, run_id_str string) veb.Result {
repo := app.find_repo_by_name_and_username(repo_name, username) or { return ctx.not_found() }

if !app.can_read_repo(ctx, repo) {
Expand Down Expand Up @@ -178,7 +178,7 @@ pub fn (mut app App) ci_run_detail(username string, repo_name string, run_id_str

// POST /:username/:repo_name/ci/:run_id_str/restart - Restart a CI run
@['/:username/:repo_name/ci/:run_id_str/restart'; post]
pub fn (mut app App) ci_restart_run(username string, repo_name string, run_id_str string) veb.Result {
pub fn (mut app App) ci_restart_run(mut ctx Context, username string, repo_name string, run_id_str 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) {
Expand Down Expand Up @@ -221,7 +221,7 @@ pub fn (mut app App) ci_restart_run(username string, repo_name string, run_id_st

// POST /:username/:repo_name/ci/:run_id_str/cancel - Cancel a CI run.
@['/:username/:repo_name/ci/:run_id_str/cancel'; post]
pub fn (mut app App) ci_cancel_run(username string, repo_name string, run_id_str string) veb.Result {
pub fn (mut app App) ci_cancel_run(mut ctx Context, username string, repo_name string, run_id_str 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()
Expand Down
9 changes: 5 additions & 4 deletions gitly.v
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ fn new_app() !&App {

mut app := &App{
// db: sqlite.connect('gitly.sqlite') or { panic(err) }
db: connect_db(conf)!
config: conf
db: connect_db(conf)!
config: conf
started_at: time.now().unix()
}

Expand Down Expand Up @@ -304,7 +304,7 @@ pub fn (mut app App) index(mut ctx Context) veb.Result {
}

@['/change_lang/:lang'; post]
pub fn (mut app App) change_lang(lang string) veb.Result {
pub fn (mut app App) change_lang(mut ctx Context, lang string) veb.Result {
if lang !in ['en', 'ru', 'es', 'jp', 'cn', 'pt'] {
ctx.res.set_status(.bad_request)
return ctx.json_error('Unsupported language')
Expand Down Expand Up @@ -735,6 +735,7 @@ fn (mut app App) migrate_tables() ! {
app.add_missing_column('Issue', 'milestone_id', 'INTEGER NOT NULL DEFAULT 0')!
app.add_missing_column('Issue', 'iteration_id', 'INTEGER NOT NULL DEFAULT 0')!
app.add_missing_column('Issue', 'time_estimate_minutes', 'INTEGER NOT NULL DEFAULT 0')!
app.add_missing_column('Issue', 'is_confidential', db_bool_column_type())!
app.add_missing_column('Label', 'scope', "TEXT NOT NULL DEFAULT ''")!
app.add_missing_column('Project', 'label_id', 'INTEGER NOT NULL DEFAULT 0')!
app.add_missing_column('Project', 'milestone_id', 'INTEGER NOT NULL DEFAULT 0')!
Expand Down Expand Up @@ -902,7 +903,7 @@ fn (mut app App) add_missing_column(table_name string, column_name string, colum
fn (mut ctx Context) json_success[T](result T) veb.Result {
response := api.ApiSuccessResponse[T]{
success: true
result: result
result: result
}

return ctx.json(response)
Expand Down
11 changes: 6 additions & 5 deletions issue.v
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ mut:
author_id int
repo_id int
is_pr bool
assigned []int @[skip]
assigned []int @[skip]
labels []Label @[skip]
comments_count int
title string
text string
is_confidential bool
created_at int
status IssueStatus
linked_issues []int @[skip]
Expand Down Expand Up @@ -394,9 +395,9 @@ fn (mut app App) sync_repo_open_issue_count(repo_id int) ! {
fn placeholder_user(user_id int) User {
username := if user_id > 0 { 'user-${user_id}' } else { 'unknown-user' }
return User{
id: user_id
id: user_id
username: username
avatar: default_avatar_name
avatar: default_avatar_name
}
}

Expand Down Expand Up @@ -513,8 +514,8 @@ fn (mut app App) assign_issue(issue_id int, user_id int) ! {
return
}
assignment := IssueAssignee{
issue_id: issue_id
user_id: user_id
issue_id: issue_id
user_id: user_id
created_at: int(time.now().unix())
}
sql app.db {
Expand Down
29 changes: 21 additions & 8 deletions issue_routes.v
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn (mut app App) handle_issues_count(username string, repo_name string) veb.Resu
count := app.get_repo_issue_count(repo.id)
return ctx.json(api.ApiIssueCount{
success: true
result: count
result: count
})
}

Expand Down Expand Up @@ -74,20 +74,27 @@ pub fn (mut app App) handle_add_repo_issue(mut ctx Context, username string, rep
}
title := ctx.form['title']
text := ctx.form['text']
is_confidential := 'confidential' in ctx.form
if !valid_title(title) || !valid_body(text) {
ctx.error('Issue title is missing or the description is too long')
return ctx.redirect('/${username}/${repo_name}/issues/new')
}
app.add_issue(repo.id, ctx.user.id, title, text) or {
issue_id := app.add_issue_returning_id(repo.id, ctx.user.id, title, text) or {
app.info(err.str())
return ctx.redirect('/${username}/${repo_name}/issues/new')
}
if is_confidential {
sql app.db {
update Issue set is_confidential = true where id == issue_id
} or { app.info(err.str()) }
}

app.increment_user_post(mut ctx.user) or { app.info(err.str()) }
app.sync_repo_open_issue_count(repo.id) or { app.info(err.str()) }
app.dispatch_webhook(repo.id, 'issue', WebhookIssuePayload{
action: 'opened'
repo: '${username}/${repo_name}'
title: title
repo: '${username}/${repo_name}'
title: title
author: ctx.user.username
})
has_first_issue_activity := app.has_activity(ctx.user.id, 'first_issue')
Expand Down Expand Up @@ -156,6 +163,12 @@ pub fn (mut app App) issues(mut ctx Context, username string, repo_name string,
mut i := 0
for i = 0; i < repo_issues.len; i++ {
issue = repo_issues[i]
if issue.is_confidential && ctx.logged_in && issue.author_id != ctx.user.id && !app.can_admin_repo(ctx, repo) {
continue
}
if issue.is_confidential && !ctx.logged_in {
continue
}
user = app.get_user_by_id(issue.author_id) or { placeholder_user(issue.author_id) }
issue.labels = app.get_issue_labels(issue.id)
issue.repo_author = repo.user_name
Expand Down Expand Up @@ -261,8 +274,8 @@ pub fn (mut app App) handle_edit_issue(mut ctx Context, username string, repo_na
}
app.dispatch_webhook(repo.id, 'issue', WebhookIssuePayload{
action: 'updated'
repo: '${username}/${repo_name}'
title: title.trim_space()
repo: '${username}/${repo_name}'
title: title.trim_space()
author: ctx.user.username
})
return ctx.redirect('/${username}/${repo_name}/issue/${issue.id}')
Expand Down Expand Up @@ -376,8 +389,8 @@ fn change_issue_status(mut app App, mut ctx Context, username string, repo_name
action := if status == .closed { 'closed' } else { 'reopened' }
app.dispatch_webhook(repo.id, 'issue', WebhookIssuePayload{
action: action
repo: '${username}/${repo_name}'
title: issue.title
repo: '${username}/${repo_name}'
title: issue.title
author: ctx.user.username
})
return ctx.redirect('/${username}/${repo_name}/issue/${issue.id}')
Expand Down
18 changes: 9 additions & 9 deletions project_governance_routes.v
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module main
import veb

@['/:username/:repo_name/settings/members']
pub fn (mut app App) repo_members(username string, repo_name string) veb.Result {
pub fn (mut app App) repo_members(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() }
if !app.can_admin_repo(ctx, repo) {
return ctx.not_found()
Expand All @@ -15,7 +15,7 @@ pub fn (mut app App) repo_members(username string, repo_name string) veb.Result
}

@['/:username/:repo_name/settings/members'; post]
pub fn (mut app App) handle_add_repo_member(username string, repo_name string) veb.Result {
pub fn (mut app App) handle_add_repo_member(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() }
if !app.can_admin_repo(ctx, repo) {
return ctx.not_found()
Expand All @@ -42,7 +42,7 @@ pub fn (mut app App) handle_add_repo_member(username string, repo_name string) v
}

@['/:username/:repo_name/settings/members/:member_id'; post]
pub fn (mut app App) handle_update_repo_member(username string, repo_name string, member_id string) veb.Result {
pub fn (mut app App) handle_update_repo_member(mut ctx Context, username string, repo_name string, member_id 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()
Expand All @@ -56,7 +56,7 @@ pub fn (mut app App) handle_update_repo_member(username string, repo_name string
}

@['/:username/:repo_name/settings/members/:member_id/delete'; post]
pub fn (mut app App) handle_delete_repo_member(username string, repo_name string, member_id string) veb.Result {
pub fn (mut app App) handle_delete_repo_member(mut ctx Context, username string, repo_name string, member_id 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()
Expand All @@ -69,7 +69,7 @@ pub fn (mut app App) handle_delete_repo_member(username string, repo_name string
}

@['/:username/:repo_name/settings/branches']
pub fn (mut app App) protected_branches(username string, repo_name string) veb.Result {
pub fn (mut app App) protected_branches(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() }
if !app.can_admin_repo(ctx, repo) {
return ctx.not_found()
Expand All @@ -80,7 +80,7 @@ pub fn (mut app App) protected_branches(username string, repo_name string) veb.R
}

@['/:username/:repo_name/settings/branches'; post]
pub fn (mut app App) handle_protect_branch(username string, repo_name string) veb.Result {
pub fn (mut app App) handle_protect_branch(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() }
if !app.can_admin_repo(ctx, repo) {
return ctx.not_found()
Expand All @@ -96,7 +96,7 @@ pub fn (mut app App) handle_protect_branch(username string, repo_name string) ve
}

@['/:username/:repo_name/settings/branches/:rule_id'; post]
pub fn (mut app App) handle_update_protected_branch(username string, repo_name string, rule_id string) veb.Result {
pub fn (mut app App) handle_update_protected_branch(mut ctx Context, username string, repo_name string, rule_id 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()
Expand All @@ -110,7 +110,7 @@ pub fn (mut app App) handle_update_protected_branch(username string, repo_name s
}

@['/:username/:repo_name/settings/branches/:rule_id/delete'; post]
pub fn (mut app App) handle_unprotect_branch(username string, repo_name string, rule_id string) veb.Result {
pub fn (mut app App) handle_unprotect_branch(mut ctx Context, username string, repo_name string, rule_id 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()
Expand All @@ -123,7 +123,7 @@ pub fn (mut app App) handle_unprotect_branch(username string, repo_name string,
}

@['/:username/:repo_name/settings/approvals'; post]
pub fn (mut app App) handle_update_repo_approvals(username string, repo_name string) veb.Result {
pub fn (mut app App) handle_update_repo_approvals(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() }
if !app.can_admin_repo(ctx, repo) {
return ctx.not_found()
Expand Down
2 changes: 1 addition & 1 deletion repo/branch_routes.v
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn (mut app App) handle_branch_count(username string, repo_name string) veb.Resu
}

@['/:user/:repo/branches']
pub fn (mut app App) branches(username string, repo_name string) veb.Result {
pub fn (mut app App) branches(mut ctx Context, username string, repo_name string) veb.Result {
repo := app.find_repo_by_name_and_username(repo_name, username) or {
return ctx.json_error('Not found')
}
Expand Down
2 changes: 1 addition & 1 deletion repo/comment.v
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mut:
}

@['/:username/:repo_name/comments'; post]
pub fn (mut app App) handle_add_comment(username string, repo_name string) veb.Result {
pub fn (mut app App) handle_add_comment(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() }
text := ctx.form['text']
issue_id := ctx.form['issue_id']
Expand Down
5 changes: 4 additions & 1 deletion repo/file.v
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ fn pretty_size_bytes(size_in_bytes int) string {
return '${size_in} ${sizes[index]}'
}

struct FileInfo {
// Named `RepoFileInfo` rather than `FileInfo` to avoid colliding with
// `os.FileInfo`, which V resolves in the wrong scope when this type is
// substituted into the `api.ApiSuccessResponse[T]` generic.
struct RepoFileInfo {
name string
last_msg string
last_hash string
Expand Down
10 changes: 5 additions & 5 deletions repo/file_routes.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import rand
// GET /:username/:repo_name/new/:branch_name... - Show create file form.
// The catch-all is required because branch names may contain `/`.
@['/:username/:repo_name/new/:branch_name...']
pub fn (mut app App) new_file(username string, repo_name string, branch_name string) veb.Result {
pub fn (mut app App) new_file(mut ctx Context, username string, repo_name string, branch_name string) veb.Result {
repo := app.find_repo_by_name_and_username(repo_name, username) or { return ctx.not_found() }

if repo.require_signed_commits || !ctx.logged_in || !app.user_can_push_branch(ctx.user.id, repo, branch_name)
Expand All @@ -23,7 +23,7 @@ pub fn (mut app App) new_file(username string, repo_name string, branch_name str

// GET /:username/:repo_name/new-ci-file - Show create .gitly-ci.yml form (pre-filled)
@['/:username/:repo_name/new-ci-file']
pub fn (mut app App) new_ci_file(username string, repo_name string) veb.Result {
pub fn (mut app App) new_ci_file(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() }

if repo.require_signed_commits || !ctx.logged_in
Expand All @@ -46,7 +46,7 @@ pub fn (mut app App) new_ci_file(username string, repo_name string) veb.Result {

// GET /:username/:repo_name/edit/:location... - Show edit file form
@['/:username/:repo_name/edit/:location...']
pub fn (mut app App) edit_file(username string, repo_name string, location string) veb.Result {
pub fn (mut app App) edit_file(mut ctx Context, username string, repo_name string, location string) veb.Result {
repo := app.find_repo_by_name_and_username(repo_name, username) or { return ctx.not_found() }
if repo.require_signed_commits || !ctx.logged_in || !app.user_can_write_repo(ctx.user.id, repo) {
return ctx.redirect_to_repository(username, repo_name)
Expand All @@ -69,7 +69,7 @@ pub fn (mut app App) edit_file(username string, repo_name string, location strin

// POST /:username/:repo_name/update-file - Save edited file
@['/:username/:repo_name/update-file'; post]
pub fn (mut app App) handle_update_file(username string, repo_name string) veb.Result {
pub fn (mut app App) handle_update_file(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 Down Expand Up @@ -132,7 +132,7 @@ pub fn (mut app App) handle_update_file(username string, repo_name string) veb.R

// POST /:username/:repo_name/create-file - Create a file in the repo
@['/:username/:repo_name/create-file'; post]
pub fn (mut app App) handle_create_file(username string, repo_name string) veb.Result {
pub fn (mut app App) handle_create_file(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 Down
Loading
Loading