Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 'work qa' #90

Merged
merged 3 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/handlers/work/_lib/qa-lib.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import * as fs from 'node:fs/promises'
import * as fsPath from 'node:path'

import { httpSmartResponse } from '@liquid-labs/http-smart-response'
import { tryExec } from '@liquid-labs/shell-toolkit'

import { getCommonImpliedParameters } from './common-implied-parameters'
import { determinePathHelper } from './determine-path-helper'
import { determineProjects } from './determine-projects'
import { WorkDB } from './work-db'

const doQA = async({ app, cache, model, reporter, req, res, workKey }) => {
const { all } = req.vars
let { projects } = req.vars

const workDB = new WorkDB({ app, reporter });

([projects, workKey] =
await determineProjects({ all, cliEndpoint : 'work qa', projects, reporter, req, workDB, workKey }))

let msg = ''

for (const projectFQN of projects) {
const { projectPath } = determinePathHelper({ app, projectFQN })

tryExec(`cd '${projectPath}' && npm run qa`, { noThrow : true })

for (const file of await fs.readdir(projectPath, { encoding : 'utf8' })) {
if (file.match(/last-.+\.txt/)) {
const qaType = file.replace(/last-(.+)\.txt/, '$1')
msg += '\n' + '<h1>' + qaType.charAt(0).toUpperCase() + qaType.slice(1) + ' for ' + projectFQN + '<rst>\n\n'
const filePath = fsPath.join(projectPath, file)
msg += await fs.readFile(filePath, { encoding : 'utf8' })
}
}
}

httpSmartResponse({ msg, req, res })
}

const getQAEndpointParams = ({ workDesc }) => ({
help : {
name : `Work qa (${workDesc})`,
summary : 'QAs work involved projects.',
description : `QAs one or more projects associated with the ${workDesc} unit of work.`
},
method : 'put',
parameters : getCommonImpliedParameters({ actionDesc : 'qa' })
})

export { doQA, getQAEndpointParams }
4 changes: 4 additions & 0 deletions src/handlers/work/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import * as cleanHandler from './clean'
import * as cleanImpliedHandler from './clean-implied'
import * as pauseHandler from './pause'
import * as pauseImpliedHandler from './pause-implied'
import * as qaHandler from './qa'
import * as qaImpliedHandler from './qa-implied'
import * as resumeHandler from './resume'
import * as saveHandler from './save'
import * as saveImpliedHandler from './save-implied'
Expand All @@ -23,6 +25,8 @@ const handlers = [
cleanImpliedHandler,
pauseHandler,
pauseImpliedHandler,
qaHandler,
qaImpliedHandler,
resumeHandler,
saveHandler,
saveImpliedHandler,
Expand Down
27 changes: 27 additions & 0 deletions src/handlers/work/qa-implied.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import createError from 'http-errors'

import { determineCurrentBranch } from '@liquid-labs/git-toolkit'

import { getCommonImpliedParameters } from './_lib/common-implied-parameters'
import { getQAEndpointParams, doQA } from './_lib/qa-lib'

let { help, method, parameters } = getQAEndpointParams({ workDesc : 'implied' })
parameters = [
...getCommonImpliedParameters({ actionDesc : 'qa' }),
...parameters
].sort((a, b) => a.name.localeCompare(b.name))

const path = ['work', 'qa']

const func = ({ app, cache, model, reporter }) => async(req, res) => {
reporter = reporter.isolate()

const cwd = req.get('X-CWD')
if (cwd === undefined) { throw createError.BadRequest("Called 'work qa' with implied work, but 'X-CWD' header not found.") }

const workKey = determineCurrentBranch({ projectPath : cwd, reporter })

await doQA({ app, cache, model, reporter, req, res, workKey })
}

export { func, help, parameters, path, method }
13 changes: 13 additions & 0 deletions src/handlers/work/qa.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { doQA, getQAEndpointParams } from './_lib/qa-lib'

const { help, method, parameters } = getQAEndpointParams({ workDesc : 'indicated' })

const path = ['work', ':workKey', 'qa']

const func = ({ app, cache, model, reporter }) => async(req, res) => {
const { workKey } = req.vars

await doQA({ app, cache, model, reporter, req, res, workKey })
}

export { func, help, parameters, path, method }