Skip to content

Commit c90924c

Browse files
feat: validate that at least one check is enabled (#95)
* chore: empty commit to sync branch * feat: validate that at least one check is enabled Add validation to ensure at least one of 'check-commits' or 'check-pull-request' is enabled. If both are set to false, the action will fail with a clear error message. Changes: - Add validation check in src/index.js (lines 42-48) - Add 4 comprehensive test cases in __tests__/index.test.js - All 55 JavaScript tests + 29 bash tests passing Co-authored-by: joshjohanning <19912012+joshjohanning@users.noreply.github.com> * chore: bump version to 3.0.6 * fix: improve error message for validation checks * fix: update coverage percentage in SVG badge --------- Co-authored-by: Josh Johanning <joshjohanning@github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: joshjohanning <19912012+joshjohanning@users.noreply.github.com>
1 parent 7d11951 commit c90924c

5 files changed

Lines changed: 90 additions & 4 deletions

File tree

__tests__/index.test.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,84 @@ describe('Azure DevOps Commit Validator', () => {
128128
// Restore context
129129
mockContext.payload.pull_request = originalPR;
130130
});
131+
132+
it('should fail if both check-commits and check-pull-request are false', async () => {
133+
mockGetInput.mockImplementation(name => {
134+
if (name === 'check-commits') return 'false';
135+
if (name === 'check-pull-request') return 'false';
136+
if (name === 'github-token') return 'github-token';
137+
return 'false';
138+
});
139+
140+
await run();
141+
142+
expect(mockSetFailed).toHaveBeenCalledWith(
143+
"At least one of 'check-commits' or 'check-pull-request' must be set to true. Both are currently set to false."
144+
);
145+
});
146+
147+
it('should pass when only check-commits is enabled', async () => {
148+
mockGetInput.mockImplementation(name => {
149+
if (name === 'check-commits') return 'true';
150+
if (name === 'check-pull-request') return 'false';
151+
if (name === 'github-token') return 'github-token';
152+
if (name === 'fail-if-missing-workitem-commit-link') return 'false';
153+
return 'false';
154+
});
155+
156+
mockOctokit.rest.pulls.listCommits.mockResolvedValue({
157+
data: []
158+
});
159+
160+
await run();
161+
162+
expect(mockSetFailed).not.toHaveBeenCalled();
163+
});
164+
165+
it('should pass when only check-pull-request is enabled', async () => {
166+
mockGetInput.mockImplementation(name => {
167+
if (name === 'check-commits') return 'false';
168+
if (name === 'check-pull-request') return 'true';
169+
if (name === 'github-token') return 'github-token';
170+
return 'false';
171+
});
172+
173+
mockOctokit.rest.pulls.get.mockResolvedValue({
174+
data: {
175+
title: 'Test PR AB#123',
176+
body: 'Test body'
177+
}
178+
});
179+
180+
await run();
181+
182+
expect(mockSetFailed).not.toHaveBeenCalled();
183+
});
184+
185+
it('should pass when both checks are enabled', async () => {
186+
mockGetInput.mockImplementation(name => {
187+
if (name === 'check-commits') return 'true';
188+
if (name === 'check-pull-request') return 'true';
189+
if (name === 'github-token') return 'github-token';
190+
if (name === 'fail-if-missing-workitem-commit-link') return 'false';
191+
return 'false';
192+
});
193+
194+
mockOctokit.rest.pulls.listCommits.mockResolvedValue({
195+
data: []
196+
});
197+
198+
mockOctokit.rest.pulls.get.mockResolvedValue({
199+
data: {
200+
title: 'Test PR AB#123',
201+
body: 'Test body'
202+
}
203+
});
204+
205+
await run();
206+
207+
expect(mockSetFailed).not.toHaveBeenCalled();
208+
});
131209
});
132210

133211
describe('Commit validation', () => {

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "azure-devops-work-item-link-enforcer-and-linker",
3-
"version": "3.0.5",
3+
"version": "3.0.6",
44
"private": true,
55
"type": "module",
66
"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 ",

src/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ export async function run() {
3939
const commentOnFailure = core.getInput('comment-on-failure') === 'true';
4040
const validateWorkItemExistsFlag = core.getInput('validate-work-item-exists') === 'true';
4141

42+
// Validate that at least one check is enabled
43+
if (!checkPullRequest && !checkCommits) {
44+
core.setFailed(
45+
`At least one of 'check-commits' or 'check-pull-request' must be set to true. Both are currently set to false.`
46+
);
47+
return;
48+
}
49+
4250
// Get context
4351
const context = github.context;
4452
const pullNumber = context.payload.pull_request?.number;

0 commit comments

Comments
 (0)