Closed captainjapeng closed 5 years ago
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.
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.
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?
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!
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.
If i remind correctly: if one pushes multiple commits newref~1
and oldref
are diffrent.
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: https://github.com/bitsbeats/drone-tree-config/pull/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.
Hey @Oduig,
awesome! I will have a detailed look and test against our infrastructure in the next few days.
Thanks for taking time!
Is there a way for this to work on Bitbucket Server?