Module: OmniFocus::Trello

Defined in:
lib/omnifocus/trello/version.rb,
lib/omnifocus/trello.rb

Constant Summary collapse

VERSION =
"1.2.2"
PREFIX =
"TR"
KEY =
"3ad9e72a2e2d41a98450ca775a0bafe4"

Instance Method Summary collapse

Instance Method Details

#fetch_trello_boards(token) ⇒ Object



69
70
71
72
# File 'lib/omnifocus/trello.rb', line 69

def fetch_trello_boards(token)
  url = "https://api.trello.com/1/members/my/boards?key=#{KEY}&token=#{token}&lists=open"
  JSON.parse(open(url).read)
end

#fetch_trello_cards(token) ⇒ Object



37
38
39
40
41
# File 'lib/omnifocus/trello.rb', line 37

def fetch_trello_cards(token)
  url = "https://api.trello.com/1/members/my/cards?key=#{KEY}&token=#{token}"

  JSON.parse(open(url).read)
end

#load_or_create_trello_configObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/omnifocus/trello.rb', line 9

def load_or_create_trello_config
  path   = File.expand_path "~/.omnifocus-trello.yml"
  config = YAML.load(File.read(path)) rescue nil

  unless config then
    config = { :token => "Open URL https://trello.com/1/authorize?key=#{KEY}&name=OmniFocus+Trello+integration&expiration=never&response_type=token and copy the token from the web page here.", :done_lists => ["Done", "Deployed", "Finished", "Cards in these boards are considered done, you add and remove names to fit your workflow."] }

    File.open(path, "w") { |f|
      YAML.dump(config, f)
    }

    abort "Created default config in #{path}. Go fill it out."
  end

  config
end

#populate_trello_tasksObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/omnifocus/trello.rb', line 26

def populate_trello_tasks
  config     = load_or_create_trello_config
  token      = config[:token]
  done_lists = config[:done_lists] || config[:done_boards]

  boards = fetch_trello_boards(token)
  fetch_trello_cards(token).each do |card|
    process_trello_card(boards, done_lists, card)
  end
end

#process_trello_card(boards, done_lists, card) ⇒ Object



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
# File 'lib/omnifocus/trello.rb', line 43

def process_trello_card(boards, done_lists, card)
  number       = card["idShort"]
  description  = if card["desc"].length > 0
    card["shortUrl"] + "\n\n" + card["desc"]
  else
    card["shortUrl"]
  end
  board        = boards.find {|candidate| candidate["id"] == card["idBoard"] }
  project_name = board["name"]
  ticket_id    = "#{PREFIX}-#{project_name}##{number}"
  title        = "#{ticket_id}: #{card["name"]}"
  list         = board["lists"].find {|candidate| candidate["id"] == card["idList"] }

  # If card is in a "done" list, mark it as completed.
  if done_lists.include?(list["name"])
    return
  end

  if existing[ticket_id]
    bug_db[existing[ticket_id]][ticket_id] = true
    return
  end

  bug_db[project_name][ticket_id] = [title, description]
end