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

Adding missing fields to User #250

Merged
merged 5 commits into from
Feb 18, 2019
Merged

Adding missing fields to User #250

merged 5 commits into from
Feb 18, 2019

Conversation

mfirry
Copy link
Contributor

@mfirry mfirry commented Feb 8, 2019

I needed these two fields for a personal project (though I know they're pretty easy to come up with... nonetheless, feel free to reject this should you think it's not required.

Note: I had to explicitly define circe's en/decoders on User's companion object and use semiauto instead of auto in Users. Not sure why I had to but I kept having weird DerivedDecoder issues without this change.

@JesusMtnez
Copy link
Contributor

@mfirry Thank you for this contribution. At first, it looks good.
Did you try to run the tests? I'm not sure if you may need to update the tests too. I cannot try them now, but I could do it later.

@BenFradet
Copy link
Contributor

I had to explicitly define circe's en/decoders on User's companion object and use semiauto instead of auto in Users. Not sure why I had to but I kept having weird DerivedDecoder issues without this change.

Weird, what kind of issue were you getting?

@mfirry
Copy link
Contributor Author

mfirry commented Feb 8, 2019

So at first I figured I could "just" add the two fields (both as Option[String]). I did that and published it locally and tried it (as a dep of my project) and I had the following:

(it's a Play app)

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[RuntimeException: java.lang.NoSuchMethodError: github4s.free.domain.User.<init>(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Lscala/Option;Lscala/Option;Lscala/Option;Lscala/Option;Lscala/Option;Lscala/Option;)V]]
  at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:323)
  at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:243)
  at play.core.server.AkkaHttpServer$$anonfun$1.applyOrElse(AkkaHttpServer.scala:382)
  at play.core.server.AkkaHttpServer$$anonfun$1.applyOrElse(AkkaHttpServer.scala:380)
  at scala.concurrent.Future.$anonfun$recoverWith$1(Future.scala:417)
  at scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:41)
  at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:64)
  at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
  at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:91)
  at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodError: github4s.free.domain.User.<init>(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Lscala/Option;Lscala/Option;Lscala/Option;Lscala/Option;Lscala/Option;Lscala/Option;)V
  at play.api.mvc.ActionBuilder$$anon$10.apply(Action.scala:425)
  at play.api.mvc.Action.$anonfun$apply$2(Action.scala:97)
  at play.api.libs.streams.StrictAccumulator.$anonfun$mapFuture$4(Accumulator.scala:175)
  at scala.util.Try$.apply(Try.scala:213)
  at play.api.libs.streams.StrictAccumulator.$anonfun$mapFuture$3(Accumulator.scala:175)
  at scala.Function1.$anonfun$andThen$1(Function1.scala:57)
  at scala.Function1.$anonfun$andThen$1(Function1.scala:57)
  at scala.Function1.$anonfun$andThen$1(Function1.scala:57)
  at play.api.libs.streams.StrictAccumulator.run(Accumulator.scala:208)
  at play.core.server.AkkaHttpServer.$anonfun$runAction$4(AkkaHttpServer.scala:376)
Caused by: java.lang.NoSuchMethodError: github4s.free.domain.User.<init>(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Lscala/Option;Lscala/Option;Lscala/Option;Lscala/Option;Lscala/Option;Lscala/Option;)V
  at github4s.api.Users$anon$importedDecoder$macro$25$1$anon$macro$23$1.from(Users.scala:45)
  at github4s.api.Users$anon$importedDecoder$macro$25$1$anon$macro$23$1.from(Users.scala:45)
  at shapeless.LabelledGeneric$$anon$1.from(generic.scala:229)
  at shapeless.LabelledGeneric$$anon$1.from(generic.scala:226)
  at io.circe.generic.decoding.DerivedDecoder$$anon$1.apply(DerivedDecoder.scala:15)
  at io.circe.Decoder.decodeJson(Decoder.scala:64)
  at io.circe.Decoder.decodeJson$(Decoder.scala:64)
  at io.circe.generic.decoding.DerivedDecoder.decodeJson(DerivedDecoder.scala:6)
  at io.circe.Parser.finishDecode(Parser.scala:13)
  at io.circe.Parser.finishDecode$(Parser.scala:9)
[info] p.c.s.AkkaHttpServer - Stopping server...

@pepegar
Copy link
Contributor

pepegar commented Feb 8, 2019

Hi @mfirry.

I believe you're having a binary compatibility issue between the library that's currently published (0.20.0), and the one you've published locally.

The error you're receiving says that the current github4s artifact in your classpath doesn't have all those fields.

