Skip to content

Commit

Permalink
Issue mozilla#16, simplify http call
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkaiQi committed Oct 26, 2017
1 parent a9d9a2f commit bfd803e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 58 deletions.
44 changes: 26 additions & 18 deletions src/components/fileviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,37 @@ export default class FileViewerContainer extends Component {
});
});

FetchAPI.getFileRevisionCoverage(revision, path,
(data) => {
console.log(data);
this.setState(() => ({ coverage: data }));
// TODO remove these log lines
console.log(this.state.coverage.data[0][0].source.file.covered);
console.log(this.state.coverage.data[0][0].source.file.uncovered);
console.log(this.state.coverage.data[0][0].source.file.percentage_covered);
}
)
FetchAPI.getFileRevisionCoverage(revision, path)
.then(response => {
if (response.status !== 200) {
console.log('Error status code' + response.status);
return;
}
response.json().then(data => {
this.setState({ coverage: data });
// TODO remove these log lines
console.log(data);
console.log(this.state.coverage.data[0][0].source.file.covered);
console.log(this.state.coverage.data[0][0].source.file.uncovered);
console.log(this.state.coverage.data[0][0].source.file.percentage_covered);
});
})
.catch(err => {
console.log('Fetch error', err);
})
};

render() {
const { revision, path } = this.props;
return (
<div>
<FileViewerMeta
revision={revision}
path={path}
<FileViewerMeta
revision={revision}
path={path}
appError={this.state.appError}
/>
<FileViewer
parsedFile={this.state.parsedFile}
<FileViewer
parsedFile={this.state.parsedFile}
coverage={this.state.coverage}
/>
</div>
Expand All @@ -65,13 +73,13 @@ export default class FileViewerContainer extends Component {

/* This component renders each line of the file with its line number */
const FileViewer = ({ parsedFile, coverage }) => {
return (
return (
<div>
<table>
<tbody>
{
{
parsedFile.map((line, lineNumber) => (
<Line
<Line
key={lineNumber}
lineNumber={lineNumber+1}
lineText={line}
Expand Down
44 changes: 4 additions & 40 deletions src/fetch_data.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as Query from './query';
const https = require('https');

export const hgHost = 'https://hg.mozilla.org';
export const ccovBackend = 'https://uplift.shipit.staging.mozilla-releng.net';
export const activeData = 'activedata.allizom.org';
export const activeData = 'https://activedata.allizom.org';

const plainHeaders = {
Accept: 'text/plain',
Expand All @@ -28,41 +27,6 @@ export const getChangesetCoverageSummary = changeset =>
export const getRawFile = (revision, path) =>
fetch(`${hgHost}/integration/mozilla-inbound/raw-file/${revision}/${path}`, { plainHeaders });

// Taken from https://github.com/mozilla/moz-coco/blob/master/src/client/Client.js
// On October 23, 2017
// Under the MPL License
export const getFileRevisionCoverage = (revision, path, callback) => {
const body = Query.testCoverage(revision, path);
const jsonbody = JSON.stringify(body);
const options = {
hostname: `${activeData}`,
port: 443,
path: '/query',
method: 'POST',
headers: {
'Content-Type': 'text/plain',
'Content-Length': Buffer.byteLength(jsonbody)
}
}
console.log("Query sent: " + jsonbody);
const respchunks = [];
const p = new Promise((resolve, reject) => {
const req = https.request(options, (res) => {
res.setEncoding('utf8');
res.on('data', (chunk) => {
respchunks.push(new Buffer(chunk));
});
res.on('end', (chunk) => {
resolve(Buffer.concat(respchunks).toString('utf8'));
});
res.on('error', (e) => {
reject(e);
});
});
req.write(jsonbody);
req.end();
});
p.then((body) => {
callback(JSON.parse(body));
}).catch((err) => console.log(`Exception in fetch_data.js: ${err}`));
}
// get coverage from ActiveData for a particular source file
export const getFileRevisionCoverage = (revision, path) =>
fetch(`${activeData}/query`, { jsonHeaders, method:"POST", body: JSON.stringify(Query.testCoverage(revision, path)) });

0 comments on commit bfd803e

Please sign in to comment.