Permalink
Browse files

moves board logic into adapter

  • Loading branch information...
1 parent 6d39e26 commit d3822ee2feb5e8378db0486a522808f2bfb7424b @rauhryan rauhryan committed Apr 6, 2013
Showing with 37 additions and 22 deletions.
  1. +2 −1 lib/app.rb
  2. +18 −2 lib/bridge/huboard.rb
  3. +12 −2 lib/helpers.rb
  4. +5 −17 lib/pebble.rb
View
@@ -44,7 +44,8 @@ def protected!
@parameters = params
return erb :home, :layout => :marketing unless authenticated?
protected!
- @repos = pebble.all_repos
+ configure_gh
+ @repos = Huboard.all_repos
erb :index
end
View
@@ -118,7 +118,12 @@ def settings_labels
end
def column_labels
- labels.select{|l| Huboard.column_pattern.match l.name }
+ labels.select{|l| Huboard.column_pattern.match l.name }.map do |l|
+ match = Huboard.column_pattern.match l.name
+ l[:index] = match[:id]
+ l[:text] = match[:name]
+ l
+ end
end
def link_labels
@@ -309,8 +314,19 @@ def gh
def board
settings = self.settings
- columns = column_labels.drop settings[:show_all] ? 0 : 1
+ columns = column_labels.drop settings[:show_all] ? 1 : 0
columns.map { |c| issues(c.name) }.flat_map {|i| i }
+ grouped = issues.group_by {|i| i["current_state"]["name"] }
+ columns = column_labels.each_with_index do |label, index|
+ label["issues"] = (grouped[label.name] || []).sort_by {|i| i["_data"]["order"] || i.number.to_f }
+ label
+ end
+
+ if settings[:show_all]
+ columns[0][:issues] = (grouped["__nil__"] || []).concat(columns[0][:issues]).sort_by { |i| i["_data"]["order"] || i["number"].to_f} unless columns.empty?
+ end
+
+ columns
end
View
@@ -1,6 +1,8 @@
require 'ghee'
#require 'rack-cache'
#require 'active_support/cache'
+require_relative 'bridge/huboard'
+
class Huboard
module Common
module Settings
@@ -121,6 +123,16 @@ def h(input = "")
end
def gh(token = nil)
+ configure_gh token
+ Huboard.client
+ end
+
+ def huboard(token = nil)
+ configure_gh token
+ Huboard
+ end
+
+ def configure_gh(token = nil)
Huboard.configure do |client|
client.api_endpoint = ENV['GITHUB_API_ENDPOINT'] || 'https://api.github.com'
@@ -132,8 +144,6 @@ def gh(token = nil)
client.access_token = token || user_token
end
- Huboard.client
-
end
def socket_backend
View
@@ -1,7 +1,6 @@
require 'time'
require 'json'
require 'yaml'
-require_relative 'bridge/huboard'
module Stint
class Pebble
@@ -15,23 +14,12 @@ def build_board(user_name, repo)
include_backlog = settings(user_name, repo)[:show_all]
board = Huboard.adapter_for(user_name, repo)
- issues = board.board
- issues_by_label = issues.group_by { |issue| issue["current_state"]["name"] }
- all_labels = labels(user_name, repo)
- all_labels = all_labels.each_with_index do |label, index|
- x = issues_by_label[label[:name]]
- label[:issues] = (x || []).sort_by { |i| i["_data"]["order"] || i["number"].to_f}
- label
- end
-
- if include_backlog
- all_labels[0][:issues] = (issues_by_label["__nil__"] || []).concat(all_labels[0][:issues]).sort_by { |i| i["_data"]["order"] || i["number"].to_f} unless all_labels.empty?
- end
+ all_labels = board.board
- {
- labels: all_labels,
- milestones: get_milestones(user_name, repo),
- other_labels: github.labels(user_name, repo).reject { |l| @huboard_patterns.any?{|p| p.match(l["name"]) } }
+ return {
+ :labels => all_labels,
+ :milestones => get_milestones(user_name, repo),
+ :other_labels => github.labels(user_name, repo).reject { |l| @huboard_patterns.any?{|p| p.match(l["name"]) } }
}
end

0 comments on commit d3822ee

Please sign in to comment.