{"action":"created","comment":{"url":"https://api.github.com/repos/openshift/sprint_tools/pulls/comments/82422829","pull_request_review_id":3334017,"id":82422829,"diff_hunk":"@@ -112,6 +114,304 @@ end\n \n trello = load_conf(TrelloHelper, CONFIG.trello, true)\n \n+def labels_in_order(card1, card2, trello)\n+  trello.product_order_hash[card1[:product]] < trello.product_order_hash[card2[:product]]\n+end\n+\n+def cards_in_order(card1, card2, trello)\n+  if card1[:release] < card2[:release]\n+    return true\n+  elsif card1[:release] == card2[:release]\n+    if TrelloHelper::RELEASE_STATE_ORDER[card1[:state]] < TrelloHelper::RELEASE_STATE_ORDER[card2[:state]]\n+      return true\n+    end\n+  end\n+  if card1[:product] != card2[:product]\n+    return true\n+  end\n+  return false\n+end\n+\n+def cards_equal(card1, card2, trello)\n+  ((TrelloHelper::RELEASE_STATE_ORDER[card1[:state]] == TrelloHelper::RELEASE_STATE_ORDER[card2[:state]]) &&\n+   (card1[:release] == card2[:release]))\n+end\n+\n+def order_card_positions(cards, index, forwards=false)\n+  needs_reshuffle = false\n+  this_card = cards[index]\n+  prev_card = if index == 0\n+    nil\n+  else\n+    cards[index - 1]\n+  end\n+  next_card = cards[index + 1]\n+  return needs_reshuffle if prev_card.nil? && next_card.nil?\n+  if prev_card\n+    if next_card\n+      if this_card[:pos] >= next_card[:pos]\n+        if prev_card[:pos] < next_card[:pos]\n+          cards[index][:pos] = Float(prev_card[:pos] + next_card[:pos]) / 2\n+        else #if prev_card[:pos] >= next_card[:pos]\n+          if next_card[:pos] <= prev_card[:pos] && forwards\n+            cards[index][:pos] = Float(prev_card[:pos]) + (Random.rand / 100)\n+          else\n+            cards[index][:pos] = Float(next_card[:pos]) - (Random.rand / 100)\n+            if cards[index][:pos] < 0\n+              # We're flying too low, sir!\n+              cards[index][:pos] = next_card[:pos] * 0.99\n+            end\n+          end\n+          needs_reshuffle = true\n+        end\n+      elsif this_card[:pos] <= prev_card[:pos]\n+        if prev_card[:pos] < next_card[:pos]\n+          cards[index][:pos] = Float(prev_card[:pos] + next_card[:pos]) / 2\n+        else #if prev_card[:pos] >= next_card[:pos]\n+          if prev_card[:pos] >= next_card[:pos] && forwards\n+            cards[index][:pos] = Float(prev_card[:pos]) + (Random.rand / 100)\n+          else\n+            cards[index][:pos] = Float(next_card[:pos]) - (Random.rand / 100)\n+            if cards[index][:pos] < 0\n+              # We're flying too low, sir!\n+              cards[index][:pos] = next_card[:pos] * 0.99\n+            end\n+          end\n+          needs_reshuffle = true\n+        end\n+      end # this_card < next_card\n+    else # next_card\n+      if this_card[:pos] <= prev_card[:pos]\n+        cards[index][:pos] = prev_card[:pos] + TRELLO_CARD_INCREMENT\n+      end\n+    end\n+  else\n+    if next_card\n+      if this_card[:pos] >= next_card[:pos]\n+        cards[index][:pos] = Float(next_card[:pos]) / 2\n+      end\n+    end\n+  end\n+  needs_reshuffle\n+end\n+\n+def reshuffle(cards)\n+  run_start = -1\n+  run_end = -1\n+  cards.each_with_index do |card, index|\n+    if card[:pos] != card[:card].pos\n+      if  run_start == -1\n+        run_start = index\n+      end\n+      run_end = index\n+    end\n+    if run_start != -1\n+      if (card[:pos] == card[:card].pos || index == (cards.length - 1))\n+        if run_end != run_start\n+          lower_bound = if run_start == 0\n+            0\n+          else\n+            cards[run_start - 1][:pos]\n+          end\n+          upper_bound = if run_end == (cards.length - 1)\n+            cards[run_end][:pos] + TRELLO_CARD_INCREMENT\n+          else\n+            card[:pos]\n+          end\n+          step_size = Float(upper_bound - lower_bound) / (3 + run_end - run_start)\n+          new_pos = lower_bound + step_size\n+          (run_start..run_end).each do |i| \n+            cards[i][:pos] = new_pos\n+            new_pos += step_size\n+          end\n+        end\n+        run_start = -1\n+        run_end = -1\n+      end\n+    end\n+  end\n+end\n+\n+def fix_card_positions(cards)\n+  needs_reshuffle = false\n+  reverse_needs_reshuffle = false\n+  forwards_needs_reshuffle = false\n+  # Fix positions backwards and forwards, and choose the order that has the least changes","path":"trello","position":null,"original_position":135,"commit_id":"f27c1dfe31bfcb840139f882f9e343072c6e890a","original_commit_id":"1b8b29cde719f3dd9851b268481a23cfb3a70cc3","user":{"login":"dobbymoodge","id":1537044,"avatar_url":"https://avatars.githubusercontent.com/u/1537044?v=3","gravatar_id":"","url":"https://api.github.com/users/dobbymoodge","html_url":"https://github.com/dobbymoodge","followers_url":"https://api.github.com/users/dobbymoodge/followers","following_url":"https://api.github.com/users/dobbymoodge/following{/other_user}","gists_url":"https://api.github.com/users/dobbymoodge/gists{/gist_id}","starred_url":"https://api.github.com/users/dobbymoodge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dobbymoodge/subscriptions","organizations_url":"https://api.github.com/users/dobbymoodge/orgs","repos_url":"https://api.github.com/users/dobbymoodge/repos","events_url":"https://api.github.com/users/dobbymoodge/events{/privacy}","received_events_url":"https://api.github.com/users/dobbymoodge/received_events","type":"User","site_admin":false},"body":"obviated","created_at":"2016-10-07T16:25:49Z","updated_at":"2016-10-07T16:25:49Z","html_url":"https://github.com/openshift/sprint_tools/pull/60#discussion_r82422829","pull_request_url":"https://api.github.com/repos/openshift/sprint_tools/pulls/60","_links":{"self":{"href":"https://api.github.com/repos/openshift/sprint_tools/pulls/comments/82422829"},"html":{"href":"https://github.com/openshift/sprint_tools/pull/60#discussion_r82422829"},"pull_request":{"href":"https://api.github.com/repos/openshift/sprint_tools/pulls/60"}}},"pull_request":{"url":"https://api.github.com/repos/openshift/sprint_tools/pulls/60","id":88438120,"html_url":"https://github.com/openshift/sprint_tools/pull/60","diff_url":"https://github.com/openshift/sprint_tools/pull/60.diff","patch_url":"https://github.com/openshift/sprint_tools/pull/60.patch","issue_url":"https://api.github.com/repos/openshift/sprint_tools/issues/60","number":60,"state":"open","locked":false,"title":"[WIP] Sort release cards","user":{"login":"dobbymoodge","id":1537044,"avatar_url":"https://avatars.githubusercontent.com/u/1537044?v=3","gravatar_id":"","url":"https://api.github.com/users/dobbymoodge","html_url":"https://github.com/dobbymoodge","followers_url":"https://api.github.com/users/dobbymoodge/followers","following_url":"https://api.github.com/users/dobbymoodge/following{/other_user}","gists_url":"https://api.github.com/users/dobbymoodge/gists{/gist_id}","starred_url":"https://api.github.com/users/dobbymoodge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dobbymoodge/subscriptions","organizations_url":"https://api.github.com/users/dobbymoodge/orgs","repos_url":"https://api.github.com/users/dobbymoodge/repos","events_url":"https://api.github.com/users/dobbymoodge/events{/privacy}","received_events_url":"https://api.github.com/users/dobbymoodge/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-10-07T13:28:05Z","updated_at":"2016-10-07T16:25:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"938149ffbbac75e075c6aad03c04304eb9dc7f6c","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/openshift/sprint_tools/pulls/60/commits","review_comments_url":"https://api.github.com/repos/openshift/sprint_tools/pulls/60/comments","review_comment_url":"https://api.github.com/repos/openshift/sprint_tools/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openshift/sprint_tools/issues/60/comments","statuses_url":"https://api.github.com/repos/openshift/sprint_tools/statuses/f27c1dfe31bfcb840139f882f9e343072c6e890a","head":{"label":"dobbymoodge:sort_release_cards_2","ref":"sort_release_cards_2","sha":"f27c1dfe31bfcb840139f882f9e343072c6e890a","user":{"login":"dobbymoodge","id":1537044,"avatar_url":"https://avatars.githubusercontent.com/u/1537044?v=3","gravatar_id":"","url":"https://api.github.com/users/dobbymoodge","html_url":"https://github.com/dobbymoodge","followers_url":"https://api.github.com/users/dobbymoodge/followers","following_url":"https://api.github.com/users/dobbymoodge/following{/other_user}","gists_url":"https://api.github.com/users/dobbymoodge/gists{/gist_id}","starred_url":"https://api.github.com/users/dobbymoodge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dobbymoodge/subscriptions","organizations_url":"https://api.github.com/users/dobbymoodge/orgs","repos_url":"https://api.github.com/users/dobbymoodge/repos","events_url":"https://api.github.com/users/dobbymoodge/events{/privacy}","received_events_url":"https://api.github.com/users/dobbymoodge/received_events","type":"User","site_admin":false},"repo":{"id":54052131,"name":"sprint_tools","full_name":"dobbymoodge/sprint_tools","owner":{"login":"dobbymoodge","id":1537044,"avatar_url":"https://avatars.githubusercontent.com/u/1537044?v=3","gravatar_id":"","url":"https://api.github.com/users/dobbymoodge","html_url":"https://github.com/dobbymoodge","followers_url":"https://api.github.com/users/dobbymoodge/followers","following_url":"https://api.github.com/users/dobbymoodge/following{/other_user}","gists_url":"https://api.github.com/users/dobbymoodge/gists{/gist_id}","starred_url":"https://api.github.com/users/dobbymoodge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dobbymoodge/subscriptions","organizations_url":"https://api.github.com/users/dobbymoodge/orgs","repos_url":"https://api.github.com/users/dobbymoodge/repos","events_url":"https://api.github.com/users/dobbymoodge/events{/privacy}","received_events_url":"https://api.github.com/users/dobbymoodge/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dobbymoodge/sprint_tools","description":"A collection of agile sprint scripting","fork":true,"url":"https://api.github.com/repos/dobbymoodge/sprint_tools","forks_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/forks","keys_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/teams","hooks_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/hooks","issue_events_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/issues/events{/number}","events_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/events","assignees_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/assignees{/user}","branches_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/branches{/branch}","tags_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/tags","blobs_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/git/refs{/sha}","trees_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/statuses/{sha}","languages_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/languages","stargazers_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/stargazers","contributors_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/contributors","subscribers_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/subscribers","subscription_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/subscription","commits_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/commits{/sha}","git_commits_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/git/commits{/sha}","comments_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/comments{/number}","issue_comment_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/issues/comments{/number}","contents_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/contents/{+path}","compare_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/merges","archive_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/downloads","issues_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/issues{/number}","pulls_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/pulls{/number}","milestones_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/milestones{/number}","notifications_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/labels{/name}","releases_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/releases{/id}","deployments_url":"https://api.github.com/repos/dobbymoodge/sprint_tools/deployments","created_at":"2016-03-16T17:20:07Z","updated_at":"2016-03-16T17:20:09Z","pushed_at":"2016-10-07T16:23:25Z","git_url":"git://github.com/dobbymoodge/sprint_tools.git","ssh_url":"git@github.com:dobbymoodge/sprint_tools.git","clone_url":"https://github.com/dobbymoodge/sprint_tools.git","svn_url":"https://github.com/dobbymoodge/sprint_tools","homepage":null,"size":428,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"openshift:master","ref":"master","sha":"4a90e43dda4add2f91597bd1bd3c70668cab4353","user":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"repo":{"id":27652746,"name":"sprint_tools","full_name":"openshift/sprint_tools","owner":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openshift/sprint_tools","description":"A collection of agile sprint scripting","fork":false,"url":"https://api.github.com/repos/openshift/sprint_tools","forks_url":"https://api.github.com/repos/openshift/sprint_tools/forks","keys_url":"https://api.github.com/repos/openshift/sprint_tools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openshift/sprint_tools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openshift/sprint_tools/teams","hooks_url":"https://api.github.com/repos/openshift/sprint_tools/hooks","issue_events_url":"https://api.github.com/repos/openshift/sprint_tools/issues/events{/number}","events_url":"https://api.github.com/repos/openshift/sprint_tools/events","assignees_url":"https://api.github.com/repos/openshift/sprint_tools/assignees{/user}","branches_url":"https://api.github.com/repos/openshift/sprint_tools/branches{/branch}","tags_url":"https://api.github.com/repos/openshift/sprint_tools/tags","blobs_url":"https://api.github.com/repos/openshift/sprint_tools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openshift/sprint_tools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openshift/sprint_tools/git/refs{/sha}","trees_url":"https://api.github.com/repos/openshift/sprint_tools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openshift/sprint_tools/statuses/{sha}","languages_url":"https://api.github.com/repos/openshift/sprint_tools/languages","stargazers_url":"https://api.github.com/repos/openshift/sprint_tools/stargazers","contributors_url":"https://api.github.com/repos/openshift/sprint_tools/contributors","subscribers_url":"https://api.github.com/repos/openshift/sprint_tools/subscribers","subscription_url":"https://api.github.com/repos/openshift/sprint_tools/subscription","commits_url":"https://api.github.com/repos/openshift/sprint_tools/commits{/sha}","git_commits_url":"https://api.github.com/repos/openshift/sprint_tools/git/commits{/sha}","comments_url":"https://api.github.com/repos/openshift/sprint_tools/comments{/number}","issue_comment_url":"https://api.github.com/repos/openshift/sprint_tools/issues/comments{/number}","contents_url":"https://api.github.com/repos/openshift/sprint_tools/contents/{+path}","compare_url":"https://api.github.com/repos/openshift/sprint_tools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openshift/sprint_tools/merges","archive_url":"https://api.github.com/repos/openshift/sprint_tools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openshift/sprint_tools/downloads","issues_url":"https://api.github.com/repos/openshift/sprint_tools/issues{/number}","pulls_url":"https://api.github.com/repos/openshift/sprint_tools/pulls{/number}","milestones_url":"https://api.github.com/repos/openshift/sprint_tools/milestones{/number}","notifications_url":"https://api.github.com/repos/openshift/sprint_tools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openshift/sprint_tools/labels{/name}","releases_url":"https://api.github.com/repos/openshift/sprint_tools/releases{/id}","deployments_url":"https://api.github.com/repos/openshift/sprint_tools/deployments","created_at":"2014-12-06T23:26:42Z","updated_at":"2016-09-13T12:50:05Z","pushed_at":"2016-10-07T16:23:25Z","git_url":"git://github.com/openshift/sprint_tools.git","ssh_url":"git@github.com:openshift/sprint_tools.git","clone_url":"https://github.com/openshift/sprint_tools.git","svn_url":"https://github.com/openshift/sprint_tools","homepage":null,"size":431,"stargazers_count":14,"watchers_count":14,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":15,"mirror_url":null,"open_issues_count":1,"forks":15,"open_issues":1,"watchers":14,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openshift/sprint_tools/pulls/60"},"html":{"href":"https://github.com/openshift/sprint_tools/pull/60"},"issue":{"href":"https://api.github.com/repos/openshift/sprint_tools/issues/60"},"comments":{"href":"https://api.github.com/repos/openshift/sprint_tools/issues/60/comments"},"review_comments":{"href":"https://api.github.com/repos/openshift/sprint_tools/pulls/60/comments"},"review_comment":{"href":"https://api.github.com/repos/openshift/sprint_tools/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openshift/sprint_tools/pulls/60/commits"},"statuses":{"href":"https://api.github.com/repos/openshift/sprint_tools/statuses/f27c1dfe31bfcb840139f882f9e343072c6e890a"}}}}
{"actor":{"display_login":"dobbymoodge"}}