WIP Adding GET /project/<projectName> endpoint.

This commit is contained in:
Jonathan Bernard
2017-11-20 10:05:55 -06:00
parent 6340b2fa49
commit f222d859e6
3 changed files with 38 additions and 13 deletions

View File

@ -1,5 +1,5 @@
import algorithm, asyncdispatch, bcrypt, cliutils, jester, json, jwt, logging,
os, osproc, sequtils, strutils, tempfile, times, unittest
options, os, osproc, sequtils, strutils, tempfile, times, unittest
import ./configuration, ./core
@ -234,8 +234,22 @@ proc start*(cfg: StrawBossConfig): void =
checkAuth(); if not authed: return true
# TODO
resp(Http501, makeJsonResp(Http501), JSON)
# Make sure we know about that project
var projDef: ProjectDef
try: projDef = cfg.findProject(@"projectName")
except: resp(Http404, makeJsonResp(Http404, getCurrentExceptionMsg()), JSON)
# Get the project configuration.
let projConf = getCurrentProjectConfig(cfg, projDef)
var respObj = newJObject()
respObj["definition"] = %projDef
#if projConf.isSome():
# let pc: ProjectConfig = projConf.get()
# respObj["configuration"] = %pc
resp($respObj, JSON)
get "/project/@projectName/runs":
## List all runs
@ -247,11 +261,7 @@ proc start*(cfg: StrawBossConfig): void =
try: project = cfg.findProject(@"projectName")
except: resp(Http404, makeJsonResp(Http404, getCurrentExceptionMsg()), JSON)
let runsDir = cfg.artifactsRepo & "/" & project.name & "/runs"
if not existsDir(runsDir): resp("[]", JSON)
let runPaths = toSeq(walkFiles(runsDir & "/*.json"))
let runRequests = runPaths.mapIt(parseRunRequest(parseFile(it)))
let runRequests = listRuns(cfg, project)
resp($(%runRequests), JSON)