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

Use Yojson to parse github json responses #177

Merged
merged 3 commits into from
Jun 22, 2020
Merged

Use Yojson to parse github json responses #177

merged 3 commits into from
Jun 22, 2020

Conversation

gpetiot
Copy link
Member

@gpetiot gpetiot commented Nov 18, 2019

First step towards fixing #175

@gpetiot gpetiot changed the title [WIP] Use Yojson to communicate with github [WIP] Use Yojson to parse github json responses Nov 18, 2019
@gpetiot gpetiot changed the title [WIP] Use Yojson to parse github json responses Use Yojson to parse github json responses Nov 18, 2019
@gpetiot gpetiot requested a review from NathanReb November 25, 2019 11:24
Copy link
Contributor

@NathanReb NathanReb left a comment

Choose a reason for hiding this comment

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

This is a much welcome change! Thanks for working on this.

We could go even further but this is already a very good first step!

Some things need to be adjusted though. I think every function parsing an API response should be tested and in particular it should behave properly on the example response from https://developer.github.com/v3.
These kind of test would rule out the bug with Location for instance!

@gpetiot gpetiot changed the title Use Yojson to parse github json responses [WIP] Use Yojson to parse github json responses Nov 28, 2019
@gpetiot gpetiot changed the title [WIP] Use Yojson to parse github json responses Use Yojson to parse github json responses Nov 28, 2019
@gpetiot gpetiot requested a review from NathanReb November 28, 2019 16:20
Copy link
Contributor

@NathanReb NathanReb left a comment

Choose a reason for hiding this comment

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

Changes look good! I have a few suggestions to slightly improve it, let me know what you think!

@gpetiot gpetiot changed the title Use Yojson to parse github json responses [DONT-MERGE] Use Yojson to parse github json responses Mar 3, 2020
@gpetiot gpetiot marked this pull request as draft April 9, 2020 17:49
@gpetiot gpetiot changed the title [DONT-MERGE] Use Yojson to parse github json responses Use Yojson to parse github json responses Apr 9, 2020
@gpetiot gpetiot marked this pull request as ready for review April 16, 2020 11:08
@gpetiot
Copy link
Member Author

gpetiot commented Apr 17, 2020

@NathanReb I have a weird bug when testing this PR with dune-release-testing (when uploading the release asset), and I'm at the point where I'm doubting my testing setup is messed up (I reduced this PR to the minimum), can you confirm you get a similar error?

@NathanReb
Copy link
Contributor

I just went through releasing dune-release-testing from master where it worked well and with your branch where I indeed got an error:

$ dune-release publish
[-] Publishing documentation
[-] Selected packages: dummy
[-] Generating documentation from _build/dummy-v0.2.0+test.tbz
[-] Publishing to github
[-] Updating local gh-pages branch
[+] No documentation changes for dummy 0.2.0+test in directory . of gh-pages branch
[-] Publishing distribution
[-] Publishing to github
[?] Push tag v0.2.0+test to git@github.com:NathanReb/dune-release-testing.git? [Y/n]

[-] Pushing tag v0.2.0+test to git@github.com:NathanReb/dune-release-testing.git
[?] Create release v0.2.0+test on git@github.com:NathanReb/dune-release-testing.git? [Y/n]

[-] Creating release v0.2.0+test on git@github.com:NathanReb/dune-release-testing.git via github's API
[+] Succesfully created release with id 25850938
[?] Upload _build/dummy-v0.2.0+test.tbz as release asset? [Y/n]

[-] Uploading _build/dummy-v0.2.0+test.tbz as a release asset for v0.2.0+test via github's API
dune-release: [ERROR] Line 1, bytes 0-33:
                      Invalid token 'HTTP/1.1 201 Created
                      Cache-Contr'

@gpetiot
Copy link
Member Author

gpetiot commented Apr 27, 2020

I found what the probllem is, in some cases Curly doesn't correctly split the headers from the body, so everything ends up in the body, that cannot be parsed as a json entity. I defined a redundant function in Curl.Response.process to fix that.
I plan to open an issue for Curly but as we don't know when it will be fixed I choose to implement the ugly workaround anyway.

dune-release correctly works with this patch.

@gpetiot
Copy link
Member Author

gpetiot commented Apr 28, 2020

It turns out the issue was due to a missing -D argument to dump the headers, otherwise they end up in the body of the response. I think it's ready for a final review now.

edit: I will let the tests as is afterall, @NathanReb can we merge it?

