Skip to content

Commit

Permalink
feat: support gitBranch query
Browse files Browse the repository at this point in the history
  • Loading branch information
xudafeng committed Feb 1, 2019
1 parent 741e9e1 commit 72458a9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ npm-debug.log
node_modules/
package-lock.json
.nyc_output
coverage/
docs_dist/
.idea/
.vscode/
Expand Down
6 changes: 4 additions & 2 deletions app/controller/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -35,7 +35,9 @@ class BuildController extends Controller {
} else {
res = await ctx.service.build.queryByJobName({
jobName,
page, num,
gitBranch,
page,
num,
});
}
} else {
Expand Down
11 changes: 7 additions & 4 deletions app/service/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 72458a9

Please sign in to comment.