Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.apiUrl = options.apiUrl || 'https://api.github.com';
this.proxyKey = options.proxyKey;
if (options.octokitAPIs === undefined) {
this.octokit = new Octokit({ baseUrl: options.apiUrl });
const defaults: { [key: string]: string | object } = {
baseUrl: this.apiUrl,
headers: {
'user-agent': `release-please/${
require('../../package.json').version
}`,
// some proxies do not require the token prefix.
Authorization: `${this.proxyKey ? '' : 'token '}${this.token}`,
},
};
this.request = request.defaults(defaults);
this.graphql = graphql;
} else {
// for the benefit of probot applications, we allow a configured instance
// of octokit to be passed in as a parameter.
probotMode = true;
this.octokit = options.octokitAPIs.octokit;
this.request = options.octokitAPIs.request;
this.graphql = options.octokitAPIs.graphql;
}
}
requestDefaults.headers["user-agent"] = [
options.userAgent,
`octokit-core.js/${VERSION} ${getUserAgent()}`,
]
.filter(Boolean)
.join(" ");
if (options.baseUrl) {
requestDefaults.baseUrl = options.baseUrl;
}
if (options.previews) {
requestDefaults.mediaType.previews = options.previews;
}
if (options.timeZone) {
requestDefaults.headers["time-zone"] = options.timeZone;
}
this.request = request.defaults(requestDefaults);
this.graphql = withCustomRequest(this.request).defaults({
...requestDefaults,
baseUrl: requestDefaults.baseUrl.replace(/\/api\/v3$/, "/api"),
});
this.log = Object.assign({
debug: () => { },
info: () => { },
warn: console.warn.bind(console),
error: console.error.bind(console),
}, options.log);
this.hook = hook;
// (1) If neither `options.authStrategy` nor `options.auth` are set, the `octokit` instance
// is unauthenticated. The `this.auth()` method is a no-op and no request hook is registred.
// (2) If only `options.auth` is set, use the default token authentication strategy.
// (3) If `options.authStrategy` is set then use it and pass in `options.auth`. Always pass own request as many strategies accept a custom request instance.
// TODO: type `options.auth` based on `options.authStrategy`.
requestDefaults.headers["user-agent"] = [
options.userAgent,
`octokit-core.js/${VERSION} ${getUserAgent()}`,
]
.filter(Boolean)
.join(" ");
if (options.baseUrl) {
requestDefaults.baseUrl = options.baseUrl;
}
if (options.previews) {
requestDefaults.mediaType.previews = options.previews;
}
if (options.timeZone) {
requestDefaults.headers["time-zone"] = options.timeZone;
}
this.request = request.defaults(requestDefaults);
this.graphql = withCustomRequest(this.request).defaults({
...requestDefaults,
baseUrl: requestDefaults.baseUrl.replace(/\/api\/v3$/, "/api"),
});
this.log = Object.assign({
debug: () => { },
info: () => { },
warn: console.warn.bind(console),
error: console.error.bind(console),
}, options.log);
this.hook = hook;
// (1) If neither `options.authStrategy` nor `options.auth` are set, the `octokit` instance
// is unauthenticated. The `this.auth()` method is a no-op and no request hook is registred.
// (2) If only `options.auth` is set, use the default token authentication strategy.
// (3) If `options.authStrategy` is set then use it and pass in `options.auth`. Always pass own request as many strategies accept a custom request instance.
// TODO: type `options.auth` based on `options.authStrategy`.
function Octokit(plugins, options) {
options = options || {};
const hook = new Hook.Collection();
const log = Object.assign(
{
debug: () => {},
info: () => {},
warn: console.warn,
error: console.error
},
options && options.log
);
const api = {
hook,
log,
request: request.defaults(parseClientOptions(options, log, hook))
};
plugins.forEach(pluginFunction => pluginFunction(api, options));
return api;
}
function init() {
logger.info("Initializing GitHub App ...");
var pem = fs.readFileSync(configuration.getOption("app-pemfile"));
auth = createAppAuth({
id: configuration.getOption('app-appid'),
privateKey: pem,
clientId: configuration.getOption('app-clientid'),
clientSecret: configuration.getOption('app-clientsecret'),
request: request.defaults({
baseUrl: configuration.getOption('baseurl')
})
});
logger.debug(auth);
}
constructor({ id, privateKey, baseUrl, cache }) {
const state = {
id,
privateKey,
request: baseUrl ? request.defaults({ baseUrl }) : request,
cache: cache || getCache()
};
this.getSignedJsonWebToken = getSignedJsonWebToken.bind(null, state);
this.getInstallationAccessToken = getInstallationAccessToken.bind(null, state);
}
}