const parse = require('diffparser');
require('request'); // Sanity check for request-promise below
const request = require('request-promise');
// Two commits to be compared
const BASE = 'ab39def';
const HEAD = '33715a7';
// https://developer.github.com/v3/repos/commits/#compare-two-commits
const API_URL = `https://api.github.com/repos/twbs/bootstrap/compare/${BASE}...${HEAD}`;
// Set the options object for request
const options = {
method: 'GET',
url: API_URL,
headers: {
'User-Agent': 'Thesis Browser v1.0', // Dummy user agent suffices
'Accept': 'application/vnd.github.v3.diff', // Set correct media type
},
};
return request(options)
.then(data => {
console.log(data); // Raw diff from GitHub
console.log(parse(data)); // Parsed diff into JSON
});