-
Notifications
You must be signed in to change notification settings - Fork 66
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
Conversation
…ation for create and get pull requests
WIP: Adding bitbucket support
add BBC fork and update PR support
examples/go/upgrade-go-version.sh
Outdated
@@ -2,5 +2,5 @@ | |||
|
|||
# Title: Upgrade Go version in go modules | |||
|
|||
go mod edit -go 1.18 | |||
go mod edit -go 1.19 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping on this comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR 😄
I started looking at it, but it will take some time since I don't have a lot of time currently. But I'm including my first comments. Feel free to take a look at them right away if you want, or wait until all comments are in if you prefer that 🙂
PS. In which detail do you want the reviews right now? I tried to avoid code style, and similar types of comments because of the current PR state you mentioned. But let me know if you prefer those straight away as well.
Owner: bbc.workspaces[0], | ||
RepoSlug: splitRepoFullName[1], | ||
} | ||
defaultReviewers, _ := bbc.bbClient.Repositories.Repository.ListDefaultReviewers(repoOptions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err check?
newPR.Reviewers = append(newPR.Reviewers, reviewer.Uuid) | ||
} | ||
|
||
prOptions := &bitbucket.PullRequestsOptions{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can pull request happen from a fork in bbc? In that case I don't think the owner here is correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add a parameter to allow users to specify a bitbucket "project" to fork into before we can specify the owner fully here.
We were hoping to do that as a separate PR and document that as a known limitation but let us know if that is a blocker we should resolve it before we get this change merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with merging something that does not have all functionality of all other systems 🙂 But please list these, as I will otherwise make comments on things that will not be relevant to you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a note in the README template about bitbucket cloud support and the current limitations that should help clarify things.
project: splitRepoFullName[0], | ||
repoName: splitRepoFullName[1], | ||
branchName: newPR.Head, | ||
prProject: splitRepoFullName[0], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that project
/repoName
and prProject
/prRepoName
are used the same here. I guess it comes from other implementations and it might be good to clarify what they are for there.
The first pair are a reference to the project where the PR is place (where is will merge), while the second one is from which repository the change is currently made. If fork
is not defined, these will be the same, since the changes will happen the same project. But they could be different, and in that case I think this will not be right.
The feedback you have given so far has been good, we were looking to answer things that stood out and could potentially be problems or explain why we had to go with app passwords over OAuth access tokens for this first pull-request for accessibility reasons. |
newPR.Reviewers = append(newPR.Reviewers, reviewer.Uuid) | ||
} | ||
|
||
prOptions := &bitbucket.PullRequestsOptions{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with merging something that does not have all functionality of all other systems 🙂 But please list these, as I will otherwise make comments on things that will not be relevant to you
} | ||
|
||
// repository contains information about a bitbucket repository | ||
type repository struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding workspace name is probably a good idea for later, even if multi workspace support is currently not implemented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be handled later? I didn't want to refactor too much more and were still only supporting single workspaces(as documented in the README)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine for now. Just would make it easier to make those changes later
return err | ||
} | ||
|
||
func (bbc *BitbucketCloud) GetRepositories(ctx context.Context) ([]scm.Repository, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to only include repository name filtering (--repo
), not for example per project which I think is by far the most popular one (organizations for GitHub).
And for specific repo names, it seems that all repositories are fetched. If possible, I think getting those repositories by name should be prefered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we had time to implement this change, is it ok if we keep this as is with repository filtering? Trying to avoid heavier refactoring of this PR as it has gotten large and would prefer to do it as a follow up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hesitant to add this as this would heavily limit the expected behaviour. But think it could be ok if
- This is clearly described in the Readme (or wherever the info is moved) under the restrictions sections.
- Mark it as beta (by adding
(beta)
to the bitbucket cloud section.
Update Docs and improve PR creation during forks
@lindell We made as many of the changes as we could with the time we had allotted to work on this and did most of the cleanup and refactoring requested. Please let us know if there are any issues that are blocking and need to be addressed before merging or if there is something we can resolve in a follow up pull request, we are hoping to get this merged as this PR has started getting large and has been outside of master branch for awhile. I think this implementation covers enough to close out issue #99 and can start being used by end users. We could create a separate issue to handle updates to include project settings and addressing other smaller feedback tasks you feel are non-blocking. We have successfully started using it to update multiple services across large and small bitbucket cloud workspaces and included documentation on how to get it working and the current limitations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the pervious comment, I did a pass and tried to be non-nitty.
Just to clarify, you are employees of Atlassian? It does change the calculation a bit, since you would have greater investment in the project after the merge.
I think the best approach right with your wish to have i merged in the current state is:
- Go through the last comments + Fix the linting errors (feel free to skip the G601 ones, since it will be fixed when we update to Go 1.22)
- Mark the project as Beta in the Readme and in the description of the
--platform
flag/option.
cmd/platform.go
Outdated
@@ -283,6 +286,37 @@ func createGiteaClient(flag *flag.FlagSet, verifyFlags bool) (multigitter.Versio | |||
return vc, nil | |||
} | |||
|
|||
// TODO: Add more code to the client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove
@@ -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). | |||
|
There was a problem hiding this comment.
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:
- Create docs/bitbucket-cloud.md and move most things there, while keeping a link to it here.
- Use
<details>
to hide most info.
examples/go/upgrade-go-version.sh
Outdated
@@ -2,5 +2,5 @@ | |||
|
|||
# Title: Upgrade Go version in go modules | |||
|
|||
go mod edit -go 1.18 | |||
go mod edit -go 1.19 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping on this comment
return scm.PullRequestStatusSuccess, nil | ||
} | ||
|
||
func (bbc *BitbucketCloud) GetOpenPullRequest(ctx context.Context, repo scm.Repository, branchName string) (scm.PullRequest, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if there is no intention to have it have it be used outside, please just make it private in that case.
|
||
func (bbc *BitbucketCloud) MergePullRequest(ctx context.Context, pr scm.PullRequest) error { | ||
bbcPR := pr.(pullRequest) | ||
repoSlug := strings.Split(bbcPR.guiURL, "/")[4] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this not the same as bbcPR .repoName
? If not please create a function to extract the slug from the PR and describe what this splitting is doing (what is the 4 previous parts of the url?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mentioned it in a resolved comment but no, when I tried to use bbcPR.repoName
it did not work and this slug is different. I used a clear variable name to clear up confusion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous 4 parts are the complete URL but for the repo slug we only care about the repo name which we are extracting from the URL in this case
|
||
func (bbc *BitbucketCloud) ClosePullRequest(ctx context.Context, pr scm.PullRequest) error { | ||
bbcPR := pr.(pullRequest) | ||
repoSlug := strings.Split(bbcPR.guiURL, "/")[4] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this not the same as bbcPR .repoName
? If not please create a function to extract the slug from the PR and describe what this splitting is doing (what is the 4 previous parts of the url?).
return err | ||
} | ||
|
||
func (bbc *BitbucketCloud) GetRepositories(ctx context.Context) ([]scm.Repository, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hesitant to add this as this would heavily limit the expected behaviour. But think it could be ok if
- This is clearly described in the Readme (or wherever the info is moved) under the restrictions sections.
- Mark it as beta (by adding
(beta)
to the bitbucket cloud section.
} | ||
|
||
// repository contains information about a bitbucket repository | ||
type repository struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine for now. Just would make it easier to make those changes later
I tested this, and was successful in creating some PRs across multiple repositories. Love it! Two areas for improvement: The error when We have 1000s of repositories in Bitbucket Cloud. Although I provided the names of fewer than 10 to |
Correct, we are developers from Atlassian and we use golang heavily on some platform tools we released here https://github.com/asecurityteam/ we still plan on submitting some smaller follow up PRs but we are trying to get this merged with the working functionality in place since this PR is getting to large and been open for longer then we prefer.
I addressed all the nits, linter fixes and added a note on Beta support in the README in our fork here asecurityteam#7 I plan on requesting a re-reviewing once I get that merged. |
I am really glad to hear that!
Noted, this is something we will probably improve in a small follow up PR
We did make a note in the README that workspaces with lots of repositories will perform slower, it will still work but there is usually a delay when initially doing look ups for repos and PRs, you should still see commands execute within 2 minutes. We noted this as part of the Beta support that it does work but the performance will likely get better once we add more options for project support. With smaller workspaces, it runs very fast so this is something specific to large workspaces. |
Alright @lindell ready for a re-review, we addressed all linting issues besides the ones you mentioned we could ignore, did the requested cleanup of TODOs, added the function for extracting the repo slug, made notes on beta support(mentioned the issue with it being slightly slower on larger workspaces until project support gets added) and updated the docs to use details to make them more minimal. |
@lindell is it possible we could get help merging this? |
I'm about to merge this PR. But I can push the go mod changes necessary (fixes for merge conflicts). It seems that "Maintainers are allowed to edit this pull request." is enabled, but I get
When I try to push the changes. |
This is a known limitation of GitHub. That setting doesn't work if the repository belongs to an organization. |
Ill address the merge conflicts now |
@lindell all merge conflicts have been addressed |
Included in release v0.53.0 🎉 |
Thanks for the contribution. I am looking forward to the fixes coming soon 🙂 |
What does this change
This is most of the changes for adding bitbucket cloud support. We have implemented the interface and have the ability to automate creating PRs, updating PRs, Closing PRs, Fetching Repos/PRs and Forking Repos.
What issue does it fix
Closes #99
Notes for the reviewer
We are still adding support for handling multiple workspaces and updating the README with a few notes for bitbucket cloud support. My goal here is to get the PR submitted for early feedback and we will update this PR once we add handling multiple workspaces.