@gpetiot gpetiot requested a review from NathanReb April 28, 2020 10:06
@gpetiot gpetiot requested a review from pitag-ha June 9, 2020 14:09
gpetiot added 2 commits June 16, 2020 23:22
Missing '-D' arg for upload archive request, otherwise the headers end up in the body

Make default_body a JSON entity
Copy link
Member

@pitag-ha pitag-ha left a comment

Choose a reason for hiding this comment

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

This seems like a very nice change to me. Before, for me, it was pretty tedious and hard to read through that part of the code and now it has become far clearer and also seems less error-prone. Thanks!

Of course, I'm missing a lot of context by the long history of discussion you've had on this, so there might be things I'm missing. But the code seems clear.

Comment on lines +63 to +64
"-D";
"-";
Copy link
Member

Choose a reason for hiding this comment

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

For me it has been a bit hard to understand why the "-D -" is necessary even after reading the commit message. I've understood it after reading the discussion. I'm wondering if it might be worth improving the commit message (or even leaving a comment here); for example, by mentioning that having the headers in the body messes up the JSON-structure of the body and by choosing a sentence that makes clear the causality (no "-D" argument => headers in the body). The latter e.g. by replacing "missing" with "added" in your commit message or so. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's true this is a bit obscure. I'm not sure the commit message is a good place for this, I was thinking of adding a few comments in the code to explain the arguments or define a simple abstraction to have a named variable for each argument, instead of handling string literals (curly should have done that, since it's only curl arguments but it can't hurt doing it ourselves) but this is a bigger change so it would be in another PR.

Copy link
Member

Choose a reason for hiding this comment

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

I like the idea of making that precise inside the code either by named variables or by comments. So yes, let's leave that for another PR.

Copy link
Contributor

@NathanReb NathanReb left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

@gpetiot gpetiot merged commit 979bad3 into tarides:master Jun 22, 2020
@gpetiot gpetiot deleted the jsonize branch June 22, 2020 09:33
pitag-ha added a commit to pitag-ha/opam-repository that referenced this pull request Jul 13, 2020
CHANGES:

### Added

- Add a `dune-release config` subcommand to display and edit the global
  configuration (tarides/dune-release#220, @NathanReb).
- Add command `delegate-info` to print information needed by external
  release scripts (tarides/dune-release#221, @pitag-ha)
- Use Curly instead of Cmd to interact with github (tarides/dune-release#202, @gpetiot)
- Add `x-commit-hash` field to the opam file when releasing (tarides/dune-release#224, @gpetiot)
- Add support for common alternative names for the license and
  ChangeLog file (tarides/dune-release#204, @paurkedal)

### Changed

- Command `tag`: improve error and log messages by comparing the provided
  commit with the commit correspondent to the provided tag (tarides/dune-release#226, @pitag-ha)
- Error logs: when an external command fails, include its error message in
  the error message posted by `dune-release` (tarides/dune-release#231, @pitag-ha)
- Error log formatting: avoid unnecessary line-breaks; indent only slightly
  in multi-lines (tarides/dune-release#234, @pitag-ha)
- Linting step of `dune-release distrib` does not fail when opam's `doc` field
  is missing. Do not try to generate nor publish the documentation when opam's
  `doc` field is missing. (tarides/dune-release#235, @gpetiot)

### Deprecated

- Deprecate opam 1.x (tarides/dune-release#195, @gpetiot)

### Fixed

- Separate packages names by spaces in `publish` logs (tarides/dune-release#171, @hannesm)
- Fix uncaught exceptions in distrib subcommand and replace them with proper
  error messages (tarides/dune-release#176, @gpetiot)
- Use the 'user' field in the configuration before inferring it from repo URI
  and handles HTTPS URIs (tarides/dune-release#183, @gpetiot)
- Ignore backup files when looking for README, CHANGES and LICENSE files
  (tarides/dune-release#194, @gpetiot)
- Do not echo input characters when reading token (tarides/dune-release#199, @gpetiot)
- Improve the output of VCS command errors (tarides/dune-release#193, @gpetiot)
- Better error handling when checking opam version (tarides/dune-release#195, @gpetiot)
- Do not write 'version' and 'name' fields in opam file (tarides/dune-release#200, @gpetiot)
- Use Yojson to parse github json response and avoid parsing bugs.
  (tarides/dune-release#177, @gpetiot)
- The `git` command used in `publish doc` should check `DUNE_RELEASE_GIT` (even
  if deprecated) before `PATH`. (tarides/dune-release#242, @gpetiot)
- Adapt the docs to the removal of the `log` subcommand (tarides/dune-release#196, @gpetiot)

### Removed

### Security
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.

3 participants