diff --git a/README.md b/README.md index be4ac4424..9fd0a3d6f 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,8 @@ The action works without configuration, however you can provide options for cust # merge commit, and it's easy to commit this by mistake. Enable this option # to also validate the commit message for one commit PRs. validateSingleCommit: true + # If you use Github Enterprise, you can set this to the URL of your server + githubBaseUrl: https://github.myorg.com/api/v3 ``` ## Event triggers diff --git a/action.yml b/action.yml index 0388ed783..824fe0069 100644 --- a/action.yml +++ b/action.yml @@ -29,3 +29,6 @@ inputs: validateSingleCommit: description: "When using \"Squash and merge\" on a PR with only one commit, GitHub will suggest using that commit message instead of the PR title for the merge commit, and it's easy to commit this by mistake. Enable this option to also validate the commit message for one commit PRs." required: false + githubBaseUrl: + description: "If you use Github Enterprise, you can set this to the URL of your server (e.g. https://github.myorg.com/api/v3)" + required: false diff --git a/src/index.js b/src/index.js index 896cdd2b9..765fc9db6 100644 --- a/src/index.js +++ b/src/index.js @@ -5,7 +5,6 @@ const validatePrTitle = require('./validatePrTitle'); module.exports = async function run() { try { - const client = github.getOctokit(process.env.GITHUB_TOKEN); const { types, scopes, @@ -13,9 +12,14 @@ module.exports = async function run() { wip, subjectPattern, subjectPatternError, - validateSingleCommit + validateSingleCommit, + githubBaseUrl } = parseConfig(); + const client = github.getOctokit(process.env.GITHUB_TOKEN, { + baseUrl: githubBaseUrl + }); + const contextPullRequest = github.context.payload.pull_request; if (!contextPullRequest) { throw new Error( diff --git a/src/parseConfig.js b/src/parseConfig.js index 25f697d0f..48d2a07f3 100644 --- a/src/parseConfig.js +++ b/src/parseConfig.js @@ -40,6 +40,11 @@ module.exports = function parseConfig() { ); } + let githubBaseUrl; + if (process.env.INPUT_GITHUBBASEURL) { + githubBaseUrl = ConfigParser.parseString(process.env.INPUT_GITHUBBASEURL); + } + return { types, scopes, @@ -47,6 +52,7 @@ module.exports = function parseConfig() { wip, subjectPattern, subjectPatternError, - validateSingleCommit + validateSingleCommit, + githubBaseUrl }; };