Reworking runs to include an id, save the run request.
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import logging, json, os, nre, sequtils, strtabs, tables, times
|
||||
import logging, json, os, nre, sequtils, strtabs, tables, times, uuids
|
||||
import private/util
|
||||
|
||||
from langutils import sameContents
|
||||
@ -25,6 +25,7 @@ type
|
||||
envVars*: StringTableRef
|
||||
|
||||
RunRequest* = object
|
||||
id*: UUID
|
||||
projectName*, stepName*, buildRef*, workspaceDir*: string
|
||||
forceRebuild*: bool
|
||||
|
||||
@ -67,6 +68,15 @@ proc `==`*(a, b: StrawBossConfig): bool =
|
||||
sameContents(a.users, b.users) and
|
||||
sameContents(a.projects, b.projects)
|
||||
|
||||
proc `==`*(a, b: RunRequest): bool =
|
||||
result =
|
||||
a.id == b.id and
|
||||
a.projectName == b.projectName and
|
||||
a.stepName == b.stepName and
|
||||
a.buildRef == b.buildRef and
|
||||
a.workspaceDir == b.workspaceDir and
|
||||
a.forceRebuild == b.forceRebuild
|
||||
|
||||
# Util methods on custom types
|
||||
proc findProject*(cfg: StrawBossConfig, projectName: string): ProjectDef =
|
||||
let candidates = cfg.projects.filterIt(it.name == projectName)
|
||||
@ -182,12 +192,9 @@ proc loadBuildStatus*(statusFile: string): BuildStatus =
|
||||
state: jsonObj.getOrFail("state", "build status").getStr,
|
||||
details: jsonObj.getIfExists("details").getStr("") )
|
||||
|
||||
|
||||
# TODO: unused and untested, add tests if we start using this
|
||||
proc parseRunRequest*(reqStr: string): RunRequest =
|
||||
let reqJson = parseJson(reqStr)
|
||||
|
||||
proc parseRunRequest*(reqJson: JsonNode): RunRequest =
|
||||
result = RunRequest(
|
||||
id: parseUUID(reqJson.getOrFail("id", "RunRequest").getStr),
|
||||
projectName: reqJson.getOrFail("projectName", "RunRequest").getStr,
|
||||
stepName: reqJson.getOrFail("stepName", "RunRequest").getStr,
|
||||
buildRef: reqJson.getOrFail("buildRef", "RunRequest").getStr,
|
||||
@ -213,6 +220,7 @@ proc `%`*(p: ProjectDef): JsonNode =
|
||||
|
||||
proc `%`*(req: RunRequest): JsonNode =
|
||||
result = %* {
|
||||
"id": $req.id,
|
||||
"projectName": req.projectName,
|
||||
"stepName": req.stepName,
|
||||
"buildRef": req.buildRef,
|
||||
|
Reference in New Issue
Block a user