Commit graph

27 commits

Author SHA1 Message Date
Harry Miller
33cab03193
fix: recognize ado:NNNNN shorthand in IsExternalRef and ExtractIdentifier (#2966)
* 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>
2026-04-02 19:20:30 -07:00
Harry
2cd88e9426 fix: address PR review feedback
- Jira: reset body reader at top of retry loop (not just in retriable
  branch) so POST/PUT retries after network errors don't send empty bodies
- GitLab: add useServerDelay pattern matching other clients; skip jitter
  for server-mandated Retry-After delays
- Sanitize: replace custom decodeRune with stdlib utf8.DecodeRuneInString
- Ready --explain: log warnings instead of silently swallowing errors from
  GetDependencyCounts, GetDependencyRecordsForIssues, DetectCycles,
  GetIssuesByIDs
- Linear: fix pagination off-by-one; check page limit before processing
  instead of after, preventing MaxPages+1 fetches
2026-03-30 09:15:55 -07:00
Harry
860ef5969b lint: suppress gosec G404 for retry jitter (math/rand is fine for backoff)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-30 09:15:53 -07:00
Harry
00b78da749 Add retry logic to Jira client and jitter to all tracker HTTP clients
- Add retry with exponential backoff to Jira doRequest (was single-attempt)
- Add MaxRetries, RetryDelay, MaxResponseSize constants to jira/types.go
- Add response body size limit via io.LimitReader to Jira client
- Handle permanent errors (400/401/403/404) without retry
- Parse Retry-After header for rate-limited responses
- Add jitter (0-50% of delay) to backoff in all 5 tracker clients:
  GitHub, GitLab, Linear, ADO, and Jira
- Guard rand.Int64N against zero delay to prevent panics
- Add retry tests: 429, 503, no-retry-on-400, max-retries-exceeded

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-30 09:11:19 -07:00
Kyriakos Toulgaridis
9dc3264663
feat: add optional group-level GitLab issue sync (PR #2801)
* feat: add optional group-level GitLab issue sync (be-711)

When gitlab.group_id is configured, FetchIssues and FetchIssuesSince
use the /groups/:id/issues API endpoint to aggregate issues across all
projects in the group. Issue creation still uses the project endpoint
(via gitlab.project_id or gitlab.default_project_id).

New config keys:
- gitlab.group_id / GITLAB_GROUP_ID
- gitlab.default_project_id / GITLAB_DEFAULT_PROJECT_ID

Backward compatible: existing project-level sync is unchanged when
group_id is not set.

* feat: add filtering support to GitLab group sync (be-4js)

Add optional filters for labels, project, milestone, and assignee to
the GitLab issue sync. Filters work on both project and group endpoints.

Filters can be set via config (gitlab.filter_labels, etc.), environment
variables (GITLAB_FILTER_LABELS, etc.), or CLI flags (--label, --project,
--milestone, --assignee). CLI flags override config defaults.

Labels, milestone, and assignee are passed as GitLab API query params.
Project filtering within a group is done client-side since the GitLab
group issues API doesn't support it natively.
2026-03-26 19:31:45 -07:00
jane
af4caf0573 test: add tests for 5xx retry and delete cache invalidation
- TestServerErrorRetry: verifies 500/502/503/504 are retried with backoff
- TestNonRetriableError: verifies 403 is NOT retried
- TestDeleteIssue_InvalidatesBlockedCache: verifies single delete clears cache
- TestDeleteIssues_InvalidatesBlockedCache: verifies batch delete clears cache
- Update TestFetchIssuesSince_Error with short timeout (500s now retried)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 09:59:20 -08:00
jane
d24890369d fix: retry GitLab API requests on 5xx server errors
Extend the existing 429 rate-limit retry logic to also cover transient
server errors (500, 502, 503, 504) with the same exponential backoff.
GitLab occasionally returns 5xx during maintenance or load spikes; these
are safe to retry.

Co-Authored-By: iliev01 <31753916+iliev01@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 09:59:20 -08:00
Steven Syrek
634bf5d4a0 refactor(storage): define Storage interface, decouple from concrete DoltStore (bd-l3o)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 10:11:08 +01:00
beads/crew/emma
a5da57e39b refactor: remove storage factory, memory backend, and provider abstraction (Phase 7)
Strip out the multi-backend storage layer: factory pattern, memory/in-memory
provider, connection string parsing, local provider, and associated tests.
Inline Dolt as the sole storage backend. Part of Dolt-Native Beads v2 epic.

WIP - SQLite removal in progress, more cleanup phases to follow.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Executed-By: beads/crew/emma
Rig: beads
Role: crew
2026-02-15 11:27:39 -08:00
jasper
619f34a441 chore: add explanatory comments to silently ignored errors across codebase
Code health review found 30+ instances of error suppression using blank
identifier without explanation. Added comments to 82 files explaining WHY
each error is safely ignored (best-effort cleanup, advisory operations,
safe defaults, etc.) to improve code maintainability.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Executed-By: beads/polecats/jasper
Rig: beads
Role: polecats
2026-02-14 17:16:43 -08:00
beads/crew/emma
3c45dcbde4 refactor: inline tracker adapters into internal packages
Move IssueTracker implementations from internal/tracker/adapters/{linear,gitlab}/
directly into internal/{linear,gitlab}/ and create a new minimal Jira tracker.
Each package now registers itself via init(), eliminating the adapter indirection
layer. Delete the adapters/ directory entirely.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Executed-By: beads/crew/emma
Rig: beads
Role: crew
2026-02-14 16:18:37 -08:00
beads/crew/lizzy
2bb827facb style: run gofmt across entire codebase (bd-nmk12)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 19:35:20 -08:00
beads/crew/lizzy
fade5297ae chore: unexport 12 dead symbols in internal/gitlab
Unexport package-internal symbols with no external callers:
- IsValidState, IssueLinksToDependencies, FilterNonScopedLabels, PriorityFromLabels
- StatusFromLabelsAndState, TypeFromLabels, StateCache, ParseLabelPrefix
- TypeMapping, GetPriorityFromLabel, GetStatusFromLabel, GetTypeFromLabel

Kept exported: Milestone, IssueLinks, SyncStats (used in exported struct fields),
IssueConversion (exported function return type), PriorityMapping, StatusMapping
(referenced in external tests), Label/Project/Namespace/IssueLink (types with
substring complexity in field names).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 17:53:51 -08:00
jane
309bab48db fix: resolve failing tests in daemon autostart, gitlab, and syncbranch
- daemon_autostart.go: Add stubbable function variables for isDoltBackend
  and singleProcessOnlyBackend to allow tests to bypass backend checks
  when testing env var behavior
- autostart_test.go: Stub out backend checks in TestDaemonAutoStart
- daemon_autostart_unit_test.go: Stub out backend checks in
  TestDaemonAutostart_StartDaemonProcess_Stubbed
- client_test.go: Update context cancellation tests to accept either
  context.Canceled or pagination limit exceeded as valid loop termination
  (both prevent infinite loops which is what the tests verify)
- ensure_worktree_test.go: Resolve symlinks before comparing paths in
  TestFreshCloneScenario (fixes macOS /var -> /private/var symlink issue)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 22:19:00 -08:00
Joseph Turian
6f89e6559e fix(test): use atomic counter in TestFetchIssues_ContextCancellation
Same data race fix as the other gitlab test - requestCount is accessed
from both the HTTP handler goroutine and the test goroutine.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 02:40:47 -08:00
Joseph Turian
f5b7025302 fix(test): use atomic counter to fix data race in gitlab test
TestFetchIssuesSince_ContextCancellation had a data race where
requestCount was written by the HTTP handler goroutine and read
by the test goroutine without synchronization.

Use sync/atomic.Int64 to make the counter thread-safe.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 01:55:48 -08:00
obsidian
a7f9e86319 fix: resolve remaining errcheck violations in gitlab files
Add explicit error suppression (`_ =`) for unchecked resp.Body.Close()
in internal/gitlab/client.go and unchecked json.NewEncoder, w.Write,
json.NewDecoder, and os.Setenv/Unsetenv calls in gitlab test files.
Replace os.Setenv/Unsetenv with t.Setenv in gitlab_test.go for
automatic cleanup.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Executed-By: beads/polecats/obsidian
Rig: beads
Role: polecats
2026-02-02 15:09:06 -07:00
beads/crew/emma
96a28eefaa fix(gitlab): address PR review findings for merge readiness
- Add wrapper functions (doPullFromGitLab, doPushToGitLab,
  detectGitLabConflicts) so integration tests compile
- Change IssueConversion.Issue from interface{} to *types.Issue
  (new package, no backwards compat needed); remove GetIssue() helper
- Replace raw http.Client in runGitLabProjects with gitlab.Client
  method (ListProjects), getting retry/auth logic for free
- Add HTTPS validation on GitLab URL to prevent sending tokens
  in cleartext (allows localhost for dev/testing)
- Add io.LimitReader (50MB) to client.go doRequest to prevent OOM
- Improve token masking: show only first 4 chars, not first+last 4

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Executed-By: beads/crew/emma
Rig: beads
Role: crew
2026-01-31 00:07:10 -08:00
Ramos
917d8be8ff fix(gitlab): P2-P3 - cleanup deprecated code and improve docs
P2 Issue #9: Remove deprecated resolveGitLabConflictsByTimestamp function
- Delete unused function that was superseded by resolveGitLabConflicts
- Remove associated tests that tested the deprecated function

P3 Issue #10: Document cross-project link limitation
- Add doc comment to CreateIssueLink clarifying same-project constraint
- Note that cross-project links will error at GitLab API level

P3 Issue #11: Fix ID collision on restart
- Add 4 random bytes to generateIssueID to prevent collisions
- Counter resets on process restart, random component ensures uniqueness
- Add test to verify random component is present

P3 Issue #12: Document error handling philosophy
- Add Error Handling Contract comment at top of gitlab_sync.go
- Documents fatal vs non-fatal error handling approach
- Clarifies that stats track error counts for reporting

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Executed-By: beads/crew/emma
Rig: beads
Role: crew
2026-01-31 00:01:47 -08:00
Ramos
745002eeac fix(gitlab): P2 - fix error handling and type safety
- Fix swallowed json.Marshal error during retry (client.go line 114)
  Now logs the error and continues to next retry attempt instead of
  silently ignoring with _.

- Add GetIssue() helper to IssueConversion for type-safe access
  Returns *types.Issue from interface{} field, nil if wrong type.
  Avoids import cycle by keeping interface{} but providing safe accessor.

- Eliminate duplicate mapping definitions between types.go and mapping.go
  Export PriorityMapping, StatusMapping, TypeMapping from types.go as
  single source of truth. DefaultMappingConfig now uses these exports.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Executed-By: beads/crew/emma
Rig: beads
Role: crew
2026-01-31 00:01:47 -08:00
Ramos
f9f3a03ad6 fix(gitlab): P1 - add pagination limit and context cancellation
Add safeguards to prevent infinite loops in FetchIssues and FetchIssuesSince:

1. MaxPages constant (1000) prevents runaway pagination from malformed
   X-Next-Page headers that never return empty
2. Context cancellation check at start of each pagination loop iteration
   allows graceful shutdown and returns partial results when cancelled
   between requests

Fixes potential DoS from malformed GitLab responses and improves
responsiveness to cancellation signals.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Executed-By: beads/crew/emma
Rig: beads
Role: crew
2026-01-31 00:01:46 -08:00
Ramos
f271075976 Add unit tests for GitLab backend (Issue #10)
Improve test coverage from 82.3% to 92.2% for internal/gitlab package:

- types_test.go: Add tests for GetPriorityFromLabel, GetStatusFromLabel,
  GetTypeFromLabel helper functions (0% → 100%)
- mapping_test.go: Add tests for priorityToLabel (42.9% → 100%) and
  IssueLinksToDependencies edge cases (73.3% → 100%)
- client_test.go: Add error handling tests for UpdateIssue, GetIssueLinks,
  FetchIssueByIID, CreateIssueLink, CreateIssue, FetchIssuesSince

All 379 new lines of tests pass.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Executed-By: beads/crew/emma
Rig: beads
Role: crew
2026-01-31 00:01:45 -08:00
Ramos
b600c477d3 Fix code review issues: path-based IDs, ID collisions, warnings
- Fix path-based project ID comparison in doPushToGitLab (skip numeric
  comparison when client.ProjectID contains "/" since we can't reliably
  compare "group/project" with numeric 789)
- Add atomic counter to generateIssueID() to prevent collisions when
  generating multiple IDs rapidly
- Add Warnings field to PullStats to track non-fatal issues like failed
  gitlab.last_sync saves
- Add tests for conflict resolution (resolveGitLabConflictsByTimestamp)

All 4 code review issues addressed with TDD.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Executed-By: beads/crew/emma
Rig: beads
Role: crew
2026-01-31 00:01:44 -08:00
Ramos
70e5cc1615 Add review fixes: URL encoding, WithEndpoint, FetchIssueByIID, CreateIssueLink
Code review identified these issues:
- ProjectID now URL-encoded via projectPath() helper for path-based IDs
- Added WithEndpoint() builder for custom API endpoints
- Added FetchIssueByIID() for fetching single issues
- Added CreateIssueLink() for creating issue dependencies

All 15 client tests pass. Ready for sync implementation.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Executed-By: beads/crew/emma
Rig: beads
Role: crew
2026-01-31 00:01:43 -08:00
Ramos
e8dd9b412d Implement GitLab to beads mapping (Issue #6)
Add bidirectional mapping between GitLab issues and beads issues:
- MappingConfig for configurable field mappings (priority, status, type, relations)
- GitLabIssueToBeads for import/pull operations
- BeadsIssueToGitLabFields for export/push operations
- IssueLinksToDependencies for dependency conversion
- Support for scoped labels (priority::*, status::*, type::*)
- FilterNonScopedLabels to preserve custom labels

All 11 mapping tests passing (30 total in gitlab package).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Executed-By: beads/crew/emma
Rig: beads
Role: crew
2026-01-31 00:01:43 -08:00
Ramos
abbc0914ec feat(gitlab): implement GitLab REST API client wrapper
TDD implementation of GitLab client for beads integration:
- NewClient constructor with builder pattern (WithHTTPClient)
- FetchIssues with pagination support via X-Next-Page header
- FetchIssuesSince for incremental sync with updated_after param
- CreateIssue for POST /projects/:id/issues
- UpdateIssue for PUT /projects/:id/issues/:iid
- GetIssueLinks for GET /projects/:id/issues/:iid/links
- Retry logic with exponential backoff for rate limiting (429)
- Proper error handling with status code context

All 11 new tests pass (19 total in gitlab package).

Closes #5

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Executed-By: beads/crew/emma
Rig: beads
Role: crew
2026-01-31 00:01:42 -08:00
Ramos
c8abf99dd8 Add GitLab types for beads integration (Issue #4)
TDD implementation of internal/gitlab/types.go:
- Issue, User, Label, Milestone, IssueLink, Project types
- SyncStats, SyncResult, Conflict for sync operations
- Label prefix parsing for priority/status/type mapping
- IsValidState helper for GitLab state validation

All 8 tests passing.

Relates to: se-devsvc/roz#4

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Executed-By: beads/crew/emma
Rig: beads
Role: crew
2026-01-31 00:01:42 -08:00