Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding bitbucket cloud support #479

Merged
merged 48 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
3d51a03
init empty files
Mar 22, 2024
ed6e44b
adding init methods
Mar 22, 2024
ecbbfc2
tidying up
Mar 22, 2024
08e2f99
added go-bitbuckety
Mar 25, 2024
f9d80fb
adding init settings function
Apr 8, 2024
0cf3f8b
adding init config
Apr 9, 2024
ce8d671
updating settings for client
Apr 9, 2024
c6d00fe
Added Bitbucket cloud platform init, authentication as well implement…
ngandhi64 Apr 11, 2024
0037e33
trying to add merge PR
Apr 12, 2024
7e4e678
removing unused field
Apr 12, 2024
4da8faf
fixing merge code, got working merges for most of the PRs
Apr 19, 2024
1e99218
adding close PR code
Apr 19, 2024
bca67e4
get rid of comment
Apr 19, 2024
c20dfb5
remove unused string
Apr 19, 2024
3247873
Merge pull request #1 from gcase555/bitbucket-init
gcase555 Apr 25, 2024
0c42004
add fork and update PR
byott May 2, 2024
3340226
Merge pull request #2 from gcase555/update-PR-fork-support
byott May 3, 2024
529ce19
updates from upstream
Jun 12, 2024
1013cba
update docs and improve fork support during PR creation
byott Jun 13, 2024
cf69583
Merge pull request #3 from gcase555/bbc-docs-and-create-pr-fix
gcase555 Jun 13, 2024
0a80442
fixing issue where current user is a default reviewer
Jun 21, 2024
97d129b
added error handling
Jun 21, 2024
471bfb9
removing println
Jun 21, 2024
6db683c
added error handling, cleanup as per feedback
Jun 21, 2024
1f94161
switch script back
Jun 21, 2024
080287c
changing middleware
Jun 21, 2024
5046599
Merge pull request #4 from asecurityteam/add-reviewers
gcase555 Jun 21, 2024
0a683fe
cleanup code files, add ID and URL from create PR response and update…
Jun 23, 2024
1d5a2c2
fixing documentation
Jun 23, 2024
73c5ee3
include branch name
Jun 24, 2024
6e09ef6
Merge pull request #5 from asecurityteam/cleanup-2
gcase555 Jun 24, 2024
b8d121a
adding repo name
Jun 24, 2024
b7aa28a
Revert "adding repo name"
Jun 24, 2024
8c14b0f
fix string char
Jun 24, 2024
2432aa3
Merge pull request #6 from asecurityteam/fix-create-pr
gcase555 Jun 24, 2024
ca93a8f
fixing script and updating README
Jul 15, 2024
5c7bdef
fixing comment
Jul 15, 2024
e122da6
adding beta comments
Jul 15, 2024
e799052
fix all linters
Jul 15, 2024
ce58a71
adding comments
Jul 15, 2024
7a8fb81
adding function for extracting slug name
Jul 15, 2024
16e4493
updates from master
Jul 15, 2024
f84981a
updates from master
Jul 15, 2024
9928e39
Merge pull request #7 from asecurityteam/more-feedback
gcase555 Jul 16, 2024
6fbd56c
Merge branch 'master' of github.com:asecurityteam/multi-gitter
Jul 16, 2024
e1bdb9b
Merge pull request #8 from asecurityteam/fix-conflicts
gcase555 Jul 16, 2024
a3125c3
fixing conflicts and running go mod tidy
Aug 5, 2024
de1ec4a
Merge pull request #10 from asecurityteam/fix-conflicts-2
gcase555 Aug 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmd/other.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ func getToken(flag *flag.FlagSet) (string, error) {
token = ght
} else if ght := os.Getenv("BITBUCKET_SERVER_TOKEN"); ght != "" {
token = ght
} else if ght := os.Getenv("BITBUCKET_CLOUD_APP_PASSWORD"); ght != "" {
token = ght
}
}

if token == "" {
return "", errors.New("either the --token flag or the GITHUB_TOKEN/GITLAB_TOKEN/GITEA_TOKEN/BITBUCKET_SERVER_TOKEN environment variable has to be set")
return "", errors.New("either the --token flag or the GITHUB_TOKEN/GITLAB_TOKEN/GITEA_TOKEN/BITBUCKET_SERVER_TOKEN/BITBUCKET_CLOUD_APP_PASSWORD environment variable has to be set")
}

