haskell-github / github

The github API for Haskell
https://hackage.haskell.org/package/github
BSD 3-Clause "New" or "Revised" License
408 stars 190 forks source link

Implement GitHub API server #258

Open iphydf opened 7 years ago

iphydf commented 7 years ago

I'd like to implement a caching GitHub API server (see https://github.com/TokTok/github-tools/issues/43) that is kept up to date via webhooks. This requires the GitHub types to be convertible back to JSON in a way that the result can be parsed again by GitHub API clients. Currently, there are FromJSON instances for all types, but no ToJSON ones.

Are there plans to support a transformation back to JSON?

phadej commented 7 years ago

There are no plans. I haven't checked, but if the majority of FromJSON can be autoderived using tuned Options than making ToJSON would be possible, so at least clients using this library can benefit from such proxy.

Yet, if the consumer is also using this library, I'd recommend using Binary instances (we do that at work)

iphydf commented 7 years ago

https://github.com/TokTok/github-tools/blob/13e4a473d45084b9c9bf98e569d90d1eb2631086/web/GitHub/Types/Base/PullRequest.hs

Doing this helps a lot if you want to keep your data structure up to date with what's actually provided by the API. I have a webhook sitting on heroku that receives all the events from the toktok organisation. If github adds a field, I will know about it, because I produce json back out of the data structure and simply compare them for equality (modulo nulls).

phadej commented 7 years ago

That's good philosophical question. How closely github package should follow GItHub api. From my (limited and non-automated maintainership) point-of-view adding fields on-need is more deliberate that trying to track GitHub api proactively. Especially as latter is made hard: have to reverse engineer and not e.g. parse some formalised spec. I'd happy to (love to!) do automation based on formalised (= machine readable) spec, but AFAIK there isn't one. See https://github.com/brendanhay/amazonka/blob/develop/gen/model/dynamodb/2012-08-10/service-2.json for example.

So I see the current way to proceed: