* fix: recognize ado:NNNNN shorthand in IsExternalRef and ExtractIdentifier
IsExternalRef and ExtractIdentifier only matched full ADO URLs
(/_workitems/edit/\d+), but BuildExternalRef produces ado:NNNNN
shorthand when org/project config is unavailable. This caused the
sync engine to treat existing beads as new, creating duplicate ADO
work items instead of updating existing ones.
Fixes harry-miller-trimble/beads#28
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: add shorthand ref support to GitHub/GitLab trackers, tighten ado:0
Address PR #2966 review feedback:
- GitHub tracker: add ghShorthandPattern (github:{id}) to IsExternalRef
and ExtractIdentifier, fixing the same duplicate-creation bug as ADO
- GitLab tracker: add glShorthandPattern (gitlab:{id}) to IsExternalRef
and ExtractIdentifier, fixing the same duplicate-creation bug as ADO
- ADO tracker: tighten regex from ^ado:(\d+)$ to ^ado:([1-9]\d*)$ to
reject ado:0 which is invalid in practice
- Add test cases for shorthand format in all three trackers
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Introduce APIError type in client.go that carries the HTTP status code,
replacing fmt.Errorf-based error strings. Update statetransition.go and
reconcile.go to use errors.As instead of strings.Contains for status
code detection, making the error handling robust against message changes.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The WIQL date format string used a literal 'Z' character instead of Go's
proper Z07:00 timezone placeholder. While .UTC() masked the issue for UTC
inputs, the format was fragile — if a non-UTC time were passed without
.UTC(), the output would claim UTC (literal Z) while containing local time.
Changes:
- Extract formatWIQLDate() helper that encapsulates UTC conversion + RFC3339
formatting, making it impossible to forget either step
- Replace inline format string in buildPullWIQLMulti() with the new helper
- Fix same pattern in mol_last_activity.go (display output)
- Add TestFormatWIQLDate with 7 cases: UTC, non-UTC offsets, nanosecond
truncation, day boundary rollovers, and Z-suffix invariant assertion
- Add non-UTC test case to TestBuildPullWIQL for end-to-end coverage
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When pushing issues to ADO, CreateIssue now handles non-initial states
(e.g., Closed, Active, Resolved) by:
1. Stripping the target state from creation fields when it is not a
valid initial state (New, To Do, Proposed)
2. Creating the work item without specifying state (ADO assigns default)
3. Transitioning to the target state via UpdateWorkItem — first tries
a direct update, then walks through known intermediate states if
the direct transition is rejected (400)
Includes default transition paths for Agile, Scrum, and CMMI process
templates covering Bug, Task, User Story, Epic, Feature, Issue, PBI,
and Requirement work item types.
Fixes: bd-cl7
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ADO Bug work items require a Severity field (Microsoft.VSTS.Common.Severity),
but bd ado sync --push-only was not setting it, causing TF401320 rule errors.
Changes:
- Add FieldSeverity constant for Microsoft.VSTS.Common.Severity
- Add SeverityForBug() to map beads priority to ADO severity values:
P0→"1 - Critical", P1→"2 - High", P2→"3 - Medium", P3/P4→"4 - Low"
- Set Severity in IssueToTracker only for Bug-type work items
- Preserve severity in metadata for round-trip fidelity (pull→push)
- Metadata-restored severity takes precedence over computed value
Fixes: bd-4ju
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Apply the same fix as the Jira client: only add jitter to our own
exponential backoff delays, not to server-mandated Retry-After values.
Adding jitter to Retry-After could violate rate limit contracts by
waiting less than the server-specified duration.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
TestTracker_InitMissingPAT, InitMissingOrg, and InitMissingProject were
not isolating from environment variables. When AZURE_DEVOPS_PAT is set
in the environment (common in CI and dev), getConfig falls through to
os.Getenv and the PAT check passes, causing the test to hit the org
validation instead and fail.
Fix: Use t.Setenv to clear all ADO env vars in tests that assert
specific missing-config errors. t.Setenv automatically restores the
original values after the test.
Fixes: bd-czk
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ExtractLinkDeps stored bare numeric IDs (e.g., "123") in
FromExternalID/ToExternalID, but the sync engine's createDependencies
looks up issues via GetIssueByExternalRef which expects full web URLs
(e.g., "https://dev.azure.com/org/proj/_workitems/edit/123").
The mismatch caused all dependency lookups to return nil, silently
skipping every dependency creation. After pulling 800+ ADO items,
dependency_count was 0 for all beads.
Fix: Use buildExternalRef (for the source work item) and a new
apiURLToWebURL helper (for relation target URLs) to produce web URLs
that match the external_ref format stored in the database.
Jira has a separate gap: its IssueToBeads returns no Dependencies at
all (the fieldmapper is hardcoded with no link extraction). That needs
its own fix since Jira link types differ from ADO.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
readMappingConfig used a hardcoded key list (bug, feature, task, epic,
chore) which silently dropped custom types like "story". Users who
set ado.type_map.story="User Story" with types.custom=story would
still see User Stories mapped to "feature" on pull because the config
was never loaded.
Jira had the same bug but worse: jira.type_map.* was documented in
CONFIG.md but the fieldmapper was entirely hardcoded with no config
reading at all.
Fix for both trackers:
- ADO: Replace readMappingConfig (hardcoded key list) with
readMappingConfigByPrefix (prefix scan via GetAllConfig), matching
the pattern Jira already uses for status_map
- Jira: Add typeMap field to fieldmapper, load jira.type_map.* keys
via the same GetAllConfig prefix scan used for jira.status_map.*,
and check custom map before hardcoded defaults in TypeToBeads/
TypeToTracker
Linear and GitHub trackers are not affected — they already use
dynamic config loading for type mappings.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add the internal/ado package implementing tracker.IssueTracker for Azure
DevOps. Provides bidirectional work item sync via the ADO REST API.
Core components:
- types.go: ADO API types, SecretString with redaction, field constants
- client.go: HTTP client with Basic auth, retry, WIQL query builder
- fieldmapper.go: configurable status/type/priority mapping
- mapping.go: bidirectional IssueToBeads/IssueToTracker conversion
- richtext.go: HTML<>Markdown conversion (goldmark + bluemonday)
- tracker.go: tracker.IssueTracker implementation with init() registration
- bootstrap.go: 4-tier deduplication for first sync
- reconcile.go: deletion detection via periodic reconciliation scan
- links.go: bidirectional link sync with direction normalization
Includes full test suite (218 tests, 92.8% coverage).
Fixes applied during fix-merge:
- errors.New() → fmt.Errorf() to match project conventions (6 instances)
- Added gosec nolint for configured API endpoint SSRF false positive
Co-Authored-By: Harry Miller <harry_miller@trimble.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>