mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-11 09:53:32 +03:00
698261e294
no issue
55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
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.username',
|
|
'github.token',
|
|
'userAgent'
|
|
);
|
|
|
|
if (Object.prototype.hasOwnProperty.call(options, 'isPublic')) {
|
|
isPublic = options.isPublic;
|
|
}
|
|
|
|
const content = fs.readFileSync(options.changelogPath);
|
|
const files = {};
|
|
|
|
files[options.gistName] = {
|
|
content: content.toString('utf8')
|
|
};
|
|
|
|
const auth = 'Basic ' + new Buffer(options.github.username + ':' + options.github.token).toString('base64');
|
|
|
|
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
|
|
};
|
|
});
|
|
};
|