From 7aa0a69215e5ec7720ce10fc7483ec67d2dd845b Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Mon, 20 Nov 2017 20:18:17 -0600 Subject: [PATCH] GET /api/project/ endpoint. --- src/main/nim/strawbosspkg/configuration.nim | 23 +++++++++++++++++++-- src/main/nim/strawbosspkg/server.nim | 6 +++--- src/test/nim/unit/tconfiguration.nim | 13 ++++++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/main/nim/strawbosspkg/configuration.nim b/src/main/nim/strawbosspkg/configuration.nim index 69947b0..651f9f6 100644 --- a/src/main/nim/strawbosspkg/configuration.nim +++ b/src/main/nim/strawbosspkg/configuration.nim @@ -204,8 +204,7 @@ proc parseRunRequest*(reqJson: JsonNode): RunRequest = proc `%`*(s: BuildStatus): JsonNode = result = %* { "state": s.state, - "details": s.details - } + "details": s.details } proc `%`*(p: ProjectDef): JsonNode = result = %* { @@ -217,6 +216,26 @@ proc `%`*(p: ProjectDef): JsonNode = result["envVars"] = newJObject() for k, v in p.envVars: result["envVars"][k] = %v +proc `%`*(s: Step): JsonNode = + result = %* { + "name": s.name, + "stepCmd": s.stepCmd, + "workingDir": s.workingDir, + "artifacts": s.artifacts, + "cmdInput": s.cmdInput, + "depends": s.depends, + "expectedEnv": s.expectedEnv, + "dontSkip": s.dontSkip } + +proc `%`*(p: ProjectConfig): JsonNode = + result = %* { + "name": p.name, + "versionCmd": p.versionCmd } + + result["steps"] = newJObject() + for name, step in p.steps: + result["steps"][name] = %step + proc `%`*(req: RunRequest): JsonNode = result = %* { "projectName": req.projectName, diff --git a/src/main/nim/strawbosspkg/server.nim b/src/main/nim/strawbosspkg/server.nim index ebaf23e..0c1a435 100644 --- a/src/main/nim/strawbosspkg/server.nim +++ b/src/main/nim/strawbosspkg/server.nim @@ -245,9 +245,9 @@ proc start*(cfg: StrawBossConfig): void = var respObj = newJObject() respObj["definition"] = %projDef - #if projConf.isSome(): - # let pc: ProjectConfig = projConf.get() - # respObj["configuration"] = %pc + if projConf.isSome(): + let pc: ProjectConfig = projConf.get() + respObj["configuration"] = %pc resp($respObj, JSON) diff --git a/src/test/nim/unit/tconfiguration.nim b/src/test/nim/unit/tconfiguration.nim index a8803e3..34d5d01 100644 --- a/src/test/nim/unit/tconfiguration.nim +++ b/src/test/nim/unit/tconfiguration.nim @@ -124,6 +124,19 @@ suite "load and save configuration objects": let cfgStr = $cfg check cfg == parseStrawBossConfig(parseJson(cfgStr)) + test "%step": + let step = Step( + name: "build", stepCmd: "true", workingDir: "dirA", + artifacts: @[], depends: @["compile"], cmdInput: @[], + expectedEnv: @["CWD", "TERM"], dontSkip: true) + + let stepJS = %step + + for k in @["name", "stepCmd", "workingDir", "artifacts", "cmdInput", + "depends", "expectedEnv", "dontSkip"]: + + check stepJS.hasKey(k) + test "loadBuildStatus": let st = loadBuildStatus("src/test/json/test-status.json")