Skip to content

Add robust Bitbucket Cloud scope handling and coverage#138

Merged
ewega merged 3 commits into
mainfrom
codex/add-bitbucket-cloud-support
Mar 11, 2026
Merged

Add robust Bitbucket Cloud scope handling and coverage#138
ewega merged 3 commits into
mainfrom
codex/add-bitbucket-cloud-support

Conversation

@Codex

@Codex Codex AI commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

Bitbucket Cloud needed reliable scope selection and documentation for BasicAuth-based connections and remote-scope browsing.

  • Scope handling
    • Propagate pagination errors when listing Bitbucket workspaces or repositories so interactive selection fails fast with context.
    • Harden parseBitbucketRepo to tolerate missing data payloads by falling back to child fields.
  • Tests
    • Added parseBitbucketRepo unit coverage to ensure bitbucketId/name/fullName fallbacks and payload fields are honored, including nil/empty data cases.
  • Docs
    • Updated scope docs to list Bitbucket in supported plugins, clarify plugin-specific repo slug formats, flag descriptions, examples, org/workspace requirements, and “What It Does” flow for repo scoping.

Example:

page, err := client.ListRemoteScopes("bitbucket", connID, workspaceID, nextToken)
if err != nil {
    return nil, fmt.Errorf("listing repositories in workspace %q (page token %s): %w", workspaceID, nextToken, err)
}

@Codex Codex AI changed the title [WIP] Add Bitbucket Cloud plugin support Add robust Bitbucket Cloud scope handling and coverage Mar 11, 2026
@ewega ewega marked this pull request as ready for review March 11, 2026 22:07
Copilot AI review requested due to automatic review settings March 11, 2026 22:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Improves Bitbucket Cloud repo scoping in the gh-devlake CLI by making remote-scope browsing fail fast on pagination errors, adds unit coverage for Bitbucket repo parsing, and updates scope documentation to include Bitbucket.

Changes:

  • Propagate pagination errors when listing Bitbucket workspaces/repos during interactive browsing.
  • Add unit tests for parseBitbucketRepo to validate payload-field precedence and fallback behavior.
  • Update configure scope add docs to include Bitbucket and expand plugin/flag descriptions and examples.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
docs/configure-scope.md Expands scope-add docs to include Bitbucket (and other plugins) plus Bitbucket “What It Does”.
cmd/configure_scopes_test.go Adds test coverage for Bitbucket remote-scope child parsing.
cmd/configure_scopes.go Changes Bitbucket remote-scope pagination to return errors instead of silently breaking.

Comment thread docs/configure-scope.md Outdated
Comment on lines +39 to +40
| `--repos` | | Comma-separated repos to add (`owner/repo,owner/repo2`) for GitHub, GitLab, Bitbucket |
| `--repos-file` | | Path to a file with repos (one `owner/repo` per line) for GitHub, GitLab, Bitbucket |

Copilot AI Mar 11, 2026

Copy link

Choose a reason for hiding this comment

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

The --repos / --repos-file descriptions show owner/repo as the canonical format for GitLab and Bitbucket as well, but those plugins use group/project (GitLab) and workspace/repo-slug (Bitbucket). Updating the wording/examples here would prevent users from passing the wrong repo slug format.

Suggested change
| `--repos` | | Comma-separated repos to add (`owner/repo,owner/repo2`) for GitHub, GitLab, Bitbucket |
| `--repos-file` | | Path to a file with repos (one `owner/repo` per line) for GitHub, GitLab, Bitbucket |
| `--repos` | | Comma-separated repos to add (`owner/repo` for GitHub, `group/project` for GitLab, `workspace/repo-slug` for Bitbucket) |
| `--repos-file` | | Path to a file with repos (one per line: `owner/repo` for GitHub, `group/project` for GitLab, `workspace/repo-slug` for Bitbucket) |

Copilot uses AI. Check for mistakes.
Comment on lines +164 to +170
t.Run("falls back to child fields when payload is sparse", func(t *testing.T) {
child := devlake.RemoteScopeChild{
Name: "frontend",
FullName: "team/frontend",
Data: []byte(`{"bitbucketId":"","name":"","fullName":""}`),
}
repo := parseBitbucketRepo(&child)

Copilot AI Mar 11, 2026

Copy link

Choose a reason for hiding this comment

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

parseBitbucketRepo currently returns nil when child.Data is missing/empty (json.Unmarshal on a nil RawMessage fails). DevLake remote-scope responses can omit the data field entirely, so this test suite should include a case with Data: nil (or empty) and expect fallback to child.Name/child.FullName; otherwise interactive Bitbucket repo browsing/search can silently drop repos.

Copilot uses AI. Check for mistakes.
Comment thread docs/configure-scope.md Outdated
| `--plugin` | *(interactive or required)* | Plugin to configure (`github`, `gitlab`, `bitbucket`, `gh-copilot`, `jenkins`, `azure-devops`, `sonarqube`) |
| `--connection-id` | *(auto-detected)* | Override the connection ID to scope |
| `--org` | *(required)* | GitHub organization slug |
| `--org` | *(required)* | Org/workspace slug (`github`, `gitlab` group path, `bitbucket` workspace, `azure-devops` org) |

Copilot AI Mar 11, 2026

Copy link

Choose a reason for hiding this comment

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

The docs mark --org as (required) for configure scope add, but in the CLI this is only required for plugins whose ConnectionDef has NeedsOrg set (e.g., Azure DevOps). Bitbucket repo scoping supports omitting --org and will prompt to select a workspace interactively, so the docs should reflect that --org is plugin-dependent/optional in interactive mode (and clarify which plugins require it).

Suggested change
| `--org` | *(required)* | Org/workspace slug (`github`, `gitlab` group path, `bitbucket` workspace, `azure-devops` org) |
| `--org` | *(plugin-dependent)* | Org/workspace slug (`github`, `gitlab` group path, `bitbucket` workspace, `azure-devops` org). Required for plugins whose connection definition needs an org (for example, Azure DevOps) or when running non-interactively; optional in interactive mode for plugins that support workspace discovery (for example, Bitbucket). |

Copilot uses AI. Check for mistakes.
@ewega

ewega commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

@codex[agent] Please address the three review comments on this PR: 1) fix the docs wording for --repos / --repos-file to cover GitHub, GitLab, and Bitbucket formats correctly; 2) add a test covering parseBitbucketRepo fallback behavior when child.Data is nil/empty; 3) update the --org docs wording to be plugin-dependent/optional in interactive mode where appropriate. After updating, rerun build/test/vet and let the review agent re-check.

@Codex

Codex AI commented Mar 11, 2026

Copy link
Copy Markdown
Contributor Author

@codex[agent] Please address the three review comments on this PR: 1) fix the docs wording for --repos / --repos-file to cover GitHub, GitLab, and Bitbucket formats correctly; 2) add a test coveri...

Addressed: updated scope docs for plugin-specific repo formats and plugin-dependent org wording, added parseBitbucketRepo test for nil/empty data fallback, and reran build/test/vet (bef8588).

@ewega ewega left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed after follow-up fixes; safe to merge.

@ewega ewega merged commit 4311c13 into main Mar 11, 2026
4 checks passed
@ewega ewega deleted the codex/add-bitbucket-cloud-support branch March 11, 2026 22:30
@ewega ewega mentioned this pull request Mar 12, 2026
5 tasks
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