2019-03-12 23:53:32 +03:00
|
|
|
const fs = require('fs');
|
|
|
|
const requestPromise = require('request-promise');
|
|
|
|
|
|
|
|
const localUtils = require('./utils');
|
|
|
|
|
|
|
|
module.exports.create = (options = {}) => {
|
|
|
|
let isPublic = true;
|
|
|
|
|
|
|
|
localUtils.checkMissingOptions(options,
|
|
|
|
'changelogPath',
|
|
|
|
'gistName',
|
|
|
|
'gistDescription',
|
|
|
|
'github',
|
|
|
|
'github.token',
|
|
|
|
'userAgent'
|
|
|
|
);
|
|
|
|
|
2020-03-10 20:07:36 +03:00
|
|
|
if (Object.prototype.hasOwnProperty.call(options, 'isPublic')) {
|
2019-03-12 23:53:32 +03:00
|
|
|
isPublic = options.isPublic;
|
|
|
|
}
|
|
|
|
|
|
|
|
const content = fs.readFileSync(options.changelogPath);
|
|
|
|
const files = {};
|
|
|
|
|
|
|
|
files[options.gistName] = {
|
|
|
|
content: content.toString('utf8')
|
|
|
|
};
|
|
|
|
|
2020-04-01 14:00:19 +03:00
|
|
|
const auth = 'token ' + options.github.token;
|
2019-03-12 23:53:32 +03:00
|
|
|
|
|
|
|
const reqOptions = {
|
|
|
|
uri: 'https://api.github.com/gists',
|
|
|
|
headers: {
|
|
|
|
'User-Agent': options.userAgent,
|
|
|
|
Authorization: auth
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
body: {
|
|
|
|
description: options.gistDescription,
|
|
|
|
public: isPublic,
|
|
|
|
files: files
|
|
|
|
},
|
|
|
|
json: true,
|
|
|
|
resolveWithFullResponse: true
|
|
|
|
};
|
|
|
|
|
|
|
|
return requestPromise(reqOptions)
|
|
|
|
.then((response) => {
|
|
|
|
return {
|
|
|
|
gistUrl: response.body.html_url
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|