Skip to content

Commit edec350

Browse files
committed
feat: enhance work item extraction from branch names to match only 3+ digit IDs and update related documentation
1 parent c8c6c63 commit edec350

4 files changed

Lines changed: 31 additions & 17 deletions

File tree

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,20 @@ jobs:
6464
6565
### Inputs
6666
67-
| Name | Description | Required | Default |
68-
| -------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | --------------------- |
69-
| `check-pull-request` | Check the pull request for `AB#xxx` (scope configurable via `pull-request-check-scope`) | `true` | `false` |
70-
| `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` |
71-
| `check-commits` | Check each commit in the pull request for `AB#xxx` | `true` | `true` |
72-
| `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` |
73-
| `link-commits-to-pull-request` | Only if `check-commits=true`, link the work items found in commits to the pull request | `false` | `true` |
74-
| `validate-work-item-exists` | Validate that the work item(s) referenced in commits and PR exist in Azure DevOps (requires `azure-devops-token` and `azure-devops-organization`) | `false` | `true` |
75-
| `append-work-item-title` | Append the work item title to `AB#xxx` references in the PR body (e.g. `AB#123` becomes `AB#123 - Fix bug`). Requires `azure-devops-token` and `azure-devops-organization` | `false` | `false` |
76-
| `add-work-item-from-branch` | Automatically extract work item ID(s) from the head branch name and add `AB#xxx` to the PR body if not already present. Best used with `check-pull-request=true` | `false` | `false` |
77-
| `azure-devops-organization` | Only if `check-commits=true`, link the work items found in commits to the pull request | `false` | `''` |
78-
| `azure-devops-token` | Only required if `link-commits-to-pull-request=true`, Azure DevOps PAT used to link work item to PR (needs to be a `full` PAT) | `false` | `''` |
79-
| `github-token` | The GitHub token that has contents-read and pull_request-write access | `true` | `${{ github.token }}` |
80-
| `comment-on-failure` | Comment on the pull request if the action fails | `true` | `true` |
67+
| Name | Description | Required | Default |
68+
| -------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | --------------------- |
69+
| `check-pull-request` | Check the pull request for `AB#xxx` (scope configurable via `pull-request-check-scope`) | `true` | `false` |
70+
| `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` |
71+
| `check-commits` | Check each commit in the pull request for `AB#xxx` | `true` | `true` |
72+
| `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` |
73+
| `link-commits-to-pull-request` | Only if `check-commits=true`, link the work items found in commits to the pull request | `false` | `true` |
74+
| `validate-work-item-exists` | Validate that the work item(s) referenced in commits and PR exist in Azure DevOps (requires `azure-devops-token` and `azure-devops-organization`) | `false` | `true` |
75+
| `append-work-item-title` | Append the work item title to `AB#xxx` references in the PR body (e.g. `AB#123` becomes `AB#123 - Fix bug`). Requires `azure-devops-token` and `azure-devops-organization` | `false` | `false` |
76+
| `add-work-item-from-branch` | Automatically extract work item ID(s) from the head branch name and add `AB#xxx` to the PR body if not already present. Only matches 3+ digit IDs. Requires `check-pull-request` or `check-commits` to also be enabled | `false` | `false` |
77+
| `azure-devops-organization` | Only if `check-commits=true`, link the work items found in commits to the pull request | `false` | `''` |
78+
| `azure-devops-token` | Only required if `link-commits-to-pull-request=true`, Azure DevOps PAT used to link work item to PR (needs to be a `full` PAT) | `false` | `''` |
79+
| `github-token` | The GitHub token that has contents-read and pull_request-write access | `true` | `${{ github.token }}` |
80+
| `comment-on-failure` | Comment on the pull request if the action fails | `true` | `true` |
8181

8282
## Screenshots
8383

__tests__/index.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,6 +2244,20 @@ describe('Azure DevOps Commit Validator', () => {
22442244
expect(extractWorkItemIdsFromBranch(null)).toEqual([]);
22452245
expect(extractWorkItemIdsFromBranch(undefined)).toEqual([]);
22462246
});
2247+
2248+
it('should ignore short numbers to avoid false positives from version numbers', () => {
2249+
expect(extractWorkItemIdsFromBranch('feature-v2-add-logging')).toEqual([]);
2250+
expect(extractWorkItemIdsFromBranch('release-1-2-3')).toEqual([]);
2251+
expect(extractWorkItemIdsFromBranch('hotfix/v3')).toEqual([]);
2252+
});
2253+
2254+
it('should match exactly 3 digit IDs', () => {
2255+
expect(extractWorkItemIdsFromBranch('task/123/fix')).toEqual(['123']);
2256+
});
2257+
2258+
it('should ignore 2-digit numbers but match longer ones in same branch', () => {
2259+
expect(extractWorkItemIdsFromBranch('hotfix/2024-bugfix')).toEqual(['2024']);
2260+
});
22472261
});
22482262

22492263
describe('Add AB# tag from branch', () => {

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ inputs:
4949
required: false
5050
default: 'false'
5151
add-work-item-from-branch:
52-
description: 'Automatically extract work item ID(s) from the head branch name and add AB#xxx to the PR body if not already present (e.g. branch task/12345/fix-bug adds AB#12345 to the PR body). Best used with check-pull-request=true.'
52+
description: 'Automatically extract work item ID(s) from the head branch name and add AB#xxx to the PR body if not already present (e.g. branch task/12345/fix-bug adds AB#12345 to the PR body). Only matches IDs with 3+ digits to avoid false positives from version numbers. Requires check-pull-request or check-commits to also be enabled.'
5353
required: false
5454
default: 'false'
5555

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import { run as linkWorkItem, validateWorkItemExists, getWorkItemTitle } from '.
1515
/** Regex pattern to match Azure DevOps work item references (AB#123) */
1616
const AB_PATTERN = /AB#[0-9]+/gi;
1717

18-
/** Regex pattern to extract work item IDs from branch names (digit sequences preceded by start or separator) */
19-
const BRANCH_WORK_ITEM_PATTERN = /(?:^|[/\-_])(\d+)/g;
18+
/** Regex pattern to extract work item IDs from branch names (3+ digit sequences preceded by start or separator) */
19+
const BRANCH_WORK_ITEM_PATTERN = /(?:^|[/\-_])(\d{3,})/g;
2020

2121
/** HTML comment markers for identifying different validation scenarios */
2222
export const COMMENT_MARKERS = {

0 commit comments

Comments
 (0)