{"action":"created","comment":{"url":"https://api.github.com/repos/sourcegraph/checkup/pulls/comments/75397025","id":75397025,"diff_hunk":"@@ -0,0 +1,114 @@\n+package checkup\n+\n+import (\n+\t\"encoding/json\"\n+\t\"io/ioutil\"\n+\t\"os\"\n+\t\"path/filepath\"\n+\t\"time\"\n+)\n+\n+const indexName = \"index.json\"\n+\n+// FS is a way to store checkup results on the local filesystem.\n+type FS struct {\n+\t// The path to the directory where check files will be stored.\n+\tDir string `json:\"dir\"`\n+\t// The URL corresponding to fs.Dir.\n+\tURL string `json:\"url\"`\n+\n+\t// Check files older than CheckExpiry will be\n+\t// deleted on calls to Maintain(). If this is\n+\t// the zero value, no old check files will be\n+\t// deleted.\n+\tCheckExpiry time.Duration `json:\"check_expiry,omitempty\"`\n+}\n+\n+func (fs FS) readIndex() (map[string]int64, error) {\n+\tindex := map[string]int64{}\n+\n+\tf, err := os.Open(filepath.Join(fs.Dir, indexName))\n+\tif os.IsNotExist(err) {\n+\t\treturn index, nil\n+\t} else if err != nil {\n+\t\treturn nil, err\n+\t}\n+\tdefer f.Close()\n+\n+\terr = json.NewDecoder(f).Decode(&index)\n+\treturn index, err\n+}\n+\n+func (fs FS) writeIndex(index map[string]int64) error {\n+\tf, err := os.Create(filepath.Join(fs.Dir, indexName))\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\tdefer f.Close()\n+\n+\treturn json.NewEncoder(f).Encode(index)\n+}\n+\n+// Store stores results on filesystem according to the configuration in fs.\n+func (fs FS) Store(results []Result) error {\n+\t// Write results to a new file\n+\tname := *GenerateFilename()\n+\tf, err := os.Create(filepath.Join(fs.Dir, name))\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\terr = json.NewEncoder(f).Encode(results)\n+\tf.Close()\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\t// Read current index file\n+\tindex, err := fs.readIndex()\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\t// Add new file to index\n+\tindex[name] = time.Now().UnixNano()","path":"fs.go","position":73,"original_position":73,"commit_id":"0ea536878d200db29b07e98c0d5b1c6b20965cb4","original_commit_id":"0ea536878d200db29b07e98c0d5b1c6b20965cb4","user":{"login":"mholt","id":1128849,"avatar_url":"https://avatars.githubusercontent.com/u/1128849?v=3","gravatar_id":"","url":"https://api.github.com/users/mholt","html_url":"https://github.com/mholt","followers_url":"https://api.github.com/users/mholt/followers","following_url":"https://api.github.com/users/mholt/following{/other_user}","gists_url":"https://api.github.com/users/mholt/gists{/gist_id}","starred_url":"https://api.github.com/users/mholt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mholt/subscriptions","organizations_url":"https://api.github.com/users/mholt/orgs","repos_url":"https://api.github.com/users/mholt/repos","events_url":"https://api.github.com/users/mholt/events{/privacy}","received_events_url":"https://api.github.com/users/mholt/received_events","type":"User","site_admin":false},"body":"Shouldn't this be the same filename that you used above in os.Create? `name` is retrieved from `GenerateFilename()` but you use a potentially different time value here.","created_at":"2016-08-18T21:56:37Z","updated_at":"2016-08-18T21:56:37Z","html_url":"https://github.com/sourcegraph/checkup/pull/13#discussion_r75397025","pull_request_url":"https://api.github.com/repos/sourcegraph/checkup/pulls/13","_links":{"self":{"href":"https://api.github.com/repos/sourcegraph/checkup/pulls/comments/75397025"},"html":{"href":"https://github.com/sourcegraph/checkup/pull/13#discussion_r75397025"},"pull_request":{"href":"https://api.github.com/repos/sourcegraph/checkup/pulls/13"}}},"pull_request":{"url":"https://api.github.com/repos/sourcegraph/checkup/pulls/13","id":81215800,"html_url":"https://github.com/sourcegraph/checkup/pull/13","diff_url":"https://github.com/sourcegraph/checkup/pull/13.diff","patch_url":"https://github.com/sourcegraph/checkup/pull/13.patch","issue_url":"https://api.github.com/repos/sourcegraph/checkup/issues/13","number":13,"state":"open","locked":false,"title":"Adds local filesystem support","user":{"login":"emersion","id":506932,"avatar_url":"https://avatars.githubusercontent.com/u/506932?v=3","gravatar_id":"","url":"https://api.github.com/users/emersion","html_url":"https://github.com/emersion","followers_url":"https://api.github.com/users/emersion/followers","following_url":"https://api.github.com/users/emersion/following{/other_user}","gists_url":"https://api.github.com/users/emersion/gists{/gist_id}","starred_url":"https://api.github.com/users/emersion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emersion/subscriptions","organizations_url":"https://api.github.com/users/emersion/orgs","repos_url":"https://api.github.com/users/emersion/repos","events_url":"https://api.github.com/users/emersion/events{/privacy}","received_events_url":"https://api.github.com/users/emersion/received_events","type":"User","site_admin":false},"body":"- [x] Go storage\r\n- [x] JS storage\r\n- [x] Go tests\r\n\r\nFixes #6","created_at":"2016-08-13T13:27:37Z","updated_at":"2016-08-18T21:56:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"52d1e8388071ec98e68b38a9f297217efed55fe3","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/sourcegraph/checkup/pulls/13/commits","review_comments_url":"https://api.github.com/repos/sourcegraph/checkup/pulls/13/comments","review_comment_url":"https://api.github.com/repos/sourcegraph/checkup/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sourcegraph/checkup/issues/13/comments","statuses_url":"https://api.github.com/repos/sourcegraph/checkup/statuses/0ea536878d200db29b07e98c0d5b1c6b20965cb4","head":{"label":"emersion:fs","ref":"fs","sha":"0ea536878d200db29b07e98c0d5b1c6b20965cb4","user":{"login":"emersion","id":506932,"avatar_url":"https://avatars.githubusercontent.com/u/506932?v=3","gravatar_id":"","url":"https://api.github.com/users/emersion","html_url":"https://github.com/emersion","followers_url":"https://api.github.com/users/emersion/followers","following_url":"https://api.github.com/users/emersion/following{/other_user}","gists_url":"https://api.github.com/users/emersion/gists{/gist_id}","starred_url":"https://api.github.com/users/emersion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emersion/subscriptions","organizations_url":"https://api.github.com/users/emersion/orgs","repos_url":"https://api.github.com/users/emersion/repos","events_url":"https://api.github.com/users/emersion/events{/privacy}","received_events_url":"https://api.github.com/users/emersion/received_events","type":"User","site_admin":false},"repo":{"id":65611634,"name":"checkup","full_name":"emersion/checkup","owner":{"login":"emersion","id":506932,"avatar_url":"https://avatars.githubusercontent.com/u/506932?v=3","gravatar_id":"","url":"https://api.github.com/users/emersion","html_url":"https://github.com/emersion","followers_url":"https://api.github.com/users/emersion/followers","following_url":"https://api.github.com/users/emersion/following{/other_user}","gists_url":"https://api.github.com/users/emersion/gists{/gist_id}","starred_url":"https://api.github.com/users/emersion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emersion/subscriptions","organizations_url":"https://api.github.com/users/emersion/orgs","repos_url":"https://api.github.com/users/emersion/repos","events_url":"https://api.github.com/users/emersion/events{/privacy}","received_events_url":"https://api.github.com/users/emersion/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/emersion/checkup","description":"Distributed, lock-free, self-hosted health checks and status pages","fork":true,"url":"https://api.github.com/repos/emersion/checkup","forks_url":"https://api.github.com/repos/emersion/checkup/forks","keys_url":"https://api.github.com/repos/emersion/checkup/keys{/key_id}","collaborators_url":"https://api.github.com/repos/emersion/checkup/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/emersion/checkup/teams","hooks_url":"https://api.github.com/repos/emersion/checkup/hooks","issue_events_url":"https://api.github.com/repos/emersion/checkup/issues/events{/number}","events_url":"https://api.github.com/repos/emersion/checkup/events","assignees_url":"https://api.github.com/repos/emersion/checkup/assignees{/user}","branches_url":"https://api.github.com/repos/emersion/checkup/branches{/branch}","tags_url":"https://api.github.com/repos/emersion/checkup/tags","blobs_url":"https://api.github.com/repos/emersion/checkup/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/emersion/checkup/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/emersion/checkup/git/refs{/sha}","trees_url":"https://api.github.com/repos/emersion/checkup/git/trees{/sha}","statuses_url":"https://api.github.com/repos/emersion/checkup/statuses/{sha}","languages_url":"https://api.github.com/repos/emersion/checkup/languages","stargazers_url":"https://api.github.com/repos/emersion/checkup/stargazers","contributors_url":"https://api.github.com/repos/emersion/checkup/contributors","subscribers_url":"https://api.github.com/repos/emersion/checkup/subscribers","subscription_url":"https://api.github.com/repos/emersion/checkup/subscription","commits_url":"https://api.github.com/repos/emersion/checkup/commits{/sha}","git_commits_url":"https://api.github.com/repos/emersion/checkup/git/commits{/sha}","comments_url":"https://api.github.com/repos/emersion/checkup/comments{/number}","issue_comment_url":"https://api.github.com/repos/emersion/checkup/issues/comments{/number}","contents_url":"https://api.github.com/repos/emersion/checkup/contents/{+path}","compare_url":"https://api.github.com/repos/emersion/checkup/compare/{base}...{head}","merges_url":"https://api.github.com/repos/emersion/checkup/merges","archive_url":"https://api.github.com/repos/emersion/checkup/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/emersion/checkup/downloads","issues_url":"https://api.github.com/repos/emersion/checkup/issues{/number}","pulls_url":"https://api.github.com/repos/emersion/checkup/pulls{/number}","milestones_url":"https://api.github.com/repos/emersion/checkup/milestones{/number}","notifications_url":"https://api.github.com/repos/emersion/checkup/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/emersion/checkup/labels{/name}","releases_url":"https://api.github.com/repos/emersion/checkup/releases{/id}","deployments_url":"https://api.github.com/repos/emersion/checkup/deployments","created_at":"2016-08-13T10:10:45Z","updated_at":"2016-08-13T10:10:46Z","pushed_at":"2016-08-18T21:52:11Z","git_url":"git://github.com/emersion/checkup.git","ssh_url":"git@github.com:emersion/checkup.git","clone_url":"https://github.com/emersion/checkup.git","svn_url":"https://github.com/emersion/checkup","homepage":"https://sourcegraph.github.io/checkup","size":395,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"sourcegraph:master","ref":"master","sha":"94097605f5f93dd2235ee9bdedfd54bfab88579e","user":{"login":"sourcegraph","id":3979584,"avatar_url":"https://avatars.githubusercontent.com/u/3979584?v=3","gravatar_id":"","url":"https://api.github.com/users/sourcegraph","html_url":"https://github.com/sourcegraph","followers_url":"https://api.github.com/users/sourcegraph/followers","following_url":"https://api.github.com/users/sourcegraph/following{/other_user}","gists_url":"https://api.github.com/users/sourcegraph/gists{/gist_id}","starred_url":"https://api.github.com/users/sourcegraph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sourcegraph/subscriptions","organizations_url":"https://api.github.com/users/sourcegraph/orgs","repos_url":"https://api.github.com/users/sourcegraph/repos","events_url":"https://api.github.com/users/sourcegraph/events{/privacy}","received_events_url":"https://api.github.com/users/sourcegraph/received_events","type":"Organization","site_admin":false},"repo":{"id":56108598,"name":"checkup","full_name":"sourcegraph/checkup","owner":{"login":"sourcegraph","id":3979584,"avatar_url":"https://avatars.githubusercontent.com/u/3979584?v=3","gravatar_id":"","url":"https://api.github.com/users/sourcegraph","html_url":"https://github.com/sourcegraph","followers_url":"https://api.github.com/users/sourcegraph/followers","following_url":"https://api.github.com/users/sourcegraph/following{/other_user}","gists_url":"https://api.github.com/users/sourcegraph/gists{/gist_id}","starred_url":"https://api.github.com/users/sourcegraph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sourcegraph/subscriptions","organizations_url":"https://api.github.com/users/sourcegraph/orgs","repos_url":"https://api.github.com/users/sourcegraph/repos","events_url":"https://api.github.com/users/sourcegraph/events{/privacy}","received_events_url":"https://api.github.com/users/sourcegraph/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sourcegraph/checkup","description":"Distributed, lock-free, self-hosted health checks and status pages","fork":false,"url":"https://api.github.com/repos/sourcegraph/checkup","forks_url":"https://api.github.com/repos/sourcegraph/checkup/forks","keys_url":"https://api.github.com/repos/sourcegraph/checkup/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sourcegraph/checkup/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sourcegraph/checkup/teams","hooks_url":"https://api.github.com/repos/sourcegraph/checkup/hooks","issue_events_url":"https://api.github.com/repos/sourcegraph/checkup/issues/events{/number}","events_url":"https://api.github.com/repos/sourcegraph/checkup/events","assignees_url":"https://api.github.com/repos/sourcegraph/checkup/assignees{/user}","branches_url":"https://api.github.com/repos/sourcegraph/checkup/branches{/branch}","tags_url":"https://api.github.com/repos/sourcegraph/checkup/tags","blobs_url":"https://api.github.com/repos/sourcegraph/checkup/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sourcegraph/checkup/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sourcegraph/checkup/git/refs{/sha}","trees_url":"https://api.github.com/repos/sourcegraph/checkup/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sourcegraph/checkup/statuses/{sha}","languages_url":"https://api.github.com/repos/sourcegraph/checkup/languages","stargazers_url":"https://api.github.com/repos/sourcegraph/checkup/stargazers","contributors_url":"https://api.github.com/repos/sourcegraph/checkup/contributors","subscribers_url":"https://api.github.com/repos/sourcegraph/checkup/subscribers","subscription_url":"https://api.github.com/repos/sourcegraph/checkup/subscription","commits_url":"https://api.github.com/repos/sourcegraph/checkup/commits{/sha}","git_commits_url":"https://api.github.com/repos/sourcegraph/checkup/git/commits{/sha}","comments_url":"https://api.github.com/repos/sourcegraph/checkup/comments{/number}","issue_comment_url":"https://api.github.com/repos/sourcegraph/checkup/issues/comments{/number}","contents_url":"https://api.github.com/repos/sourcegraph/checkup/contents/{+path}","compare_url":"https://api.github.com/repos/sourcegraph/checkup/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sourcegraph/checkup/merges","archive_url":"https://api.github.com/repos/sourcegraph/checkup/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sourcegraph/checkup/downloads","issues_url":"https://api.github.com/repos/sourcegraph/checkup/issues{/number}","pulls_url":"https://api.github.com/repos/sourcegraph/checkup/pulls{/number}","milestones_url":"https://api.github.com/repos/sourcegraph/checkup/milestones{/number}","notifications_url":"https://api.github.com/repos/sourcegraph/checkup/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sourcegraph/checkup/labels{/name}","releases_url":"https://api.github.com/repos/sourcegraph/checkup/releases{/id}","deployments_url":"https://api.github.com/repos/sourcegraph/checkup/deployments","created_at":"2016-04-13T00:44:55Z","updated_at":"2016-08-18T19:08:33Z","pushed_at":"2016-08-18T21:52:11Z","git_url":"git://github.com/sourcegraph/checkup.git","ssh_url":"git@github.com:sourcegraph/checkup.git","clone_url":"https://github.com/sourcegraph/checkup.git","svn_url":"https://github.com/sourcegraph/checkup","homepage":"https://sourcegraph.github.io/checkup","size":392,"stargazers_count":1185,"watchers_count":1185,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":46,"mirror_url":null,"open_issues_count":13,"forks":46,"open_issues":13,"watchers":1185,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sourcegraph/checkup/pulls/13"},"html":{"href":"https://github.com/sourcegraph/checkup/pull/13"},"issue":{"href":"https://api.github.com/repos/sourcegraph/checkup/issues/13"},"comments":{"href":"https://api.github.com/repos/sourcegraph/checkup/issues/13/comments"},"review_comments":{"href":"https://api.github.com/repos/sourcegraph/checkup/pulls/13/comments"},"review_comment":{"href":"https://api.github.com/repos/sourcegraph/checkup/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sourcegraph/checkup/pulls/13/commits"},"statuses":{"href":"https://api.github.com/repos/sourcegraph/checkup/statuses/0ea536878d200db29b07e98c0d5b1c6b20965cb4"}}}}
{"actor":{"display_login":"mholt"}}