forked from vieter-v/vieter
refactor: moved BuildLog to models
parent
6bd5b7cb48
commit
2fc25f1afe
|
@ -1,6 +1,6 @@
|
|||
module client
|
||||
|
||||
import db { BuildLog }
|
||||
import models { BuildLog }
|
||||
import net.http { Method }
|
||||
import response { Response }
|
||||
import time
|
||||
|
|
|
@ -3,8 +3,8 @@ module logs
|
|||
import cli
|
||||
import env
|
||||
import client
|
||||
import db
|
||||
import console
|
||||
import models { BuildLog }
|
||||
|
||||
struct Config {
|
||||
address string [required]
|
||||
|
@ -67,7 +67,7 @@ pub fn cmd() cli.Command {
|
|||
}
|
||||
|
||||
// print_log_list prints a list of logs.
|
||||
fn print_log_list(logs []db.BuildLog) ? {
|
||||
fn print_log_list(logs []BuildLog) ? {
|
||||
data := logs.map([it.id.str(), it.repo_id.str(), it.start_time.str(),
|
||||
it.exit_code.str()])
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module db
|
||||
|
||||
import sqlite
|
||||
import models
|
||||
import models { BuildLog, GitRepo }
|
||||
|
||||
struct VieterDb {
|
||||
conn sqlite.DB
|
||||
|
|
|
@ -66,6 +66,7 @@ pub fn (db &VieterDb) update_git_repo(repo_id int, params map[string]string) {
|
|||
}
|
||||
}
|
||||
values_str := values.join(', ')
|
||||
// I think this is actual SQL & not the ORM language
|
||||
query := 'update GitRepo set $values_str where id == $repo_id'
|
||||
|
||||
db.conn.exec_none(query)
|
||||
|
|
|
@ -1,31 +1,6 @@
|
|||
module db
|
||||
|
||||
import time
|
||||
|
||||
pub struct BuildLog {
|
||||
pub:
|
||||
id int [primary; sql: serial]
|
||||
repo_id int [nonull]
|
||||
start_time time.Time [nonull]
|
||||
end_time time.Time [nonull]
|
||||
arch string [nonull]
|
||||
exit_code int [nonull]
|
||||
}
|
||||
|
||||
// str returns a string representation.
|
||||
pub fn (bl &BuildLog) str() string {
|
||||
mut parts := [
|
||||
'id: $bl.id',
|
||||
'repo id: $bl.repo_id',
|
||||
'start time: $bl.start_time',
|
||||
'end time: $bl.end_time',
|
||||
'arch: $bl.arch',
|
||||
'exit code: $bl.exit_code',
|
||||
]
|
||||
str := parts.join('\n')
|
||||
|
||||
return str
|
||||
}
|
||||
import models { BuildLog }
|
||||
|
||||
// get_build_logs returns all BuildLog's in the database.
|
||||
pub fn (db &VieterDb) get_build_logs() []BuildLog {
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
module models
|
||||
|
||||
import time
|
||||
|
||||
pub struct BuildLog {
|
||||
pub:
|
||||
id int [primary; sql: serial]
|
||||
repo_id int [nonull]
|
||||
start_time time.Time [nonull]
|
||||
end_time time.Time [nonull]
|
||||
arch string [nonull]
|
||||
exit_code int [nonull]
|
||||
}
|
||||
|
||||
// str returns a string representation.
|
||||
pub fn (bl &BuildLog) str() string {
|
||||
mut parts := [
|
||||
'id: $bl.id',
|
||||
'repo id: $bl.repo_id',
|
||||
'start time: $bl.start_time',
|
||||
'end time: $bl.end_time',
|
||||
'arch: $bl.arch',
|
||||
'exit code: $bl.exit_code',
|
||||
]
|
||||
str := parts.join('\n')
|
||||
|
||||
return str
|
||||
}
|
|
@ -4,7 +4,7 @@ import web
|
|||
import net.http
|
||||
import response { new_data_response, new_response }
|
||||
import db
|
||||
import models { GitRepoArch }
|
||||
import models { GitRepo, GitRepoArch, GitRepoFilter }
|
||||
|
||||
// get_repos returns the current list of repos.
|
||||
['/api/repos'; get]
|
||||
|
|
|
@ -8,6 +8,7 @@ import db
|
|||
import time
|
||||
import os
|
||||
import util
|
||||
import models { BuildLog }
|
||||
|
||||
// get_logs returns all build logs in the database. A 'repo' query param can
|
||||
// optionally be added to limit the list of build logs to that repository.
|
||||
|
@ -97,7 +98,7 @@ fn (mut app App) post_log() web.Result {
|
|||
}
|
||||
|
||||
// Store log in db
|
||||
log := db.BuildLog{
|
||||
log := BuildLog{
|
||||
repo_id: repo_id
|
||||
start_time: start_time
|
||||
end_time: end_time
|
||||
|
|
Loading…
Reference in New Issue