Add findProject for looking up projects from the StrawBossConfig object properly.

This commit is contained in:
Jonathan Bernard 2017-04-25 12:54:08 -05:00
parent 81674dfa3f
commit 9d00d638db
2 changed files with 12 additions and 5 deletions

View File

@ -56,6 +56,15 @@ proc `==`*(a, b: ProjectDef): bool =
a.defaultBranch == b.defaultBranch and a.defaultBranch == b.defaultBranch and
a.repo == b.repo a.repo == b.repo
# Util methods on custom types
proc findProject*(cfg: StrawBossConfig, projectName: string): ProjectDef =
let candidates = cfg.projects.filterIt(it.name == projectName)
if candidates.len == 0:
raise newException(KeyError, "no project named " & projectName)
elif candidates.len > 0:
raise newException(KeyError, "multiple projects named " & projectName)
else: result = candidates[0]
# internal utils # internal utils
let nullNode = newJNull() let nullNode = newJNull()

View File

@ -164,9 +164,7 @@ proc runStep*(cfg: StrawBossConfig, req: RunRequest,
if not existsDir(req.workspaceDir): createDir(req.workspaceDir) if not existsDir(req.workspaceDir): createDir(req.workspaceDir)
# Find the project definition # Find the project definition
let matching = cfg.projects.filterIt(it.name == req.projectName) let projectDef = cfg.findProject(req.projectName)
if matching.len == 0: raiseEx "no such project: " & req.projectName
elif matching.len > 1: raiseEx "more than one project named : " & req.projectName
# Read in the existing system environment # Read in the existing system environment
var env = loadEnv() var env = loadEnv()
@ -183,13 +181,13 @@ proc runStep*(cfg: StrawBossConfig, req: RunRequest,
artifactsRepo: cfg.artifactsRepo, artifactsRepo: cfg.artifactsRepo,
buildRef: buildRef:
if req.buildRef != nil and req.buildRef.len > 0: req.buildRef if req.buildRef != nil and req.buildRef.len > 0: req.buildRef
else: matching[0].defaultBranch, else: projectDef.defaultBranch,
dir: req.workspaceDir, dir: req.workspaceDir,
env: env, env: env,
openedFiles: @[stdoutFile, stderrFile], openedFiles: @[stdoutFile, stderrFile],
outputHandler: combineProcMsgHandlers(outputHandler, logFilesOH), outputHandler: combineProcMsgHandlers(outputHandler, logFilesOH),
project: ProjectConfig(), project: ProjectConfig(),
projectDef: matching[0], projectDef: projectDef,
status: result, status: result,
statusFile: req.workspaceDir & "/" & "status.json", statusFile: req.workspaceDir & "/" & "status.json",
step: Step(), step: Step(),