@@ -206,6 +206,81 @@ describe('Azure DevOps Commit Validator', () => {
206206
207207 expect ( mockSetFailed ) . not . toHaveBeenCalled ( ) ;
208208 } ) ;
209+
210+ it ( 'should fail when link-commits-to-pull-request is true but azure-devops-organization is missing' , async ( ) => {
211+ mockGetInput . mockImplementation ( name => {
212+ const defaults = {
213+ 'check-pull-request' : 'false' ,
214+ 'check-commits' : 'true' ,
215+ 'fail-if-missing-workitem-commit-link' : 'true' ,
216+ 'link-commits-to-pull-request' : 'true' ,
217+ 'azure-devops-token' : 'test-token' ,
218+ 'azure-devops-organization' : '' , // Missing org
219+ 'github-token' : 'github-token' ,
220+ 'comment-on-failure' : 'true' ,
221+ 'validate-work-item-exists' : 'false'
222+ } ;
223+ return defaults [ name ] || '' ;
224+ } ) ;
225+
226+ await run ( ) ;
227+
228+ expect ( mockSetFailed ) . toHaveBeenCalledWith (
229+ 'Azure DevOps organization is required when link-commits-to-pull-request is true'
230+ ) ;
231+ } ) ;
232+
233+ it ( 'should fail when link-commits-to-pull-request is true but azure-devops-token is missing' , async ( ) => {
234+ mockGetInput . mockImplementation ( name => {
235+ const defaults = {
236+ 'check-pull-request' : 'false' ,
237+ 'check-commits' : 'true' ,
238+ 'fail-if-missing-workitem-commit-link' : 'true' ,
239+ 'link-commits-to-pull-request' : 'true' ,
240+ 'azure-devops-token' : '' , // Missing token
241+ 'azure-devops-organization' : 'test-org' ,
242+ 'github-token' : 'github-token' ,
243+ 'comment-on-failure' : 'true' ,
244+ 'validate-work-item-exists' : 'false'
245+ } ;
246+ return defaults [ name ] || '' ;
247+ } ) ;
248+
249+ await run ( ) ;
250+
251+ expect ( mockSetFailed ) . toHaveBeenCalledWith (
252+ 'Azure DevOps token is required when link-commits-to-pull-request is true'
253+ ) ;
254+ } ) ;
255+
256+ it ( 'should pass when link-commits-to-pull-request is false even if azure-devops config is missing' , async ( ) => {
257+ mockGetInput . mockImplementation ( name => {
258+ const defaults = {
259+ 'check-pull-request' : 'false' ,
260+ 'check-commits' : 'true' ,
261+ 'fail-if-missing-workitem-commit-link' : 'true' ,
262+ 'link-commits-to-pull-request' : 'false' , // Linking disabled
263+ 'azure-devops-token' : '' ,
264+ 'azure-devops-organization' : '' ,
265+ 'github-token' : 'github-token' ,
266+ 'comment-on-failure' : 'true' ,
267+ 'validate-work-item-exists' : 'false'
268+ } ;
269+ return defaults [ name ] || '' ;
270+ } ) ;
271+
272+ mockOctokit . paginate . mockResolvedValueOnce ( [
273+ {
274+ sha : '1234567890abcdef' ,
275+ commit : { message : 'Fix: AB#123' }
276+ }
277+ ] ) ;
278+
279+ await run ( ) ;
280+
281+ // Should not call setFailed for missing Azure DevOps config since linking is disabled
282+ expect ( mockSetFailed ) . not . toHaveBeenCalled ( ) ;
283+ } ) ;
209284 } ) ;
210285
211286 describe ( 'Commit validation' , ( ) => {
@@ -1175,7 +1250,7 @@ describe('Azure DevOps Commit Validator', () => {
11751250 } ) ;
11761251
11771252 describe ( 'Edge cases - Work item linking with missing credentials' , ( ) => {
1178- it ( 'should attempt linking without failing when credentials are present ' , async ( ) => {
1253+ it ( 'should fail when linking is enabled but credentials are missing ' , async ( ) => {
11791254 mockGetInput . mockImplementation ( name => {
11801255 if ( name === 'check-commits' ) return 'true' ;
11811256 if ( name === 'check-pull-request' ) return 'false' ;
@@ -1202,8 +1277,12 @@ describe('Azure DevOps Commit Validator', () => {
12021277
12031278 await run ( ) ;
12041279
1205- // Should still call linkWorkItem even with empty credentials
1206- expect ( mockLinkWorkItem ) . toHaveBeenCalled ( ) ;
1280+ // Should fail due to missing Azure DevOps organization
1281+ expect ( mockSetFailed ) . toHaveBeenCalledWith (
1282+ 'Azure DevOps organization is required when link-commits-to-pull-request is true'
1283+ ) ;
1284+ // Should not call linkWorkItem since validation failed
1285+ expect ( mockLinkWorkItem ) . not . toHaveBeenCalled ( ) ;
12071286 } ) ;
12081287 } ) ;
12091288
0 commit comments