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

Bitbucket Server support? #2

Closed
captainjapeng opened this issue Jun 10, 2019 · 7 comments
Closed

Bitbucket Server support? #2

captainjapeng opened this issue Jun 10, 2019 · 7 comments
Labels
help wanted Extra attention is needed

Comments

@captainjapeng
Copy link

Is there a way for this to work on Bitbucket Server?

@foosinn
Copy link
Contributor

foosinn commented Jun 11, 2019

this would require some code changes and some new test.

https://github.com/drone/go-scm can handle all provides that drone uses.

i you or someone else wants do do the changes, i am happy to merge them.

@foosinn foosinn added the help wanted Extra attention is needed label Jun 11, 2019
Oduig pushed a commit to Oduig/drone-tree-config that referenced this issue Jul 7, 2019
@Oduig
Copy link

Oduig commented Jul 7, 2019

I forked this repository to attempt the changes myself. I have no previous experience with golang, but it seems like we are going to hit a wall with go-scm because two API calls are missing. That means we have two options.

  1. Make a PR for https://github.com/drone/go-scm with implementations for the missing calls for every SCM system.
  2. Implement the necessary logic as part of this plugin, focus on BitBucket for the moment and add repositories as we go along.

Missing API calls

    changes, _, err := req.Client.Repositories.CompareCommits(ctx, req.Repo.Namespace, req.Repo.Name, before, req.Build.After)

The first is a call to repos/%s/compare/oldref...newref to run a diff between two commits. I wonder if we can just call repos/%s/commits/newref instead?

_, ls, _, err := req.Client.Repositories.GetContents(ctx, req.Repo.Namespace, req.Repo.Name, dir, &ref)

The second is more troublesome, in that the call to repos/%s/contents/path accepts directories, but the source code of go-scm assumes that you're calling it on a file, causing it to crash because the response has a different format than the one expected. See https://developer.github.com/v3/repos/contents/#get-contents.

I worry that adding the above two API calls to go-scm is going to take a long time. Is there anyone that could help with that? Alternatively, would you accept a PR for drone-tree-config that just implements BitBucket support natively in this plugin?

@foosinn
Copy link
Contributor

foosinn commented Jul 8, 2019

I would be ok with it if we can abstract the provider to an interface. That way it should be easy to add new providers afterwards.

For now we would have just a bitbucket and a github provider. Users that require more would be able to add them.

Thanks for taking the time!

@Oduig
Copy link

Oduig commented Jul 8, 2019

Thanks, I'll do my best to find the time for that! Regarding the first API call, is there a difference between /compare/oldref...newref and /commits/newref? It seems to me that the content of a commit is by definition the same as the diff with the previous commit, but I might be overlooking something.

(This is assuming that oldref is newref~1, which seems to always be true in the source code.)

Edit: also made an issue in go-scm for long term improvement.

@foosinn
Copy link
Contributor

foosinn commented Jul 8, 2019

If i remind correctly: if one pushes multiple commits newref~1 and oldref are diffrent.

@Oduig
Copy link

Oduig commented Jul 28, 2019

I managed to extract a common interface and finish an implementation with BitBucket support. I'll test it over the next few days and send a PR.
Edit: #4

It's quite a big change due to SCM-specific code having to be separated. It is fully backwards compatible with one exception, I thought it better to rename the GITHUB_SERVER variable to SERVER rather than making separate versions for each SCM. I have the image up on jodiug/drone-tree-config, if anyone in the community would like to test it that would be very helpful.

The following environment variables need to be passed to drone-tree-config to add BitBucket support:

AUTH_SERVER: https://bitbucket.org
SERVER: https://api.bitbucket.org
BITBUCKET_CLIENT: client_id
BITBUCKET_SECRET: client_secret

You can use the same client credentials as you use for drone-master.

@foosinn
Copy link
Contributor

foosinn commented Jul 30, 2019

Hey @Oduig,

awesome! I will have a detailed look and test against our infrastructure in the next few days.

Thanks for taking time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants