{"action":"created","comment":{"url":"https://api.github.com/repos/gomods/athens/pulls/comments/197605360","pull_request_review_id":131387731,"id":197605360,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5NzYwNTM2MA==","diff_hunk":"@@ -0,0 +1,80 @@\n+package gcp\n+\n+import (\n+\t\"context\"\n+\t\"fmt\"\n+\t\"strings\"\n+\t\"time\"\n+\n+\t\"cloud.google.com/go/storage\"\n+\t\"google.golang.org/api/option\"\n+)\n+\n+// Storage implements the (github.com/gomods/pkg/storage).Saver interface\n+type Storage struct {\n+\tbucket *storage.BucketHandle\n+}\n+\n+// New returns a new Storage instance\n+// authenticated using the provided ClientOptions for the associated bucket\n+func New(ctx context.Context, bucketname string, cred option.ClientOption) (*Storage, error) {\n+\tclient, err := storage.NewClient(ctx, cred)\n+\tif err != nil {\n+\t\treturn nil, fmt.Errorf(\"could not create new client: %s\", err)\n+\t}\n+\tbkt := client.Bucket(bucketname)\n+\treturn &Storage{bucket: bkt}, nil\n+}\n+\n+// Save uploads the modules .mod, .zip and .info files for a given version\n+func (s *Storage) Save(ctx context.Context, module, version string, mod, zip, info []byte) error {\n+\terrs := make(chan error, 3)\n+\t// dispatch go routine for each file to upload\n+\tgo save(ctx, errs, s.bucket, module, version, \"mod\", mod)\n+\tgo save(ctx, errs, s.bucket, module, version, \"zip\", zip)\n+\tgo save(ctx, errs, s.bucket, module, version, \"info\", info)\n+\n+\terrsOut := make([]string, 0, 3)\n+\t// wait for each routine above to send a value\n+\tfor count := 0; count < 3; count++ {\n+\t\terr := <-errs\n+\t\tif err != nil {\n+\t\t\terrsOut = append(errsOut, err.Error())\n+\t\t}\n+\t}\n+\n+\t// return concatenated error string if there is anything to report\n+\tif len(errsOut) > 0 {\n+\t\treturn fmt.Errorf(\"one or more errors occured saving %s/@v/%s: %s\", module, version, strings.Join(errsOut, \", \"))\n+\t}\n+\treturn nil\n+}\n+\n+// save waits for writeToBucket to complete or times out after five minutes\n+func save(ctx context.Context, errs chan<- error, bkt *storage.BucketHandle, module, version, ext string, content []byte) {\n+\tctxWT, cancel := context.WithTimeout(ctx, 5*time.Minute)\n+\n+\tselect {\n+\tcase errs <- writeToBucket(ctxWT, bkt, fmt.Sprintf(\"%s/@v/%s.%s\", module, version, ext), content):\n+\t\tcancel()\n+\tcase <-ctxWT.Done():\n+\t\terrs <- fmt.Errorf(\"WARNING: context deadline exceeded during write of %s version %s\", module, version)\n+\t}\n+}\n+\n+// writeToBucket performs the actual write to a gcp storage bucket\n+func writeToBucket(ctx context.Context, bkt *storage.BucketHandle, filename string, file []byte) error {\n+\twc := bkt.Object(filename).NewWriter(ctx)\n+\tdefer func(w *storage.Writer) {\n+\t\tif err := w.Close(); err != nil {\n+\t\t\t// TODO: what kind of logging? the app's logger","path":"pkg/storage/gcp/saver.go","position":70,"original_position":70,"commit_id":"672bf22dfd4365566a522d45385cccc0243c34fb","original_commit_id":"672bf22dfd4365566a522d45385cccc0243c34fb","user":{"login":"michalpristas","id":1522652,"node_id":"MDQ6VXNlcjE1MjI2NTI=","avatar_url":"https://avatars1.githubusercontent.com/u/1522652?v=4","gravatar_id":"","url":"https://api.github.com/users/michalpristas","html_url":"https://github.com/michalpristas","followers_url":"https://api.github.com/users/michalpristas/followers","following_url":"https://api.github.com/users/michalpristas/following{/other_user}","gists_url":"https://api.github.com/users/michalpristas/gists{/gist_id}","starred_url":"https://api.github.com/users/michalpristas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michalpristas/subscriptions","organizations_url":"https://api.github.com/users/michalpristas/orgs","repos_url":"https://api.github.com/users/michalpristas/repos","events_url":"https://api.github.com/users/michalpristas/events{/privacy}","received_events_url":"https://api.github.com/users/michalpristas/received_events","type":"User","site_admin":false},"body":"log.Print - uses application logger and can be configured to stderr or sth else","created_at":"2018-06-23T07:35:14Z","updated_at":"2018-06-23T07:35:15Z","html_url":"https://github.com/gomods/athens/pull/183#discussion_r197605360","pull_request_url":"https://api.github.com/repos/gomods/athens/pulls/183","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/gomods/athens/pulls/comments/197605360"},"html":{"href":"https://github.com/gomods/athens/pull/183#discussion_r197605360"},"pull_request":{"href":"https://api.github.com/repos/gomods/athens/pulls/183"}}},"pull_request":{"url":"https://api.github.com/repos/gomods/athens/pulls/183","id":195288964,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk1Mjg4OTY0","html_url":"https://github.com/gomods/athens/pull/183","diff_url":"https://github.com/gomods/athens/pull/183.diff","patch_url":"https://github.com/gomods/athens/pull/183.patch","issue_url":"https://api.github.com/repos/gomods/athens/issues/183","number":183,"state":"open","locked":false,"title":"[WIP] GCP storage saver","user":{"login":"robjloranger","id":13278126,"node_id":"MDQ6VXNlcjEzMjc4MTI2","avatar_url":"https://avatars0.githubusercontent.com/u/13278126?v=4","gravatar_id":"","url":"https://api.github.com/users/robjloranger","html_url":"https://github.com/robjloranger","followers_url":"https://api.github.com/users/robjloranger/followers","following_url":"https://api.github.com/users/robjloranger/following{/other_user}","gists_url":"https://api.github.com/users/robjloranger/gists{/gist_id}","starred_url":"https://api.github.com/users/robjloranger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robjloranger/subscriptions","organizations_url":"https://api.github.com/users/robjloranger/orgs","repos_url":"https://api.github.com/users/robjloranger/repos","events_url":"https://api.github.com/users/robjloranger/events{/privacy}","received_events_url":"https://api.github.com/users/robjloranger/received_events","type":"User","site_admin":false},"body":"a bit rough still, and missing tests","created_at":"2018-06-15T21:40:31Z","updated_at":"2018-06-23T07:35:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a9cdfc2af4145c8c24121ade9353a2692fa27374","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/gomods/athens/pulls/183/commits","review_comments_url":"https://api.github.com/repos/gomods/athens/pulls/183/comments","review_comment_url":"https://api.github.com/repos/gomods/athens/pulls/comments{/number}","comments_url":"https://api.github.com/repos/gomods/athens/issues/183/comments","statuses_url":"https://api.github.com/repos/gomods/athens/statuses/672bf22dfd4365566a522d45385cccc0243c34fb","head":{"label":"robjloranger:gcp-storage","ref":"gcp-storage","sha":"672bf22dfd4365566a522d45385cccc0243c34fb","user":{"login":"robjloranger","id":13278126,"node_id":"MDQ6VXNlcjEzMjc4MTI2","avatar_url":"https://avatars0.githubusercontent.com/u/13278126?v=4","gravatar_id":"","url":"https://api.github.com/users/robjloranger","html_url":"https://github.com/robjloranger","followers_url":"https://api.github.com/users/robjloranger/followers","following_url":"https://api.github.com/users/robjloranger/following{/other_user}","gists_url":"https://api.github.com/users/robjloranger/gists{/gist_id}","starred_url":"https://api.github.com/users/robjloranger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robjloranger/subscriptions","organizations_url":"https://api.github.com/users/robjloranger/orgs","repos_url":"https://api.github.com/users/robjloranger/repos","events_url":"https://api.github.com/users/robjloranger/events{/privacy}","received_events_url":"https://api.github.com/users/robjloranger/received_events","type":"User","site_admin":false},"repo":{"id":133978026,"node_id":"MDEwOlJlcG9zaXRvcnkxMzM5NzgwMjY=","name":"athens","full_name":"robjloranger/athens","owner":{"login":"robjloranger","id":13278126,"node_id":"MDQ6VXNlcjEzMjc4MTI2","avatar_url":"https://avatars0.githubusercontent.com/u/13278126?v=4","gravatar_id":"","url":"https://api.github.com/users/robjloranger","html_url":"https://github.com/robjloranger","followers_url":"https://api.github.com/users/robjloranger/followers","following_url":"https://api.github.com/users/robjloranger/following{/other_user}","gists_url":"https://api.github.com/users/robjloranger/gists{/gist_id}","starred_url":"https://api.github.com/users/robjloranger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robjloranger/subscriptions","organizations_url":"https://api.github.com/users/robjloranger/orgs","repos_url":"https://api.github.com/users/robjloranger/repos","events_url":"https://api.github.com/users/robjloranger/events{/privacy}","received_events_url":"https://api.github.com/users/robjloranger/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/robjloranger/athens","description":"A proxy server and registry for vgo","fork":true,"url":"https://api.github.com/repos/robjloranger/athens","forks_url":"https://api.github.com/repos/robjloranger/athens/forks","keys_url":"https://api.github.com/repos/robjloranger/athens/keys{/key_id}","collaborators_url":"https://api.github.com/repos/robjloranger/athens/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/robjloranger/athens/teams","hooks_url":"https://api.github.com/repos/robjloranger/athens/hooks","issue_events_url":"https://api.github.com/repos/robjloranger/athens/issues/events{/number}","events_url":"https://api.github.com/repos/robjloranger/athens/events","assignees_url":"https://api.github.com/repos/robjloranger/athens/assignees{/user}","branches_url":"https://api.github.com/repos/robjloranger/athens/branches{/branch}","tags_url":"https://api.github.com/repos/robjloranger/athens/tags","blobs_url":"https://api.github.com/repos/robjloranger/athens/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/robjloranger/athens/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/robjloranger/athens/git/refs{/sha}","trees_url":"https://api.github.com/repos/robjloranger/athens/git/trees{/sha}","statuses_url":"https://api.github.com/repos/robjloranger/athens/statuses/{sha}","languages_url":"https://api.github.com/repos/robjloranger/athens/languages","stargazers_url":"https://api.github.com/repos/robjloranger/athens/stargazers","contributors_url":"https://api.github.com/repos/robjloranger/athens/contributors","subscribers_url":"https://api.github.com/repos/robjloranger/athens/subscribers","subscription_url":"https://api.github.com/repos/robjloranger/athens/subscription","commits_url":"https://api.github.com/repos/robjloranger/athens/commits{/sha}","git_commits_url":"https://api.github.com/repos/robjloranger/athens/git/commits{/sha}","comments_url":"https://api.github.com/repos/robjloranger/athens/comments{/number}","issue_comment_url":"https://api.github.com/repos/robjloranger/athens/issues/comments{/number}","contents_url":"https://api.github.com/repos/robjloranger/athens/contents/{+path}","compare_url":"https://api.github.com/repos/robjloranger/athens/compare/{base}...{head}","merges_url":"https://api.github.com/repos/robjloranger/athens/merges","archive_url":"https://api.github.com/repos/robjloranger/athens/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/robjloranger/athens/downloads","issues_url":"https://api.github.com/repos/robjloranger/athens/issues{/number}","pulls_url":"https://api.github.com/repos/robjloranger/athens/pulls{/number}","milestones_url":"https://api.github.com/repos/robjloranger/athens/milestones{/number}","notifications_url":"https://api.github.com/repos/robjloranger/athens/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/robjloranger/athens/labels{/name}","releases_url":"https://api.github.com/repos/robjloranger/athens/releases{/id}","deployments_url":"https://api.github.com/repos/robjloranger/athens/deployments","created_at":"2018-05-18T16:18:44Z","updated_at":"2018-06-15T02:21:10Z","pushed_at":"2018-06-22T21:26:36Z","git_url":"git://github.com/robjloranger/athens.git","ssh_url":"git@github.com:robjloranger/athens.git","clone_url":"https://github.com/robjloranger/athens.git","svn_url":"https://github.com/robjloranger/athens","homepage":"https://research.swtch.com/vgo-module","size":43266,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"gomods:master","ref":"master","sha":"2d25ccb3dea2bab4e208849cae58039ddf26e14e","user":{"login":"gomods","id":36861827,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM2ODYxODI3","avatar_url":"https://avatars3.githubusercontent.com/u/36861827?v=4","gravatar_id":"","url":"https://api.github.com/users/gomods","html_url":"https://github.com/gomods","followers_url":"https://api.github.com/users/gomods/followers","following_url":"https://api.github.com/users/gomods/following{/other_user}","gists_url":"https://api.github.com/users/gomods/gists{/gist_id}","starred_url":"https://api.github.com/users/gomods/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gomods/subscriptions","organizations_url":"https://api.github.com/users/gomods/orgs","repos_url":"https://api.github.com/users/gomods/repos","events_url":"https://api.github.com/users/gomods/events{/privacy}","received_events_url":"https://api.github.com/users/gomods/received_events","type":"Organization","site_admin":false},"repo":{"id":122872932,"node_id":"MDEwOlJlcG9zaXRvcnkxMjI4NzI5MzI=","name":"athens","full_name":"gomods/athens","owner":{"login":"gomods","id":36861827,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM2ODYxODI3","avatar_url":"https://avatars3.githubusercontent.com/u/36861827?v=4","gravatar_id":"","url":"https://api.github.com/users/gomods","html_url":"https://github.com/gomods","followers_url":"https://api.github.com/users/gomods/followers","following_url":"https://api.github.com/users/gomods/following{/other_user}","gists_url":"https://api.github.com/users/gomods/gists{/gist_id}","starred_url":"https://api.github.com/users/gomods/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gomods/subscriptions","organizations_url":"https://api.github.com/users/gomods/orgs","repos_url":"https://api.github.com/users/gomods/repos","events_url":"https://api.github.com/users/gomods/events{/privacy}","received_events_url":"https://api.github.com/users/gomods/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/gomods/athens","description":"A proxy server and registry for vgo","fork":false,"url":"https://api.github.com/repos/gomods/athens","forks_url":"https://api.github.com/repos/gomods/athens/forks","keys_url":"https://api.github.com/repos/gomods/athens/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gomods/athens/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gomods/athens/teams","hooks_url":"https://api.github.com/repos/gomods/athens/hooks","issue_events_url":"https://api.github.com/repos/gomods/athens/issues/events{/number}","events_url":"https://api.github.com/repos/gomods/athens/events","assignees_url":"https://api.github.com/repos/gomods/athens/assignees{/user}","branches_url":"https://api.github.com/repos/gomods/athens/branches{/branch}","tags_url":"https://api.github.com/repos/gomods/athens/tags","blobs_url":"https://api.github.com/repos/gomods/athens/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gomods/athens/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gomods/athens/git/refs{/sha}","trees_url":"https://api.github.com/repos/gomods/athens/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gomods/athens/statuses/{sha}","languages_url":"https://api.github.com/repos/gomods/athens/languages","stargazers_url":"https://api.github.com/repos/gomods/athens/stargazers","contributors_url":"https://api.github.com/repos/gomods/athens/contributors","subscribers_url":"https://api.github.com/repos/gomods/athens/subscribers","subscription_url":"https://api.github.com/repos/gomods/athens/subscription","commits_url":"https://api.github.com/repos/gomods/athens/commits{/sha}","git_commits_url":"https://api.github.com/repos/gomods/athens/git/commits{/sha}","comments_url":"https://api.github.com/repos/gomods/athens/comments{/number}","issue_comment_url":"https://api.github.com/repos/gomods/athens/issues/comments{/number}","contents_url":"https://api.github.com/repos/gomods/athens/contents/{+path}","compare_url":"https://api.github.com/repos/gomods/athens/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gomods/athens/merges","archive_url":"https://api.github.com/repos/gomods/athens/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gomods/athens/downloads","issues_url":"https://api.github.com/repos/gomods/athens/issues{/number}","pulls_url":"https://api.github.com/repos/gomods/athens/pulls{/number}","milestones_url":"https://api.github.com/repos/gomods/athens/milestones{/number}","notifications_url":"https://api.github.com/repos/gomods/athens/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gomods/athens/labels{/name}","releases_url":"https://api.github.com/repos/gomods/athens/releases{/id}","deployments_url":"https://api.github.com/repos/gomods/athens/deployments","created_at":"2018-02-25T20:19:41Z","updated_at":"2018-06-22T13:18:51Z","pushed_at":"2018-06-23T07:09:56Z","git_url":"git://github.com/gomods/athens.git","ssh_url":"git@github.com:gomods/athens.git","clone_url":"https://github.com/gomods/athens.git","svn_url":"https://github.com/gomods/athens","homepage":"https://research.swtch.com/vgo-module","size":42805,"stargazers_count":291,"watchers_count":291,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"archived":false,"open_issues_count":62,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":18,"open_issues":62,"watchers":291,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/gomods/athens/pulls/183"},"html":{"href":"https://github.com/gomods/athens/pull/183"},"issue":{"href":"https://api.github.com/repos/gomods/athens/issues/183"},"comments":{"href":"https://api.github.com/repos/gomods/athens/issues/183/comments"},"review_comments":{"href":"https://api.github.com/repos/gomods/athens/pulls/183/comments"},"review_comment":{"href":"https://api.github.com/repos/gomods/athens/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/gomods/athens/pulls/183/commits"},"statuses":{"href":"https://api.github.com/repos/gomods/athens/statuses/672bf22dfd4365566a522d45385cccc0243c34fb"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"michalpristas"}}