@kazupon/lerna-changelog
Version:
Generate a changelog for a lerna monorepo
45 lines (44 loc) • 1.61 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const configuration_error_1 = __importDefault(require("./configuration-error"));
const fetch_1 = __importDefault(require("./fetch"));
class GithubAPI {
constructor(config) {
this.cacheDir =
config.cacheDir && path_1.default.join(config.rootPath, config.cacheDir, 'github');
this.auth = this.getAuthToken();
if (!this.auth) {
throw new configuration_error_1.default('Must provide GITHUB_AUTH');
}
}
getBaseIssueUrl(repo) {
return `https://github.com/${repo}/issues/`;
}
async getIssueData(repo, issue) {
return this._fetch(`https://api.github.com/repos/${repo}/issues/${issue}`);
}
async getUserData(login) {
return this._fetch(`https://api.github.com/users/${login}`);
}
async _fetch(url) {
const res = await fetch_1.default(url, {
cacheManager: this.cacheDir,
headers: {
Authorization: `token ${this.auth}`
}
});
const parsedResponse = await res.json();
if (res.ok) {
return parsedResponse;
}
throw new configuration_error_1.default(`Fetch error: ${res.statusText}.\n${JSON.stringify(parsedResponse)}`);
}
getAuthToken() {
return process.env.GITHUB_AUTH || '';
}
}
exports.default = GithubAPI;