Commit 01e0ab6
authored
feat: add automatic AB# tagging from branch name (#152)
* feat: add automatic AB# tagging from branch name
Add new `add-ab-tag-from-branch` input that extracts work item IDs from
the head branch name and appends AB#xxx to the PR body if not already
present. Supports common branch formats like task/12345/description,
task-12345, 12345-description, and more.
closes #151
* refactor: rename add-ab-tag-from-branch to add-work-item-from-branch
* docs: update description for add-work-item-from-branch input to clarify usage with check-pull-request
* feat: enhance work item extraction from branch names to match only 3+ digit IDs and update related documentation
* feat!: require Azure DevOps validation for branch work item extraction
- add-work-item-from-branch now requires azure-devops-token and
azure-devops-organization; extracted IDs are always validated against
Azure DevOps before being added to the PR body
- Remove 3-digit minimum from branch regex since validation catches
false positives
- Sanitize branch name in job summary to prevent markdown injection
- Fix JSDoc param type for extractWorkItemIdsFromBranch
- Clean up dangling append-work-item-title test references
- Add tests for validation of branch-extracted IDs and missing token
* fix: address PR review findings for branch extraction
- Fix GHAS incomplete string escaping: escape backslashes in branchName
- Allow add-work-item-from-branch as standalone (update guard condition)
- Cap branch ID extraction at 5 to limit API calls
- Fix misleading azure-devops-token/organization descriptions in README
- Add test for standalone branch extraction usage
* chore: bump version to 4.1.0 in package.json
* feat: restrict branch work item extraction to keyword prefixes
Only extract work item IDs from branch names when they follow a
recognized keyword prefix (e.g. task/12345, bug-67890) instead of
matching any bare number. This prevents false positives from
year-like numbers or version segments in branch names.
Add configurable `branch-work-item-prefixes` input (default:
task, bug, bugfix) so users can customize the keyword list.
Resolves the false positive concern raised in #151.
* fix: revert version number to 4.1.0 in package.json
* fix: update coverage percentage in coverage.svg to 87.09%
* fix: handle validateWorkItemExists object return in branch tagging path
The branch-tagging validation loop was treating the return value of
validateWorkItemExists() as a boolean, but it returns an object
({ exists, authError?, errorMessage? }). This meant auth errors were
silently swallowed and invalid work items could be incorrectly added.
- Check result.exists and result.authError consistently with other
call sites
- Update test mocks to return { exists: true/false } objects
- Add test for auth error during branch work item validation
* feat: reduce false positives in branch work item extraction
Add three safeguards against incorrect work item linking from branch names:
1. Date pattern exclusion - numbers followed by date-like patterns
(e.g. 2024-01-15) are automatically rejected
2. First-segment-only matching - keywords must appear at the start of
the branch or after a path separator (/), preventing keywords in
description segments from triggering extraction (e.g. fix-bug-67890)
3. Configurable minimum digits - new branch-work-item-min-digits input
lets users filter out short numbers (years, versions, etc.)
Add dedicated "Auto-Tag from Branch Name" section to README with
examples table showing what matches and what does not.
* refactor: deduplicate escapeRegExp and validate empty prefixes
- Move escapeRegExp() above buildBranchWorkItemPattern() and reuse it
instead of duplicating the regex escape logic
- Fail fast with a clear error when add-work-item-from-branch is enabled
but branch-work-item-prefixes is empty
* fix: reset AB_PATTERN.lastIndex before .test() calls
The module-level AB_PATTERN regex has the /g flag, which causes
.test() to advance lastIndex after each match. In a loop over
multiple commits, this can cause false negatives when the next
string's AB# reference appears before the stale lastIndex position.
Reset lastIndex to 0 before each .test() call in both the commit
validation loop and the PR validation path.
* docs: fix permissions wording in README github-token description
* docs: fix permissions wording in action.yml github-token description
* chore: linting
* docs: update azure-devops-token and azure-devops-organization descriptions in action.yml
* test: clarify test name for branch work item validation
* chore: change branch-work-item-min-digits default from 1 to 51 parent b4b2805 commit 01e0ab6
7 files changed
Lines changed: 838 additions & 34 deletions
File tree
- __tests__
- badges
- src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
85 | 127 | | |
86 | 128 | | |
87 | 129 | | |
| |||
0 commit comments