universal-user-agent#getUserAgent JavaScript Examples
The following examples show how to use
universal-user-agent#getUserAgent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.js From zcl-eth-key-converter with MIT License | 6 votes |
createBasicAuth = function createBasicAuth(options) {
console.warn(`[@octokit/auth-basic] Basic authentication has been deprecated. See https://github.com/octokit/auth-basic.js/#deprecation`);
["username", "password", "on2Fa"].forEach((option) => {
if (!options.hasOwnProperty(option)) {
throw new Error(`[@octokit/auth-basic] ${option} option is required`);
}
});
const strategyOptions = Object.assign({
token: {},
}, options);
const state = {
strategyOptions,
request: strategyOptions.request ||
request.defaults({
baseUrl: "https://api.github.com",
headers: {
"user-agent": `octokit-auth-basic.js/${VERSION} ${getUserAgent()}`,
},
}),
};
return Object.assign(auth.bind(null, state), {
hook: hook.bind(null, state),
});
}
Example #2
Source File: index.js From ipfs-action with MIT License | 5 votes |
userAgent = `octokit-endpoint.js/${VERSION} ${getUserAgent()}`
Example #3
Source File: index.js From change-string-case-action with ISC License | 5 votes |
constructor(options = {}) {
const hook = new Collection();
const requestDefaults = {
baseUrl: request.endpoint.DEFAULTS.baseUrl,
headers: {},
request: Object.assign({}, options.request, {
hook: hook.bind(null, "request"),
}),
mediaType: {
previews: [],
format: "",
},
};
// prepend default user agent with `options.userAgent` if set
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`.
if (!options.authStrategy) {
if (!options.auth) {
// (1)
this.auth = async () => ({
type: "unauthenticated",
});
}
else {
// (2)
const auth = createTokenAuth(options.auth);
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
}
else {
const auth = options.authStrategy(Object.assign({
request: this.request,
}, options.auth));
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
// apply plugins
// https://stackoverflow.com/a/16345172
const classConstructor = this.constructor;
classConstructor.plugins.forEach((plugin) => {
Object.assign(this, plugin(this, options));
});
}
Example #4
Source File: index.js From ipfs-action with MIT License | 5 votes |
request = withDefaults(endpoint, {
headers: {
"user-agent": `octokit-request.js/${VERSION} ${getUserAgent()}`,
},
})
Example #5
Source File: index.js From deploy-gae-action with MIT License | 5 votes |
constructor(options = {}) {
const hook = new Collection();
const requestDefaults = {
baseUrl: request.endpoint.DEFAULTS.baseUrl,
headers: {},
request: Object.assign({}, options.request, {
hook: hook.bind(null, "request"),
}),
mediaType: {
previews: [],
format: "",
},
};
// prepend default user agent with `options.userAgent` if set
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`.
if (!options.authStrategy) {
if (!options.auth) {
// (1)
this.auth = async () => ({
type: "unauthenticated",
});
}
else {
// (2)
const auth = createTokenAuth(options.auth);
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
}
else {
const auth = options.authStrategy(Object.assign({
request: this.request,
}, options.auth));
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
// apply plugins
// https://stackoverflow.com/a/16345172
const classConstructor = this.constructor;
classConstructor.plugins.forEach((plugin) => {
Object.assign(this, plugin(this, options));
});
}
Example #6
Source File: index.js From compute-tag with BSD 3-Clause "New" or "Revised" License | 5 votes |
graphql$1 = withDefaults(request, {
headers: {
"user-agent": `octokit-graphql.js/${VERSION} ${getUserAgent()}`,
},
method: "POST",
url: "/graphql",
})
Example #7
Source File: index.js From github-actions-issue-to-work-item with GNU General Public License v3.0 | 5 votes |
userAgent = `octokit-endpoint.js/${VERSION} ${getUserAgent()}`
Example #8
Source File: defaults.js From replace-action with MIT License | 5 votes |
userAgent = `octokit-endpoint.js/${VERSION} ${getUserAgent()}`
Example #9
Source File: index.js From action-download-artifact with MIT License | 5 votes |
request = withDefaults(endpoint, {
headers: {
"user-agent": `octokit-request.js/${VERSION} ${getUserAgent()}`,
},
})
Example #10
Source File: index.js From verify-linked-issue-action with MIT License | 5 votes |
graphql = withDefaults(request, {
headers: {
"user-agent": `octokit-graphql.js/${VERSION} ${getUserAgent()}`,
},
method: "POST",
url: "/graphql",
})
Example #11
Source File: index.js From action-install-gh-release with Apache License 2.0 | 5 votes |
request = withDefaults(endpoint, {
headers: {
"user-agent": `octokit-request.js/${VERSION} ${getUserAgent()}`,
},
})
Example #12
Source File: index.js From github-action-get-latest-release with MIT License | 5 votes |
userAgent = `octokit-endpoint.js/${VERSION} ${getUserAgent()}`
Example #13
Source File: index.js From javascript-actions with MIT License | 5 votes |
request = withDefaults(endpoint, {
headers: {
"user-agent": `octokit-request.js/${VERSION} ${getUserAgent()}`,
},
})
Example #14
Source File: index.js From payload-info-action with MIT License | 5 votes |
request = withDefaults(endpoint, {
headers: {
"user-agent": `octokit-request.js/${VERSION} ${getUserAgent()}`
}
})
Example #15
Source File: index.js From change-string-case-action with ISC License | 5 votes |
constructor(options = {}) {
const hook = new Collection();
const requestDefaults = {
baseUrl: request.endpoint.DEFAULTS.baseUrl,
headers: {},
request: Object.assign({}, options.request, {
hook: hook.bind(null, "request"),
}),
mediaType: {
previews: [],
format: "",
},
};
// prepend default user agent with `options.userAgent` if set
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`.
if (!options.authStrategy) {
if (!options.auth) {
// (1)
this.auth = async () => ({
type: "unauthenticated",
});
}
else {
// (2)
const auth = createTokenAuth(options.auth);
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
}
else {
const auth = options.authStrategy(Object.assign({
request: this.request,
}, options.auth));
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
// apply plugins
// https://stackoverflow.com/a/16345172
const classConstructor = this.constructor;
classConstructor.plugins.forEach((plugin) => {
Object.assign(this, plugin(this, options));
});
}
Example #16
Source File: defaults.js From payload-info-action with MIT License | 5 votes |
userAgent = `octokit-endpoint.js/${VERSION} ${getUserAgent()}`
Example #17
Source File: index.js From dotnet-bump-version with MIT License | 5 votes |
constructor(options = {}) {
const hook = new Collection();
const requestDefaults = {
baseUrl: request.endpoint.DEFAULTS.baseUrl,
headers: {},
request: Object.assign({}, options.request, {
hook: hook.bind(null, "request"),
}),
mediaType: {
previews: [],
format: "",
},
};
// prepend default user agent with `options.userAgent` if set
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);
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 registered.
// (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`.
if (!options.authStrategy) {
if (!options.auth) {
// (1)
this.auth = async () => ({
type: "unauthenticated",
});
}
else {
// (2)
const auth = createTokenAuth(options.auth);
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
}
else {
const auth = options.authStrategy(Object.assign({
request: this.request,
}, options.auth));
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
// apply plugins
// https://stackoverflow.com/a/16345172
const classConstructor = this.constructor;
classConstructor.plugins.forEach((plugin) => {
Object.assign(this, plugin(this, options));
});
}
Example #18
Source File: index.js From random-rickroll with Apache License 2.0 | 5 votes |
graphql$1 = withDefaults(request, {
headers: {
"user-agent": `octokit-graphql.js/${VERSION} ${getUserAgent()}`,
},
method: "POST",
url: "/graphql",
})
Example #19
Source File: index.js From dotnet-bump-version with MIT License | 5 votes |
request = withDefaults(endpoint, {
headers: {
"user-agent": `octokit-request.js/${VERSION} ${getUserAgent()}`,
},
})
Example #20
Source File: index.js From random-rickroll with Apache License 2.0 | 5 votes |
constructor(options = {}) {
const hook = new Collection();
const requestDefaults = {
baseUrl: request.endpoint.DEFAULTS.baseUrl,
headers: {},
request: Object.assign({}, options.request, {
hook: hook.bind(null, "request"),
}),
mediaType: {
previews: [],
format: "",
},
};
// prepend default user agent with `options.userAgent` if set
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`.
if (!options.authStrategy) {
if (!options.auth) {
// (1)
this.auth = async () => ({
type: "unauthenticated",
});
}
else {
// (2)
const auth = createTokenAuth(options.auth);
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
}
else {
const auth = options.authStrategy(Object.assign({
request: this.request,
}, options.auth));
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
// apply plugins
// https://stackoverflow.com/a/16345172
const classConstructor = this.constructor;
classConstructor.plugins.forEach((plugin) => {
Object.assign(this, plugin(this, options));
});
}
Example #21
Source File: index.js From discord-commits with MIT License | 5 votes |
request = withDefaults(endpoint, {
headers: {
"user-agent": `octokit-request.js/${VERSION} ${getUserAgent()}`,
},
})
Example #22
Source File: index.js From dotnet-bump-version with MIT License | 5 votes |
constructor(options = {}) {
const hook = new Collection();
const requestDefaults = {
baseUrl: request.endpoint.DEFAULTS.baseUrl,
headers: {},
request: Object.assign({}, options.request, {
hook: hook.bind(null, "request"),
}),
mediaType: {
previews: [],
format: "",
},
};
// prepend default user agent with `options.userAgent` if set
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);
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 registered.
// (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`.
if (!options.authStrategy) {
if (!options.auth) {
// (1)
this.auth = async () => ({
type: "unauthenticated",
});
}
else {
// (2)
const auth = createTokenAuth(options.auth);
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
}
else {
const auth = options.authStrategy(Object.assign({
request: this.request,
}, options.auth));
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
// apply plugins
// https://stackoverflow.com/a/16345172
const classConstructor = this.constructor;
classConstructor.plugins.forEach((plugin) => {
Object.assign(this, plugin(this, options));
});
}
Example #23
Source File: index.js From discord-commits with MIT License | 5 votes |
graphql$1 = withDefaults(request, {
headers: {
"user-agent": `octokit-graphql.js/${VERSION} ${getUserAgent()}`,
},
method: "POST",
url: "/graphql",
})
Example #24
Source File: index.js From ipfs-action with MIT License | 4 votes |
constructor(options = {}) {
const hook = new Collection();
const requestDefaults = {
baseUrl: request.endpoint.DEFAULTS.baseUrl,
headers: {},
request: Object.assign({}, options.request, {
// @ts-ignore internal usage only, no need to type
hook: hook.bind(null, "request"),
}),
mediaType: {
previews: [],
format: "",
},
};
// prepend default user agent with `options.userAgent` if set
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);
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 registered.
// (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`.
if (!options.authStrategy) {
if (!options.auth) {
// (1)
this.auth = async () => ({
type: "unauthenticated",
});
}
else {
// (2)
const auth = createTokenAuth(options.auth);
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
}
else {
const { authStrategy, ...otherOptions } = options;
const auth = authStrategy(Object.assign({
request: this.request,
log: this.log,
// we pass the current octokit instance as well as its constructor options
// to allow for authentication strategies that return a new octokit instance
// that shares the same internal state as the current one. The original
// requirement for this was the "event-octokit" authentication strategy
// of https://github.com/probot/octokit-auth-probot.
octokit: this,
octokitOptions: otherOptions,
}, options.auth));
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
// apply plugins
// https://stackoverflow.com/a/16345172
const classConstructor = this.constructor;
classConstructor.plugins.forEach((plugin) => {
Object.assign(this, plugin(this, options));
});
}
Example #25
Source File: index.js From action-install-gh-release with Apache License 2.0 | 4 votes |
constructor(options = {}) {
const hook = new Collection();
const requestDefaults = {
baseUrl: request.endpoint.DEFAULTS.baseUrl,
headers: {},
request: Object.assign({}, options.request, {
// @ts-ignore internal usage only, no need to type
hook: hook.bind(null, "request"),
}),
mediaType: {
previews: [],
format: "",
},
};
// prepend default user agent with `options.userAgent` if set
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);
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 registered.
// (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`.
if (!options.authStrategy) {
if (!options.auth) {
// (1)
this.auth = async () => ({
type: "unauthenticated",
});
}
else {
// (2)
const auth = createTokenAuth(options.auth);
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
}
else {
const { authStrategy, ...otherOptions } = options;
const auth = authStrategy(Object.assign({
request: this.request,
log: this.log,
// we pass the current octokit instance as well as its constructor options
// to allow for authentication strategies that return a new octokit instance
// that shares the same internal state as the current one. The original
// requirement for this was the "event-octokit" authentication strategy
// of https://github.com/probot/octokit-auth-probot.
octokit: this,
octokitOptions: otherOptions,
}, options.auth));
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
// apply plugins
// https://stackoverflow.com/a/16345172
const classConstructor = this.constructor;
classConstructor.plugins.forEach((plugin) => {
Object.assign(this, plugin(this, options));
});
}
Example #26
Source File: index.js From discord-commits with MIT License | 4 votes |
constructor(options = {}) {
const hook = new Collection();
const requestDefaults = {
baseUrl: request.endpoint.DEFAULTS.baseUrl,
headers: {},
request: Object.assign({}, options.request, {
hook: hook.bind(null, "request"),
}),
mediaType: {
previews: [],
format: "",
},
};
// prepend default user agent with `options.userAgent` if set
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);
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 registered.
// (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`.
if (!options.authStrategy) {
if (!options.auth) {
// (1)
this.auth = async () => ({
type: "unauthenticated",
});
}
else {
// (2)
const auth = createTokenAuth(options.auth);
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
}
else {
const { authStrategy, ...otherOptions } = options;
const auth = authStrategy(Object.assign({
request: this.request,
log: this.log,
// we pass the current octokit instance as well as its constructor options
// to allow for authentication strategies that return a new octokit instance
// that shares the same internal state as the current one. The original
// requirement for this was the "event-octokit" authentication strategy
// of https://github.com/probot/octokit-auth-probot.
octokit: this,
octokitOptions: otherOptions,
}, options.auth));
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
// apply plugins
// https://stackoverflow.com/a/16345172
const classConstructor = this.constructor;
classConstructor.plugins.forEach((plugin) => {
Object.assign(this, plugin(this, options));
});
}
Example #27
Source File: index.js From compute-tag with BSD 3-Clause "New" or "Revised" License | 4 votes |
constructor(options = {}) {
const hook = new Collection();
const requestDefaults = {
baseUrl: request.endpoint.DEFAULTS.baseUrl,
headers: {},
request: Object.assign({}, options.request, {
// @ts-ignore internal usage only, no need to type
hook: hook.bind(null, "request"),
}),
mediaType: {
previews: [],
format: "",
},
};
// prepend default user agent with `options.userAgent` if set
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);
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 registered.
// (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`.
if (!options.authStrategy) {
if (!options.auth) {
// (1)
this.auth = async () => ({
type: "unauthenticated",
});
}
else {
// (2)
const auth = createTokenAuth(options.auth);
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
}
else {
const { authStrategy, ...otherOptions } = options;
const auth = authStrategy(Object.assign({
request: this.request,
log: this.log,
// we pass the current octokit instance as well as its constructor options
// to allow for authentication strategies that return a new octokit instance
// that shares the same internal state as the current one. The original
// requirement for this was the "event-octokit" authentication strategy
// of https://github.com/probot/octokit-auth-probot.
octokit: this,
octokitOptions: otherOptions,
}, options.auth));
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
// apply plugins
// https://stackoverflow.com/a/16345172
const classConstructor = this.constructor;
classConstructor.plugins.forEach((plugin) => {
Object.assign(this, plugin(this, options));
});
}
Example #28
Source File: index.js From verify-linked-issue-action with MIT License | 4 votes |
constructor(options = {}) {
const hook = new Collection();
const requestDefaults = {
baseUrl: request.endpoint.DEFAULTS.baseUrl,
headers: {},
request: Object.assign({}, options.request, {
// @ts-ignore internal usage only, no need to type
hook: hook.bind(null, "request"),
}),
mediaType: {
previews: [],
format: "",
},
};
// prepend default user agent with `options.userAgent` if set
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);
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 registered.
// (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`.
if (!options.authStrategy) {
if (!options.auth) {
// (1)
this.auth = async () => ({
type: "unauthenticated",
});
}
else {
// (2)
const auth = createTokenAuth(options.auth);
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
}
else {
const { authStrategy, ...otherOptions } = options;
const auth = authStrategy(Object.assign({
request: this.request,
log: this.log,
// we pass the current octokit instance as well as its constructor options
// to allow for authentication strategies that return a new octokit instance
// that shares the same internal state as the current one. The original
// requirement for this was the "event-octokit" authentication strategy
// of https://github.com/probot/octokit-auth-probot.
octokit: this,
octokitOptions: otherOptions,
}, options.auth));
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
// apply plugins
// https://stackoverflow.com/a/16345172
const classConstructor = this.constructor;
classConstructor.plugins.forEach((plugin) => {
Object.assign(this, plugin(this, options));
});
}
Example #29
Source File: index.js From action-download-artifact with MIT License | 4 votes |
constructor(options = {}) {
const hook = new Collection();
const requestDefaults = {
baseUrl: request.endpoint.DEFAULTS.baseUrl,
headers: {},
request: Object.assign({}, options.request, {
// @ts-ignore internal usage only, no need to type
hook: hook.bind(null, "request"),
}),
mediaType: {
previews: [],
format: "",
},
};
// prepend default user agent with `options.userAgent` if set
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);
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 registered.
// (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`.
if (!options.authStrategy) {
if (!options.auth) {
// (1)
this.auth = async () => ({
type: "unauthenticated",
});
}
else {
// (2)
const auth = createTokenAuth(options.auth);
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
}
else {
const { authStrategy, ...otherOptions } = options;
const auth = authStrategy(Object.assign({
request: this.request,
log: this.log,
// we pass the current octokit instance as well as its constructor options
// to allow for authentication strategies that return a new octokit instance
// that shares the same internal state as the current one. The original
// requirement for this was the "event-octokit" authentication strategy
// of https://github.com/probot/octokit-auth-probot.
octokit: this,
octokitOptions: otherOptions,
}, options.auth));
// @ts-ignore ¯\_(ツ)_/¯
hook.wrap("request", auth.hook);
this.auth = auth;
}
// apply plugins
// https://stackoverflow.com/a/16345172
const classConstructor = this.constructor;
classConstructor.plugins.forEach((plugin) => {
Object.assign(this, plugin(this, options));
});
}