diff --git a/README.md b/README.md index 799d71fb6..b49139944 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,6 @@ Note that since PR titles only have a single line, you have to use the `!` synta See [Conventional Commits](https://www.conventionalcommits.org/) for more examples. -### Work in progress - -Github has support for [draft pull requests](https://github.blog/2019-02-14-introducing-draft-pull-requests/), which will disable the merge button until the PR is marked as ready for merge. - -However, [this feature might be disabled for your repository](https://github.community/t/draft-pull-requests-not-available/1753/7). In this case you can use the special `[WIP] ` prefix to indicate that a pull request is work in progress and isn't ready to be merged. This will avoid the validation of the PR title and the pull request checks remain pending. - ## Example config ```yml @@ -54,11 +48,18 @@ jobs: ui # Configure that a scope must always be provided. requireScope: true + # For work-in-progress PRs you can typically use draft pull requests + # from Github. However, private repositories on the free plan don't have + # this option and therefore this action allows you to opt-in to using the + # special "[WIP]" prefix to indicate this state. This will avoid the + # validation of the PR title and the pull request checks remain pending. + # Note that a second check will be reported if this is enabled. + wip: true ``` ## Event triggers There are two events that can be used as triggers for this action, each with different characteristics: -1. [`pull_request_target`](https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/): This allows the action to be used in a fork-based workflow, where e.g. you want to accept pull requests in a public repository. In this case, the configuration from the main branch of your repository will be used for the check. This means that you need to have this configuration in the main branch for the action to run at all (e.g. it won't run within a PR that adds the action initially). Also if you change configuration in a PR, the changes will not be reflected for the current PR – only subsequent ones after the changes are in the main branch. -2. `pull_request`: This configuration uses the latest configuration that is available in the current branch. It will only work if the branch is based in the repository itself. If this configuration is used and a pull request from a fork is opened, you'll encounter an error as the Github token environment parameter is not available. +1. [`pull_request_target`](https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/): This allows the action to be used in a fork-based workflow, where e.g. you want to accept pull requests in a public repository. In this case, the configuration from the main branch of your repository will be used for the check. This means that you need to have this configuration in the main branch for the action to run at all (e.g. it won't run within a PR that adds the action initially). Also if you change the configuration in a PR, the changes will not be reflected for the current PR – only subsequent ones after the changes are in the main branch. +2. `pull_request`: This configuration uses the latest configuration that is available in the current branch. It will only work if the branch is based in the repository itself. If this configuration is used and a pull request from a fork is opened, you'll encounter an error as the Github token environment parameter is not available. This option is viable if all contributors have write access to the repository. diff --git a/action.yml b/action.yml index ca6558002..57ffa7dad 100644 --- a/action.yml +++ b/action.yml @@ -17,3 +17,6 @@ inputs: requireScope: description: "Configure that a scope must always be provided." required: false + wip: + description: "For work-in-progress PRs you can typically use draft pull requests from Github. However, private repositories on the free plan don't have this option and therefore this action allows you to opt-in to using the special '[WIP]' prefix to indicate this state. This will avoid the validation of the PR title and the pull request checks remain pending. Note that a second check will be reported if this is enabled." + required: false diff --git a/src/index.js b/src/index.js index 3373f23dc..ed82c5b8a 100644 --- a/src/index.js +++ b/src/index.js @@ -6,7 +6,7 @@ const validatePrTitle = require('./validatePrTitle'); module.exports = async function run() { try { const client = github.getOctokit(process.env.GITHUB_TOKEN); - const {types, scopes, requireScope} = parseConfig(); + const {types, scopes, requireScope, wip} = parseConfig(); const contextPullRequest = github.context.payload.pull_request; if (!contextPullRequest) { @@ -29,7 +29,7 @@ module.exports = async function run() { }); // Pull requests that start with "[WIP] " are excluded from the check. - const isWip = /^\[WIP\]\s/.test(pullRequest.title); + const isWip = wip && /^\[WIP\]\s/.test(pullRequest.title); let validationError; if (!isWip) { @@ -40,25 +40,28 @@ module.exports = async function run() { } } - const newStatus = isWip || validationError != null ? 'pending' : 'success'; + if (wip) { + const newStatus = + isWip || validationError != null ? 'pending' : 'success'; - // When setting the status to "pending", the checks don't - // complete. This can be used for WIP PRs in repositories - // which don't support draft pull requests. - // https://developer.github.com/v3/repos/statuses/#create-a-status - await client.request('POST /repos/:owner/:repo/statuses/:sha', { - owner, - repo, - sha: pullRequest.head.sha, - state: newStatus, - target_url: 'https://github.com/amannn/action-semantic-pull-request', - description: isWip - ? 'This PR is marked with "[WIP]".' - : validationError - ? 'PR title validation failed' - : 'Ready for review & merge.', - context: 'action-semantic-pull-request' - }); + // When setting the status to "pending", the checks don't + // complete. This can be used for WIP PRs in repositories + // which don't support draft pull requests. + // https://developer.github.com/v3/repos/statuses/#create-a-status + await client.request('POST /repos/:owner/:repo/statuses/:sha', { + owner, + repo, + sha: pullRequest.head.sha, + state: newStatus, + target_url: 'https://github.com/amannn/action-semantic-pull-request', + description: isWip + ? 'This PR is marked with "[WIP]".' + : validationError + ? 'PR title validation failed' + : 'Ready for review & merge.', + context: 'action-semantic-pull-request' + }); + } if (!isWip && validationError) { throw validationError; diff --git a/src/parseConfig.js b/src/parseConfig.js index dc83c1b68..ecc10e14d 100644 --- a/src/parseConfig.js +++ b/src/parseConfig.js @@ -16,5 +16,10 @@ module.exports = function parseConfig() { requireScope = ConfigParser.parseBoolean(process.env.INPUT_REQUIRESCOPE); } - return {types, scopes, requireScope}; + let wip; + if (process.env.INPUT_WIP) { + wip = ConfigParser.parseBoolean(process.env.INPUT_WIP); + } + + return {types, scopes, requireScope, wip}; };