Coder Social home page Coder Social logo

bitbucket-scala-client's Introduction

Codacy Badge Circle CI Maven Central

Bitbucket Scala client

This is a simple library that aims to have basic functions of the Bitbucket API. This library is meant to support Codacy when interacting with Bitbucket.

Usage

Import on SBT:

"com.codacy" %% "bitbucket-scala-client" % "<VERSION>"

Creators

  1. Rodrigo Fernandes

What is Codacy?

Codacy is an Automated Code Review Tool that monitors your technical debt, helps you improve your code quality, teaches best practices to your developers, and helps you save time in Code Reviews.

Among Codacy’s features:

  • Identify new Static Analysis issues
  • Commit and Pull Request Analysis with GitHub, BitBucket/Stash, GitLab (and also direct git repositories)
  • Auto-comments on Commits and Pull Requests
  • Integrations with Slack, HipChat, Jira, YouTrack
  • Track issues in Code Style, Security, Error Proneness, Performance, Unused Code and other categories

Codacy also helps keep track of Code Coverage, Code Duplication, and Code Complexity.

Codacy supports PHP, Python, Ruby, Java, JavaScript, and Scala, among others.

Free for Open Source

Codacy is free for Open Source projects.

License

bitbucket-scala-client is available under the The Apache Software License, Version 2.0.

bitbucket-scala-client's People

Contributors

ajanczak avatar albertoadami avatar andreatp avatar andrzej-janczak avatar bmbferreira avatar carlospinho04 avatar caxaria avatar jllopes avatar josemiguelmelo avatar lazybun avatar lolgab avatar lorandszakacs avatar machadoit avatar manufacturist avatar mrfyda avatar mw-ding avatar nmatpt avatar pcmanticore avatar pedrobpereira avatar pedrocodacy avatar pedrorijo91 avatar prendi avatar rtfpessoa avatar unthingable avatar xplosunn avatar zamblauskas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bitbucket-scala-client's Issues

'!' in the API url

Hey guys,
I've used your client for a batch webhook update on all of our BitBucket repos.
I refactored authentication to also support AppPassword method, but had to remove all the '!' from the urls, otherwise was getting 401 unauthorized from BitBucket.

Why was the '!' needed in the first place, cannot find anything on BitBucket docs ?

Related commits:
zamblauskas@43f9fd5
zamblauskas@2ed4d57

If you would confirm that '!' is not needed, I'd be glad to create a PR for the AppPassword authentication method.

getPullRequests error with multiple PR types

https://github.com/codacy/bitbucket-scala-client/blob/master/src/main/scala/com/codacy/client/bitbucket/service/PullRequestServices.scala#L15

Apparently, with the current API listing multiple PR types with a comma leads to a 401. But this works:

   def getPullRequests(owner: String, repository: String, states: Seq[String] = Seq("OPEN")): RequestResponse[Seq[PullRequest]] = {
    val url = s"https://bitbucket.org/!api/2.0/repositories/$owner/$repository/pullrequests?state=${states.mkString("&state=")}"

    client.executePaginated(Request(url, classOf[Seq[PullRequest]]))
  }

From API docs:

state	string	

Only return pull requests that are in this state. This parameter can be repeated.

BB auth

Possibly doing something stupid, but it's enough of a use case to ask for some documented help. An attempt to connect to BB:

import com.codacy.client.bitbucket.client.BitbucketClient
import com.codacy.client.bitbucket.service.{PullRequestServices, UserServices}
import play.api.libs.oauth.{ConsumerKey, OAuth, ServiceInfo}

val sInfo = ServiceInfo(
  "https://bitbucket.org/api/1.0/oauth/request_token",
  "https://bitbucket.org/site/oauth2/authorize",
  "https://bitbucket.org/site/oauth2/access_token",
  key=ConsumerKey("XXX","YYY")
)

val oauth = OAuth(sInfo)
val rqToken = oauth.retrieveRequestToken("http://localhost:1234").right.get

val client = new BitbucketClient("XXX", "YYY", rqToken.token, rqToken.secret)

val ps = new PullRequestServices(client)
val us = new UserServices(client)
us.getUser
ps.getPullRequests("owner", "repository")

XXX/YYY are key/secret in BB API OAuth consumer, "owner" and "repository" are both valid. Details:
image

rqToken is successfully created with a token and secret, but attempts to use PullRequestServices and UserServices result in 401 Unauthorized. What is the proper way to do this?

