diff --git a/app/common/error/index.js b/app/common/error/index.js index bfc23f7..cf6ff77 100644 --- a/app/common/error/index.js +++ b/app/common/error/index.js @@ -2,7 +2,7 @@ // key: error code // value: error details -// value.message: default error message +// value.message: default error message module.exports = new Map([ [ 'ERR_RELIABLE_INTERNAL_SERVER_ERROR', { diff --git a/app/controller/build.js b/app/controller/build.js index a74b226..cd77ed0 100644 --- a/app/controller/build.js +++ b/app/controller/build.js @@ -32,6 +32,10 @@ class BuildController extends Controller { jobName, buildNumber, }); + // 如果没有git提交时间,用报告创建时间替代 + if (!res.data.data.gitCommitInfo.date) { + res.data.data.gitCommitInfo.date = res.data.createdAt; + } } else { res = await ctx.service.build.queryByJobName({ jobName, @@ -51,6 +55,42 @@ class BuildController extends Controller { ctx.body = res; } + /** + * 查询最近的报告 + */ + async queryLatest() { + const { ctx } = this; + const Sequelize = ctx.app.Sequelize; + const Op = Sequelize.Op; + const { jobName, gitBranch, subJobName } = ctx.request.body; + const query = { + limit: 5, + where: {}, + order: [ + [ + 'createdAt', + 'DESC', + ], + ], + }; + if (jobName) { + query.where.jobName = jobName.replace('__', '/'); + } + if (gitBranch) { + query.where.gitBranch = gitBranch; + } + if (subJobName) { + // "subJobName": xxx + query.where.extendInfo = { + [Op.like]: Sequelize.literal(`\'%"${subJobName}"%\'`), + }; + } + const result = await this.ctx.model.Build.findAll(query); + ctx.success({ + result, + }); + } + async queryLatestByJobNameAndGitBranch() { const jobName = this.ctx.params.jobName; const gitBranch = this.ctx.params.gitBranch; @@ -72,6 +112,25 @@ class BuildController extends Controller { }); } + async queryLatestByJobName() { + const jobName = this.ctx.params.jobName; + const result = await this.ctx.model.Build.findAll({ + limit: 3, + where: { + jobName: jobName.replace('__', '/'), + }, + order: [ + [ + 'createdAt', + 'DESC', + ], + ], + }); + this.ctx.success({ + result, + }); + } + async update() { const ctx = this.ctx; const uniqId = ctx.params.uniqId; diff --git a/app/controller/gw.js b/app/controller/gw.js index 90f6dcf..64e82d4 100644 --- a/app/controller/gw.js +++ b/app/controller/gw.js @@ -68,6 +68,7 @@ class GwController extends Controller { gitBranch, data, state, + extendInfo: data.extendInfo || {}, }); } diff --git a/app/controller/insight.js b/app/controller/insight.js index 675c35b..27274f4 100644 --- a/app/controller/insight.js +++ b/app/controller/insight.js @@ -60,7 +60,7 @@ class InsightController extends Controller { 'createdAt', 'finishedAt', ], - limit: 100, + limit: 5, order: [[ 'createdAt', 'DESC' ]], }; if (allBranches === 'N') { @@ -78,7 +78,7 @@ class InsightController extends Controller { if (res.length === 0) return null; const lastCommit = { - committer: ctx.safeGet(res, '[0].data.gitCommitInfo.committer.name'), + committer: ctx.safeGet(res, '[0].data.gitCommitInfo.author'), shortHash: ctx.safeGet(res, '[0].data.gitCommitInfo.shortHash'), commitUrl: this._getCommitUrl(res[0]), }; diff --git a/app/extend/helper.js b/app/extend/helper.js index c1adb21..ff6d562 100644 --- a/app/extend/helper.js +++ b/app/extend/helper.js @@ -46,7 +46,7 @@ module.exports = { text.push(`#### Platform: ${environment.platform}`); text.push('#### Commit'); text.push(`[${gitCommitInfo.shortHash}](${gitUrl}/commit/${gitCommitInfo.hash}): ${gitCommitInfo.subject}`); - text.push(`> committer:[@${gitCommitInfo.committer.name}]() author:[@${gitCommitInfo.author.name}]()`); + text.push(`> committer:[@${gitCommitInfo.author.name}]() author:[@${gitCommitInfo.author.name}]()`); // test report info diff --git a/app/router.js b/app/router.js index 087390e..76cc9c7 100644 --- a/app/router.js +++ b/app/router.js @@ -12,7 +12,9 @@ module.exports = app => { router.post('/api/gw', controller.gw.index); // latestBuild + router.post('/api/latestBuild', controller.build.queryLatest); router.get('/api/latestBuild/:jobName/:gitBranch+', controller.build.queryLatestByJobNameAndGitBranch); + router.get('/api/latestBuild/:jobName', controller.build.queryLatestByJobName); // insight router.get('/api/insight/ci', controller.insight.ci); diff --git a/view/.babelrc b/view/.babelrc index 79f0ada..9b2c266 100644 --- a/view/.babelrc +++ b/view/.babelrc @@ -12,6 +12,8 @@ "style": "css" } ], + "@babel/plugin-proposal-nullish-coalescing-operator", + "@babel/plugin-proposal-optional-chaining", "@babel/plugin-transform-runtime", "@babel/plugin-proposal-class-properties", "@babel/plugin-proposal-export-default-from" diff --git a/view/.browserslistrc b/view/.browserslistrc deleted file mode 100644 index 0079123..0000000 --- a/view/.browserslistrc +++ /dev/null @@ -1,8 +0,0 @@ -> 1% -last 2 versions -Firefox ESR -not ie 10 -not ie_mob 10 - -[development] -last 1 chrome version diff --git a/view/lib/render.js b/view/lib/render.js index 35e9e00..b2a0e6c 100644 --- a/view/lib/render.js +++ b/view/lib/render.js @@ -7,7 +7,7 @@ const templatePath = path.join(__dirname, '..', 'index.html'); const template = fs.readFileSync(templatePath, 'utf8'); module.exports = async (context, options = {}) => { - const content = template.replace(//, () => { + return template.replace(//, () => { return `