GitHub PullRequestReviewCommentEvent at 2014-09-23 23:01:11
Repository: flynn
Actor: titanous
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/flynn/flynn/pulls/comments/17945118","id":17945118,"diff_hunk":"@@ -0,0 +1,234 @@\n+package main\n+\n+import (\n+\t\"bytes\"\n+\t\"encoding/json\"\n+\t\"fmt\"\n+\t\"io\"\n+\t\"io/ioutil\"\n+\t\"log\"\n+\t\"net/http\"\n+\t\"os\"\n+\t\"strings\"\n+\n+\tct \"github.com/flynn/flynn/controller/types\"\n+)\n+\n+type exampler struct {\n+\tconf     *config\n+\tclient   *http.Client\n+\texamples map[string]*request\n+}\n+\n+func main() {\n+\tconf, err := loadConfigFromEnv()\n+\tif err != nil {\n+\t\tlog.Fatal(err)\n+\t}\n+\n+\tclient.Transport = &roundTripRecorder{roundTripper: client.Transport}\n+\n+\te := &exampler{\n+\t\tconf:     conf,\n+\t\tclient:   client,\n+\t\texamples: make(map[string]*request),\n+\t}\n+\n+\tkeyId := e.createKey()\n+\te.getKey(keyId)\n+\te.listKeys()\n+\te.deleteKey(keyId)\n+\n+\te.createApp()\n+\te.getApp()\n+\te.updateApp()\n+\n+\tartifactId := e.createArtifact()\n+\te.createRelease(artifactId)\n+\n+\te.listArtifacts()\n+\te.listReleases()\n+\n+\te.deleteApp()\n+\n+\t// TODO: hit all controller endpoints\n+\n+\tres := make(map[string]string)\n+\tfor k, v := range e.examples {\n+\t\tres[k] = requestMarkdown(v)\n+\t}\n+\n+\tdata, _ := json.Marshal(res)\n+\tif len(os.Args) > 1 {\n+\t\tioutil.WriteFile(os.Args[1], data, 0644)\n+\t} else {\n+\t\tio.Copy(os.Stdout, bytes.NewReader(data))\n+\t}\n+}\n+\n+func generatePublicKey() (string, error) {\n+\tkey := `ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDPI19fkFmPNg3MGqJorFTbetPJjxlhLDUJFALYe5DyqW0lAnb2R7XvXzj+kRX9LkwOeQjf6nM4bcXbd/H3YPlMDc9JfDuSGlwvo0X8KUQ6PopgyfQ15GA+8YDgwYcBJowIXqAc52GVNnBUeoZzBKvNnsVjAw6KkTPS0aZ6KBZadtYx+Y1fJJBoygh/gtPZ/MQry3XQRvbKPa0iU34Wcx8pXx5QVFLHvyORczQlEVyq5qa5DT86CRR/wC4yH32hkNGalGXY7sZg0j4EY4AeD2yCcmsp7hTt4Ql4gRp3r04ye4DZ7epdXW2tp2vJ3IVn+l6BSNooBIfoD7ZdkUVce51z some-comment`\n+\treturn key, nil\n+}\n+\n+func (e *exampler) DoNewRequest(method, path string, header http.Header, body io.Reader) (*http.Response, error) {\n+\turl := \"http://\" + e.conf.controllerDomain + path\n+\treq, err := e.NewRequest(method, url, header, body)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\tres, err := e.client.Do(req)\n+\treturn res, err\n+}\n+\n+func (e *exampler) NewRequest(method, url string, header http.Header, body io.Reader) (*http.Request, error) {\n+\treq, err := http.NewRequest(method, url, body)\n+\tif header != nil {\n+\t\treq.Header = header\n+\t}\n+\treq.SetBasicAuth(\"\", e.conf.controllerKey)\n+\treturn req, err\n+}\n+\n+func (e *exampler) createResource(path string, body io.Reader) (*http.Response, error) {\n+\theader := http.Header{}\n+\theader.Add(\"Content-Type\", \"application/json\")\n+\treturn e.DoNewRequest(\"POST\", path, header, body)\n+}\n+\n+func (e *exampler) createKey() string {\n+\tkey, err := generatePublicKey()\n+\tres, err := e.createResource(\"/keys\", strings.NewReader(fmt.Sprintf(`{\n+    \"key\": \"ssh-rsa %s\"\n+  }`, key)))\n+\tvar k ct.Key\n+\tdec := json.NewDecoder(res.Body)\n+\tif err = dec.Decode(&k); err != nil && err != io.EOF {\n+\t\tlog.Fatal(err)\n+\t}\n+\te.examples[\"key_create\"] = getRequests()[0]\n+\treturn k.ID","path":"controller/examples/examples.go","position":110,"original_position":110,"commit_id":"f73bd3026ce9566c46543f5b4b9312508afe8b94","original_commit_id":"f73bd3026ce9566c46543f5b4b9312508afe8b94","user":{"login":"titanous","id":13026,"avatar_url":"https://avatars.githubusercontent.com/u/13026?v=2","gravatar_id":"","url":"https://api.github.com/users/titanous","html_url":"https://github.com/titanous","followers_url":"https://api.github.com/users/titanous/followers","following_url":"https://api.github.com/users/titanous/following{/other_user}","gists_url":"https://api.github.com/users/titanous/gists{/gist_id}","starred_url":"https://api.github.com/users/titanous/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/titanous/subscriptions","organizations_url":"https://api.github.com/users/titanous/orgs","repos_url":"https://api.github.com/users/titanous/repos","events_url":"https://api.github.com/users/titanous/events{/privacy}","received_events_url":"https://api.github.com/users/titanous/received_events","type":"User","site_admin":false},"body":"Is there a situation where we don't want `getRequests()[0]`? I think we could simplify this a lot by making a slice of structs like this:\r\n\r\n```go\r\n{\"key_create\", e.createKey},\r\n{\"key_get\", e.getKey},\r\n// etc...\r\n```\r\n\r\nAnd then save any ids like the key ID in a `map[string]string` field of `e`.","created_at":"2014-09-23T23:01:11Z","updated_at":"2014-09-23T23:01:11Z","html_url":"https://github.com/flynn/flynn/pull/238#discussion_r17945118","pull_request_url":"https://api.github.com/repos/flynn/flynn/pulls/238","_links":{"self":{"href":"https://api.github.com/repos/flynn/flynn/pulls/comments/17945118"},"html":{"href":"https://github.com/flynn/flynn/pull/238#discussion_r17945118"},"pull_request":{"href":"https://api.github.com/repos/flynn/flynn/pulls/238"}}},"pull_request":{"url":"https://api.github.com/repos/flynn/flynn/pulls/238","id":21608028,"html_url":"https://github.com/flynn/flynn/pull/238","diff_url":"https://github.com/flynn/flynn/pull/238.diff","patch_url":"https://github.com/flynn/flynn/pull/238.patch","issue_url":"https://api.github.com/repos/flynn/flynn/issues/238","number":238,"state":"open","locked":false,"title":"Controller examples","user":{"login":"jvatic","id":171040,"avatar_url":"https://avatars.githubusercontent.com/u/171040?v=2","gravatar_id":"","url":"https://api.github.com/users/jvatic","html_url":"https://github.com/jvatic","followers_url":"https://api.github.com/users/jvatic/followers","following_url":"https://api.github.com/users/jvatic/following{/other_user}","gists_url":"https://api.github.com/users/jvatic/gists{/gist_id}","starred_url":"https://api.github.com/users/jvatic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jvatic/subscriptions","organizations_url":"https://api.github.com/users/jvatic/orgs","repos_url":"https://api.github.com/users/jvatic/repos","events_url":"https://api.github.com/users/jvatic/events{/privacy}","received_events_url":"https://api.github.com/users/jvatic/received_events","type":"User","site_admin":false},"body":"...for use in docs.\r\n\r\nrefs #175 \r\n","created_at":"2014-09-22T20:51:24Z","updated_at":"2014-09-23T23:01:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"edabd0aa8c17a4df48155fac05078dd8eb52e8a5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/flynn/flynn/pulls/238/commits","review_comments_url":"https://api.github.com/repos/flynn/flynn/pulls/238/comments","review_comment_url":"https://api.github.com/repos/flynn/flynn/pulls/comments/{number}","comments_url":"https://api.github.com/repos/flynn/flynn/issues/238/comments","statuses_url":"https://api.github.com/repos/flynn/flynn/statuses/f73bd3026ce9566c46543f5b4b9312508afe8b94","head":{"label":"flynn:controller-examples","ref":"controller-examples","sha":"f73bd3026ce9566c46543f5b4b9312508afe8b94","user":{"login":"flynn","id":4973613,"avatar_url":"https://avatars.githubusercontent.com/u/4973613?v=2","gravatar_id":"","url":"https://api.github.com/users/flynn","html_url":"https://github.com/flynn","followers_url":"https://api.github.com/users/flynn/followers","following_url":"https://api.github.com/users/flynn/following{/other_user}","gists_url":"https://api.github.com/users/flynn/gists{/gist_id}","starred_url":"https://api.github.com/users/flynn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flynn/subscriptions","organizations_url":"https://api.github.com/users/flynn/orgs","repos_url":"https://api.github.com/users/flynn/repos","events_url":"https://api.github.com/users/flynn/events{/privacy}","received_events_url":"https://api.github.com/users/flynn/received_events","type":"Organization","site_admin":false},"repo":{"id":11290232,"name":"flynn","full_name":"flynn/flynn","owner":{"login":"flynn","id":4973613,"avatar_url":"https://avatars.githubusercontent.com/u/4973613?v=2","gravatar_id":"","url":"https://api.github.com/users/flynn","html_url":"https://github.com/flynn","followers_url":"https://api.github.com/users/flynn/followers","following_url":"https://api.github.com/users/flynn/following{/other_user}","gists_url":"https://api.github.com/users/flynn/gists{/gist_id}","starred_url":"https://api.github.com/users/flynn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flynn/subscriptions","organizations_url":"https://api.github.com/users/flynn/orgs","repos_url":"https://api.github.com/users/flynn/repos","events_url":"https://api.github.com/users/flynn/events{/privacy}","received_events_url":"https://api.github.com/users/flynn/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/flynn/flynn","description":"A next generation open source platform as a service (PaaS)","fork":false,"url":"https://api.github.com/repos/flynn/flynn","forks_url":"https://api.github.com/repos/flynn/flynn/forks","keys_url":"https://api.github.com/repos/flynn/flynn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/flynn/flynn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/flynn/flynn/teams","hooks_url":"https://api.github.com/repos/flynn/flynn/hooks","issue_events_url":"https://api.github.com/repos/flynn/flynn/issues/events{/number}","events_url":"https://api.github.com/repos/flynn/flynn/events","assignees_url":"https://api.github.com/repos/flynn/flynn/assignees{/user}","branches_url":"https://api.github.com/repos/flynn/flynn/branches{/branch}","tags_url":"https://api.github.com/repos/flynn/flynn/tags","blobs_url":"https://api.github.com/repos/flynn/flynn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/flynn/flynn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/flynn/flynn/git/refs{/sha}","trees_url":"https://api.github.com/repos/flynn/flynn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/flynn/flynn/statuses/{sha}","languages_url":"https://api.github.com/repos/flynn/flynn/languages","stargazers_url":"https://api.github.com/repos/flynn/flynn/stargazers","contributors_url":"https://api.github.com/repos/flynn/flynn/contributors","subscribers_url":"https://api.github.com/repos/flynn/flynn/subscribers","subscription_url":"https://api.github.com/repos/flynn/flynn/subscription","commits_url":"https://api.github.com/repos/flynn/flynn/commits{/sha}","git_commits_url":"https://api.github.com/repos/flynn/flynn/git/commits{/sha}","comments_url":"https://api.github.com/repos/flynn/flynn/comments{/number}","issue_comment_url":"https://api.github.com/repos/flynn/flynn/issues/comments/{number}","contents_url":"https://api.github.com/repos/flynn/flynn/contents/{+path}","compare_url":"https://api.github.com/repos/flynn/flynn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/flynn/flynn/merges","archive_url":"https://api.github.com/repos/flynn/flynn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/flynn/flynn/downloads","issues_url":"https://api.github.com/repos/flynn/flynn/issues{/number}","pulls_url":"https://api.github.com/repos/flynn/flynn/pulls{/number}","milestones_url":"https://api.github.com/repos/flynn/flynn/milestones{/number}","notifications_url":"https://api.github.com/repos/flynn/flynn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/flynn/flynn/labels{/name}","releases_url":"https://api.github.com/repos/flynn/flynn/releases{/id}","created_at":"2013-07-09T18:22:06Z","updated_at":"2014-09-23T22:10:00Z","pushed_at":"2014-09-23T22:12:02Z","git_url":"git://github.com/flynn/flynn.git","ssh_url":"git@github.com:flynn/flynn.git","clone_url":"https://github.com/flynn/flynn.git","svn_url":"https://github.com/flynn/flynn","homepage":"https://flynn.io","size":14602,"stargazers_count":2478,"watchers_count":2478,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":126,"mirror_url":null,"open_issues_count":67,"forks":126,"open_issues":67,"watchers":2478,"default_branch":"master"}},"base":{"label":"flynn:master","ref":"master","sha":"95de45cab438a561caecd3ca48f33ed27977dcd9","user":{"login":"flynn","id":4973613,"avatar_url":"https://avatars.githubusercontent.com/u/4973613?v=2","gravatar_id":"","url":"https://api.github.com/users/flynn","html_url":"https://github.com/flynn","followers_url":"https://api.github.com/users/flynn/followers","following_url":"https://api.github.com/users/flynn/following{/other_user}","gists_url":"https://api.github.com/users/flynn/gists{/gist_id}","starred_url":"https://api.github.com/users/flynn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flynn/subscriptions","organizations_url":"https://api.github.com/users/flynn/orgs","repos_url":"https://api.github.com/users/flynn/repos","events_url":"https://api.github.com/users/flynn/events{/privacy}","received_events_url":"https://api.github.com/users/flynn/received_events","type":"Organization","site_admin":false},"repo":{"id":11290232,"name":"flynn","full_name":"flynn/flynn","owner":{"login":"flynn","id":4973613,"avatar_url":"https://avatars.githubusercontent.com/u/4973613?v=2","gravatar_id":"","url":"https://api.github.com/users/flynn","html_url":"https://github.com/flynn","followers_url":"https://api.github.com/users/flynn/followers","following_url":"https://api.github.com/users/flynn/following{/other_user}","gists_url":"https://api.github.com/users/flynn/gists{/gist_id}","starred_url":"https://api.github.com/users/flynn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flynn/subscriptions","organizations_url":"https://api.github.com/users/flynn/orgs","repos_url":"https://api.github.com/users/flynn/repos","events_url":"https://api.github.com/users/flynn/events{/privacy}","received_events_url":"https://api.github.com/users/flynn/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/flynn/flynn","description":"A next generation open source platform as a service (PaaS)","fork":false,"url":"https://api.github.com/repos/flynn/flynn","forks_url":"https://api.github.com/repos/flynn/flynn/forks","keys_url":"https://api.github.com/repos/flynn/flynn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/flynn/flynn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/flynn/flynn/teams","hooks_url":"https://api.github.com/repos/flynn/flynn/hooks","issue_events_url":"https://api.github.com/repos/flynn/flynn/issues/events{/number}","events_url":"https://api.github.com/repos/flynn/flynn/events","assignees_url":"https://api.github.com/repos/flynn/flynn/assignees{/user}","branches_url":"https://api.github.com/repos/flynn/flynn/branches{/branch}","tags_url":"https://api.github.com/repos/flynn/flynn/tags","blobs_url":"https://api.github.com/repos/flynn/flynn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/flynn/flynn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/flynn/flynn/git/refs{/sha}","trees_url":"https://api.github.com/repos/flynn/flynn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/flynn/flynn/statuses/{sha}","languages_url":"https://api.github.com/repos/flynn/flynn/languages","stargazers_url":"https://api.github.com/repos/flynn/flynn/stargazers","contributors_url":"https://api.github.com/repos/flynn/flynn/contributors","subscribers_url":"https://api.github.com/repos/flynn/flynn/subscribers","subscription_url":"https://api.github.com/repos/flynn/flynn/subscription","commits_url":"https://api.github.com/repos/flynn/flynn/commits{/sha}","git_commits_url":"https://api.github.com/repos/flynn/flynn/git/commits{/sha}","comments_url":"https://api.github.com/repos/flynn/flynn/comments{/number}","issue_comment_url":"https://api.github.com/repos/flynn/flynn/issues/comments/{number}","contents_url":"https://api.github.com/repos/flynn/flynn/contents/{+path}","compare_url":"https://api.github.com/repos/flynn/flynn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/flynn/flynn/merges","archive_url":"https://api.github.com/repos/flynn/flynn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/flynn/flynn/downloads","issues_url":"https://api.github.com/repos/flynn/flynn/issues{/number}","pulls_url":"https://api.github.com/repos/flynn/flynn/pulls{/number}","milestones_url":"https://api.github.com/repos/flynn/flynn/milestones{/number}","notifications_url":"https://api.github.com/repos/flynn/flynn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/flynn/flynn/labels{/name}","releases_url":"https://api.github.com/repos/flynn/flynn/releases{/id}","created_at":"2013-07-09T18:22:06Z","updated_at":"2014-09-23T22:10:00Z","pushed_at":"2014-09-23T22:12:02Z","git_url":"git://github.com/flynn/flynn.git","ssh_url":"git@github.com:flynn/flynn.git","clone_url":"https://github.com/flynn/flynn.git","svn_url":"https://github.com/flynn/flynn","homepage":"https://flynn.io","size":14602,"stargazers_count":2478,"watchers_count":2478,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":126,"mirror_url":null,"open_issues_count":67,"forks":126,"open_issues":67,"watchers":2478,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/flynn/flynn/pulls/238"},"html":{"href":"https://github.com/flynn/flynn/pull/238"},"issue":{"href":"https://api.github.com/repos/flynn/flynn/issues/238"},"comments":{"href":"https://api.github.com/repos/flynn/flynn/issues/238/comments"},"review_comments":{"href":"https://api.github.com/repos/flynn/flynn/pulls/238/comments"},"review_comment":{"href":"https://api.github.com/repos/flynn/flynn/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/flynn/flynn/pulls/238/commits"},"statuses":{"href":"https://api.github.com/repos/flynn/flynn/statuses/f73bd3026ce9566c46543f5b4b9312508afe8b94"}}}}