{"action":"created","comment":{"url":"https://api.github.com/repos/drone-plugins/drone-downstream/pulls/comments/85817280","pull_request_review_id":6510050,"id":85817280,"diff_hunk":"@@ -29,46 +30,56 @@ func (p *Plugin) Exec() error {\n \tclient := drone.NewClientToken(p.Server, p.Token)\n \n \tfor _, entry := range p.Repos {\n-\n-\t\t// parses the repository name in owner/name@branch format\n-\t\towner, name, branch := parseRepoBranch(entry)\n+\t        owner, name, branch := parseRepoBranch(entry)\n \t\tif len(owner) == 0 || len(name) == 0 {\n \t\t\treturn fmt.Errorf(\"Error: unable to parse repository name %s.\\n\", entry)\n \t\t}\n-\t\tif p.Fork {\n-\t\t\t// get the latest build for the specified repository\n-\t\t\tbuild, err := client.BuildLast(owner, name, branch)\n-\t\t\tif err != nil {\n-\t\t\t\treturn fmt.Errorf(\"Error: unable to get latest build for %s.\\n\", entry)\n-\t\t\t}\n-\t\t\t// start a new  build\n-\t\t\t_, err = client.BuildFork(owner, name, build.Number)\n-\t\t\tif err != nil {\n-\t\t\t\treturn fmt.Errorf(\"Error: unable to trigger a new build for %s.\\n\", entry)\n-\t\t\t}\n-\n-\t\t\tfmt.Printf(\"Starting new build %d for %s\\n\", build.Number, entry)\n \n-\t\t} else {\n-\t\t\t// get the latest build for the specified repository\n-\t\t\tbuild, err := client.BuildLast(owner, name, branch)\n-\t\t\tif err != nil {\n-\t\t\t\treturn fmt.Errorf(\"Error: unable to get latest build for %s.\\n\", entry)\n+\t\ttimeout := time.After(p.Timeout)\n+\t\ttick := time.Tick(500 * time.Millisecond)\n+\t\n+\t\t// Keep trying until we're timed out, successful or got an error\n+\t\t// Tagged with \"I\" due to break nested in select\n+                I:\n+\t\tfor {\n+\t\t\tselect {\n+\t\t\t// Got a timeout! fail with a timeout error\n+\t\t\tcase <-timeout:\n+\t\t\t\treturn fmt.Errorf(\"Error: timed out waiting on a build for %s.\\n\", entry)\n+\t\t\t// Got a tick, we should check on the build status\n+\t\t\tcase <-tick:\n+\t\t\t\t// get the latest build for the specified repository\n+\t\t\t\tbuild, err := client.BuildLast(owner, name, branch)\n+\t\t\t\tif err != nil {\n+\t\t\t\t\treturn fmt.Errorf(\"Error: unable to get latest build for %s.\\n\", entry)\n+\t\t\t\t}\n+\t\t\t\tif (build.Status != drone.StatusRunning || p.Wait == false) {\n+\t\t\t\t\tif p.Fork {\n+\t\t\t\t\t      \t// start a new  build\n+\t\t\t\t\t\t_, err = client.BuildFork(owner, name, build.Number)\n+\t\t\t\t\t\tif err != nil {\n+\t\t\t\t\t\t\treturn fmt.Errorf(\"Error: unable to trigger a new build for %s.\\n\", entry)\n+\t\t\t\t\t\t}\n+\t\t\t\t\t\tfmt.Printf(\"Starting new build %d for %s.\\n\", build.Number, entry)\n+                                                break I;\n+\t\t\t\t\t} else {\n+\t\t\t\t\t\t// rebuild the latest build\n+\t\t\t\t\t\t_, err = client.BuildStart(owner, name, build.Number)\n+\t\t\t\t\t\tif err != nil {\n+\t\t\t\t\t\t\treturn fmt.Errorf(\"Error: unable to trigger build for %s.\\n\", entry)\n+\t\t\t\t\t\t}\n+\t\t\t\t\t\tfmt.Printf(\"Restarting build %d for %s\\n\", build.Number, entry)\n+                                                break I;\n+\t\t\t\t\t}\n+\t\t\t\t} else if p.Wait == true {\n+\t\t\t\t\tfmt.Printf(\"Waiting on running build for: \" + entry + \"\\n\")","path":"plugin.go","position":90,"original_position":90,"commit_id":"64742d574e1d7d8c2c65317869c1b4426e20695e","original_commit_id":"64742d574e1d7d8c2c65317869c1b4426e20695e","user":{"login":"tboerger","id":156964,"avatar_url":"https://avatars.githubusercontent.com/u/156964?v=3","gravatar_id":"","url":"https://api.github.com/users/tboerger","html_url":"https://github.com/tboerger","followers_url":"https://api.github.com/users/tboerger/followers","following_url":"https://api.github.com/users/tboerger/following{/other_user}","gists_url":"https://api.github.com/users/tboerger/gists{/gist_id}","starred_url":"https://api.github.com/users/tboerger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tboerger/subscriptions","organizations_url":"https://api.github.com/users/tboerger/orgs","repos_url":"https://api.github.com/users/tboerger/repos","events_url":"https://api.github.com/users/tboerger/events{/privacy}","received_events_url":"https://api.github.com/users/tboerger/received_events","type":"User","site_admin":false},"body":"Waiting for? The unit?","created_at":"2016-10-31T19:44:21Z","updated_at":"2016-10-31T19:44:21Z","html_url":"https://github.com/drone-plugins/drone-downstream/pull/16#discussion_r85817280","pull_request_url":"https://api.github.com/repos/drone-plugins/drone-downstream/pulls/16","_links":{"self":{"href":"https://api.github.com/repos/drone-plugins/drone-downstream/pulls/comments/85817280"},"html":{"href":"https://github.com/drone-plugins/drone-downstream/pull/16#discussion_r85817280"},"pull_request":{"href":"https://api.github.com/repos/drone-plugins/drone-downstream/pulls/16"}}},"pull_request":{"url":"https://api.github.com/repos/drone-plugins/drone-downstream/pulls/16","id":91663328,"html_url":"https://github.com/drone-plugins/drone-downstream/pull/16","diff_url":"https://github.com/drone-plugins/drone-downstream/pull/16.diff","patch_url":"https://github.com/drone-plugins/drone-downstream/pull/16.patch","issue_url":"https://api.github.com/repos/drone-plugins/drone-downstream/issues/16","number":16,"state":"open","locked":false,"title":"Added ability to wait before triggering a downstream build if current status is \"running\"","user":{"login":"bchivari","id":16390791,"avatar_url":"https://avatars.githubusercontent.com/u/16390791?v=3","gravatar_id":"","url":"https://api.github.com/users/bchivari","html_url":"https://github.com/bchivari","followers_url":"https://api.github.com/users/bchivari/followers","following_url":"https://api.github.com/users/bchivari/following{/other_user}","gists_url":"https://api.github.com/users/bchivari/gists{/gist_id}","starred_url":"https://api.github.com/users/bchivari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bchivari/subscriptions","organizations_url":"https://api.github.com/users/bchivari/orgs","repos_url":"https://api.github.com/users/bchivari/repos","events_url":"https://api.github.com/users/bchivari/events{/privacy}","received_events_url":"https://api.github.com/users/bchivari/received_events","type":"User","site_admin":false},"body":"I'm not sure if you'd like to include this upstream but it has proved quite useful for me when dealing with downstream projects that have more than one upstream dependency that could trigger a build.","created_at":"2016-10-31T18:26:12Z","updated_at":"2016-10-31T19:44:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"63f4be80ba28ad6f3776eab1fa7eb6a2f81ae7c2","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/drone-plugins/drone-downstream/pulls/16/commits","review_comments_url":"https://api.github.com/repos/drone-plugins/drone-downstream/pulls/16/comments","review_comment_url":"https://api.github.com/repos/drone-plugins/drone-downstream/pulls/comments{/number}","comments_url":"https://api.github.com/repos/drone-plugins/drone-downstream/issues/16/comments","statuses_url":"https://api.github.com/repos/drone-plugins/drone-downstream/statuses/64742d574e1d7d8c2c65317869c1b4426e20695e","head":{"label":"bchivari:master","ref":"master","sha":"64742d574e1d7d8c2c65317869c1b4426e20695e","user":{"login":"bchivari","id":16390791,"avatar_url":"https://avatars.githubusercontent.com/u/16390791?v=3","gravatar_id":"","url":"https://api.github.com/users/bchivari","html_url":"https://github.com/bchivari","followers_url":"https://api.github.com/users/bchivari/followers","following_url":"https://api.github.com/users/bchivari/following{/other_user}","gists_url":"https://api.github.com/users/bchivari/gists{/gist_id}","starred_url":"https://api.github.com/users/bchivari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bchivari/subscriptions","organizations_url":"https://api.github.com/users/bchivari/orgs","repos_url":"https://api.github.com/users/bchivari/repos","events_url":"https://api.github.com/users/bchivari/events{/privacy}","received_events_url":"https://api.github.com/users/bchivari/received_events","type":"User","site_admin":false},"repo":{"id":72464136,"name":"drone-downstream","full_name":"bchivari/drone-downstream","owner":{"login":"bchivari","id":16390791,"avatar_url":"https://avatars.githubusercontent.com/u/16390791?v=3","gravatar_id":"","url":"https://api.github.com/users/bchivari","html_url":"https://github.com/bchivari","followers_url":"https://api.github.com/users/bchivari/followers","following_url":"https://api.github.com/users/bchivari/following{/other_user}","gists_url":"https://api.github.com/users/bchivari/gists{/gist_id}","starred_url":"https://api.github.com/users/bchivari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bchivari/subscriptions","organizations_url":"https://api.github.com/users/bchivari/orgs","repos_url":"https://api.github.com/users/bchivari/repos","events_url":"https://api.github.com/users/bchivari/events{/privacy}","received_events_url":"https://api.github.com/users/bchivari/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bchivari/drone-downstream","description":"Drone plugin to trigger downstream repositories to build","fork":true,"url":"https://api.github.com/repos/bchivari/drone-downstream","forks_url":"https://api.github.com/repos/bchivari/drone-downstream/forks","keys_url":"https://api.github.com/repos/bchivari/drone-downstream/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bchivari/drone-downstream/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bchivari/drone-downstream/teams","hooks_url":"https://api.github.com/repos/bchivari/drone-downstream/hooks","issue_events_url":"https://api.github.com/repos/bchivari/drone-downstream/issues/events{/number}","events_url":"https://api.github.com/repos/bchivari/drone-downstream/events","assignees_url":"https://api.github.com/repos/bchivari/drone-downstream/assignees{/user}","branches_url":"https://api.github.com/repos/bchivari/drone-downstream/branches{/branch}","tags_url":"https://api.github.com/repos/bchivari/drone-downstream/tags","blobs_url":"https://api.github.com/repos/bchivari/drone-downstream/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bchivari/drone-downstream/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bchivari/drone-downstream/git/refs{/sha}","trees_url":"https://api.github.com/repos/bchivari/drone-downstream/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bchivari/drone-downstream/statuses/{sha}","languages_url":"https://api.github.com/repos/bchivari/drone-downstream/languages","stargazers_url":"https://api.github.com/repos/bchivari/drone-downstream/stargazers","contributors_url":"https://api.github.com/repos/bchivari/drone-downstream/contributors","subscribers_url":"https://api.github.com/repos/bchivari/drone-downstream/subscribers","subscription_url":"https://api.github.com/repos/bchivari/drone-downstream/subscription","commits_url":"https://api.github.com/repos/bchivari/drone-downstream/commits{/sha}","git_commits_url":"https://api.github.com/repos/bchivari/drone-downstream/git/commits{/sha}","comments_url":"https://api.github.com/repos/bchivari/drone-downstream/comments{/number}","issue_comment_url":"https://api.github.com/repos/bchivari/drone-downstream/issues/comments{/number}","contents_url":"https://api.github.com/repos/bchivari/drone-downstream/contents/{+path}","compare_url":"https://api.github.com/repos/bchivari/drone-downstream/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bchivari/drone-downstream/merges","archive_url":"https://api.github.com/repos/bchivari/drone-downstream/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bchivari/drone-downstream/downloads","issues_url":"https://api.github.com/repos/bchivari/drone-downstream/issues{/number}","pulls_url":"https://api.github.com/repos/bchivari/drone-downstream/pulls{/number}","milestones_url":"https://api.github.com/repos/bchivari/drone-downstream/milestones{/number}","notifications_url":"https://api.github.com/repos/bchivari/drone-downstream/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bchivari/drone-downstream/labels{/name}","releases_url":"https://api.github.com/repos/bchivari/drone-downstream/releases{/id}","deployments_url":"https://api.github.com/repos/bchivari/drone-downstream/deployments","created_at":"2016-10-31T18:06:07Z","updated_at":"2016-10-31T18:06:08Z","pushed_at":"2016-10-31T18:29:19Z","git_url":"git://github.com/bchivari/drone-downstream.git","ssh_url":"git@github.com:bchivari/drone-downstream.git","clone_url":"https://github.com/bchivari/drone-downstream.git","svn_url":"https://github.com/bchivari/drone-downstream","homepage":null,"size":387,"stargazers_count":0,"watchers_count":0,"language":"Go","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":"drone-plugins:master","ref":"master","sha":"e6e5010d3459f7d18190ae3735362fbb4fc928d7","user":{"login":"drone-plugins","id":11234644,"avatar_url":"https://avatars.githubusercontent.com/u/11234644?v=3","gravatar_id":"","url":"https://api.github.com/users/drone-plugins","html_url":"https://github.com/drone-plugins","followers_url":"https://api.github.com/users/drone-plugins/followers","following_url":"https://api.github.com/users/drone-plugins/following{/other_user}","gists_url":"https://api.github.com/users/drone-plugins/gists{/gist_id}","starred_url":"https://api.github.com/users/drone-plugins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drone-plugins/subscriptions","organizations_url":"https://api.github.com/users/drone-plugins/orgs","repos_url":"https://api.github.com/users/drone-plugins/repos","events_url":"https://api.github.com/users/drone-plugins/events{/privacy}","received_events_url":"https://api.github.com/users/drone-plugins/received_events","type":"Organization","site_admin":false},"repo":{"id":45135370,"name":"drone-downstream","full_name":"drone-plugins/drone-downstream","owner":{"login":"drone-plugins","id":11234644,"avatar_url":"https://avatars.githubusercontent.com/u/11234644?v=3","gravatar_id":"","url":"https://api.github.com/users/drone-plugins","html_url":"https://github.com/drone-plugins","followers_url":"https://api.github.com/users/drone-plugins/followers","following_url":"https://api.github.com/users/drone-plugins/following{/other_user}","gists_url":"https://api.github.com/users/drone-plugins/gists{/gist_id}","starred_url":"https://api.github.com/users/drone-plugins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drone-plugins/subscriptions","organizations_url":"https://api.github.com/users/drone-plugins/orgs","repos_url":"https://api.github.com/users/drone-plugins/repos","events_url":"https://api.github.com/users/drone-plugins/events{/privacy}","received_events_url":"https://api.github.com/users/drone-plugins/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/drone-plugins/drone-downstream","description":"Drone plugin to trigger downstream repositories to build","fork":false,"url":"https://api.github.com/repos/drone-plugins/drone-downstream","forks_url":"https://api.github.com/repos/drone-plugins/drone-downstream/forks","keys_url":"https://api.github.com/repos/drone-plugins/drone-downstream/keys{/key_id}","collaborators_url":"https://api.github.com/repos/drone-plugins/drone-downstream/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/drone-plugins/drone-downstream/teams","hooks_url":"https://api.github.com/repos/drone-plugins/drone-downstream/hooks","issue_events_url":"https://api.github.com/repos/drone-plugins/drone-downstream/issues/events{/number}","events_url":"https://api.github.com/repos/drone-plugins/drone-downstream/events","assignees_url":"https://api.github.com/repos/drone-plugins/drone-downstream/assignees{/user}","branches_url":"https://api.github.com/repos/drone-plugins/drone-downstream/branches{/branch}","tags_url":"https://api.github.com/repos/drone-plugins/drone-downstream/tags","blobs_url":"https://api.github.com/repos/drone-plugins/drone-downstream/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/drone-plugins/drone-downstream/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/drone-plugins/drone-downstream/git/refs{/sha}","trees_url":"https://api.github.com/repos/drone-plugins/drone-downstream/git/trees{/sha}","statuses_url":"https://api.github.com/repos/drone-plugins/drone-downstream/statuses/{sha}","languages_url":"https://api.github.com/repos/drone-plugins/drone-downstream/languages","stargazers_url":"https://api.github.com/repos/drone-plugins/drone-downstream/stargazers","contributors_url":"https://api.github.com/repos/drone-plugins/drone-downstream/contributors","subscribers_url":"https://api.github.com/repos/drone-plugins/drone-downstream/subscribers","subscription_url":"https://api.github.com/repos/drone-plugins/drone-downstream/subscription","commits_url":"https://api.github.com/repos/drone-plugins/drone-downstream/commits{/sha}","git_commits_url":"https://api.github.com/repos/drone-plugins/drone-downstream/git/commits{/sha}","comments_url":"https://api.github.com/repos/drone-plugins/drone-downstream/comments{/number}","issue_comment_url":"https://api.github.com/repos/drone-plugins/drone-downstream/issues/comments{/number}","contents_url":"https://api.github.com/repos/drone-plugins/drone-downstream/contents/{+path}","compare_url":"https://api.github.com/repos/drone-plugins/drone-downstream/compare/{base}...{head}","merges_url":"https://api.github.com/repos/drone-plugins/drone-downstream/merges","archive_url":"https://api.github.com/repos/drone-plugins/drone-downstream/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/drone-plugins/drone-downstream/downloads","issues_url":"https://api.github.com/repos/drone-plugins/drone-downstream/issues{/number}","pulls_url":"https://api.github.com/repos/drone-plugins/drone-downstream/pulls{/number}","milestones_url":"https://api.github.com/repos/drone-plugins/drone-downstream/milestones{/number}","notifications_url":"https://api.github.com/repos/drone-plugins/drone-downstream/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/drone-plugins/drone-downstream/labels{/name}","releases_url":"https://api.github.com/repos/drone-plugins/drone-downstream/releases{/id}","deployments_url":"https://api.github.com/repos/drone-plugins/drone-downstream/deployments","created_at":"2015-10-28T19:01:17Z","updated_at":"2016-08-30T17:46:37Z","pushed_at":"2016-10-31T18:29:19Z","git_url":"git://github.com/drone-plugins/drone-downstream.git","ssh_url":"git@github.com:drone-plugins/drone-downstream.git","clone_url":"https://github.com/drone-plugins/drone-downstream.git","svn_url":"https://github.com/drone-plugins/drone-downstream","homepage":null,"size":389,"stargazers_count":3,"watchers_count":3,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":1,"forks":7,"open_issues":1,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/drone-plugins/drone-downstream/pulls/16"},"html":{"href":"https://github.com/drone-plugins/drone-downstream/pull/16"},"issue":{"href":"https://api.github.com/repos/drone-plugins/drone-downstream/issues/16"},"comments":{"href":"https://api.github.com/repos/drone-plugins/drone-downstream/issues/16/comments"},"review_comments":{"href":"https://api.github.com/repos/drone-plugins/drone-downstream/pulls/16/comments"},"review_comment":{"href":"https://api.github.com/repos/drone-plugins/drone-downstream/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/drone-plugins/drone-downstream/pulls/16/commits"},"statuses":{"href":"https://api.github.com/repos/drone-plugins/drone-downstream/statuses/64742d574e1d7d8c2c65317869c1b4426e20695e"}}}}
{"actor":{"display_login":"tboerger"}}