Commit graph

7 commits

Author SHA1 Message Date
maxinflection
16b1dd0a71
feat(gitlab): sync issue dependency links on push (#4294)
* feat(gitlab): sync issue dependency links on push

After issue content syncs, mirror local beads dependency edges as GitLab
issue links: blocks -> GitLab blocks/is_blocked_by (direction-normalized),
related/relates-to -> a single relates_to link per unordered pair (deduped).
Children of synced epics also keep the epic's milestone during a
dependency-only sync. Reports links_pushed in --json.

Additive only (never deletes remote links). License-aware: blocks/
is_blocked_by needs GitLab Premium/Ultimate; on instances without it the
link is reported as a single curated, non-fatal message (links_license_skipped
in JSON) while relates_to and milestones still apply. Genuine (non-license)
link failures remain real warnings, kept distinct from the license case.

Feature: max-efe

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

* refactor(gitlab): address review — drop dead RelationMap, add push link parity

Follow-up to maphew's review on #4294.

- Delete the dead GitLab RelationMap: issueLinksToDependencies maps link
  types via hardcoded constants and ignores MappingConfig, so the field, its
  default, and the test assertion were dead config surface implying a
  configurability that does not exist. (Linear's RelationMap is untouched.)

- Give `bd gitlab push` dependency-link + epic-milestone parity with
  `bd gitlab sync`: extract the shared pushGitLabDependencyLinks helper from
  runGitLabSync's inline block and call it from runGitLabPush, scoped to the
  requested IssueIDs. Render push output natively so the link pass runs
  before the summary, dry-run ordering is correct, and the --json payload
  carries links_pushed / links_license_skipped / milestones_updated, matching
  sync in all output modes; also guard OnMessage under !jsonOutput.

Reviewed with /code-review + /codex (dry-run "Synced" line, output ordering,
and --json link-stat omission all caught and fixed here).

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

* fix(gitlab): check outputJSON error in runGitLabSync (errcheck)

CI lint (first run on this branch, only-new-issues=false) flagged the
unchecked outputJSON return in the sync --json path. Return it, matching
runGitLabPush. Fixes the Lint / Build Artifacts / PR Lint failures.

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

* fix(gitlab): carry closed state on push; surface failed-close in sync result

GitLab's POST /issues (and milestone/work-item creation) cannot set state,
so closed beads were pushed as opened issues and closed epics as active
milestones — milestone progress read 0/X even when all children were done.

- Close after create on all three paths (CreateIssue, createMilestone,
  createTaskWorkItem) via a best-effort follow-up state_event=close.
- BeadsIssueToGitLabFields emits state_event close/reopen so the update path
  flips both directions (reopening a bead reopens the GitLab issue). deferred
  stays open — only "done" work counts toward milestone completion.
- A failed best-effort close now records a warning on TrackerIssue.Warnings,
  which the engine drains into the sync result (visible in --json) instead of
  a bare stderr print that left --json reporting errors:0 while the issue was
  left open.

On close failure the created issue and its external_ref are still returned so
the next push doesn't create a duplicate (the push skip-guard means it won't
retry the close until the bead is next modified — hence the surfaced warning).

Reviewed via /code-review + Codex.

bd: max-9t6

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

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-08 08:00:41 -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
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
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
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
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
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