Skip to content

feat(project): pick the source link by account in project sync - #81

Merged
Sahilb315 merged 5 commits into
mainfrom
claude/pensive-sagan-3x8any-sync-account
Nov 24, 2026
Merged

Sahilb315 merged 5 commits into
mainfrom
claude/pensive-sagan-3x8any-sync-account

Conversation

@abhisek

@abhisek abhisek commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

What was wrong

safedep project sync asked for --link-id, the internal id of a source integration row. Users never see that id, and no command lists it for GitHub. The only place it appeared was the error for a tenant with more than one GitHub link. A sync also needed every repository named, at most 100 per call, so a whole org took many calls.

What changes

  • The repository owner picks the link. safedep project sync safedep/vet safedep/pmg matches the owner against the account of each link, ignoring case: the GitHub login or the Bitbucket workspace slug. The match also picks the source.
    • Names of several owners are all resolved first, then synced with one request per link. A bad name sends no request.
    • With exactly one link of the source, that link is used even when the owner does not match. An empty or old account name keeps working.
  • --account <name> picks the link by its account name. Every name resolves through it. You need it with --repository-id or --repository-uuid when the tenant has more than one link of that source.
  • --link-id is hidden on project sync and on the Bitbucket commands repository list, allowlist update and link delete. It still works, so scripts keep running. With both flags, they must name the same link.
  • --all needs --account or --link-id.
    • It lists every repository the link can read, removes duplicates and syncs in batches of 100.
    • On Bitbucket it syncs only the repositories that SafeDep scans, and it says how many it skipped.
    • It prints one progress line per batch on stderr.
  • Failures name accounts, not link ids.
    • "No linked account named X" lists the linked accounts.
    • A run over several accounts that stops says which account's projects exist and which account's request failed, with the server message.
    • --all says "at least the first N".
    • Rerun advice appears only for Unavailable, DeadlineExceeded and ResourceExhausted.
  • A disabled Bitbucket repository fails before any write. The error names the repository and gives the allowlist update command.
  • New package internal/sourcelink holds the account rules for GitHub and Bitbucket. Each internal/cmd package can use it without importing another.

Compatibility

  • Exit codes do not change.
  • JSON keeps the top-level link_id for a run through one link and adds account. A run through more than one link leaves the top-level link_id and account out and sets them on each project.
  • Plain output adds account as the last column, so scripts that read the earlier columns keep working.
  • --link-id alone still lists no links, so a repeated link delete --link-id stays idempotent.

Tests

  • Table tests with fakes of the RPC interfaces the commands use. They cover:
    • owner match and the single-link fallback;
    • two owners, and checking every name before the first write;
    • batches of 100 over listing pages of uneven size, and duplicates across pages;
    • the Bitbucket scan-state filter;
    • account-naming errors and rerun advice;
    • an expired session in --all, which keeps the login guidance;
    • the Bitbucket commands with --account.
  • Each new test was checked to fail with its code removed.
  • make build, make test, make lint and make lint-conventions pass.

The docs pages for project sync and the four Bitbucket commands are updated.


Generated by Claude Code

Summary by CodeRabbit

  • New Features
    • Select Bitbucket workspaces by account name when listing repositories, updating allowlists, deleting links, or syncing projects. Account matching is case-insensitive.
    • Use --all to sync eligible repositories across linked GitHub or Bitbucket accounts. Results are deduplicated and processed in batches; Bitbucket sync includes only repositories enabled for scanning.
    • Sync output includes account and repository details, with summaries for multi-account runs.
  • Bug Fixes
    • Sync stops when a batch or account fails and reports completed work and failure details. Temporary failures include rerun guidance.

project sync and the Bitbucket link commands asked for --link-id, an
internal ID that users never see. GitHub had no command that lists it.

The owner of each OWNER/REPOSITORY name now picks the GitHub organization
or user, or the Bitbucket workspace, with that account. The match also
picks the source. Names with two owners make one sync request per link,
and the CLI resolves every name before the first write. A tenant with one
link keeps working when the account name is missing or stale.

--account names the link for the ID selectors, for --all and for the
Bitbucket repository list, allowlist update and link delete commands.
--link-id stays as a hidden flag for scripts. With a known source it
lists no links.

--all syncs every repository of one account in requests of 100. On
Bitbucket it syncs only repositories with scan state enabled, because the
server refuses the others. A failure after earlier requests wrote projects
reports the synced count and says to rerun when the failure is temporary.

Output and errors name accounts. JSON adds account and link_id to each
project and keeps the top-level link_id when one link served the run.

The selection rules live in internal/sourcelink, shared by both command
trees.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MhRi597EX9odoSDXbVBsxz
A sync of names from several accounts sends one request per account. When
a later request failed, the error said "Projects exist for the first N
repositories", but the requests follow the accounts, not the argument
order, and the error did not name the failed account. The error now names
the accounts whose projects exist and the account whose request failed.
An --all run keeps the count, worded "at least the first N", because the
failed batch can be committed before the server times out.

An Unauthenticated failure is returned as it is, so the entry point shows
the login guidance.

A Bitbucket name whose scan state is not enabled made the server refuse
its request after the requests of other workspaces had written projects.
The CLI now refuses the name before any write and gives the allowlist
update command that enables it.

