Skip to content

Commit

Permalink
Upgrade to use express.js v5 (#945)
Browse files Browse the repository at this point in the history
resolves: #941
fixes: #935

Signed-off-by: Lan Xia <[email protected]>
  • Loading branch information
llxia authored Dec 4, 2024
1 parent 9627800 commit 6568dc3
Show file tree
Hide file tree
Showing 11 changed files with 928 additions and 230 deletions.
980 changes: 843 additions & 137 deletions TestResultSummaryService/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion TestResultSummaryService/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"compression": "^1.7.4",
"cors": "^2.8.5",
"csv": "^5.5.0",
"express": "^4.21.1",
"express": "^5.0.1",
"express-rate-limit": "^6.6.0",
"express-swagger-generator": "^1.1.17",
"got": "^11.8.5",
Expand Down
8 changes: 2 additions & 6 deletions TestResultSummaryService/routes/getAllChildBuilds.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ const { TestResultsDB, ObjectID } = require('../Database');
*/

module.exports = async (req, res) => {
const url = req.query.url;
const buildName = req.query.buildName;
let buildNum = req.query.buildNum;
let parentId = req.query.parentId;
let buildResult = req.query.buildResult;
let testSummaryResult = req.query.testSummaryResult;
const { url, buildName } = req.query;
let { buildNum, parentId, buildResult, testSummaryResult } = req.query;

let info = {};
if (parentId) {
Expand Down
8 changes: 4 additions & 4 deletions TestResultSummaryService/routes/getAuditLogs.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { AuditLogsDB, ObjectID } = require('../Database');
module.exports = async (req, res) => {
if (req.query.buildNum)
req.query.buildNum = parseInt(req.query.buildNum, 10);
if (req.query.buildId) req.query.buildId = new ObjectID(req.query.buildId);
const query = { ...req.query };
if (query.buildNum) query.buildNum = parseInt(query.buildNum, 10);
if (query.buildId) query.buildId = new ObjectID(query.buildId);
const db = new AuditLogsDB();
const result = await db.aggregate([
{ $match: req.query },
{ $match: query },
{ $sort: { timestamp: 1 } },
]);
res.send(result);
Expand Down
5 changes: 3 additions & 2 deletions TestResultSummaryService/routes/getBuildList.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { BuildListDB, ObjectID } = require('../Database');
module.exports = async (req, res) => {
if (req.query._id) req.query._id = new ObjectID(req.query._id);
const query = { ...req.query };
if (query._id) query._id = new ObjectID(query._id);
const db = new BuildListDB();
const result = await db.getData(req.query).sort({ buildUrl: 1 }).toArray();
const result = await db.getData(query).sort({ buildUrl: 1 }).toArray();
res.send(result);
};
6 changes: 3 additions & 3 deletions TestResultSummaryService/routes/getChildBuilds.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { TestResultsDB, ObjectID } = require('../Database');
module.exports = async (req, res) => {
if (req.query.parentId)
req.query.parentId = new ObjectID(req.query.parentId);
const query = { ...req.query };
if (query.parentId) query.parentId = new ObjectID(query.parentId);
const db = new TestResultsDB();
const result = await db.getData(req.query).toArray();
const result = await db.getData(query).toArray();
res.send(result);
};
13 changes: 7 additions & 6 deletions TestResultSummaryService/routes/getData.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const { TestResultsDB, ObjectID } = require('../Database');
module.exports = async (req, res) => {
if (req.query.buildNum)
req.query.buildNum = parseInt(req.query.buildNum, 10);
if (req.query._id) req.query._id = new ObjectID(req.query._id);
if (req.query.parentId)
req.query.parentId = new ObjectID(req.query.parentId);
const query = { ...req.query };
if (query.buildNum) query.buildNum = parseInt(query.buildNum, 10);
if (query._id) query._id = new ObjectID(query._id);

if (query.parentId) query.parentId = new ObjectID(query.parentId);
const db = new TestResultsDB();
const result = await db.getData(req.query).toArray();
const result = await db.getData({ _id: new ObjectID(query._id) }).toArray();
console.log(result);
res.send(result);
};
7 changes: 4 additions & 3 deletions TestResultSummaryService/routes/getErrorInOutput.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ const { removeTimestamp } = require('./utils/removeTimestamp');
const matchStrings = ['Unhandled exception'];

module.exports = async (req, res) => {
if (req.query.id) {
req.query.id = new ObjectID(req.query.id);
const query = { ...req.query };
if (query.id) {
query.id = new ObjectID(query.id);
const outputDB = new OutputDB();
const result = await outputDB.getData(req.query.id).toArray();
const result = await outputDB.getData(query.id).toArray();

if (result && result.length > 0 && result[0].output) {
const output = removeTimestamp(result[0].output);
Expand Down
5 changes: 2 additions & 3 deletions TestResultSummaryService/routes/getJenkins.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ const JenkinsInfo = require('../JenkinsInfo');
const fs = require('fs');

module.exports = async (req, res) => {
const { url, buildName, buildNum } = req.query;
if (req.query.buildNum)
req.query.buildNum = parseInt(req.query.buildNum, 10);
let { url, buildName, buildNum } = req.query;
if (buildNum) buildNum = parseInt(buildNum, 10);
const jenkinsInfo = new JenkinsInfo();
try {
const output = await jenkinsInfo.getBuildOutput(
Expand Down
119 changes: 57 additions & 62 deletions TestResultSummaryService/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,68 @@
const app = require('express').Router();
const wrap = (fn) => (req, res) =>
fn(req, res).catch(console.error.bind(console));

app.get('/compareTestDuration', wrap(require('./compareTestDuration')));
app.get('/compareTestsOutput', wrap(require('./compareTestsOutput')));
app.get('/deleteBuildData', wrap(require('./deleteBuildData')));
app.get('/deleteBuildListById', wrap(require('./deleteBuildListById')));
app.get('/compareTestDuration', require('./compareTestDuration'));
app.get('/compareTestsOutput', require('./compareTestsOutput'));
app.get('/deleteBuildData', require('./deleteBuildData'));
app.get('/deleteBuildListById', require('./deleteBuildListById'));
app.get(
'/deleteBuildsAndChildrenByFields',
wrap(require('./deleteBuildsAndChildrenByFields').default)
);
app.get('/deleteCollection', wrap(require('./deleteCollection')));
app.get('/deleteUnusedOutput', wrap(require('./deleteUnusedOutput')));
app.get('/getAllChildBuilds', wrap(require('./getAllChildBuilds')));
app.get('/getAllTestsWithHistory', wrap(require('./getAllTestsWithHistory')));
app.get('/getApplicationTests', wrap(require('./getApplicationTests')));
app.get('/getAuditLogs', wrap(require('./getAuditLogs')));
app.get('/getBenchmarkMetricProps', wrap(require('./getBenchmarkMetricProps')));
app.get('/getBuildHistory', wrap(require('./getBuildHistory')));
app.get('/getBuildList', wrap(require('./getBuildList')));
app.get('/getBuildStages', wrap(require('./getBuildStages')));
app.get('/getChildBuilds', wrap(require('./getChildBuilds')));
app.get('/getDashboardBuildInfo', wrap(require('./getDashboardBuildInfo')));
app.get('/getData', wrap(require('./getData')));
app.get('/getErrorInOutput', wrap(require('./getErrorInOutput')));
app.get('/getHistoryPerTest', wrap(require('./getHistoryPerTest')));
app.get('/getJenkins', wrap(require('./getJenkins')));
app.get('/getJenkinsBuildInfo', wrap(require('./test/getJenkinsBuildInfo')));
app.get('/getLastBuildInfo', wrap(require('./getLastBuildInfo')));
app.get('/getLogStream', wrap(require('./getLogStream')));
app.get('/getOutputById', wrap(require('./getOutputById')));
app.get('/getOutputByTestInfo', wrap(require('./getOutputByTestInfo')));
app.get('/getTestAvgDuration', wrap(require('./getTestAvgDuration')));
app.get('/getTestInfoByBuildInfo', wrap(require('./getTestInfoByBuildInfo')));
app.get('/getAzDoRun', wrap(require('./getAzDoRun')));
app.get('/getParents', wrap(require('./getParents')));
app.get('/getPerffarmRunCSV', wrap(require('./getPerffarmRunCSV')));
app.get('/getTabularData', wrap(require('./getTabularData')));
app.get('/getTabularDropdown', wrap(require('./getTabularDropdown')));
app.get('/getTestBuildsByMachine', wrap(require('./getTestBuildsByMachine')));
app.get('/getTestById', wrap(require('./getTestById')));
app.get('/getTestBySearch', wrap(require('./getTestBySearch')));
app.get('/getTestByVersionInfo', wrap(require('./getTestByVersionInfo')));
app.get('/getTestNames', wrap(require('./getTestNames')));
app.get('/getTestByTestName', wrap(require('./getTestByTestName')));
app.get('/getTestPerPlatform', wrap(require('./getTestPerPlatform')));
app.get('/getTopLevelBuildNames', wrap(require('./getTopLevelBuildNames')));
app.get('/getTotals', wrap(require('./getTotals')));
app.get('/parseJenkinsUrl', wrap(require('./parseJenkinsUrl')));
app.get('/populateDB', wrap(require('./populateDB')));
app.get('/getFeedbackUrl', wrap(require('./getFeedbackUrl')));
app.get('/rescanBuild', wrap(require('./rescanBuild')));
app.get('/testParserViaFile', wrap(require('./test/testParserViaFile')));
app.get(
'/testParserViaLogStream',
wrap(require('./test/testParserViaLogStream'))
require('./deleteBuildsAndChildrenByFields').default
);
app.get('/deleteCollection', require('./deleteCollection'));
app.get('/deleteUnusedOutput', require('./deleteUnusedOutput'));
app.get('/getAllChildBuilds', require('./getAllChildBuilds'));
app.get('/getAllTestsWithHistory', require('./getAllTestsWithHistory'));
app.get('/getApplicationTests', require('./getApplicationTests'));
app.get('/getAuditLogs', require('./getAuditLogs'));
app.get('/getBenchmarkMetricProps', require('./getBenchmarkMetricProps'));
app.get('/getBuildHistory', require('./getBuildHistory'));
app.get('/getBuildList', require('./getBuildList'));
app.get('/getBuildStages', require('./getBuildStages'));
app.get('/getChildBuilds', require('./getChildBuilds'));
app.get('/getDashboardBuildInfo', require('./getDashboardBuildInfo'));
app.get('/getData', require('./getData'));
app.get('/getErrorInOutput', require('./getErrorInOutput'));
app.get('/getHistoryPerTest', require('./getHistoryPerTest'));
app.get('/getJenkins', require('./getJenkins'));
app.get('/getJenkinsBuildInfo', require('./test/getJenkinsBuildInfo'));
app.get('/getLastBuildInfo', require('./getLastBuildInfo'));
app.get('/getLogStream', require('./getLogStream'));
app.get('/getOutputById', require('./getOutputById'));
app.get('/getOutputByTestInfo', require('./getOutputByTestInfo'));
app.get('/getTestAvgDuration', require('./getTestAvgDuration'));
app.get('/getTestInfoByBuildInfo', require('./getTestInfoByBuildInfo'));
app.get('/getAzDoRun', require('./getAzDoRun'));
app.get('/getParents', require('./getParents'));
app.get('/getPerffarmRunCSV', require('./getPerffarmRunCSV'));
app.get('/getTabularData', require('./getTabularData'));
app.get('/getTabularDropdown', require('./getTabularDropdown'));
app.get('/getTestBuildsByMachine', require('./getTestBuildsByMachine'));
app.get('/getTestById', require('./getTestById'));
app.get('/getTestBySearch', require('./getTestBySearch'));
app.get('/getTestByVersionInfo', require('./getTestByVersionInfo'));
app.get('/getTestNames', require('./getTestNames'));
app.get('/getTestByTestName', require('./getTestByTestName'));
app.get('/getTestPerPlatform', require('./getTestPerPlatform'));
app.get('/getTopLevelBuildNames', require('./getTopLevelBuildNames'));
app.get('/getTotals', require('./getTotals'));
app.get('/parseJenkinsUrl', require('./parseJenkinsUrl'));
app.get('/populateDB', require('./populateDB'));
app.get('/getFeedbackUrl', require('./getFeedbackUrl'));
app.get('/rescanBuild', require('./rescanBuild'));
app.get('/testParserViaFile', require('./test/testParserViaFile'));
app.get('/testParserViaLogStream', require('./test/testParserViaLogStream'));

app.get('/updateComments', wrap(require('./updateComments')));
app.get('/updateKeepForever', wrap(require('./updateKeepForever')));
app.get('/updateComments', require('./updateComments'));
app.get('/updateKeepForever', require('./updateKeepForever'));

// jwt
app.post('/auth/register', wrap(require('./jwt/register')));
app.post('/auth/verify', wrap(require('./jwt/verify')));
app.post('/auth/register', require('./jwt/register'));
app.post('/auth/verify', require('./jwt/verify'));

app.post('/getParentSpecificData', wrap(require('./getParentSpecificData')));
app.post('/getSpecificData', wrap(require('./getSpecificData')));
app.post('/upsertBuildList', wrap(require('./upsertBuildList')));
app.post('/postTapFiles', wrap(require('./postTapFiles')));
app.post('/postIssueFeedback', wrap(require('./postIssueFeedback')));
app.post('/getParentSpecificData', require('./getParentSpecificData'));
app.post('/getSpecificData', require('./getSpecificData'));
app.post('/upsertBuildList', require('./upsertBuildList'));
app.post('/postTapFiles', require('./postTapFiles'));
app.post('/postIssueFeedback', require('./postIssueFeedback'));

module.exports = app;
5 changes: 2 additions & 3 deletions TestResultSummaryService/routes/test/getJenkinsBuildInfo.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const JenkinsInfo = require('../../JenkinsInfo');

module.exports = async (req, res) => {
const { url, buildName, buildNum } = req.query;
if (req.query.buildNum)
req.query.buildNum = parseInt(req.query.buildNum, 10);
let { url, buildName, buildNum } = req.query;
if (buildNum) buildNum = parseInt(buildNum, 10);
const jenkinsInfo = new JenkinsInfo();
try {
const output = await jenkinsInfo.getBuildInfo(url, buildName, buildNum);
Expand Down

0 comments on commit 6568dc3

Please sign in to comment.