Skip to content

Commit

Permalink
fix: list bug fix (#84)
Browse files Browse the repository at this point in the history
* fix: list bug fix
  • Loading branch information
xudafeng authored Aug 12, 2022
1 parent 4ff9d5f commit c4319fb
Show file tree
Hide file tree
Showing 20 changed files with 118 additions and 109 deletions.
2 changes: 1 addition & 1 deletion app/common/error/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
59 changes: 59 additions & 0 deletions app/controller/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions app/controller/gw.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class GwController extends Controller {
gitBranch,
data,
state,
extendInfo: data.extendInfo || {},
});
}

Expand Down
4 changes: 2 additions & 2 deletions app/controller/insight.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class InsightController extends Controller {
'createdAt',
'finishedAt',
],
limit: 100,
limit: 5,
order: [[ 'createdAt', 'DESC' ]],
};
if (allBranches === 'N') {
Expand All @@ -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]),
};
Expand Down
2 changes: 1 addition & 1 deletion app/extend/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions view/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 0 additions & 8 deletions view/.browserslistrc

This file was deleted.

3 changes: 1 addition & 2 deletions view/lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(/<!--\s*data\s*-->/, () => {
return template.replace(/<!--\s*data\s*-->/, () => {
return `
<script>
window.pageConfig = ${JSON.stringify(options, null, 2)};
Expand All @@ -17,6 +17,5 @@ module.exports = async (context, options = {}) => {
}).replace(/<!--\s*title\s*-->/, () => {
return `${options.title}`;
});
return content;
};

4 changes: 3 additions & 1 deletion view/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"@babel/core": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-export-default-from": "^7.0.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.7",
"@babel/plugin-proposal-optional-chaining": "^7.16.7",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/preset-env": "^7.0.0",
Expand All @@ -38,7 +40,6 @@
"babel-plugin-istanbul": "^5.0.1",
"cross-env": "^7.0.3",
"css-loader": "^0.28.11",
"dayjs": "^1.7.7",
"eslint": "^4.5.0",
"eslint-config-antife": "^1.0.2",
"eslint-plugin-mocha": "^5.0.0",
Expand All @@ -52,6 +53,7 @@
"macaca-electron": "18",
"macaca-wd": "3",
"mini-css-extract-plugin": "^2.5.3",
"moment": "^2.29.4",
"postcss-loader": "^2.1.6",
"qrcode-react": "^0.1.16",
"query-string": "^6.2.0",
Expand Down
13 changes: 7 additions & 6 deletions view/src/components/BuildsTable.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import React from 'react';
import dayjs from 'dayjs';
import moment from 'moment';
import { Link } from 'react-router-dom';
import {
Table,
Expand All @@ -18,10 +18,11 @@ import {
} from '../util/index';

import './buildsTable.less';
import { strUtil } from '../util/dataUtil';

export default class BuildsTable extends React.Component {
handleTableChange = (pagination, filters, sorter) => {
const pager = { ...this.props.pagination };
const pager = { ...this.props.pagination, ...pagination };
pager.current = pagination.current;
this.props.updatePagination(pager, this.props.jobName);
}
Expand Down Expand Up @@ -49,7 +50,7 @@ export default class BuildsTable extends React.Component {
}, {
title: <FormattedMessage id='builds.buildNumber' />,
dataIndex: 'buildNumber',
width: 160,
width: 200,
render: (value, record) => (
<span>
<a
Expand All @@ -65,7 +66,7 @@ export default class BuildsTable extends React.Component {
href={record.buildUrl}
target="_blank"
>
{value}
{strUtil.cutStrTail(15, value)}
</a>
</span>
),
Expand All @@ -77,7 +78,7 @@ export default class BuildsTable extends React.Component {
dataIndex: 'buildEndTime',
render: (text, record) => (
<span>
{dayjs(text).format('YYYY-MM-DD HH:mm:ss')}
{moment(text).format('YYYY-MM-DD HH:mm:ss')}
</span>
),
}, {
Expand All @@ -94,7 +95,7 @@ export default class BuildsTable extends React.Component {
width: 120,
render: (text, record) =>
<span>
{record.gitCommitInfo.committer.name}
{record.gitCommitInfo.author?.name}
</span>,
}, {
title: <FormattedMessage id='builds.detailInfo' />,
Expand Down
5 changes: 3 additions & 2 deletions view/src/components/BuildsTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ class BuildsTabs extends React.Component {
Object.assign(pager, pagination);
this.setState({
pagination: pager,
}, () => {
this.fetch(pagination, tab);
});
this.fetch(pagination, tab);
}

fetch = (pager, tab) => {
const param = {
num: this.state.pagination.pageSize,
num: pager && pager.pageSize || this.state.pagination.pageSize,
page: pager && pager.current || 1,
jobName: tab,
};
Expand Down
8 changes: 4 additions & 4 deletions view/src/components/DingdingSetting.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ const DingdingSetting = () => {
<Form.Item
{...field}
{...webhookFormItemLayout}
name={[field.name, 'url']}
fieldKey={[field.fieldKey, 'url']}
name={[field?.name, 'url']}
fieldKey={[field?.fieldKey, 'url']}
validateTrigger={['onBlur']}
rules={[{
required: true,
Expand All @@ -107,7 +107,7 @@ const DingdingSetting = () => {
<Input
addonBefore={
<Form.Item
name={[field.name, 'tag']}
name={[field?.name, 'tag']}
initialValue="build"
noStyle
>
Expand All @@ -122,7 +122,7 @@ const DingdingSetting = () => {
style={{
cursor: 'pointer',
}}
onClick={() => remove(field.name)}
onClick={() => remove(field?.name)}
/>
}
/>
Expand Down
24 changes: 10 additions & 14 deletions view/src/components/OneBuildTabs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import React from 'react';
import dayjs from 'dayjs';
import moment from 'moment';
import safeGet from 'lodash.get';
import { Spin, Tabs } from 'antd';
import { FormattedMessage } from 'react-intl';
Expand All @@ -11,8 +11,6 @@ import TestTable from './TestTable';
import ExtraTable from './ExtraTable';
import FileTable from './FileTable';

import { getBuildLink } from '../util';

const TabPane = Tabs.TabPane;

export default class OneBuildTabs extends React.Component {
Expand All @@ -38,12 +36,11 @@ export default class OneBuildTabs extends React.Component {
};
if (data && data.packages && data.packages.length && data.gitCommitInfo) {
data.packages.forEach(item => {
const commitTime = data.gitCommitInfo.committer.date * 1000;
data.gitCommitInfo.commitTime = dayjs(commitTime).format('YYYY-MM-DD HH:mm:ss');
data.gitCommitInfo.commitTime = moment(data.gitCommitInfo?.date).format('YYYY-MM-DD HH:mm:ss');
data.gitCommitInfo.gitHref = `${data.gitCommitInfo.gitUrl}/commit/${data.gitCommitInfo.hash}`;
result.packages.push({
...item,
download: getBuildLink(this.props.data, item.path),
download: item.path || '',
gitCommitInfo: data.gitCommitInfo,
buildUniqId: data.buildUniqId,
});
Expand All @@ -55,22 +52,21 @@ export default class OneBuildTabs extends React.Component {
getTestInfo () {
const data = this.props.data;
const result = [];
if (data && data.testInfo && data.testInfo.tests) {
if (data && data.testInfo) {
const report = data.testInfo.testHtmlReporterPath;
const coverage = data.testInfo.coverageHtmlReporterPath;
const commitTime = data.gitCommitInfo.committer.date * 1000;
result.push({
lineCoverage: data.testInfo.linePercent,
passingRate: data.testInfo.passPercent,
testInfo: data.testInfo,
testReporter: getBuildLink(this.props.data, report),
coverageReporter: getBuildLink(this.props.data, coverage),
testReporter: report || '',
coverageReporter: coverage || '',
gitBranch: data.gitCommitInfo.gitBranch,
gitCommit: data.gitCommitInfo.shortHash,
gitHref: `${data.gitCommitInfo.gitUrl}/commit/${data.gitCommitInfo.hash}`,
committer: data.gitCommitInfo.committer.name,
committerEmail: data.gitCommitInfo.committer.email,
commitTime: dayjs(commitTime).format('YYYY-MM-DD HH:mm:ss'),
committer: data.gitCommitInfo.author?.name,
committerEmail: data.gitCommitInfo.author?.email,
commitTime: moment(data.gitCommitInfo?.date).format('YYYY-MM-DD HH:mm:ss'),
});
}
return result;
Expand All @@ -83,7 +79,7 @@ export default class OneBuildTabs extends React.Component {
data.files.forEach(item => {
result.push({
fileName: item,
fileAddress: getBuildLink(this.props.data, item),
fileAddress: item || '',
});
});
}
Expand Down
8 changes: 4 additions & 4 deletions view/src/components/PkgTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ export default class PkgTable extends React.Component {
<Popover content={
<ul className="commit-pop-block">
<li>
committer name: { safeGet(record, 'gitCommitInfo.committer.name') }
committer name: { safeGet(record, 'gitCommitInfo.author.name') }
</li>
<li>
committer email: { safeGet(record, 'gitCommitInfo.committer.email') }
committer email: { safeGet(record, 'gitCommitInfo.author.email') }
</li>
<li>
author name: { safeGet(record, 'gitCommitInfo.author.name') }
Expand All @@ -100,7 +100,7 @@ export default class PkgTable extends React.Component {
target="_blank"
>
{record.gitCommitInfo.shortHash}
</a> {record.gitCommitInfo.committer.name}
</a> {record.gitCommitInfo.author?.name}
</Popover>
);
},
Expand Down Expand Up @@ -171,7 +171,7 @@ export default class PkgTable extends React.Component {
${safeGet(this.state.record, 'gitCommitInfo.commitTime')} |
${safeGet(this.state.record, 'gitCommitInfo.shortHash')} |
${safeGet(this.state.record, 'gitCommitInfo.gitBranch')} |
${safeGet(this.state.record, 'gitCommitInfo.committer.name')}`
${safeGet(this.state.record, 'gitCommitInfo.author.name')}`
}
</div>
</Modal>
Expand Down
Loading

0 comments on commit c4319fb

Please sign in to comment.