Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,84 @@ describe('Azure DevOps Commit Validator', () => {
// Restore context
mockContext.payload.pull_request = originalPR;
});

it('should fail if both check-commits and check-pull-request are false', async () => {
mockGetInput.mockImplementation(name => {
if (name === 'check-commits') return 'false';
if (name === 'check-pull-request') return 'false';
if (name === 'github-token') return 'github-token';
return 'false';
});

await run();

expect(mockSetFailed).toHaveBeenCalledWith(
"At least one of 'check-commits' or 'check-pull-request' must be set to true. Both are currently set to false."
);
});

it('should pass when only check-commits is enabled', async () => {
mockGetInput.mockImplementation(name => {
if (name === 'check-commits') return 'true';
if (name === 'check-pull-request') return 'false';
if (name === 'github-token') return 'github-token';
if (name === 'fail-if-missing-workitem-commit-link') return 'false';
return 'false';
});

mockOctokit.rest.pulls.listCommits.mockResolvedValue({
data: []
});

await run();

expect(mockSetFailed).not.toHaveBeenCalled();
});

it('should pass when only check-pull-request is enabled', async () => {
mockGetInput.mockImplementation(name => {
if (name === 'check-commits') return 'false';
if (name === 'check-pull-request') return 'true';
if (name === 'github-token') return 'github-token';
return 'false';
});

mockOctokit.rest.pulls.get.mockResolvedValue({
data: {
title: 'Test PR AB#123',
body: 'Test body'
}
});

await run();

expect(mockSetFailed).not.toHaveBeenCalled();
});

it('should pass when both checks are enabled', async () => {
mockGetInput.mockImplementation(name => {
if (name === 'check-commits') return 'true';
if (name === 'check-pull-request') return 'true';
if (name === 'github-token') return 'github-token';
if (name === 'fail-if-missing-workitem-commit-link') return 'false';
return 'false';
});

mockOctokit.rest.pulls.listCommits.mockResolvedValue({
data: []
});

mockOctokit.rest.pulls.get.mockResolvedValue({
data: {
title: 'Test PR AB#123',
body: 'Test body'
}
});

await run();

expect(mockSetFailed).not.toHaveBeenCalled();
});
});

describe('Commit validation', () => {
Expand Down
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "azure-devops-work-item-link-enforcer-and-linker",
"version": "3.0.5",
"version": "3.0.6",
"private": true,
"type": "module",
"description": "GitHub Action to enforce that each commit in a pull request be linked to an Azure DevOps work item and automatically link the pull request to each work item ",
Expand Down
8 changes: 8 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ export async function run() {
const commentOnFailure = core.getInput('comment-on-failure') === 'true';
const validateWorkItemExistsFlag = core.getInput('validate-work-item-exists') === 'true';

// Validate that at least one check is enabled
if (!checkPullRequest && !checkCommits) {
core.setFailed(
`At least one of 'check-commits' or 'check-pull-request' must be set to true. Both are currently set to false.`
);
return;
}

// Get context
const context = github.context;
const pullNumber = context.payload.pull_request?.number;
Expand Down