You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add pull-request-check-scope input to control where AB# is checked (#149)
* feat: add `pull-request-check-scope` input to control where AB# is checked
closes#146
* chore: update package-lock.json
* fix: align descriptions and defaults for check-pull-request across action.yml, README, and JSDoc
| `check-pull-request` | Check the pull request body and title for `AB#xxx` | `true` | `true` |
68
+
| `check-pull-request` | Check the pull request for `AB#xxx` (scope configurable via `pull-request-check-scope`) | `true` | `false` |
69
+
| `pull-request-check-scope` | Only if `check-pull-request=true`, where to look for `AB#` in the PR: `title-or-body`, `body-only`, or `title-only` | `false` | `title-or-body` |
69
70
| `check-commits` | Check each commit in the pull request for `AB#xxx` | `true` | `true` |
70
71
| `fail-if-missing-workitem-commit-link` | Only if `check-commits=true`, fail the action if a commit in the pull request is missing AB# in every commit message | `false` | `true` |
71
72
| `link-commits-to-pull-request` | Only if `check-commits=true`, link the work items found in commits to the pull request | `false` | `true` |
"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 ",
`Invalid value '${pullRequestCheckScopeRaw}' for 'pull-request-check-scope'. Using default 'title-or-body'. Valid values are: ${validScopes.join(', ')}`
51
+
);
52
+
}
53
+
42
54
// Validate that at least one check is enabled
43
55
if(!checkPullRequest&&!checkCommits){
44
56
core.setFailed(
@@ -108,7 +120,8 @@ export async function run() {
108
120
validateWorkItemExistsFlag,
109
121
azureDevopsOrganization,
110
122
azureDevopsToken,
111
-
workItemToCommitMap
123
+
workItemToCommitMap,
124
+
pullRequestCheckScope
112
125
);
113
126
}
114
127
@@ -415,7 +428,8 @@ async function checkCommitsForWorkItems(
415
428
* @param {string} azureDevopsOrganization - Azure DevOps organization name
416
429
* @param {string} azureDevopsToken - Azure DevOps PAT token
417
430
* @param {Map} workItemToCommitMap - Map of work item IDs to commit info from checkCommitsForWorkItems
418
-
* @returns {Array} Returns array of invalid work item IDs found in PR title/body
431
+
* @param {string} pullRequestCheckScope - Where to look for AB# in the PR: 'title-or-body', 'body-only', or 'title-only'
432
+
* @returns {Array} Returns array of invalid work item IDs found in the PR based on pullRequestCheckScope
419
433
*/
420
434
asyncfunctioncheckPullRequestForWorkItems(
421
435
octokit,
@@ -425,7 +439,8 @@ async function checkPullRequestForWorkItems(
425
439
validateWorkItemExistsFlag,
426
440
azureDevopsOrganization,
427
441
azureDevopsToken,
428
-
workItemToCommitMap
442
+
workItemToCommitMap,
443
+
pullRequestCheckScope='title-or-body'
429
444
){
430
445
const{ owner, repo }=context.repo;
431
446
@@ -439,11 +454,32 @@ async function checkPullRequestForWorkItems(
439
454
constpullBody=pullRequest.data.body||'';
440
455
constpullTitle=pullRequest.data.title||'';
441
456
457
+
// Determine which text to check based on pull-request-check-scope
458
+
lettextToCheck;
459
+
letscopeDescription;
460
+
switch(pullRequestCheckScope){
461
+
case'body-only':
462
+
textToCheck=pullBody;
463
+
scopeDescription='body';
464
+
break;
465
+
case'title-only':
466
+
textToCheck=pullTitle;
467
+
scopeDescription='title';
468
+
break;
469
+
case'title-or-body':
470
+
default:
471
+
textToCheck=`${pullTitle}${pullBody}`;
472
+
scopeDescription='title or body';
473
+
break;
474
+
}
475
+
476
+
core.info(`Checking PR ${scopeDescription} for work item links (scope: ${pullRequestCheckScope})`);
477
+
442
478
// Define common comment text patterns
443
479
constFAILURE_COMMENT_TEXT=':x: This pull request is not linked to a work item.';
444
480
constSUCCESS_COMMENT_TEXT=':white_check_mark: This pull request is now linked to a work item.';
445
481
446
-
if(!AB_PATTERN.test(`${pullTitle}${pullBody}`)){
482
+
if(!AB_PATTERN.test(textToCheck)){
447
483
core.info('PR not linked to a work item');
448
484
core.error(
449
485
`Pull Request not linked to work item(s): The pull request #${pullNumber} is not linked to any work item(s)`
@@ -455,7 +491,7 @@ async function checkPullRequestForWorkItems(
455
491
octokit,
456
492
context,
457
493
pullNumber,
458
-
`${FAILURE_COMMENT_TEXT} Please update the title or body to include a work item and re-run the failed job to continue. Any new commits to the pull request will also re-run the job.`,
494
+
`${FAILURE_COMMENT_TEXT} Please update the ${scopeDescription} to include a work item and re-run the failed job to continue. Any new commits to the pull request will also re-run the job.`,
459
495
FAILURE_COMMENT_TEXT
460
496
);
461
497
}
@@ -489,8 +525,8 @@ async function checkPullRequestForWorkItems(
489
525
core.info('... PR comment updated to success');
490
526
}
491
527
492
-
// Extract work items from PR body and title and validate they exist
0 commit comments