Commit 62ccd676 authored by 智勇's avatar 智勇

统一变量名

parent 93611fc2
......@@ -15,24 +15,24 @@ const sendFailMail = async (data, item, executionTimeMs) => {
const duration = data.duration / 1000
const executionTime = executionTimeMs / 1000
const text = `<font color=#FF7F50> 扫描结果 : ${item.status.qualityGateStatus}<br/>`
+ `<font color=#000000> 项目名称 : ${data.project}<br/>`
+ `分支名称 : ${data.branch}<br/>`
+ `<font color=#000000> 项目名称 : ${data.projectName}<br/>`
+ `分支名称 : ${data.branchName}<br/>`
+ `扫描时间 : ${duration}s<br/>`
+ `分析时间 : ${executionTime}s<br/>`
+ `扫描日期 : ${item.analysisDate}<br/>`
+ `查看详情 : ${config.sonarHost}/project/activity?id=${data.project}&&selected_date=${item.analysisDate}`
sendMail(address, `${data.project} ${title}`, text)
+ `查看详情 : ${config.sonarHost}/project/activity?id=${data.projectName}&&selected_date=${item.analysisDate}`
sendMail(address, `${data.projectName} ${title}`, text)
}
const sendExceptionMail = async (data) => {
const address = data.gitUser ? `${data.gitUser}@quantgroup.cn` : data.gitUserMail
const text = '<font color=#FF0000> 扫描结果 : 扫描任务执行失败 <br/>'
+ `<font color=#000000> 结果信息 : ${data.error} <br/>`
+ `项目名称 : ${data.project}<br/>`
+ `分支名称 : ${data.branch}<br/>`
+ `Sonar详情 : ${config.sonarHost}/dashboard?id=${data.project} <br/>`
+ `项目名称 : ${data.projectName}<br/>`
+ `分支名称 : ${data.branchName}<br/>`
+ `Sonar详情 : ${config.sonarHost}/dashboard?id=${data.projectName} <br/>`
+ `Jenskins详情 : ${data.absoluteUrl}console <br/>`
sendMail(address, `${data.project} ${title}`, text)
sendMail(address, `${data.projectName} ${title}`, text)
}
const sendExistMail = async (data, gitUser) => {
......@@ -70,13 +70,6 @@ const callback = async (ctx) => {
return
}
// const saveData = {
// buildId: data.buildId,
// buildJob: data.buildJob,
// branchName: data.branch,
// projectName: data.project,
// }
if (data.error) {
data.buildResult = 'error'
if (data.mail !== 'noMail') {
......@@ -101,13 +94,13 @@ const callback = async (ctx) => {
await sleep(1 * 1000)
}
const res = await awaitRequest({
url: `${config.sonarHost}/api/project_branches/list?project=${data.project}`,
url: `${config.sonarHost}/api/project_branches/list?project=${data.projectName}`,
method: 'GET',
})
logger.info('analysisResult', data.project, JSON.stringify(res))
logger.info('analysisResult', data.projectName, JSON.stringify(res))
for (const i of res.branches) {
if (i.name === 'master' && i.status.qualityGateStatus !== 'OK' && data.mail !== 'noMail') {
logger.info(data.project, '触发质量阀,发送邮件通知')
logger.info(data.projectName, '触发质量阀,发送邮件通知')
sendFailMail(data, i, executionTimeMs)
}
data.buildResult = 'success'
......@@ -157,7 +150,6 @@ const getSonarJob = async (ctx) => {
const curDate = new Date()
const date = new Date(curDate.getTime() - 3 * 24 * 60 * 60 * 1000)
Object.assign(query, { updatedAt: { $gte: date } })
console.log(1, query)
const data = await SonarJob.getSonarJob(query, { _id: 0 }, { updatedAt: -1 }, page)
const count = await SonarJob.getSonarJobCount(query)
ctx.body = ctx.ok({ data, count })
......@@ -173,13 +165,49 @@ const fetchQuality = async (ctx) => {
}
// const data = await SonarJob.getSonarJobGroup(query);
const data = await SonarJob.getSonarJob(query, {
let data = await SonarJob.getSonarJob(query, {
_id: 0, projectName: 1, buildResult: 1, sonarResult: 1,
}, {}, {});
// console.log(1, data)
data = data.reduce((prev, next) => {
if (!prev[next.projectName]) {
prev[next.projectName] = {
exception: 0,
fail: 0,
success: 0,
sum: 0,
}
}
if (next.buildResult === 'error') {
prev[next.projectName].exception += 1
prev[next.projectName].sum += 1
}
if (next.buildResult === 'success') {
if (next.sonarResult === 'OK') {
prev[next.projectName].success += 1
} else {
prev[next.projectName].fail += 1
}
prev[next.projectName].sum += 1
}
return prev
}, {})
const res = []
for (const i in data) {
if (Object.prototype.hasOwnProperty.call(data, i)) {
res.push({
repository: i,
success: data[i].success,
fail: data[i].fail,
exception: data[i].exception,
run: data[i].sum,
})
}
}
ctx.body = ctx.ok(data)
ctx.body = ctx.ok(res)
}
const router = new Router()
......
......@@ -44,18 +44,17 @@ schema.statics.getSonarJobCount = function (query) {
}
schema.statics.getSonarJobGroup = function (query) {
console.log(2, { $match: query })
return this.aggregate([
{ $match: query },
// { $match: { sonarResult: 'WARN' } },
{
$match: {
updatedAt:
{
$gte: '2019-12-03T16:00:00.000Z',
$lte: '2019-12-04T16:00:00.000Z',
$group: {
_id: '$projectName',
result: {
$push: { sonarResult: '$sonarResult', buildResult: '$buildResult', updatedAt: '$updatedAt' },
},
},
},
{ $group: { _id: '$projectName', result: { $push: { sonarResult: '$sonarResult', buildResult: '$buildResult' } } } },
])
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment