diff --git a/.github/linters/.eslintrc.yml b/.github/linters/.eslintrc.yml index 7f660fc..0d90eec 100644 --- a/.github/linters/.eslintrc.yml +++ b/.github/linters/.eslintrc.yml @@ -42,6 +42,7 @@ rules: 'i18n-text/no-en': 'off', 'import/no-namespace': 'off', 'no-console': 'off', + 'no-shadow': 'off', 'no-unused-vars': 'off', 'prettier/prettier': 'error', 'semi': 'off', @@ -63,6 +64,7 @@ rules: '@typescript-eslint/no-misused-new': 'error', '@typescript-eslint/no-namespace': 'error', '@typescript-eslint/no-require-imports': 'error', + '@typescript-eslint/no-shadow': 'error', '@typescript-eslint/no-unnecessary-qualifier': 'error', '@typescript-eslint/no-unnecessary-type-assertion': 'error', '@typescript-eslint/no-unused-vars': 'error', diff --git a/README.md b/README.md index 590132d..a0078f5 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,6 @@ sizeup: The default configuration that is used when no configuration file is provided can be found in [`src/config/default.yaml`](./src/config/default.yaml). -The full specification for the configuration file is provide by the JSON schema at [`src/config/schema.json`](./src/config/schema.json). +The full specification for the configuration file, which includes options that are not specified in the example above or in the default configuration, is provided by the JSON schema at [`src/config/schema.json`](./src/config/schema.json). For details about what configuration can be provided under the `sizeup` key, please see the [`sizeup-core` library's configuration guide](https://github.com/lerebear/sizeup-core#configuration). diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index c3a8273..cf0a5e4 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -145,6 +145,28 @@ describe('action', () => { ) }) + it('skips labelling a pull request when running in shadow mode', async () => { + // Mock the @actions/github context. + Object.defineProperty(github, 'context', { + value: pullRequestEventContext() + }) + + loadConfigurationMock.mockImplementation(() => ({ + // Mock config such that the only opted-in user is @glortho. The pull request will be created + // by @lerebear, who should therefore *not* be considered opted in. + optIns: ['glortho'], + shadowOptOuts: true + })) + + await main.run() + + expect(runMock).toHaveReturned() + expect(setFailedMock).not.toHaveBeenCalled() + expect(infoMock).toHaveBeenCalledWith( + 'Skipping labeling because this workflow is running in shadow mode' + ) + }) + it('skips commenting on a draft pull request when configured to do so', async () => { // Mock the @actions/github context. Object.defineProperty(github, 'context', { @@ -164,6 +186,29 @@ describe('action', () => { ) }) + it('skips commenting on a pull request when running in shadow mode', async () => { + // Mock the @actions/github context. + Object.defineProperty(github, 'context', { + value: pullRequestEventContext() + }) + + loadConfigurationMock.mockImplementation(() => ({ + // Mock config such that the only opted-in user is @glortho. The pull request will be created + // by @lerebear, who should therefore *not* be considered opted in. + optIns: ['glortho'], + shadowOptOuts: true, + commenting: { scoreThreshold: 0 } + })) + + await main.run() + + expect(runMock).toHaveReturned() + expect(setFailedMock).not.toHaveBeenCalled() + expect(infoMock).toHaveBeenCalledWith( + 'Skipping commenting because this workflow is running in shadow mode' + ) + }) + it('runs the workflow sucessfully when optIns configuration is present and the pull request author is in it', async () => { // Mock the @actions/github context. Object.defineProperty(github, 'context', { @@ -172,7 +217,7 @@ describe('action', () => { loadConfigurationMock.mockImplementation(() => ({ // Mock config such that the only opted-in user is @glortho. The pull request will be created - // by @lerebear, who should therefore not be considered optedpin. + // by @lerebear, who should therefore *not* be considered opted in. optIns: ['lerebear'] })) diff --git a/badges/coverage.svg b/badges/coverage.svg index 337ea38..a8068d8 100644 --- a/badges/coverage.svg +++ b/badges/coverage.svg @@ -1 +1 @@ -Coverage: 64.96%Coverage64.96% \ No newline at end of file +Coverage: 68.02%Coverage68.02% \ No newline at end of file diff --git a/dist/config/schema.json b/dist/config/schema.json index 1b5221e..49c1d38 100644 --- a/dist/config/schema.json +++ b/dist/config/schema.json @@ -59,6 +59,11 @@ "type": "string" } }, + "shadowOptOuts": { + "description": "Whether or not to compute a score even for users who have opted out of the workflow", + "type": "boolean", + "default": false + }, "sizeup": { "$ref": "https://raw.githubusercontent.com/lerebear/sizeup/main/src/config/schema.json" } diff --git a/dist/index.js b/dist/index.js index df21989..6d31d14 100644 --- a/dist/index.js +++ b/dist/index.js @@ -16492,7 +16492,7 @@ const COMMENT_METADATA = '