feat(server): allow filtering of builds per repo

pull/169/head
Jef Roosens 2022-05-07 15:31:01 +02:00
parent 7e01dbafec
commit 393e641a76
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 22 additions and 6 deletions

View File

@ -4,7 +4,7 @@ import time
pub struct BuildLog {
id int [primary; sql: serial]
repo GitRepo [nonull]
repo_id int [nonull]
start_time time.Time [nonull]
end_time time.Time [nonull]
exit_code int [nonull]
@ -19,6 +19,16 @@ pub fn (db &VieterDb) get_build_logs() []BuildLog {
return res
}
// get_build_logs_for_repo returns all BuildLog's in the database for a given
// repo.
pub fn (db &VieterDb) get_build_logs_for_repo(repo_id int) []BuildLog {
res := sql db.conn {
select from BuildLog where repo_id == repo_id order by id
}
return res
}
// get_build_log tries to return a specific BuildLog.
pub fn (db &VieterDb) get_build_log(id int) ?BuildLog {
res := sql db.conn {

View File

@ -15,7 +15,11 @@ fn (mut app App) get_logs() web.Result {
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
}
logs := app.db.get_build_logs()
logs := if 'repo' in app.query {
app.db.get_build_logs_for_repo(app.query['repo'].int())
} else {
app.db.get_build_logs()
}
return app.json(http.Status.ok, new_data_response(logs))
}
@ -56,13 +60,15 @@ fn (mut app App) post_log() web.Result {
arch := app.query['arch']
repo := app.db.get_git_repo(app.query['repo'].int()) or {
return app.json(http.Status.bad_request, new_response('Unknown repo.'))
repo := app.query['repo'].int()
if repo == 0 {
return app.json(http.Status.bad_request, new_response('Invalid Git repo.'))
}
// Store log in db
log := db.BuildLog{
repo: repo
repo_id: repo
start_time: start_time
end_time: end_time
exit_code: exit_code
@ -70,7 +76,7 @@ fn (mut app App) post_log() web.Result {
app.db.add_build_log(log)
repo_logs_dir := os.join_path(app.conf.data_dir, logs_dir_name, repo.id.str(), arch)
repo_logs_dir := os.join_path(app.conf.data_dir, logs_dir_name, repo.str(), arch)
// Create the logs directory of it doesn't exist
if !os.exists(repo_logs_dir) {