Commit graph

15 commits

Author SHA1 Message Date
beads/crew/emma
ead8d09a82 fix(gitlab): resolve hardcoded work item type ID and O(n) milestone scan
- Query Task work item type ID dynamically via GraphQL instead of
  hardcoding gid://gitlab/WorkItems::Type/5 (varies by GitLab instance).
  Result is cached per session with fallback for older GitLab versions.
- Add FetchMilestoneByIID using the iids[] API parameter to fetch a
  single milestone directly, replacing the O(n) FetchMilestones scan
  in findParentEpicMilestone.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Executed-By: beads/crew/emma
2026-04-02 21:00:37 -07:00
beads/crew/emma
29531d2b68 feat: GitLab sync — dedup fixes, type filtering, epic→milestone mapping, work item hierarchy (#2889)
- Fix pull dedup: check wisps table and match work_items URLs
- Add type-based filtering to GitLab sync CLI
- Default-exclude molecule/message/event types from push
- Fix source_system update that breaks external_ref persistence
- Map all beads statuses to GitLab scoped labels for board columns
- Handle status::review and status::done labels on pull
- Map epic beads to GitLab milestones instead of issues
- Create task beads as GitLab Task work items with parent hierarchy
- Walk parent chain to find epic milestone, use API ID not IID

Co-authored-by: ktoulgaridis <ktoulg@gmail.com>

Executed-By: beads/crew/emma
2026-04-02 20:58:25 -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
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
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
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
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
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