Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
feat: allow Dependabot handling to be configured (#227)
Browse files Browse the repository at this point in the history
Co-authored-by: z0al <ah.tajelsir@gmail.com>

Signed-off-by: Stephen Kitt <skitt@redhat.com>
  • Loading branch information
skitt authored Aug 26, 2021
1 parent 1b1f914 commit eaef15f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
25 changes: 22 additions & 3 deletions src/__tests__/support.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
2 changes: 1 addition & 1 deletion src/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export async function getActionContext(): Promise<ActionContext> {
'<!-- By Dependent Issues (Action) - DO NOT REMOVE -->',
label: core.getInput('label'),
check_issues: core.getInput('check_issues'),
ignore_dependabot: core.getInput('ignore_dependabot'),
keywords: core
.getInput('keywords')
.trim()
Expand Down
4 changes: 2 additions & 2 deletions src/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type ActionContext = {
actionRepoURL: string;
label: string;
check_issues: string;
ignore_dependabot: string;
keywords: string[];
};
};

0 comments on commit eaef15f

Please sign in to comment.