return token, nil
Expand Down
40 changes: 37 additions & 3 deletions cmd/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/lindell/multi-gitter/internal/http"
"github.com/lindell/multi-gitter/internal/multigitter"
"github.com/lindell/multi-gitter/internal/scm/bitbucketcloud"
"github.com/lindell/multi-gitter/internal/scm/bitbucketserver"
"github.com/lindell/multi-gitter/internal/scm/gitea"
"github.com/lindell/multi-gitter/internal/scm/github"
Expand All @@ -22,7 +23,7 @@ func configurePlatform(cmd *cobra.Command) {
flags.StringP("base-url", "g", "", "Base URL of the target platform, needs to be changed for GitHub enterprise, a self-hosted GitLab instance, Gitea or BitBucket.")
flags.BoolP("insecure", "", false, "Insecure controls whether a client verifies the server certificate chain and host name. Used only for Bitbucket server.")
flags.StringP("username", "u", "", "The Bitbucket server username.")
flags.StringP("token", "T", "", "The personal access token for the targeting platform. Can also be set using the GITHUB_TOKEN/GITLAB_TOKEN/GITEA_TOKEN/BITBUCKET_SERVER_TOKEN environment variable.")
flags.StringP("token", "T", "", "The personal access token for the targeting platform. Can also be set using the GITHUB_TOKEN/GITLAB_TOKEN/GITEA_TOKEN/BITBUCKET_SERVER_TOKEN/BITBUCKET_CLOUD_APP_PASSWORD environment variable.")

flags.StringSliceP("org", "O", nil, "The name of a GitHub organization. All repositories in that organization will be used.")
flags.StringSliceP("group", "G", nil, "The name of a GitLab organization. All repositories in that group will be used.")
Expand All @@ -36,9 +37,9 @@ func configurePlatform(cmd *cobra.Command) {
flags.BoolP("ssh-auth", "", false, `Use SSH cloning URL instead of HTTPS + token. This requires that a setup with ssh keys that have access to all repos and that the server is already in known_hosts.`)
flags.BoolP("skip-forks", "", false, `Skip repositories which are forks.`)

flags.StringP("platform", "p", "github", "The platform that is used. Available values: github, gitlab, gitea, bitbucket_server.")
flags.StringP("platform", "p", "github", "The platform that is used. Available values: github, gitlab, gitea, bitbucket_server, bitbucket_cloud.")
_ = cmd.RegisterFlagCompletionFunc("platform", func(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
return []string{"github", "gitlab", "gitea", "bitbucket_server"}, cobra.ShellCompDirectiveDefault
return []string{"github", "gitlab", "gitea", "bitbucket_server", "bitbucket_cloud"}, cobra.ShellCompDirectiveDefault
})

// Autocompletion for organizations
Expand Down Expand Up @@ -114,6 +115,8 @@ func getVersionController(flag *flag.FlagSet, verifyFlags bool, readOnly bool) (
return createGiteaClient(flag, verifyFlags)
case "bitbucket_server":
return createBitbucketServerClient(flag, verifyFlags)
case "bitbucket_cloud":
return createBitbucketCloudClient(flag, verifyFlags)
default:
return nil, fmt.Errorf("unknown platform: %s", platform)
}
Expand Down Expand Up @@ -283,6 +286,37 @@ func createGiteaClient(flag *flag.FlagSet, verifyFlags bool) (multigitter.Versio
return vc, nil
}

// TODO: Add more code to the client
Copy link
Owner

Choose a reason for hiding this comment

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

Please remove

func createBitbucketCloudClient(flag *flag.FlagSet, verifyFlags bool) (multigitter.VersionController, error) {
workspaces, _ := flag.GetStringSlice("org")
users, _ := flag.GetStringSlice("user")
repos, _ := flag.GetStringSlice("repo")
username, _ := flag.GetString("username")
sshAuth, _ := flag.GetBool("ssh-auth")
fork, _ := flag.GetBool("fork")
newOwner, _ := flag.GetString("fork-owner")

if verifyFlags && len(workspaces) == 0 && len(users) == 0 && len(repos) == 0 {
return nil, errors.New("no workspace, user or repository set")
}

if username == "" {
lindell marked this conversation as resolved.
Show resolved Hide resolved
return nil, errors.New("no username set")
}

token, err := getToken(flag)
if err != nil {
return nil, err
}

vc, err := bitbucketcloud.New(username, token, repos, workspaces, users, fork, sshAuth, newOwner, http.NewLoggingRoundTripper)
if err != nil {
return nil, err
}

return vc, nil
}

func createBitbucketServerClient(flag *flag.FlagSet, verifyFlags bool) (multigitter.VersionController, error) {
bitbucketServerBaseURL, _ := flag.GetString("base-url")
projects, _ := flag.GetStringSlice("org")
Expand Down
24 changes: 24 additions & 0 deletions docs/README.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,27 @@ All configuration in multi-gitter can be done through command line flags, config
{{end}}{{end}}

Do you have a nice script that might be useful to others? Please create a PR that adds it to the [examples folder](/examples).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lindell we added a section here in the README to document how to use bitbucket cloud and the limitations as well as links to official documentation.

Copy link
Owner

Choose a reason for hiding this comment

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

I think the documentation look good. But it is a bit too much to have in the main readme.

We could either:

  1. Create docs/bitbucket-cloud.md and move most things there, while keeping a link to it here.
  2. Use <details> to hide most info.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, comments added about beta support and documented any issues/missing features

## Bitbucket Cloud

In order to use bitbucket cloud you will need to create and use an [App Password](https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/). The app password you create needs sufficient permissions so ensure you grant it Read and Write access to projects, repositories and pull requests and at least Read access to your account and workspace membership.

You will need to configure the bitbucket workspace using the `org` option for multi-gitter for the repositories you want to make changes to e.g. `multi-gitter run examples/go/upgrade-go-version.sh -u your_username --org "your_workspace"`

### Example
Here is an example of using the command line options to run a script from the `examples/` directory and make pull-requests for a few repositories in a specified workspace.
```shell
export BITBUCKET_CLOUD_APP_PASSWORD="your_app_password"
multi-gitter run examples/go/upgrade-go-version.sh -u your_username --org "your_workspace" --repo "your_first_repository,your_second_repository" --platform bitbucket_cloud -m "your_commit_message" -B your_branch_name
```

### Bitbucket Cloud Limitations
Currently, we add the repositories default reviewers as a reviewer for any pull-request you create. If you want to specify specific reviewers, you will need to add them using their `UUID` instead of their username since bitbucket does not allow us to look up a `UUID` using their username. [This article has more information about where you can get a users UUID.](https://community.atlassian.com/t5/Bitbucket-articles/Retrieve-the-Atlassian-Account-ID-AAID-in-bitbucket-org/ba-p/2471787)

We don't support specifying specific projects for bitbucket cloud yet, you should still be able to make changes to the repositories you want but certain functionality, like forking, does not work as well until we implement that feature.
Using `fork: true` is currently experimental within multi-gitter for Bitbucket Cloud, and will be addressed in future updates.
Here are the known limitations:
- The forked repository will appear in the user-provided workspace/orgName, with the given repo name, but will appear in a random project within that workspace.
- Using `git-type: cmd` is required for Bitbucket Cloud forking for now until better support is added, as `git-type: go` causes inconsistent behavior(intermittent unauthorized errors).

We also only support modifying a single workspace, any additional workspaces passed into the multi-gitter `org` option will be ignored after the first value.
2 changes: 1 addition & 1 deletion examples/go/upgrade-go-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

# Title: Upgrade Go version in go modules

go mod edit -go 1.18
go mod edit -go 1.19
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We changed this for testing, we'll switch it back

Copy link
Owner

Choose a reason for hiding this comment

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

ping on this comment

go mod tidy
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/gfleury/go-bitbucket-v1 v0.0.0-20240131155556-0b41d7863037
github.com/go-git/go-git/v5 v5.12.0
github.com/google/go-github/v59 v59.0.0
github.com/ktrysmt/go-bitbucket v0.9.76
github.com/mitchellh/mapstructure v1.5.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
Expand Down
Loading
Loading