diff --git a/README.md b/README.md index 267f772..5e547df 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,10 @@ jobs: # Enable by setting the value to "on". Default "off" check_issues: off + # (Optional) Ignore dependabot PRs. + # Enable by setting the value to "on". Default "off" + ignore_dependabot: off + # (Optional) A comma-separated list of keywords. Default # "depends on, blocked by" keywords: depends on, blocked by @@ -63,6 +67,7 @@ Here how it can look like in practice: - **label** (Optional): The label to use to mark dependent issues. Default `dependent`. - **check_issues** (Optional): Enable checking for dependencies in issues. Enable by setting the value to `on`. Default `off`. +- **ignore_dependabot** (Optional): Ignore dependabot PRs. Enable by setting the value to `on`. Default `off`. Use this if you run the action on `pull_request` rather than `pull_request_target`. - **keywords** (Optional): A comma-separated list of keywords. Default `depends on, blocked by`. ## Environment variables diff --git a/src/__tests__/support.test.ts b/src/__tests__/support.test.ts index 5f88e2d..f26b4fc 100644 --- a/src/__tests__/support.test.ts +++ b/src/__tests__/support.test.ts @@ -2,20 +2,39 @@ import { isSupported } from '../support'; describe('isSupported', () => { it('should not fail when given incomplete issue data', () => { + const config: any = { + ignore_dependabot: 'off', + }; const issue: any = { user: null, }; - expect(isSupported(issue)).toEqual(true); + expect(isSupported(config, issue)).toEqual(true); }); - it('should return false for Dependabot issues or pull requests', () => { + it('should return false for ignored Dependabot issues or pull requests', () => { + const config: any = { + ignore_dependabot: 'on', + }; + const issue: any = { + user: { + login: 'dependabot[bot]', + }, + }; + + expect(isSupported(config, issue)).toEqual(false); + }); + + it('should return true for non-ignored Dependabot issues or pull requests', () => { + const config: any = { + ignore_dependabot: 'off', + }; const issue: any = { user: { login: 'dependabot[bot]', }, }; - expect(isSupported(issue)).toEqual(false); + expect(isSupported(config, issue)).toEqual(true); }); }); diff --git a/src/check.ts b/src/check.ts index 5b860f4..6512569 100644 --- a/src/check.ts +++ b/src/check.ts @@ -26,7 +26,7 @@ export async function checkIssues(context: ActionContext) { for (const issue of context.issues) { core.startGroup(`Checking #${issue.number}`); - if (!isSupported(issue)) { + if (!isSupported(config, issue)) { core.info('Unsupported issue or pull request. Skipped'); core.endGroup(); continue; diff --git a/src/context.ts b/src/context.ts index 5a2a751..ab5179c 100644 --- a/src/context.ts +++ b/src/context.ts @@ -15,6 +15,7 @@ export async function getActionContext(): Promise { '', label: core.getInput('label'), check_issues: core.getInput('check_issues'), + ignore_dependabot: core.getInput('ignore_dependabot'), keywords: core .getInput('keywords') .trim() diff --git a/src/support.ts b/src/support.ts index eb1c151..c7b5ae9 100644 --- a/src/support.ts +++ b/src/support.ts @@ -11,6 +11,6 @@ function isDependabotPR(issue: Issue) { return issue.user?.login === 'dependabot[bot]'; } -export function isSupported(issue: Issue) { - return !isDependabotPR(issue); +export function isSupported(config: { ignore_dependabot: string }, issue: Issue) { + return !(config.ignore_dependabot === 'on' && isDependabotPR(issue)); } diff --git a/src/types.ts b/src/types.ts index cc5cbc6..e7363ce 100644 --- a/src/types.ts +++ b/src/types.ts @@ -30,6 +30,7 @@ export type ActionContext = { actionRepoURL: string; label: string; check_issues: string; + ignore_dependabot: string; keywords: string[]; }; };