Selection errors now say when a link has no account name, and point to
the --source value under which a single link serves the name. Names
given with --repository-id or --repository-uuid resolve through the link
that the selection picks. One loop sends the requests of both sources.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MhRi597EX9odoSDXbVBsxz
@safedep

safedep Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

SafeDep Report Summary

Green Malicious Packages Badge Green Vulnerable Packages Badge Green Risky License Badge

No dependency changes detected. Nothing to scan.

View complete scan results →

This report is generated by SafeDep GitHub App

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T06:41:48.278010Z 3e4981b New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 52 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: QUIET
  • Plan: Advanced
  • Run ID: 6283c9c6-c7c4-4816-9280-90831df23f48
Commits

Reviewing files that changed from the base of the PR and between 4f0d307 and 3e4981b.

Files selected for processing: 1

  • internal/sourcelink/sourcelink_test.go

No actionable comments were generated in the recent review.

Walkthrough

The changes add account-based Bitbucket link selection and shared source-link resolution. Project sync gains account and all-repository modes, owner-based repository grouping, batched requests, partial-failure reporting, and account-aware output.

Changes: Account-aware Bitbucket integration and project sync

Layer / File(s) Summary
Shared link selection and Bitbucket commands
internal/sourcelink/sourcelink.go, internal/sourcelink/sourcelink_test.go, internal/bitbucketlink/bitbucketlink.go, internal/cmd/integration/bitbucket/*, internal/cmd/integration/bitbucket/bitbucket_test.go, internal/tui/renderable.go, docs/cmd/integration-bitbucket-*
Shared selection matches account names without regard to case and checks account and link-ID combinations. Bitbucket commands use --account as the primary selector, retain hidden --link-id support, and include account details in output. Tests and command documentation cover selection and result behavior.
Project sync selection and execution
internal/cmd/project/sync.go, internal/cmd/project/sync_run.go, internal/cmd/project/github.go, internal/cmd/project/bitbucket.go, internal/cmd/project/*_test.go, docs/cmd/project-sync.md
Project sync adds account selection and owner-based repository grouping. It prepares GitHub or Bitbucket requests after resolving repositories, then submits the requests. Bitbucket resolution checks scan state and rejects disabled repositories before sync requests.
All-repository batching and partial failures
internal/cmd/project/sync_all.go, internal/cmd/project/errors.go, internal/cmd/project/sync_all_test.go, docs/cmd/project-sync.md
The --all flows list and deduplicate repositories, then sync them in batches of up to 100. Bitbucket sync includes only repositories with enabled scan state. Partial failures report completed work and applicable rerun guidance.
Project sync results and output
internal/cmd/project/sync_output.go, internal/cmd/project/sync_test.go, internal/tui/renderable.go, docs/cmd/project-sync.md
JSON, plain, and table output includes repository, account, and link details. Output handles empty account or name fields, multiple links, and all-mode repository counts.

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant sourcelink
  participant LinkListers
  participant RepositoryListers
  participant ProjectSyncRPC
  CLI->>LinkListers: List links for allowed sources
  CLI->>sourcelink: Select links and group repository names
  CLI->>RepositoryListers: Resolve names and prepare requests
  CLI->>ProjectSyncRPC: Submit prepared repository requests
Loading

Possibly related PRs

  • safedep/cli#66: Adds the Bitbucket link-delete command and its --link-id behavior, which this change updates with account selection.

Suggested reviewers: arunanshub

Merge Risk: Minimal · previous review 4f0d3

The change adds account-based link selection and batched all-repository sync for project sync and the Bitbucket commands, and no concrete merge-blocking issue was found. The remaining unknowns are minor and concern how partial-sync errors are rendered.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "feat(project): pick the source link by account in project sync" matches the main change. The PR objectives say project sync now selects a source link by repository owner or --account instea…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "feat(project): pick the source link by account in project sync" matches the main change. The PR objectives say project sync now selects a source link by repository owner or --account instead of requiring the internal link ID. The raw summary confirms the new sourcelink package, the --account flag on project sync, and the account-based selection logic in sync_run.go and sourcelink.go. The title is specific and does not use vague terms.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: QUIET
  • Plan: Advanced
  • Run ID: 760be1a4-17db-4b2a-86e9-460dbd871f57
Commits

Reviewing files that changed from the base of the PR and between ead8257 and 4f0d307.

Files selected for processing: 1

  • internal/cmd/project/errors.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

main now has internal/rpcerror, which finds the innermost gRPC status of
a wrapped error. rpcMessage used its own copy of that lookup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MhRi597EX9odoSDXbVBsxz

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f0d30780a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/sourcelink/sourcelink_test.go Resolved
GroupByOwner maps free-form OWNER/REPOSITORY names to links, and the
table test covers only hand-picked names. The fuzz test checks, for any
names, links and source: every name lands in exactly one group, each
group has its own link of the allowed source, each name goes to the one
link with its owner's account or to the only allowed link, and an
unresolvable owner fails. With --account set, one group keeps every name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MhRi597EX9odoSDXbVBsxz
@Sahilb315
Sahilb315 merged commit 4f724c1 into main Nov 24, 2026
7 checks passed
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.

3 participants