Add findProject for looking up projects from the StrawBossConfig object properly.
This commit is contained in:
parent
81674dfa3f
commit
9d00d638db
@ -56,6 +56,15 @@ proc `==`*(a, b: ProjectDef): bool =
|
||||
a.defaultBranch == b.defaultBranch and
|
||||
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
|
||||
|
||||
let nullNode = newJNull()
|
||||
|
@ -164,9 +164,7 @@ proc runStep*(cfg: StrawBossConfig, req: RunRequest,
|
||||
if not existsDir(req.workspaceDir): createDir(req.workspaceDir)
|
||||
|
||||
# Find the project definition
|
||||
let matching = cfg.projects.filterIt(it.name == req.projectName)
|
||||
if matching.len == 0: raiseEx "no such project: " & req.projectName
|
||||
elif matching.len > 1: raiseEx "more than one project named : " & req.projectName
|
||||
let projectDef = cfg.findProject(req.projectName)
|
||||
|
||||
# Read in the existing system environment
|
||||
var env = loadEnv()
|
||||
@ -183,13 +181,13 @@ proc runStep*(cfg: StrawBossConfig, req: RunRequest,
|
||||
artifactsRepo: cfg.artifactsRepo,
|
||||
buildRef:
|
||||
if req.buildRef != nil and req.buildRef.len > 0: req.buildRef
|
||||
else: matching[0].defaultBranch,
|
||||
else: projectDef.defaultBranch,
|
||||
dir: req.workspaceDir,
|
||||
env: env,
|
||||
openedFiles: @[stdoutFile, stderrFile],
|
||||
outputHandler: combineProcMsgHandlers(outputHandler, logFilesOH),
|
||||
project: ProjectConfig(),
|
||||
projectDef: matching[0],
|
||||
projectDef: projectDef,
|
||||
status: result,
|
||||
statusFile: req.workspaceDir & "/" & "status.json",
|
||||
step: Step(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user