5 ms·
Me: Wow, that associative array looks very powerful. Is there a way to leverage it to do something useful like convert curl-obtained JSON array of file patches
by jancsika 7y ago
Me: Wow, that associative array looks very powerful. Is there a way to leverage it to do something useful like convert curl-obtained JSON array of file patches from Github's API to the mbox format that `git am` expects?
Unix: No, that JSON data is too structured. But if you have a more error-prone format like CSV I can show you a neat trick to filter your bowlers by number of spares.
- james_s_tayler 7y agocan't u just process JSON data with jq? https://stedolan.github.io/jq/ https://stedolan.github.io/jq/
- jancsika 7y agoI'd still need to find a way to massage the data into the mbox format because that is the ancient format that git understands. I'm not saying that there isn't a way to do that. Only that it can only be done poorly with a big ugly (and probably buggy) spaghetti script that looks nothing like what the expressive demo suggests it should look like.
- james_s_tayler 7y agoIf you're getting a bunch of stuff with curl from GitHub can't you just use curl to get the patches directly from github? Append .patch to the end of a pr or commit and it spits out the mbox formatted patch. https://github.com/jiphex/mbox/commit/f139c575e306a1691a31d8c2f4b44f48984b1267.patch https://github.com/jiphex/mbox/commit/f139c575e306a1691a31d8...
- jancsika 7y agoIf you do that with curl it will redirect to the login page. Github obviously wants me to use their API. I assume this wasn't always the case as the use case I'm referencing is a build script I'm debugging.
- detaro 7y agoThe example link above works for me, interestingly enough.
- james_s_tayler 7y agoI just tried running curl on it now and it came back fine without redirecting me. For a private repo you just need to set the correct options to curl. curl -Lk --cookie "user_session=your_session_cookie_here" https://github.com/your_org/your_project/pull/123.patch https://github.com/your_org/your_project/pull/123.patch
- jancsika 7y agoAnd what is the unix tool I use to automatically retrieve the session cookie and paste it there?
- james_s_tayler 7y agoNaturally, you use curl. You just instruct curl to save the cookies that the login process sends back to you. Then you reuse those cookies on the subsequent request. Found an example here. https://gist.github.com/d48/3501047 https://gist.github.com/d48/3501047
- 0815test 7y agoLuckily for us, Unix is easy to enhance by adding new "skills" to it - a quick search brought me to https://ilya-sher.org/2018/04/10/list-of-json-tools-for-command-line/ https://ilya-sher.org/2018/04/10/list-of-json-tools-for-comm...
- PyroLagus 7y agoWell, there's jq, which is perfect for that job, but unfortunately it's not a standard utility, and I'm not sure it ever will be, because we have to stick only with stuff invented in the 90's.
- lazyjones 7y agohttps://github.com/dominictarr/JSON.sh https://github.com/dominictarr/JSON.sh https://github.com/step-/JSON.awk https://github.com/step-/JSON.awk
- JdeBP 7y agoYou have conflated the awk tool with an entire operating system. The operating system of course has many tools, and there are many more tools that one can further add to it, dealing with a range of file formats.
- ori_b 7y agoGron converts json into something processable.