Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
* [html5] fix danger when renaming files.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrRaindrop committed Jul 28, 2017
1 parent 8631f2c commit 9602b19
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,10 @@ function findReviewer(resolve, reject) {
return
}
parseDeleteAndNormalLines(result.data, fileToDeletedLinesMap, fileToNormalLinesMap)
var promises = danger.git.modified_files.map(function(file) {
var promises = danger.git.modifiedgit _files.map(function(file) {
let repoURL = danger.github.pr.base.repo.html_url
let fileName = file.replace(/^.*[\\\/]/, '')
let blameURL = repoURL + '/blame/' + danger.github.pr.base.ref + '/' + file
// console.log("Getting blame html: " + blameURL)
return getContent(blameURL)
});

Expand All @@ -316,18 +315,25 @@ function getContent(url) {
return new Promise((resolve, reject) => {
// select http or https module, depending on reqested url
const lib = url.startsWith('https') ? require('https') : require('http');
const request = lib.get(url, (response) => {
// handle http errors
if (response.statusCode < 200 || response.statusCode > 299) {
reject(new Error('Failed to load page, status code: ' + response.statusCode));
}
// temporary data holder
const body = [];
// on every content chunk, push it to the data array
response.on('data', (chunk) => body.push(chunk));
// we are done, resolve promise with those joined chunks
response.on('end', () => resolve(body.join('')));
});
const request = lib.get(url, (function (url) {
return (response) => {
// handle http errors
if (response.statusCode < 200 || response.statusCode > 299) {
if (response.statusCode === 404) {
// ignore this, probably a renamed file.
return resolve('')
}
reject(new Error('Failed to load page, status code: ' + response.statusCode + ', '
+ ' url: ' + url));
}
// temporary data holder
const body = [];
// on every content chunk, push it to the data array
response.on('data', (chunk) => body.push(chunk));
// we are done, resolve promise with those joined chunks
response.on('end', () => resolve(body.join('')));
}
})(url));
// handle connection errors of the request
request.on('error', (err) => reject(err))
})
Expand Down

0 comments on commit 9602b19

Please sign in to comment.