Skip to content

Commit 842c5ac

Browse files
ayushsnhaExtravert-ir
authored andcommitted
Fixing buildset req (#3)
* Adding builders to state * indentation fix * printing buildData in commitsCard.js * changing into functional component and mapping stateToProps * buildset endpoint now loads only relevent data * fixing reducer- builders were undefined * Adding builds to PR tab * increasing the range of unixF * adding message to outer check
1 parent 3ff7737 commit 842c5ac

File tree

10 files changed

+305
-167
lines changed

10 files changed

+305
-167
lines changed

app.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ app.get('/api/pulls', (req, res) => {
128128

129129
//------- BUILD-SET END-POINT -------
130130

131-
function buildSetReq() {
131+
function buildSetReq(str) {
132+
//https://build.reactos.org/api/v2/buildsets?field=bsid&field=sourcestamps&order=-bsid&offset=0&limit=200
132133
const buildSets = {
133-
uri:
134-
'https://build.reactos.org/api/v2/buildsets?field=bsid&field=sourcestamps&order=-bsid&offset=0&limit=200',
134+
uri: `https://build.reactos.org/api/v2/buildsets?field=bsid&field=sourcestamps&field=submitted_at&order=-bsid${str}`,
135135
headers: {
136136
'User-Agent': 'Request-Promise'
137137
},
@@ -142,7 +142,12 @@ function buildSetReq() {
142142
}
143143

144144
app.get('/api/buildsets', (req, res) => {
145-
rp(buildSetReq())
145+
let q =
146+
'&submitted_at__le=' +
147+
req.query.submitted_at__le +
148+
'&submitted_at__ge=' +
149+
req.query.submitted_at__ge;
150+
rp(buildSetReq(q))
146151
.then(body => {
147152
res.json(body);
148153
})

client/src/components/BuildDetails.js

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,61 @@
11
import React from 'react';
22
import { connect } from 'react-redux';
3-
4-
function Build({builderid, number, builderName, started_at, complete_at, state_string}) {
5-
return (<React.Fragment>
6-
<div className='col-sm-3'>
7-
<a
8-
target='_blank'
9-
rel='noreferrer noopener'
10-
href={`https://build.reactos.org/#builders/${
11-
builderid
12-
}/builds/${number}`}
13-
>
14-
{builderName}
15-
</a>
16-
</div>
17-
<div className='col-sm-3'>
18-
{state_string}
19-
{state_string === 'build successful' ? (
20-
<i className='fa fa-check' />
21-
) : (
22-
<i />
23-
)}
24-
</div>
25-
<div className='col-sm-3'>started_at:{started_at}</div>
26-
<div className='col-sm-3'>complete_at:{complete_at}</div>
27-
</React.Fragment>);
3+
function Build({ builderName, ...build }) {
4+
let completedDate = new Date(build.complete_at * 1000);
5+
let startedDate = new Date(build.started_at * 1000);
6+
return (
7+
<React.Fragment>
8+
<div className='col-sm-2'>
9+
<a
10+
target='_blank'
11+
rel='noreferrer noopener'
12+
href={`https://build.reactos.org/#builders/${
13+
build.builderid
14+
}/builds/${build.number}`}
15+
>
16+
{builderName}
17+
</a>
18+
</div>
19+
<div className='col-sm-3'>
20+
{build.state_string}
21+
{build.state_string === 'build successful' ? (
22+
<i className='fa fa-check' />
23+
) : (
24+
<i />
25+
)}
26+
</div>
27+
<div className='col-sm-3'>Started: {startedDate.toLocaleString()}</div>
28+
<div className='col-sm-4'>
29+
Completed: {build.complete_at ? completedDate.toLocaleString() : <p />}
30+
</div>
31+
</React.Fragment>
32+
);
2833
}
2934

3035
function renderBuild(props) {
3136
return <Build key={props.buildid} {...props} />;
3237
}
3338

34-
function BuildDetails({builds}) {
35-
return (<React.Fragment>
36-
{builds.length > 0 ? (
37-
<div className='row'>{builds.map(renderBuild)}</div>
38-
) : (
39-
<p>
40-
<strong>No data Exists</strong>
41-
</p>
42-
)}
43-
</React.Fragment>);
39+
function BuildDetails({ builds }) {
40+
return (
41+
<React.Fragment>
42+
{builds.length > 0 ? (
43+
<div className='row'>{builds.map(renderBuild)}</div>
44+
) : (
45+
<p>
46+
<strong>No data Exists</strong>
47+
</p>
48+
)}
49+
</React.Fragment>
50+
);
4451
}
4552

4653
const mapStateToProps = ({ builders }, ownProps) => {
4754
return {
48-
builds: ownProps.builds.map(
49-
build => {...build, builderName: builders[build.builderid].name}
50-
)
55+
builds: ownProps.builds.map(build => ({
56+
...build,
57+
builderName: builders[build.builderid].name
58+
}))
5159
};
5260
};
5361

client/src/components/CommitsCard.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ function CommitsCard(props) {
8383
</div>
8484
<hr />
8585
<h5>Build Details:</h5>
86-
<BuildDetails builds={props.builds} />
86+
{props.builds ? (
87+
<BuildDetails builds={props.builds} />
88+
) : (
89+
<div>
90+
<strong>Loading Build Data ...</strong>
91+
</div>
92+
)}
8793
</CardBody>
8894
</UncontrolledCollapse>
8995
</Card>

client/src/components/Pulls.js

Lines changed: 82 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -7,80 +7,93 @@ import Loading from './Loading';
77
import PullsCard from './PullsCard';
88

99
class Pulls extends React.Component {
10-
componentDidMount() {
11-
this.props.loadPulls();
12-
}
13-
renderPulls = pull => {
14-
return (
15-
<div className='panel-margin' key={pull.id}>
16-
<PullsCard {...pull} />
17-
</div>
18-
);
19-
};
20-
render() {
21-
return (
22-
<div className='container margin'>
23-
<h2>Latest Pulls</h2>
24-
<PullState />
25-
{this.props.isLoading.load ? (
26-
<Loading text='Fetching latest PRs for you...' />
27-
) : (
28-
<div>
29-
<div>{this.props.pulls.map(this.renderPulls)}</div>
30-
{this.props.error ? (
31-
<div className='error'>
32-
Unexpected Error occured. Kindly Reload the page
33-
<br />
34-
Err:{this.props.error}
35-
</div>
36-
) : (
37-
<div>
38-
<button
39-
type='button'
40-
onClick={() => {
41-
this.props.loadPulls(this.props.page.prev);
42-
}}
43-
className='btn btn-primary '
44-
disabled={this.props.page.prev === null || this.props.error !== null}
45-
>
46-
<i className='fa fa-caret-left' aria-hidden='true' />
47-
Previous Page{' '}
48-
</button>{' '}
49-
<button
50-
type='button'
51-
onClick={() => {
52-
this.props.loadPulls(this.props.page.next);
53-
}}
54-
className='btn btn-primary'
55-
disabled={this.props.page.next === null || this.props.error !== null}
56-
>
57-
Next Page{' '}
58-
<i className='fa fa-caret-right' aria-hidden='true' />
59-
</button>
60-
<footer className='blockquote-footer'>
61-
Page {this.props.page.next - 1}
62-
</footer>
63-
<div className='footer-blockquote' />
64-
</div>
65-
)}
66-
</div>
67-
)}
68-
</div>
69-
);
70-
}
10+
componentDidMount() {
11+
this.props.loadPulls();
12+
}
13+
renderPulls = pull => {
14+
return (
15+
<div className='panel-margin' key={pull.id}>
16+
<PullsCard {...pull} builds={this.props.build[pull.number]} />
17+
</div>
18+
);
19+
};
20+
render() {
21+
return (
22+
<div className='container margin'>
23+
<h2>Latest Pulls</h2>
24+
<PullState />
25+
{this.props.isLoading.load ? (
26+
<Loading text='Fetching latest PRs for you...' />
27+
) : (
28+
<div>
29+
<div>{this.props.pulls.map(this.renderPulls)}</div>
30+
{this.props.error ? (
31+
<div className='error'>
32+
Unexpected Error occured. Kindly Reload the page
33+
<br />
34+
Err:{this.props.error}
35+
</div>
36+
) : (
37+
<div>
38+
<button
39+
type='button'
40+
onClick={() => {
41+
this.props.loadPulls(this.props.page.prev);
42+
}}
43+
className='btn btn-primary '
44+
disabled={
45+
this.props.page.prev === null || this.props.error !== null
46+
}
47+
>
48+
<i className='fa fa-caret-left' aria-hidden='true' />
49+
Previous Page{' '}
50+
</button>{' '}
51+
<button
52+
type='button'
53+
onClick={() => {
54+
this.props.loadPulls(this.props.page.next);
55+
}}
56+
className='btn btn-primary'
57+
disabled={
58+
this.props.page.next === null || this.props.error !== null
59+
}
60+
>
61+
Next Page{' '}
62+
<i className='fa fa-caret-right' aria-hidden='true' />
63+
</button>
64+
<footer className='blockquote-footer'>
65+
Page {this.props.page.next - 1}
66+
</footer>
67+
<div className='footer-blockquote' />
68+
</div>
69+
)}
70+
</div>
71+
)}
72+
</div>
73+
);
74+
}
7175
}
7276

73-
const mapStateToProps = ({ pulls, page, isLoading, error }) => ({
74-
pulls,
75-
page,
76-
isLoading,
77-
error
77+
const mapStateToProps = ({
78+
pulls,
79+
builders,
80+
page,
81+
isLoading,
82+
error,
83+
build
84+
}) => ({
85+
pulls,
86+
builders,
87+
page,
88+
isLoading,
89+
error,
90+
build
7891
});
7992

8093
const mapDispatchToProps = dispatch => ({
81-
loadPulls: next => dispatch(loadPulls(next))
94+
loadPulls: next => dispatch(loadPulls(next))
8295
});
8396
export default connect(
84-
mapStateToProps,
85-
mapDispatchToProps
97+
mapStateToProps,
98+
mapDispatchToProps
8699
)(Pulls);

0 commit comments

Comments
 (0)