iamdanfox / ghupdate

Update GitHub pages with wysiwyg and no git commands
https://iamdanfox.github.io/ghupdate
5 stars 1 forks source link

Save textarea changes in a commit #8

Closed iamdanfox closed 9 years ago

iamdanfox commented 9 years ago

https://developer.github.com/v3/git/commits/#create-a-commit

Using the manual API, it seems like we'd need to create and save a blob, then update the tree, then create a commit...

It may be worth using an API wrapping library like Octokit.js instead.

iamdanfox commented 9 years ago

Oh man Octokit looks great...

Write multiple files (update or add) in one commit

var repo = gh.getRepo(username, reponame);

var branch = repo.getBranch("BRANCH_NAME");

var contents = {
  "FILE1.txt": "Contents of the file",
  "FILE2.txt": {isBase64: true, content: "BASE_64_ENCODED_STRING"}
}
branch.writeMany(contents, message)
.then(function() {});

(Would need lots of .thens to work properly)

iamdanfox commented 9 years ago

Running with github.js.

Need to figure out a nice way to keep a connection to the github api running alongside selected stuff, even if the user hasn't logged in with OAuth!

iamdanfox commented 9 years ago

So close... The write method is failing to send a valid author {name, email} to github.

If I manually change the .commit function https://github.com/michael/github/blob/master/github.js#L412

          "author": {
            "name": options.user,
            "email": "iamdanfox@gmail.com"
          },

Everything works

SUCCESS https://github.com/iamdanfox/ghupdate/commit/d5aff7de7167a4bf01d3b0c9bb89513740fd6a0c