xtof54 xtof54 - 1 year ago 173
Git Question

Run git push from javascript hosted in static site

Imagine a static web site compiled with jekyll and hosted on github pages. Is it possible to have some javascript on this page that asks the user some input, and then "git push" this input into some github repository ?

In other words, how to write in javascript the following program:

  • Ask the user for his name, put the name in variable s

  • Download (or pull) from a given github repo a text file "allnames.txt"

  • Add s at the end of allnames.txt

  • Commit and push the file "allnames.txt" back into github

Of course, I understand the potential security risks, because the javascript code would need to embed private ssh keys. But this would be a fun way to add dynamicity to a static web site, and may be someone knows of some solution to make this secure ?

Thank you !

Answer Source

If you know the internals of git (blobs, trees, commits), then you should be able to implement a solution with the GitHub REST API. This is not going to be done in 5 minutes. As for security, you should be able to use OAuth, so no need for private ssh key.

Have a look at: https://developer.github.com/v3/git/

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download