Skip to content

Commit aceb7cf

Browse files
ayushsnhaExtravert-ir
authored andcommitted
Testman integration (#4)
1 parent 842c5ac commit aceb7cf

File tree

18 files changed

+276
-41
lines changed

18 files changed

+276
-41
lines changed

app.js

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const dotenv = require('dotenv');
22
const express = require('express');
33
const rp = require('request-promise');
4+
const convert = require('xml-js');
45
const app = express();
56
//app.disable('query parser');
67
dotenv.config();
@@ -82,7 +83,7 @@ app.get('/api/branches', (req, res) => {
8283
res.json(body);
8384
})
8485
.catch(function(err) {
85-
res.json({ error: 'oops...something went wrong' });
86+
res.json({ error: 'oops...something went wrong' + err });
8687
});
8788
});
8889

@@ -122,7 +123,7 @@ app.get('/api/pulls', (req, res) => {
122123
res.json(dataAndPage);
123124
})
124125
.catch(function(err) {
125-
res.json({ error: 'oops...something went wrong' });
126+
res.json({ error: 'oops...something went wrong' + err });
126127
});
127128
});
128129

@@ -152,7 +153,7 @@ app.get('/api/buildsets', (req, res) => {
152153
res.json(body);
153154
})
154155
.catch(function(err) {
155-
res.json({ error: 'oops...something went wrong' });
156+
res.json({ error: 'oops...something went wrong' + err });
156157
});
157158
});
158159

@@ -179,7 +180,7 @@ app.get('/api/buildreq', (req, res) => {
179180
res.json(body);
180181
})
181182
.catch(function(err) {
182-
res.json({ error: 'oops...something went wrong' });
183+
res.json({ error: 'oops...something went wrong' + err });
183184
});
184185
});
185186

@@ -206,11 +207,11 @@ app.get('/api/builds', (req, res) => {
206207
res.json(body);
207208
})
208209
.catch(function(err) {
209-
res.json({ error: 'oops...something went wrong' });
210+
res.json({ error: 'oops...something went wrong' + err });
210211
});
211212
});
212213

213-
//------- BRANCHES END-POINT -------
214+
//------- BUILDERS END-POINT -------
214215

215216
function builderReq() {
216217
const builders = {
@@ -231,7 +232,32 @@ app.get('/api/builders', (req, res) => {
231232
res.json(body);
232233
})
233234
.catch(function(err) {
234-
res.json({ error: 'oops...something went wrong' });
235+
res.json({ error: 'oops...something went wrong' + err });
236+
});
237+
});
238+
239+
//------- TESTMAN END-POINT -------
240+
241+
function testReq(startrev, endrev, page) {
242+
const tests = {
243+
uri: `https://reactos.org/testman/ajax-search.php?startrev=${startrev}&endrev=${endrev}&page=${page}&resultlist=0&requesttype=2`,
244+
resolveWithFullResponse: false,
245+
headers: {
246+
'User-Agent': 'Request-Promise'
247+
}
248+
};
249+
250+
return tests;
251+
}
252+
253+
app.get('/api/testman', (req, res) => {
254+
rp(testReq(req.query.startrev, req.query.endrev, req.query.page))
255+
.then(body => {
256+
const result = convert.xml2json(body, { compact: true, spaces: 2 });
257+
res.send(result);
258+
})
259+
.catch(function(err) {
260+
res.json({ error: 'oops...something went wrong' + err });
235261
});
236262
});
237263

