octoherd / script-setup-renovate

An octoherd script to setup renovate
ISC License
3 stars 0 forks source link

Use atob/btoa instead of Buffer for Base64 en/decode #11

Open oscard0m opened 3 years ago

oscard0m commented 3 years ago

Considerations: Use polyfill for Node: https://github.com/gr2m/octoherd-script-normalize-package-repository-field/blob/0272b1555ba5479e01e7a240d3e5ec646024bf37/script.js#L85-L92

Originally posted here: https://github.com/octoherd/script-setup-renovate/issues/3#issuecomment-792326838

gr2m commented 3 years ago

for reference: here is some good docs on base64: https://developer.mozilla.org/en-US/docs/Glossary/Base64. We might need to use TextEncoder instead of atob/btoa (see https://discourse.wicg.io/t/base64-with-textencoder-textdecoder/1307), I need to do some more research.

great insights: https://stackoverflow.com/questions/30631927/converting-to-base64-in-javascript-without-deprecated-escape-call

gr2m commented 3 years ago

I'm making it an official @octokit plugin after all, as so many folks run into headaches with the repository contents APIs: https://github.com/octokit/plugin-create-or-update-text-file.js

gr2m commented 3 years ago

Plugin is ready. We'll see how it will hold up across node / browser / deno, but at least it has the universal base64 encoding/decoding logic in a single place, and it is definitely better to only use Buffer directly

Next step is to add the plugin to @octoherd/octokit and then update the scripts to use the new octokit.createOrUpdateTextFile() method instead of sending requests to get/update file contents and handle the encoding/decoding within the script