{"action":"created","comment":{"url":"https://api.github.com/repos/hackmdio/hackmd/pulls/comments/83618760","pull_request_review_id":4448450,"id":83618760,"diff_hunk":"@@ -0,0 +1,131 @@\n+'use strict';\n+\n+var fs = require('fs');\n+var process = require('process');\n+var child_process = require('child_process');\n+var Promise = require('bluebird');\n+var NodeGit = require('nodegit');\n+var LZString = require('lz-string');\n+var models = require(\"./lib/models\");\n+\n+var repoRootDir = './notes';\n+\n+process.chdir(repoRootDir);\n+\n+\n+function exportNotes() {\n+  return models.Note\n+  .findAll()\n+  .then(function (notes) {\n+    // Iterate over all notes\n+    return Promise.all(notes.map(function (note) {\n+      var file = LZString.compressToBase64(note.id);\n+\n+      // Export note to file\n+      return new Promise(function (resolve) {\n+        console.log('Exporting ' + note.id + ' to ' + file);\n+        var body = LZString.decompressFromBase64(note.content);\n+        fs.writeFile(file, body, resolve);\n+      })\n+      .then(function () {\n+        return file;\n+      });\n+\n+    }));\n+  });\n+}\n+\n+\n+function addToIndexAndReturnTree(files, index) {\n+  return Promise.all(files.map(function (file) {\n+    console.log('Adding ' + file + ' to git index');\n+    return index.addByPath(file);\n+  }))\n+  .then(function () {\n+    console.log('Write files to git index');\n+    return index.write();\n+  })\n+  .then(function () {\n+    console.log('Write git index to tree');\n+    return index.writeTree();\n+  });\n+}\n+\n+\n+function getHeadCommit(repo) {\n+  return NodeGit.Reference\n+  .nameToId(repo, 'HEAD')\n+  .then(function (headRef) {\n+    return repo.getCommit(headRef);\n+  });\n+}\n+\n+\n+function commit(repo, tree) {\n+  return getHeadCommit(repo)\n+  .then(function (head) {\n+    console.log('Commiting...');\n+    var sig = NodeGit.Signature.now('Committer', 'johndoe@localhost');\n+    return repo.createCommit('HEAD', sig, sig, 'Automated import', tree, [head]);\n+  });\n+}\n+\n+\n+\n+NodeGit.Repository","path":"bin/dump-to-git.js","position":75,"original_position":75,"commit_id":"a7cd6e0b9fb96919fe5e4a687ce85ce3f248c1bf","original_commit_id":"a7cd6e0b9fb96919fe5e4a687ce85ce3f248c1bf","user":{"login":"ccoenen","id":124909,"avatar_url":"https://avatars.githubusercontent.com/u/124909?v=3","gravatar_id":"","url":"https://api.github.com/users/ccoenen","html_url":"https://github.com/ccoenen","followers_url":"https://api.github.com/users/ccoenen/followers","following_url":"https://api.github.com/users/ccoenen/following{/other_user}","gists_url":"https://api.github.com/users/ccoenen/gists{/gist_id}","starred_url":"https://api.github.com/users/ccoenen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ccoenen/subscriptions","organizations_url":"https://api.github.com/users/ccoenen/orgs","repos_url":"https://api.github.com/users/ccoenen/repos","events_url":"https://api.github.com/users/ccoenen/events{/privacy}","received_events_url":"https://api.github.com/users/ccoenen/received_events","type":"User","site_admin":false},"body":"this whole following structure is very deeply nested promise code. Currently, I find this rather hard to read. I think 2-3 things should be broken out as regular named functions, so that the overall program flow is easier to follow.","created_at":"2016-10-17T10:46:54Z","updated_at":"2016-10-17T10:46:54Z","html_url":"https://github.com/hackmdio/hackmd/pull/126#discussion_r83618760","pull_request_url":"https://api.github.com/repos/hackmdio/hackmd/pulls/126","_links":{"self":{"href":"https://api.github.com/repos/hackmdio/hackmd/pulls/comments/83618760"},"html":{"href":"https://github.com/hackmdio/hackmd/pull/126#discussion_r83618760"},"pull_request":{"href":"https://api.github.com/repos/hackmdio/hackmd/pulls/126"}}},"pull_request":{"url":"https://api.github.com/repos/hackmdio/hackmd/pulls/126","id":71037381,"html_url":"https://github.com/hackmdio/hackmd/pull/126","diff_url":"https://github.com/hackmdio/hackmd/pull/126.diff","patch_url":"https://github.com/hackmdio/hackmd/pull/126.patch","issue_url":"https://api.github.com/repos/hackmdio/hackmd/issues/126","number":126,"state":"open","locked":false,"title":"Dump all notes to a git repo for backup purpose","user":{"login":"DrMurx","id":1222566,"avatar_url":"https://avatars.githubusercontent.com/u/1222566?v=3","gravatar_id":"","url":"https://api.github.com/users/DrMurx","html_url":"https://github.com/DrMurx","followers_url":"https://api.github.com/users/DrMurx/followers","following_url":"https://api.github.com/users/DrMurx/following{/other_user}","gists_url":"https://api.github.com/users/DrMurx/gists{/gist_id}","starred_url":"https://api.github.com/users/DrMurx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DrMurx/subscriptions","organizations_url":"https://api.github.com/users/DrMurx/orgs","repos_url":"https://api.github.com/users/DrMurx/repos","events_url":"https://api.github.com/users/DrMurx/events{/privacy}","received_events_url":"https://api.github.com/users/DrMurx/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-05-23T10:21:07Z","updated_at":"2016-10-17T11:02:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9ca81fcddc85170bdc2669cbec021a646adb3987","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/hackmdio/hackmd/pulls/126/commits","review_comments_url":"https://api.github.com/repos/hackmdio/hackmd/pulls/126/comments","review_comment_url":"https://api.github.com/repos/hackmdio/hackmd/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hackmdio/hackmd/issues/126/comments","statuses_url":"https://api.github.com/repos/hackmdio/hackmd/statuses/a7cd6e0b9fb96919fe5e4a687ce85ce3f248c1bf","head":{"label":"DrMurx:master","ref":"master","sha":"a7cd6e0b9fb96919fe5e4a687ce85ce3f248c1bf","user":{"login":"DrMurx","id":1222566,"avatar_url":"https://avatars.githubusercontent.com/u/1222566?v=3","gravatar_id":"","url":"https://api.github.com/users/DrMurx","html_url":"https://github.com/DrMurx","followers_url":"https://api.github.com/users/DrMurx/followers","following_url":"https://api.github.com/users/DrMurx/following{/other_user}","gists_url":"https://api.github.com/users/DrMurx/gists{/gist_id}","starred_url":"https://api.github.com/users/DrMurx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DrMurx/subscriptions","organizations_url":"https://api.github.com/users/DrMurx/orgs","repos_url":"https://api.github.com/users/DrMurx/repos","events_url":"https://api.github.com/users/DrMurx/events{/privacy}","received_events_url":"https://api.github.com/users/DrMurx/received_events","type":"User","site_admin":false},"repo":{"id":59471838,"name":"hackmd","full_name":"DrMurx/hackmd","owner":{"login":"DrMurx","id":1222566,"avatar_url":"https://avatars.githubusercontent.com/u/1222566?v=3","gravatar_id":"","url":"https://api.github.com/users/DrMurx","html_url":"https://github.com/DrMurx","followers_url":"https://api.github.com/users/DrMurx/followers","following_url":"https://api.github.com/users/DrMurx/following{/other_user}","gists_url":"https://api.github.com/users/DrMurx/gists{/gist_id}","starred_url":"https://api.github.com/users/DrMurx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DrMurx/subscriptions","organizations_url":"https://api.github.com/users/DrMurx/orgs","repos_url":"https://api.github.com/users/DrMurx/repos","events_url":"https://api.github.com/users/DrMurx/events{/privacy}","received_events_url":"https://api.github.com/users/DrMurx/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/DrMurx/hackmd","description":"Realtime collaborative markdown notes on all platforms.","fork":true,"url":"https://api.github.com/repos/DrMurx/hackmd","forks_url":"https://api.github.com/repos/DrMurx/hackmd/forks","keys_url":"https://api.github.com/repos/DrMurx/hackmd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DrMurx/hackmd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DrMurx/hackmd/teams","hooks_url":"https://api.github.com/repos/DrMurx/hackmd/hooks","issue_events_url":"https://api.github.com/repos/DrMurx/hackmd/issues/events{/number}","events_url":"https://api.github.com/repos/DrMurx/hackmd/events","assignees_url":"https://api.github.com/repos/DrMurx/hackmd/assignees{/user}","branches_url":"https://api.github.com/repos/DrMurx/hackmd/branches{/branch}","tags_url":"https://api.github.com/repos/DrMurx/hackmd/tags","blobs_url":"https://api.github.com/repos/DrMurx/hackmd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DrMurx/hackmd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DrMurx/hackmd/git/refs{/sha}","trees_url":"https://api.github.com/repos/DrMurx/hackmd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DrMurx/hackmd/statuses/{sha}","languages_url":"https://api.github.com/repos/DrMurx/hackmd/languages","stargazers_url":"https://api.github.com/repos/DrMurx/hackmd/stargazers","contributors_url":"https://api.github.com/repos/DrMurx/hackmd/contributors","subscribers_url":"https://api.github.com/repos/DrMurx/hackmd/subscribers","subscription_url":"https://api.github.com/repos/DrMurx/hackmd/subscription","commits_url":"https://api.github.com/repos/DrMurx/hackmd/commits{/sha}","git_commits_url":"https://api.github.com/repos/DrMurx/hackmd/git/commits{/sha}","comments_url":"https://api.github.com/repos/DrMurx/hackmd/comments{/number}","issue_comment_url":"https://api.github.com/repos/DrMurx/hackmd/issues/comments{/number}","contents_url":"https://api.github.com/repos/DrMurx/hackmd/contents/{+path}","compare_url":"https://api.github.com/repos/DrMurx/hackmd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DrMurx/hackmd/merges","archive_url":"https://api.github.com/repos/DrMurx/hackmd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DrMurx/hackmd/downloads","issues_url":"https://api.github.com/repos/DrMurx/hackmd/issues{/number}","pulls_url":"https://api.github.com/repos/DrMurx/hackmd/pulls{/number}","milestones_url":"https://api.github.com/repos/DrMurx/hackmd/milestones{/number}","notifications_url":"https://api.github.com/repos/DrMurx/hackmd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DrMurx/hackmd/labels{/name}","releases_url":"https://api.github.com/repos/DrMurx/hackmd/releases{/id}","deployments_url":"https://api.github.com/repos/DrMurx/hackmd/deployments","created_at":"2016-05-23T09:59:09Z","updated_at":"2016-05-23T09:59:10Z","pushed_at":"2016-05-23T10:19:30Z","git_url":"git://github.com/DrMurx/hackmd.git","ssh_url":"git@github.com:DrMurx/hackmd.git","clone_url":"https://github.com/DrMurx/hackmd.git","svn_url":"https://github.com/DrMurx/hackmd","homepage":"https://hackmd.io","size":9675,"stargazers_count":0,"watchers_count":0,"language":"CSS","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"hackmdio:master","ref":"master","sha":"f3418a619ca672d52136e8ddd0846ea56a876904","user":{"login":"hackmdio","id":13574138,"avatar_url":"https://avatars.githubusercontent.com/u/13574138?v=3","gravatar_id":"","url":"https://api.github.com/users/hackmdio","html_url":"https://github.com/hackmdio","followers_url":"https://api.github.com/users/hackmdio/followers","following_url":"https://api.github.com/users/hackmdio/following{/other_user}","gists_url":"https://api.github.com/users/hackmdio/gists{/gist_id}","starred_url":"https://api.github.com/users/hackmdio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hackmdio/subscriptions","organizations_url":"https://api.github.com/users/hackmdio/orgs","repos_url":"https://api.github.com/users/hackmdio/repos","events_url":"https://api.github.com/users/hackmdio/events{/privacy}","received_events_url":"https://api.github.com/users/hackmdio/received_events","type":"Organization","site_admin":false},"repo":{"id":35017238,"name":"hackmd","full_name":"hackmdio/hackmd","owner":{"login":"hackmdio","id":13574138,"avatar_url":"https://avatars.githubusercontent.com/u/13574138?v=3","gravatar_id":"","url":"https://api.github.com/users/hackmdio","html_url":"https://github.com/hackmdio","followers_url":"https://api.github.com/users/hackmdio/followers","following_url":"https://api.github.com/users/hackmdio/following{/other_user}","gists_url":"https://api.github.com/users/hackmdio/gists{/gist_id}","starred_url":"https://api.github.com/users/hackmdio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hackmdio/subscriptions","organizations_url":"https://api.github.com/users/hackmdio/orgs","repos_url":"https://api.github.com/users/hackmdio/repos","events_url":"https://api.github.com/users/hackmdio/events{/privacy}","received_events_url":"https://api.github.com/users/hackmdio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hackmdio/hackmd","description":"Realtime collaborative markdown notes on all platforms.","fork":false,"url":"https://api.github.com/repos/hackmdio/hackmd","forks_url":"https://api.github.com/repos/hackmdio/hackmd/forks","keys_url":"https://api.github.com/repos/hackmdio/hackmd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hackmdio/hackmd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hackmdio/hackmd/teams","hooks_url":"https://api.github.com/repos/hackmdio/hackmd/hooks","issue_events_url":"https://api.github.com/repos/hackmdio/hackmd/issues/events{/number}","events_url":"https://api.github.com/repos/hackmdio/hackmd/events","assignees_url":"https://api.github.com/repos/hackmdio/hackmd/assignees{/user}","branches_url":"https://api.github.com/repos/hackmdio/hackmd/branches{/branch}","tags_url":"https://api.github.com/repos/hackmdio/hackmd/tags","blobs_url":"https://api.github.com/repos/hackmdio/hackmd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hackmdio/hackmd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hackmdio/hackmd/git/refs{/sha}","trees_url":"https://api.github.com/repos/hackmdio/hackmd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hackmdio/hackmd/statuses/{sha}","languages_url":"https://api.github.com/repos/hackmdio/hackmd/languages","stargazers_url":"https://api.github.com/repos/hackmdio/hackmd/stargazers","contributors_url":"https://api.github.com/repos/hackmdio/hackmd/contributors","subscribers_url":"https://api.github.com/repos/hackmdio/hackmd/subscribers","subscription_url":"https://api.github.com/repos/hackmdio/hackmd/subscription","commits_url":"https://api.github.com/repos/hackmdio/hackmd/commits{/sha}","git_commits_url":"https://api.github.com/repos/hackmdio/hackmd/git/commits{/sha}","comments_url":"https://api.github.com/repos/hackmdio/hackmd/comments{/number}","issue_comment_url":"https://api.github.com/repos/hackmdio/hackmd/issues/comments{/number}","contents_url":"https://api.github.com/repos/hackmdio/hackmd/contents/{+path}","compare_url":"https://api.github.com/repos/hackmdio/hackmd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hackmdio/hackmd/merges","archive_url":"https://api.github.com/repos/hackmdio/hackmd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hackmdio/hackmd/downloads","issues_url":"https://api.github.com/repos/hackmdio/hackmd/issues{/number}","pulls_url":"https://api.github.com/repos/hackmdio/hackmd/pulls{/number}","milestones_url":"https://api.github.com/repos/hackmdio/hackmd/milestones{/number}","notifications_url":"https://api.github.com/repos/hackmdio/hackmd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hackmdio/hackmd/labels{/name}","releases_url":"https://api.github.com/repos/hackmdio/hackmd/releases{/id}","deployments_url":"https://api.github.com/repos/hackmdio/hackmd/deployments","created_at":"2015-05-04T06:06:45Z","updated_at":"2016-10-17T01:57:44Z","pushed_at":"2016-10-17T10:11:30Z","git_url":"git://github.com/hackmdio/hackmd.git","ssh_url":"git@github.com:hackmdio/hackmd.git","clone_url":"https://github.com/hackmdio/hackmd.git","svn_url":"https://github.com/hackmdio/hackmd","homepage":"https://hackmd.io","size":12511,"stargazers_count":988,"watchers_count":988,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":131,"mirror_url":null,"open_issues_count":50,"forks":131,"open_issues":50,"watchers":988,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hackmdio/hackmd/pulls/126"},"html":{"href":"https://github.com/hackmdio/hackmd/pull/126"},"issue":{"href":"https://api.github.com/repos/hackmdio/hackmd/issues/126"},"comments":{"href":"https://api.github.com/repos/hackmdio/hackmd/issues/126/comments"},"review_comments":{"href":"https://api.github.com/repos/hackmdio/hackmd/pulls/126/comments"},"review_comment":{"href":"https://api.github.com/repos/hackmdio/hackmd/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hackmdio/hackmd/pulls/126/commits"},"statuses":{"href":"https://api.github.com/repos/hackmdio/hackmd/statuses/a7cd6e0b9fb96919fe5e4a687ce85ce3f248c1bf"}}}}
{"actor":{"display_login":"ccoenen"}}