forked from kupuguy/gitthello
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.rb
More file actions
88 lines (68 loc) · 2.13 KB
/
app.rb
File metadata and controls
88 lines (68 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require 'rubygems'
require 'bundler/setup'
require 'sinatra'
require "sinatra/multi_route"
require 'json'
require 'github_api'
require 'trello'
require 'dotenv'
require_relative 'lib/gitthello'
set :static, true
Dotenv.load
ENV['environment'] = ENV['RACK_ENV'] || 'development'
get '/' do
@config = Gitthello.configuration
@github = Github.new(:oauth_token => @config.github.token)
@boards = @config.boards.map do |_,board_config|
Gitthello::Board.new(board_config)
end
Trello.configure do |cfg|
cfg.member_token = @config.trello.token
cfg.developer_public_key = @config.trello.dev_key
end
@github_usable = begin
!!@github.issues.list
rescue
false
end
@trello_usable = begin
!!Trello::Board.all.count
rescue
false
end
haml :index
end
get '/issues/*' do
content_type :json
@config = Gitthello.configuration
@github = Github.new(:oauth_token => @config.github.token)
is_configed_repo = (@config.boards.map do |_,board_config|
Gitthello::Board.new(board_config)
end.map(&:repo_for_new_cards).
include?(params[:splat].first))
if is_configed_repo
owner,repo = params[:splat].first.split(/\//)
{ :value => @github.issues.list(:user => owner, :repo => repo,
:state => "open" ).count }
else
{ :value => 0 }
end.to_json
end
get '/lists/:board_name' do
content_type :json
@config = Gitthello.configuration
Trello.configure do |cfg|
cfg.member_token = @config.trello.token
cfg.developer_public_key = @config.trello.dev_key
end
is_configed_board = (@config.boards.map do |_,board_config|
Gitthello::Board.new(board_config)
end.map(&:name).
include?(params[:board_name]))
if is_configed_board
brd = Trello::Board.all.select { |b| b.name == params[:board_name] }.first
{ :value => brd.lists.count }
else
{ :value => 0 }
end.to_json
end