Can you share your libraryDependencies value to see if there's any issue there?

you could try doing a sbt clean, followed by bumping github4s version & releasing locally, followed by depending on the new locally published dependency in your play app. That should work?

@mfirry
Copy link
Contributor Author

mfirry commented Feb 8, 2019

Hi @pepegar,
"com.47deg" %% "github4s" % "0.20.1-SNAPSHOT" is on my deps list.

I'll try what you suggest and update this PR if it works.

Thanks a lot.

@mfirry
Copy link
Contributor Author

mfirry commented Feb 8, 2019

Looks like you were right @pepegar. I'll update this in a minute.

Copy link
Contributor

@BenFradet BenFradet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

successfully ran the tests locally 👍

@mfirry
Copy link
Contributor Author

mfirry commented Feb 8, 2019

I might need to add more fields (like type, hireable, public_repos and so on...).

Should I do this in one big PR (this one) or smaller ones?

@pepegar
Copy link
Contributor

pepegar commented Feb 8, 2019

@mfirry regarding adding more fields, I don't have a strong opinion. If you want to keep adding commits to this PR is fine from my side. Just mark this PR as WIP and ping us when you're done.

@mfirry mfirry changed the title "followers_url" and "following_url" fields added to User WIP: adding missing fields to User Feb 8, 2019
@mfirry mfirry changed the title WIP: adding missing fields to User Adding missing fields to User Feb 8, 2019
@mfirry
Copy link
Contributor Author

mfirry commented Feb 8, 2019

I'm re-thinking about the following and followers part... I might add getFollowing and getFollowers to the User algebra. I'll make a quick try and let you guys know.

Having a url as a String field of the User does not seem very useful.

@mfirry
Copy link
Contributor Author

mfirry commented Feb 8, 2019

Ok it does work but the User object in the /following call is slightly different than the one in the /users/_username_ (for example it misses the public_repos field).

How to go about it?

  • having lots of optional fields
  • define another User case class (think LightUser) with less fields

I'll spend the weekend thinking about.

What's your take?

@pepegar
Copy link
Contributor

pepegar commented Feb 8, 2019

Hi @mfirry,

hum... that's tricky :)

How many different fields are there? My gut feeling is that, if there's no a lot of different fields I prefer to keep a single entity User.

If the fields change a lot though, it may make sense to have different entities.

Sorry to give you such a vague answer :)

I think we could discuss it much better if you can push your WIP to see how many optional fields we end up with.

@mfirry
Copy link
Contributor Author

mfirry commented Feb 11, 2019

To answer your question, here's the list of fields you get from the users api and you don't get from the following one:

<   "name": "Tom Preston-Werner",
<   "company": null,
<   "blog": "http://tom.preston-werner.com",
<   "location": "San Francisco",
<   "email": null,
<   "hireable": null,
<   "bio": null,
<   "public_repos": 61,
<   "public_gists": 62,
<   "followers": 21344,
<   "following": 11,
<   "created_at": "2007-10-20T05:24:19Z",
<   "updated_at": "2018-12-18T19:52:12Z"

Of all of these, in this PR, I've added hirebale, bio and public_repos...
Here's what I figured I could do: I'm gonna set public_repos as Option[Int] and end this one here.

I'll open a separate PR in order to be able to add the GetFollowing to the Users ops ADT.

Deal? :)

@mfirry
Copy link
Contributor Author

mfirry commented Feb 15, 2019

Hi. I'm pretty much done here. Let me know if it makes sense to you. Cheers!

@pepegar
Copy link
Contributor

pepegar commented Feb 15, 2019

Hey @mfirry, sorry I forgot about this. I'll review it ASAP, thank you!

@Yawolf
Copy link

Yawolf commented Feb 18, 2019

Hi @mfirry, thanks for your contribution! I think your changes are good! However you have to fix also the test so we can have a green in travis and merge your PR 🙂

Fix the tests so we can fully review you PR!!

Thanks! 😄

@mfirry
Copy link
Contributor Author

mfirry commented Feb 18, 2019

Uh sorry. My bad. Don't know how that happened. Fixing it as we speak.

@mfirry
Copy link
Contributor Author

mfirry commented Feb 18, 2019

So some integration tests fail... but it's not clear to me whether I can do anything about it. Can somebody else have a look and point me to the right direction?
Thanks

Copy link
Member

@juanpedromoreno juanpedromoreno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mfirry , I ran the tests locally and they succeeded

@juanpedromoreno juanpedromoreno merged commit 72dd2ca into 47degrees:master Feb 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants