Code Monkey home page Code Monkey logo

Comments (7)

foosinn avatar foosinn commented on July 22, 2024 1

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!

from drone-tree-config.

foosinn avatar foosinn commented on July 22, 2024 1

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

from drone-tree-config.

foosinn avatar foosinn commented on July 22, 2024

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.

from drone-tree-config.

Oduig avatar Oduig commented on July 22, 2024

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?

from drone-tree-config.

Oduig avatar Oduig commented on July 22, 2024

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.

from drone-tree-config.

Oduig avatar Oduig commented on July 22, 2024

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.

from drone-tree-config.

foosinn avatar foosinn commented on July 22, 2024

Hey @Oduig,

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

Thanks for taking time!

from drone-tree-config.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.