Skip to content

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

Open
joshjohanning wants to merge 12 commits intomainfrom
add-work-item-linkage-from-branch-name
Open

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

Conversation

@joshjohanning
Copy link
Copy Markdown
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 work item IDs from branch names that follow a keyword prefix pattern (e.g. task/12345, bug-67890)
  • New branch-work-item-prefixes input - configurable comma-separated list of keyword prefixes (default: task, bug, bugfix)
  • 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 node24 runtime upgrade and the add-work-item-table feature
  • Sanitized branch name in job summary - backticks in branch names are escaped to prevent markdown injection
  • Synced package.json scripts with standard template (format:write, ci-test, bundle, package:watch, etc.)
  • Added Mandatory Workflow section to copilot-instructions.md for better agent compliance
  • Fixed copilot-instructions.md inaccuracies (getInput() reference, template literal guidance)
  • Fixed ESLint quote errors in tests (double quotes to template literals)

Supported branch formats

Branch name Extracts Notes
task/12345/make-it-better AB#12345 Keyword prefix + separator + ID
task/12345-make-it-better AB#12345 ID ends at non-digit
task-12345 AB#12345 Hyphen separator
task_12345 AB#12345 Underscore separator
bug/12345/task/67890 AB#12345, AB#67890 Multiple IDs supported
users/josh/task/12345/fix AB#12345 Nested after user segment
12345-make-it-better (nothing) No keyword prefix - ignored
hotfix/2024-bugfix (nothing) No keyword prefix - ignored
feature-v2-add-logging (nothing) No keyword prefix - ignored

Design decisions

  • Keyword prefix matching - only matches numbers preceded by a configurable keyword (e.g. task, bug, bugfix) and a separator (/, -, _). This avoids false positives from year-like numbers or version strings in branch names.
  • Prefix boundary checking - hotfix/12345 does NOT match when prefix is fix, because fix in hotfix is preceded by a letter, not a separator or start-of-string
  • validate-work-item-exists is independent - add-work-item-from-branch has validation built in. validate-work-item-exists separately controls whether human-written AB# references in commits/PR body are validated.
  • Branch extraction runs before commit/PR checks - so newly added AB# tags satisfy subsequent check-pull-request validation

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

This comment was marked as outdated.

This comment was marked as outdated.

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

This comment was marked as outdated.

- 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

This comment was marked as outdated.

@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
Copy Markdown
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
Copy Markdown

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

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.
@joshjohanning joshjohanning marked this pull request as ready for review March 29, 2026 15:18
@joshjohanning joshjohanning requested a review from Copilot March 29, 2026 15:18
Copy link
Copy Markdown
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 no new comments.

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

4 participants