From 72458a93c047e2281282173272e7ca03321f35fd Mon Sep 17 00:00:00 2001 From: xudafeng Date: Fri, 1 Feb 2019 23:46:47 +0800 Subject: [PATCH] feat: support gitBranch query --- .gitignore | 1 + app/controller/build.js | 6 ++++-- app/service/build.js | 11 +++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 7c0d85e..5f1bbec 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ npm-debug.log node_modules/ package-lock.json .nyc_output +coverage/ docs_dist/ .idea/ .vscode/ diff --git a/app/controller/build.js b/app/controller/build.js index 4ee0312..4b38d6b 100644 --- a/app/controller/build.js +++ b/app/controller/build.js @@ -23,7 +23,7 @@ class BuildController extends Controller { const page = Number(ctx.query.page) || 1; const num = Number(ctx.query.num) || ctx.app.config.modelQueryConfig.pagination.num; - const { jobName, buildNumber } = ctx.query; + const { jobName, buildNumber, gitBranch, } = ctx.query; let res; if (jobName) { @@ -35,7 +35,9 @@ class BuildController extends Controller { } else { res = await ctx.service.build.queryByJobName({ jobName, - page, num, + gitBranch, + page, + num, }); } } else { diff --git a/app/service/build.js b/app/service/build.js index 0840784..56240bf 100644 --- a/app/service/build.js +++ b/app/service/build.js @@ -48,13 +48,17 @@ module.exports = class BuildService extends Service { }; } - async queryByJobName({ page, num, jobName }) { + async queryByJobName({ page, num, jobName, gitBranch }) { const ctx = this.ctx; const allJobName = await ctx.model.JobName.findAll({ attributes: [ 'jobName', ], }).map(i => i.jobName); + const param = { jobName }; + if (gitBranch) { + param.gitBranch = gitBranch; + } const total = await ctx.model.Build.count(); const result = await ctx.model.Build.findAll({ limit: num, @@ -65,15 +69,14 @@ module.exports = class BuildService extends Service { 'DESC', ], ], - where: { - jobName, - }, + where: param, }); return { success: true, message: '', data: { allJobName, + gitBranch, total, page, result,