client/src/components/Commits.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ class Commits extends React.Component {
1414
renderCommits = commit => {
1515
return (
1616
<div className='panel-margin' key={commit.sha}>
17-
<CommitsCard {...commit} builds={this.props.build[commit.sha]} />
17+
<CommitsCard
18+
{...commit}
19+
builds={this.props.build[commit.sha]}
20+
tests={this.props.testData[commit.sha]}
21+
/>
1822
</div>
1923
);
2024
};
@@ -86,15 +90,17 @@ const mapStateToProps = ({
8690
error,
8791
branch,
8892
page,
89-
build
93+
build,
94+
testData
9095
}) => ({
9196
isLoading,
9297
commits,
9398
builders,
9499
error,
95100
branch,
96101
page,
97-
build
102+
build,
103+
testData
98104
});
99105

100106
const mapDispatchToProps = dispatch => ({

client/src/components/CommitsCard.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { UncontrolledCollapse, CardBody, Card, CardHeader } from 'reactstrap';
33
import BuildDetails from './BuildDetails';
4+
import TestDetails from './TestDetails';
45

56
function CommitsCard(props) {
67
let tog = 'toggler' + props.sha;
@@ -87,7 +88,16 @@ function CommitsCard(props) {
8788
<BuildDetails builds={props.builds} />
8889
) : (
8990
<div>
90-
<strong>Loading Build Data ...</strong>
91+
<strong>Loading Builds...</strong>
92+
</div>
93+
)}
94+
<hr />
95+
<h5>Test Details:</h5>
96+
{props.tests ? (
97+
<TestDetails tests={props.tests} />
98+
) : (
99+
<div>
100+
<strong>No data Exists</strong>
91101
</div>
92102
)}
93103
</CardBody>

client/src/components/Pulls.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ class Pulls extends React.Component {
1313
renderPulls = pull => {
1414
return (
1515
<div className='panel-margin' key={pull.id}>
16-
<PullsCard {...pull} builds={this.props.build[pull.number]} />
16+
<PullsCard
17+
{...pull}
18+
builds={this.props.build[pull.number]}
19+
tests={this.props.testData[pull.merge_commit_sha]}
20+
/>
1721
</div>
1822
);
1923
};
@@ -80,14 +84,16 @@ const mapStateToProps = ({
8084
page,
8185
isLoading,
8286
error,
83-
build
87+
build,
88+
testData
8489
}) => ({
8590
pulls,
8691
builders,
8792
page,
8893
isLoading,
8994
error,
90-
build
95+
build,
96+
testData
9197
});
9298

9399
const mapDispatchToProps = dispatch => ({

client/src/components/PullsCard.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { UncontrolledCollapse, CardBody, Card, CardHeader } from 'reactstrap';
33
import BuildDetails from './BuildDetails';
4+
import TestDetails from './TestDetails';
45

56
function PullsCard(props) {
67
let tog = 'toggler' + props.id;
@@ -12,6 +13,7 @@ function PullsCard(props) {
1213
<CardHeader className='new' type='button' id={tog}>
1314
<div className='row'>
1415
<div className='col-sm'>{props.number}</div>
16+
<div className='col-sm'>{props.merge_commit_sha.substring(0, 7)}</div>
1517
<div className='col-sm'>{props.state}</div>
1618
<div className='col-sm'>{props.user.login}</div>
1719
</div>
@@ -49,7 +51,16 @@ function PullsCard(props) {
4951
{props.builds ? (
5052
<BuildDetails builds={props.builds} />
5153
) : (
52-
<div>Loading Pulls data...</div>
54+
<div>Loading Builds...</div>
55+
)}
56+
<hr />
57+
<h5>Test Details:</h5>
58+
{props.tests ? (
59+
<TestDetails tests={props.tests} />
60+
) : (
61+
<p>
62+
<strong>No data Exists</strong>
63+
</p>
5364
)}
5465
</CardBody>
5566
</UncontrolledCollapse>

client/src/components/TestDetails.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from 'react';
2+
3+
function renderTest(test) {
4+
return (
5+
<React.Fragment key={test.id}>
6+
<div className='col-sm-2'>Test id: {test.id}</div>
7+
<div className='col-sm-4'>
8+
<a
9+
target='_blank'
10+
rel='noreferrer noopener'
11+
href={`https://reactos.org/testman/compare.php?ids=${test.id}`}
12+
>
13+
{test.source}
14+
</a>
15+
</div>
16+
<div className='col-sm-3'>Count: {test.count}</div>
17+
<div className='col-sm-3'>Failures: {test.failures}</div>
18+
</React.Fragment>
19+
);
20+
}
21+
22+
function TestDetails(props) {
23+
return (
24+
<React.Fragment>
25+
{props.tests.length > 0 ? (
26+
<div className='row'>{props.tests.map(renderTest)}</div>
27+
) : (
28+
<p>
29+
<strong>No data Exists</strong>
30+
</p>
31+
)}
32+
</React.Fragment>
33+
);
34+
}
35+
36+
export default TestDetails;

client/src/redux/actions/index.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { COMMITS, BRANCHES, PULLS, BUILD_DATA, BUILDERS } from '../constants';
1+
import {
2+
COMMITS,
3+
BRANCHES,
4+
PULLS,
5+
BUILD_DATA,
6+
BUILDERS,
7+
TESTMAN_DATA
8+
} from '../constants';
29

310
export const loadCommits = newPage => ({
411
type: COMMITS.LOAD,
@@ -28,6 +35,19 @@ export const setBuildSetsError = error => ({
2835
error
2936
});
3037

38+
export const loadTestman = () => ({
39+
type: TESTMAN_DATA.LOAD
40+
});
41+
export const setTestman = tests => ({
42+
type: TESTMAN_DATA.LOAD_SUCCESS,
43+
tests
44+
});
45+
46+
export const setTestmanError = error => ({
47+
type: TESTMAN_DATA.LOAD_FAIL,
48+
error
49+
});
50+
3151
export const setPages = (next, prev) => ({
3252
type: 'PAGE_LOAD_SUCCESS',
3353
next,

client/src/redux/api/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@ export const fetchCommits = async (sha, page) => {
77
return data;
88
};
99

10+
export const fetchTests = async (startrev, endrev, page) => {
11+
let results = [];
12+
let keepGoing = true;
13+
while (keepGoing) {
14+
const response = await fetch(
15+
`/api/testman?startrev=${startrev}&endrev=${endrev}&page=${page}`
16+
);
17+
let data = await response.json();
18+
results.push(data.results.result);
19+
if (parseInt(data.results.resultcount._text) > 10) {
20+
page++;
21+
} else {
22+
keepGoing = false;
23+
return results.flat();
24+
}
25+
if (response.status >= 400) {
26+
throw new Error(data.errors);
27+
}
28+
}
29+
};
30+
1031
export const fetchBuildSets = async str => {
1132
if (str) {
1233
const response = await fetch(`/api/buildsets?${str}`);

client/src/redux/constants/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ export const BUILD_DATA = {
2424
LOAD_FAIL: 'BUILD_DATA_LOAD_FAIL'
2525
};
2626

27+
export const TESTMAN_DATA = {
28+
LOAD: 'TESTMAN_DATA_LOAD',
29+
LOAD_SUCCESS: 'TESTMAN_DATA_LOAD_SUCCESS',
30+
LOAD_FAIL: 'TESTMAN_DATA_LOAD_FAIL'
31+
};
32+
2733
export const BUILDERS = {
2834
LOAD: 'BUILDER_LOAD',
2935
LOAD_SUCCESS: 'BUILDER_LOAD_SUCCESS',

client/src/redux/reducers/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import pullsReducer from './pullsReducer';
1010
import pageReducer from './pageReducer';
1111
import pullStateReducer from './pullStateReducer';
1212
import buildStatusReducer from './buildStatusReducer';
13+
import testmanReducer from './testmanReducer';
1314

1415
const rootReducer = combineReducers({
1516
isLoading: loadingReducer,
@@ -21,7 +22,8 @@ const rootReducer = combineReducers({
2122
pulls: pullsReducer,
2223
pullState: pullStateReducer,
2324
page: pageReducer,
24-
build: buildStatusReducer
25+
build: buildStatusReducer,
26+
testData: testmanReducer
2527
});
2628

2729
export default rootReducer;

0 commit comments

Comments
 (0)