Skip to content

feat: add automatic AB# tagging from branch name#152

Draft
joshjohanning wants to merge 8 commits intomainfrom
add-work-item-linkage-from-branch-name
Draft

feat: add automatic AB# tagging from branch name#152
joshjohanning wants to merge 8 commits intomainfrom
add-work-item-linkage-from-branch-name

Conversation

@joshjohanning
Copy link
Owner

@joshjohanning joshjohanning commented Mar 6, 2026

Summary

Add new add-work-item-from-branch input that extracts work item IDs from the head branch name and adds AB#xxx to the PR body if not already present. Each extracted ID is validated against Azure DevOps before being added, preventing false positives from version numbers or other numeric patterns in branch names.

Resolves #151

Changes

  • New add-work-item-from-branch input -- extracts digit sequences from branch names preceded by a separator (/, -, _) or start of string
  • Always validates extracted IDs -- requires azure-devops-token and azure-devops-organization; each ID is checked against Azure DevOps and only valid work items are added to the PR body. Invalid IDs are skipped with a warning.
  • Merged with main -- includes the breaking node20 to node24 runtime upgrade, and the add-work-item-table feature (which replaced the old append-work-item-title input)
  • Sanitized branch name in job summary -- backticks in branch names are escaped to prevent markdown injection
  • Cleaned up dangling append-work-item-title references from test mocks

Supported branch formats

Branch name Extracted
task/12345/make-it-better AB#12345
task/12345-make-it-better AB#12345
task/12345 AB#12345
task-12345 AB#12345
12345-make-it-better AB#12345
12345make-it-better AB#12345
12345 AB#12345

Multiple IDs in a single branch name are also supported (e.g. fix/12345/67890 adds both AB#12345 and AB#67890), and IDs already referenced in the PR body are skipped.

Design decisions

  • No digit-length minimum on the regex -- since every extracted ID is validated against Azure DevOps, there's no need for an arbitrary 3+ digit floor. Numbers like 2024 from hotfix-2024-something are safely filtered out by the Azure DevOps validation.
  • validate-work-item-exists is independent -- add-work-item-from-branch has validation built in (it must confirm numbers are real work items). validate-work-item-exists separately controls whether human-written AB# references in commits/PR body are validated. These are separate concerns; a user can enable branch extraction while trusting manually-written references.
  • Branch extraction runs before commit/PR checks -- so newly added AB# tags satisfy subsequent check-pull-request validation.

Usage

- uses: joshjohanning/azdo_commit_message_validator@v4
  with:
    add-work-item-from-branch: true
    check-pull-request: true
    check-commits: true
    fail-if-missing-workitem-commit-link: true
    link-commits-to-pull-request: true
    azure-devops-organization: my-azdo-org
    azure-devops-token: ${{ secrets.AZURE_DEVOPS_PAT }}

Test coverage

  • Unit tests for extractWorkItemIdsFromBranch (various branch formats, duplicates, empty input, short numbers)
  • Integration tests for the full flow (add tag, skip existing, empty body, multiple IDs, partial existing)
  • Tests for validation: skip invalid IDs, skip all if none valid, fail if token/org missing
  • 105 tests passing

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
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements a new add-ab-tag-from-branch input that automatically extracts Azure DevOps work item IDs from the head branch name and appends the corresponding AB#xxx tags to the PR body if not already present. This addresses feature request #151 from users who want branch names like task/12345/fix-bug to automatically populate the PR body with AB#12345.

Changes:

  • New add-work-item-from-branch input and its extraction/update logic (extractWorkItemIdsFromBranch, addWorkItemsToPRBody functions)
  • Comprehensive test suite covering happy path, duplicate prevention, empty body, multiple IDs, and disabled scenarios
  • Documentation updates (README, action.yml) and version bump to 3.3.0

Reviewed changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/index.js Core implementation: new regex pattern, extractWorkItemIdsFromBranch export, addWorkItemsToPRBody async function, and wiring into run()
__tests__/index.test.js Unit tests for extractWorkItemIdsFromBranch and integration tests for Add AB# tag from branch scenarios
action.yml New add-work-item-from-branch input declaration
README.md New feature listed in Key Features, new row in the Inputs table
package.json / package-lock.json Minor version bump to 3.3.0
badges/coverage.svg Updated coverage badge from 85.12% to 86.26%

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 7 changed files in this pull request and generated 3 comments.


You can also share your feedback on Copilot code review. Take the survey.

@joshjohanning joshjohanning requested a review from Copilot March 18, 2026 19:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.


You can also share your feedback on Copilot code review. Take the survey.

- 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
@joshjohanning joshjohanning requested a review from Copilot March 18, 2026 19:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.


You can also share your feedback on Copilot code review. Take the survey.

@joshjohanning joshjohanning marked this pull request as draft March 18, 2026 19:59
- 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
@joshjohanning
Copy link
Owner Author

joshjohanning commented Mar 18, 2026

Moving this back to draft while I work through the false positive problem with branch name extraction.

The core issue: extracting bare numbers from branch names (e.g. task/12345/fix-bug) and treating them as work item IDs will inevitably produce false positives. Numbers like 2024 from hotfix-2024-bugfix can match real work items in Azure DevOps, so validation alone doesn't solve it -- it just confirms the work item exists, not that the branch intended to reference it.

The 3-digit minimum helps with very short numbers (v2, release-1-2-3) but doesn't help with year-like numbers or other common numeric patterns in branch names.

Still thinking through the best approach here. Some options under consideration:

  • Requiring a specific prefix pattern (e.g. only match numbers after task/, bug/, feature/, etc.)
  • Making the minimum digit count configurable
  • Accepting the trade-off and documenting the known limitation clearly

Will update once I have a cleaner solution.

cc @davetevans

@davetevans
Copy link

I would vote for the prefix pattern matching task/, bug/ etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatically add AB# tag from id in source branch

3 participants