diff --git a/source/app/action/index.mjs b/source/app/action/index.mjs index 4008a6bbe44..53261d12bd9 100644 --- a/source/app/action/index.mjs +++ b/source/app/action/index.mjs @@ -146,6 +146,8 @@ function quit(reason) { "quota.required.search": _quota_required_search, "notice.release": _notice_releases, "clean.workflows": _clean_workflows, + "github.api.rest": _github_api_rest, + "github.api.graphql": _github_api_graphql, ...config } = metadata.plugins.core.inputs.action({core, preset}) const q = {...query, ...(_repo ? {repo: _repo} : null), template} @@ -175,12 +177,14 @@ function quit(reason) { conf.settings.token = token const api = {} const resources = {} - api.graphql = octokit.graphql.defaults({headers: {authorization: `token ${token}`}}) + api.graphql = octokit.graphql.defaults({headers: {authorization: `token ${token}`}, baseUrl: _github_api_graphql || undefined}) info("GitHub GraphQL API", "ok") - const octoraw = github.getOctokit(token) + info("GitHub GraphQL API endpoint", api.graphql.baseUrl) + const octoraw = github.getOctokit(token, {baseUrl: _github_api_rest || undefined}) api.rest = octoraw.rest api.rest.request = octoraw.request info("GitHub REST API", "ok") + info("GitHub REST API endpoint", api.rest.baseUrl) //Apply mocking if needed if (mocked) { Object.assign(api, await mocks(api)) diff --git a/source/app/web/instance.mjs b/source/app/web/instance.mjs index edf1c329963..f2fb8605645 100644 --- a/source/app/web/instance.mjs +++ b/source/app/web/instance.mjs @@ -54,7 +54,7 @@ export default async function({sandbox = false} = {}) { console.debug(util.inspect(conf.settings, {depth: Infinity, maxStringLength: 256})) //Load octokits - const api = {graphql: octokit.graphql.defaults({headers: {authorization: `token ${token}`}}), rest: new OctokitRest.Octokit({auth: token})} + const api = {graphql: octokit.graphql.defaults({headers: {authorization: `token ${token}`}, baseUrl:conf.settings.api?.graphql ?? undefined}), rest: new OctokitRest.Octokit({auth: token, baseUrl: conf.settings.api?.rest ?? undefined})} //Apply mocking if needed if (mock) Object.assign(api, await mocks(api)) diff --git a/source/app/web/settings.example.json b/source/app/web/settings.example.json index b0ab88af8e1..1e00a54ded4 100644 --- a/source/app/web/settings.example.json +++ b/source/app/web/settings.example.json @@ -25,6 +25,10 @@ "secret": null, "//": "GitHub OAUTH client secret", "url":"https://example.com", "//": "GitHub OAUTH callback url (must be the same as the web instance host)" }, + "api":{ + "rest": null, "//": "GitHub REST API custom endpoint", + "graphql": null, "//": "GitHub GraphQL API custom endpoint" + }, "control":{ "token": null, "//": "Control token (can be used by external services to perform actions on instance, such as stopping it for redeploys)" }, diff --git a/source/plugins/core/metadata.yml b/source/plugins/core/metadata.yml index 42315594003..d27330c7a28 100644 --- a/source/plugins/core/metadata.yml +++ b/source/plugins/core/metadata.yml @@ -201,6 +201,28 @@ inputs: extras: - metrics.run.puppeteer.user.js + github_api_rest: + description: | + GitHub REST API endpoint + + Can be used to support [GitHub enterprises server](https://github.com/enterprise). + Leave empty to use default endpoint. + type: string + default: "" + example: https://api.github.com + global: yes + + github_api_graphql: + description: | + GitHub GraphQL API endpoint + + Can be used to support [GitHub enterprises server](https://github.com/enterprise). + Leave empty to use default endpoint. + type: string + default: "" + example: https://api.github.com/graphql + global: yes + config_timezone: description: | Timezone for dates