Error when trying to use the REST library on SBT REPL

Hi,

I just wanted to try your Bitbucket REST lib (which looks awesome by the way). When I execute a request inside of a SBT REPL, I get the following error:

scala> val client = new BitbucketClient(key="MY_KEY", secretKey="MY_SECRET_KEY", token="MY_TOKEN", secretToken = "MY_SECRET_TOKEN")
scala> val repos = new RepositoryServices(client)
scala> repos.getRepositories("my_user")

0:33:00.517 [run-main-0] ERROR com.ning.http.client.AsyncHttpClient - Unable to instantiate provider com.ning.http.client.providers.netty.NettyAsyncHttpProvider.  Trying other providers.
20:33:00.520 [run-main-0] ERROR com.ning.http.client.AsyncHttpClient - java.util.concurrent.RejectedExecutionException: Task org.jboss.netty.util.internal.DeadLockProofWorker$1@1300de50 rejected from java.util.concurrent.ThreadPoolExecutor@44c4148e[Running, pool size = 15, active threads = 15, queued tasks = 0, completed tasks = 0]
java.util.concurrent.RejectedExecutionException: Task org.jboss.netty.util.internal.DeadLockProofWorker$1@1300de50 rejected from java.util.concurrent.ThreadPoolExecutor@44c4148e[Running, pool size = 15, active threads = 15, queued tasks = 0, completed tasks = 0]
    at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2047) ~[na:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:823) ~[na:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1369) ~[na:1.8.0_45]
    at org.jboss.netty.util.internal.DeadLockProofWorker.start(DeadLockProofWorker.java:38) ~[netty-3.9.8.Final.jar:na]
    at org.jboss.netty.channel.socket.nio.AbstractNioSelector.openSelector(AbstractNioSelector.java:368) ~[netty-3.9.8.Final.jar:na]
    at org.jboss.netty.channel.socket.nio.AbstractNioSelector.<init>(AbstractNioSelector.java:100) ~[netty-3.9.8.Final.jar:na]
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.<init>(AbstractNioWorker.java:52) ~[netty-3.9.8.Final.jar:na]
    at org.jboss.netty.channel.socket.nio.NioWorker.<init>(NioWorker.java:45) ~[netty-3.9.8.Final.jar:na]
    at org.jboss.netty.channel.socket.nio.NioWorkerPool.createWorker(NioWorkerPool.java:45) ~[netty-3.9.8.Final.jar:na]
    at org.jboss.netty.channel.socket.nio.NioWorkerPool.createWorker(NioWorkerPool.java:28) ~[netty-3.9.8.Final.jar:na]
    at org.jboss.netty.channel.socket.nio.AbstractNioWorkerPool.newWorker(AbstractNioWorkerPool.java:142) ~[netty-3.9.8.Final.jar:na]
    at org.jboss.netty.channel.socket.nio.AbstractNioWorkerPool.init(AbstractNioWorkerPool.java:80) ~[netty-3.9.8.Final.jar:na]
    at org.jboss.netty.channel.socket.nio.NioWorkerPool.<init>(NioWorkerPool.java:39) ~[netty-3.9.8.Final.jar:na]
    at org.jboss.netty.channel.socket.nio.NioWorkerPool.<init>(NioWorkerPool.java:33) ~[netty-3.9.8.Final.jar:na]
    at org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory.<init>(NioClientSocketChannelFactory.java:151) ~[netty-3.9.8.Final.jar:na]
    at org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory.<init>(NioClientSocketChannelFactory.java:133) ~[netty-3.9.8.Final.jar:na]
    at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.<init>(NettyAsyncHttpProvider.java:263) ~[async-http-client-1.8.15.jar:na]
    at sun.reflect.GeneratedConstructorAccessor25.newInstance(Unknown Source) ~[na:na]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_45]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422) ~[na:1.8.0_45]
    at com.ning.http.client.AsyncHttpClient.loadDefaultProvider(AsyncHttpClient.java:554) [async-http-client-1.8.15.jar:na]
    at com.ning.http.client.AsyncHttpClient.<init>(AsyncHttpClient.java:187) [async-http-client-1.8.15.jar:na]
    at play.api.libs.ws.ning.NingWSClient.<init>(NingWS.scala:38) [play-ws_2.10-2.3.9.jar:2.3.9]
    at com.codacy.client.bitbucket.client.BitbucketClient.withClient(BitbucketClient.scala:153) [classes/:na]
    at com.codacy.client.bitbucket.client.BitbucketClient.withClientEither(BitbucketClient.scala:127) [classes/:na]
    at com.codacy.client.bitbucket.client.BitbucketClient.get(BitbucketClient.scala:98) [classes/:na]
    at com.codacy.client.bitbucket.client.BitbucketClient.execute(BitbucketClient.scala:28) [classes/:na]
    at com.codacy.client.bitbucket.service.RepositoryServices.getRepositories(RepositoryServices.scala:14) [classes/:na]
    at $line20.$read$$iw$$iw$.<init>(<console>:12) [na:na]
    at $line20.$read$$iw$$iw$.<clinit>(<console>) [na:na]
    at $line20.$eval$.<init>(<console>:7) [na:na]
    at $line20.$eval$.<clinit>(<console>) [na:na]
    at $line20.$eval.$print(<console>) [na:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_45]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_45]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_45]
    at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:734) [scala-compiler-2.10.5.jar:na]
    at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:983) [scala-compiler-2.10.5.jar:na]
    at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:573) [scala-compiler-2.10.5.jar:na]
    at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:604) [scala-compiler-2.10.5.jar:na]
    at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:568) [scala-compiler-2.10.5.jar:na]
    at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:760) [scala-compiler-2.10.5.jar:na]
    at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:805) [scala-compiler-2.10.5.jar:na]
    at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:717) [scala-compiler-2.10.5.jar:na]
    at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:581) [scala-compiler-2.10.5.jar:na]
    at scala.tools.nsc.interpreter.ILoop.innerLoop$1(ILoop.scala:588) [scala-compiler-2.10.5.jar:na]
    at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:591) [scala-compiler-2.10.5.jar:na]
    at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:882) [scala-compiler-2.10.5.jar:na]
    at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:837) [scala-compiler-2.10.5.jar:na]
    at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:837) [scala-compiler-2.10.5.jar:na]
    at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135) [scala-compiler-2.10.5.jar:na]
    at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:837) [scala-compiler-2.10.5.jar:na]
    at scala.tools.nsc.interpreter.ILoop.main(ILoop.scala:904) [scala-compiler-2.10.5.jar:na]
    at xsbt.ConsoleInterface.run(ConsoleInterface.scala:62) [compiler-interface.jar:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_45]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_45]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_45]
    at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:101) [compile-0.13.8.jar:0.13.8]
    at sbt.compiler.AnalyzingCompiler.console(AnalyzingCompiler.scala:76) [compile-0.13.8.jar:0.13.8]
    at sbt.Console.sbt$Console$$console0$1(Console.scala:22) [actions-0.13.8.jar:0.13.8]
    at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply$mcV$sp(Console.scala:23) [actions-0.13.8.jar:0.13.8]
    at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply(Console.scala:23) [actions-0.13.8.jar:0.13.8]
    at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply(Console.scala:23) [actions-0.13.8.jar:0.13.8]
    at sbt.Logger$$anon$4.apply(Logger.scala:85) [logging-0.13.8.jar:0.13.8]
    at sbt.TrapExit$App.run(TrapExit.scala:248) [run-0.13.8.jar:0.13.8]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45]
res11: com.codacy.client.bitbucket.client.RequestResponse[Seq[com.codacy.client.bitbucket.SimpleRepository]] =
RequestResponse(None,
java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2047)
java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:823)
java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1369)
java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
com.ning.http.client.providers.jdk.JDKAsyncHttpProvider.execute(JDKAsyncHttpProvider.java:161)
com.ning.http.client.providers.jdk.JDKAsyncHttpProvider.execute(JDKAsyncHttpProvider.java:124)
com.ning.http.client.AsyncHttpClient.executeRequest(AsyncHttpClient.java:499)
play.api.libs.ws.ning.NingWSClient.executeRequest(NingW.

Do you have any idea what the problem is here?

Another question: BitbucketClient demands four parameters. Shouldn't it be enough to just specify the OAuth token and the secret token? Is there a reason why it also needs key and secretKey?When I execute requests to Bitbucket from cURL e.g., I only have to use these two:

curl "https://bitbucketories/user/repo?oauth_token_secret=XYZ&oauth_token=XYZ"

Thanks,
Michael

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.