{"action":"created","comment":{"url":"https://api.github.com/repos/travis-ci/worker/pulls/comments/39059248","id":39059248,"diff_hunk":"@@ -0,0 +1,181 @@\n+package image\n+\n+import (\n+\t\"encoding/json\"\n+\t\"io/ioutil\"\n+\t\"net/http\"\n+\t\"net/url\"\n+\t\"strings\"\n+\t\"time\"\n+\n+\t\"github.com/cenkalti/backoff\"\n+)\n+\n+const (\n+\timageAPIRequestContentType = \"application/x-www-form-urlencoded; boundary=NL\"\n+)\n+\n+type APISelector struct {\n+\tbaseURL *url.URL\n+\n+\tmaxInterval    time.Duration\n+\tmaxElapsedTime time.Duration\n+}\n+\n+func NewAPISelector(u *url.URL) *APISelector {\n+\treturn &APISelector{\n+\t\tbaseURL: u,\n+\n+\t\tmaxInterval:    10 * time.Second,\n+\t\tmaxElapsedTime: time.Minute,\n+\t}\n+}\n+\n+func (as *APISelector) Select(params *Params) (string, error) {\n+\timageName, err := as.queryWithTags(params.Infra, as.buildCandidateTags(params))\n+\tif err != nil {\n+\t\treturn \"default\", err\n+\t}\n+\n+\tif imageName != \"\" {\n+\t\treturn imageName, nil\n+\t}\n+\n+\treturn \"default\", nil\n+}\n+\n+func (as *APISelector) queryWithTags(infra string, tags [][]string) (string, error) {\n+\tbodyLines := []string{}\n+\n+\tfor _, ts := range tags {\n+\t\tqs := url.Values{}\n+\t\tqs.Set(\"infra\", infra)\n+\t\tqs.Set(\"fields[images]\", \"name\")\n+\t\tqs.Set(\"limit\", \"1\")\n+\t\tif len(tags) > 0 {","path":"src/github.com/travis-ci/worker/image/api_selector.go","position":55,"original_position":55,"commit_id":"e65e27747d7d176deba99d9c5b8eb62eb0759168","original_commit_id":"e65e27747d7d176deba99d9c5b8eb62eb0759168","user":{"login":"henrikhodne","id":24421,"avatar_url":"https://avatars.githubusercontent.com/u/24421?v=3","gravatar_id":"","url":"https://api.github.com/users/henrikhodne","html_url":"https://github.com/henrikhodne","followers_url":"https://api.github.com/users/henrikhodne/followers","following_url":"https://api.github.com/users/henrikhodne/following{/other_user}","gists_url":"https://api.github.com/users/henrikhodne/gists{/gist_id}","starred_url":"https://api.github.com/users/henrikhodne/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/henrikhodne/subscriptions","organizations_url":"https://api.github.com/users/henrikhodne/orgs","repos_url":"https://api.github.com/users/henrikhodne/repos","events_url":"https://api.github.com/users/henrikhodne/events{/privacy}","received_events_url":"https://api.github.com/users/henrikhodne/received_events","type":"User","site_admin":false},"body":"I'm not quite sure I understand the logic here, but should this be `len(tags)` or `len(ts)`?","created_at":"2015-09-09T15:42:55Z","updated_at":"2015-09-09T15:42:55Z","html_url":"https://github.com/travis-ci/worker/pull/85#discussion_r39059248","pull_request_url":"https://api.github.com/repos/travis-ci/worker/pulls/85","_links":{"self":{"href":"https://api.github.com/repos/travis-ci/worker/pulls/comments/39059248"},"html":{"href":"https://github.com/travis-ci/worker/pull/85#discussion_r39059248"},"pull_request":{"href":"https://api.github.com/repos/travis-ci/worker/pulls/85"}}},"pull_request":{"url":"https://api.github.com/repos/travis-ci/worker/pulls/85","id":44063715,"html_url":"https://github.com/travis-ci/worker/pull/85","diff_url":"https://github.com/travis-ci/worker/pull/85.diff","patch_url":"https://github.com/travis-ci/worker/pull/85.patch","issue_url":"https://api.github.com/repos/travis-ci/worker/issues/85","number":85,"state":"open","locked":false,"title":"Image selector implementations and integration with GCE backend","user":{"login":"meatballhat","id":45143,"avatar_url":"https://avatars.githubusercontent.com/u/45143?v=3","gravatar_id":"","url":"https://api.github.com/users/meatballhat","html_url":"https://github.com/meatballhat","followers_url":"https://api.github.com/users/meatballhat/followers","following_url":"https://api.github.com/users/meatballhat/following{/other_user}","gists_url":"https://api.github.com/users/meatballhat/gists{/gist_id}","starred_url":"https://api.github.com/users/meatballhat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meatballhat/subscriptions","organizations_url":"https://api.github.com/users/meatballhat/orgs","repos_url":"https://api.github.com/users/meatballhat/repos","events_url":"https://api.github.com/users/meatballhat/events{/privacy}","received_events_url":"https://api.github.com/users/meatballhat/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-09-03T02:26:50Z","updated_at":"2015-09-09T15:42:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dca109de6ef38684e36be41817034f4b4827d74f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/travis-ci/worker/pulls/85/commits","review_comments_url":"https://api.github.com/repos/travis-ci/worker/pulls/85/comments","review_comment_url":"https://api.github.com/repos/travis-ci/worker/pulls/comments{/number}","comments_url":"https://api.github.com/repos/travis-ci/worker/issues/85/comments","statuses_url":"https://api.github.com/repos/travis-ci/worker/statuses/e65e27747d7d176deba99d9c5b8eb62eb0759168","head":{"label":"travis-ci:meat-image-selection-provider","ref":"meat-image-selection-provider","sha":"e65e27747d7d176deba99d9c5b8eb62eb0759168","user":{"login":"travis-ci","id":639823,"avatar_url":"https://avatars.githubusercontent.com/u/639823?v=3","gravatar_id":"","url":"https://api.github.com/users/travis-ci","html_url":"https://github.com/travis-ci","followers_url":"https://api.github.com/users/travis-ci/followers","following_url":"https://api.github.com/users/travis-ci/following{/other_user}","gists_url":"https://api.github.com/users/travis-ci/gists{/gist_id}","starred_url":"https://api.github.com/users/travis-ci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/travis-ci/subscriptions","organizations_url":"https://api.github.com/users/travis-ci/orgs","repos_url":"https://api.github.com/users/travis-ci/repos","events_url":"https://api.github.com/users/travis-ci/events{/privacy}","received_events_url":"https://api.github.com/users/travis-ci/received_events","type":"Organization","site_admin":false},"repo":{"id":27410275,"name":"worker","full_name":"travis-ci/worker","owner":{"login":"travis-ci","id":639823,"avatar_url":"https://avatars.githubusercontent.com/u/639823?v=3","gravatar_id":"","url":"https://api.github.com/users/travis-ci","html_url":"https://github.com/travis-ci","followers_url":"https://api.github.com/users/travis-ci/followers","following_url":"https://api.github.com/users/travis-ci/following{/other_user}","gists_url":"https://api.github.com/users/travis-ci/gists{/gist_id}","starred_url":"https://api.github.com/users/travis-ci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/travis-ci/subscriptions","organizations_url":"https://api.github.com/users/travis-ci/orgs","repos_url":"https://api.github.com/users/travis-ci/repos","events_url":"https://api.github.com/users/travis-ci/events{/privacy}","received_events_url":"https://api.github.com/users/travis-ci/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/travis-ci/worker","description":"Worky worky work work","fork":false,"url":"https://api.github.com/repos/travis-ci/worker","forks_url":"https://api.github.com/repos/travis-ci/worker/forks","keys_url":"https://api.github.com/repos/travis-ci/worker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/travis-ci/worker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/travis-ci/worker/teams","hooks_url":"https://api.github.com/repos/travis-ci/worker/hooks","issue_events_url":"https://api.github.com/repos/travis-ci/worker/issues/events{/number}","events_url":"https://api.github.com/repos/travis-ci/worker/events","assignees_url":"https://api.github.com/repos/travis-ci/worker/assignees{/user}","branches_url":"https://api.github.com/repos/travis-ci/worker/branches{/branch}","tags_url":"https://api.github.com/repos/travis-ci/worker/tags","blobs_url":"https://api.github.com/repos/travis-ci/worker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/travis-ci/worker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/travis-ci/worker/git/refs{/sha}","trees_url":"https://api.github.com/repos/travis-ci/worker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/travis-ci/worker/statuses/{sha}","languages_url":"https://api.github.com/repos/travis-ci/worker/languages","stargazers_url":"https://api.github.com/repos/travis-ci/worker/stargazers","contributors_url":"https://api.github.com/repos/travis-ci/worker/contributors","subscribers_url":"https://api.github.com/repos/travis-ci/worker/subscribers","subscription_url":"https://api.github.com/repos/travis-ci/worker/subscription","commits_url":"https://api.github.com/repos/travis-ci/worker/commits{/sha}","git_commits_url":"https://api.github.com/repos/travis-ci/worker/git/commits{/sha}","comments_url":"https://api.github.com/repos/travis-ci/worker/comments{/number}","issue_comment_url":"https://api.github.com/repos/travis-ci/worker/issues/comments{/number}","contents_url":"https://api.github.com/repos/travis-ci/worker/contents/{+path}","compare_url":"https://api.github.com/repos/travis-ci/worker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/travis-ci/worker/merges","archive_url":"https://api.github.com/repos/travis-ci/worker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/travis-ci/worker/downloads","issues_url":"https://api.github.com/repos/travis-ci/worker/issues{/number}","pulls_url":"https://api.github.com/repos/travis-ci/worker/pulls{/number}","milestones_url":"https://api.github.com/repos/travis-ci/worker/milestones{/number}","notifications_url":"https://api.github.com/repos/travis-ci/worker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/travis-ci/worker/labels{/name}","releases_url":"https://api.github.com/repos/travis-ci/worker/releases{/id}","created_at":"2014-12-02T02:02:55Z","updated_at":"2015-09-01T18:06:45Z","pushed_at":"2015-09-08T20:44:11Z","git_url":"git://github.com/travis-ci/worker.git","ssh_url":"git@github.com:travis-ci/worker.git","clone_url":"https://github.com/travis-ci/worker.git","svn_url":"https://github.com/travis-ci/worker","homepage":null,"size":5072,"stargazers_count":12,"watchers_count":12,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":2,"forks":2,"open_issues":2,"watchers":12,"default_branch":"master"}},"base":{"label":"travis-ci:master","ref":"master","sha":"c75ae07974c080d7c019f2b00a3c3d7d4b9b9877","user":{"login":"travis-ci","id":639823,"avatar_url":"https://avatars.githubusercontent.com/u/639823?v=3","gravatar_id":"","url":"https://api.github.com/users/travis-ci","html_url":"https://github.com/travis-ci","followers_url":"https://api.github.com/users/travis-ci/followers","following_url":"https://api.github.com/users/travis-ci/following{/other_user}","gists_url":"https://api.github.com/users/travis-ci/gists{/gist_id}","starred_url":"https://api.github.com/users/travis-ci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/travis-ci/subscriptions","organizations_url":"https://api.github.com/users/travis-ci/orgs","repos_url":"https://api.github.com/users/travis-ci/repos","events_url":"https://api.github.com/users/travis-ci/events{/privacy}","received_events_url":"https://api.github.com/users/travis-ci/received_events","type":"Organization","site_admin":false},"repo":{"id":27410275,"name":"worker","full_name":"travis-ci/worker","owner":{"login":"travis-ci","id":639823,"avatar_url":"https://avatars.githubusercontent.com/u/639823?v=3","gravatar_id":"","url":"https://api.github.com/users/travis-ci","html_url":"https://github.com/travis-ci","followers_url":"https://api.github.com/users/travis-ci/followers","following_url":"https://api.github.com/users/travis-ci/following{/other_user}","gists_url":"https://api.github.com/users/travis-ci/gists{/gist_id}","starred_url":"https://api.github.com/users/travis-ci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/travis-ci/subscriptions","organizations_url":"https://api.github.com/users/travis-ci/orgs","repos_url":"https://api.github.com/users/travis-ci/repos","events_url":"https://api.github.com/users/travis-ci/events{/privacy}","received_events_url":"https://api.github.com/users/travis-ci/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/travis-ci/worker","description":"Worky worky work work","fork":false,"url":"https://api.github.com/repos/travis-ci/worker","forks_url":"https://api.github.com/repos/travis-ci/worker/forks","keys_url":"https://api.github.com/repos/travis-ci/worker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/travis-ci/worker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/travis-ci/worker/teams","hooks_url":"https://api.github.com/repos/travis-ci/worker/hooks","issue_events_url":"https://api.github.com/repos/travis-ci/worker/issues/events{/number}","events_url":"https://api.github.com/repos/travis-ci/worker/events","assignees_url":"https://api.github.com/repos/travis-ci/worker/assignees{/user}","branches_url":"https://api.github.com/repos/travis-ci/worker/branches{/branch}","tags_url":"https://api.github.com/repos/travis-ci/worker/tags","blobs_url":"https://api.github.com/repos/travis-ci/worker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/travis-ci/worker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/travis-ci/worker/git/refs{/sha}","trees_url":"https://api.github.com/repos/travis-ci/worker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/travis-ci/worker/statuses/{sha}","languages_url":"https://api.github.com/repos/travis-ci/worker/languages","stargazers_url":"https://api.github.com/repos/travis-ci/worker/stargazers","contributors_url":"https://api.github.com/repos/travis-ci/worker/contributors","subscribers_url":"https://api.github.com/repos/travis-ci/worker/subscribers","subscription_url":"https://api.github.com/repos/travis-ci/worker/subscription","commits_url":"https://api.github.com/repos/travis-ci/worker/commits{/sha}","git_commits_url":"https://api.github.com/repos/travis-ci/worker/git/commits{/sha}","comments_url":"https://api.github.com/repos/travis-ci/worker/comments{/number}","issue_comment_url":"https://api.github.com/repos/travis-ci/worker/issues/comments{/number}","contents_url":"https://api.github.com/repos/travis-ci/worker/contents/{+path}","compare_url":"https://api.github.com/repos/travis-ci/worker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/travis-ci/worker/merges","archive_url":"https://api.github.com/repos/travis-ci/worker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/travis-ci/worker/downloads","issues_url":"https://api.github.com/repos/travis-ci/worker/issues{/number}","pulls_url":"https://api.github.com/repos/travis-ci/worker/pulls{/number}","milestones_url":"https://api.github.com/repos/travis-ci/worker/milestones{/number}","notifications_url":"https://api.github.com/repos/travis-ci/worker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/travis-ci/worker/labels{/name}","releases_url":"https://api.github.com/repos/travis-ci/worker/releases{/id}","created_at":"2014-12-02T02:02:55Z","updated_at":"2015-09-01T18:06:45Z","pushed_at":"2015-09-08T20:44:11Z","git_url":"git://github.com/travis-ci/worker.git","ssh_url":"git@github.com:travis-ci/worker.git","clone_url":"https://github.com/travis-ci/worker.git","svn_url":"https://github.com/travis-ci/worker","homepage":null,"size":5072,"stargazers_count":12,"watchers_count":12,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":2,"forks":2,"open_issues":2,"watchers":12,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/travis-ci/worker/pulls/85"},"html":{"href":"https://github.com/travis-ci/worker/pull/85"},"issue":{"href":"https://api.github.com/repos/travis-ci/worker/issues/85"},"comments":{"href":"https://api.github.com/repos/travis-ci/worker/issues/85/comments"},"review_comments":{"href":"https://api.github.com/repos/travis-ci/worker/pulls/85/comments"},"review_comment":{"href":"https://api.github.com/repos/travis-ci/worker/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/travis-ci/worker/pulls/85/commits"},"statuses":{"href":"https://api.github.com/repos/travis-ci/worker/statuses/e65e27747d7d176deba99d9c5b8eb62eb0759168"}}}}