Class: Fastlane::Actions::TrelloMoveCardAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/trello/actions/trello_move_card.rb

Class Method Summary collapse

Class Method Details

.authorsObject



74
75
76
# File 'lib/fastlane/plugin/trello/actions/trello_move_card.rb', line 74

def self.authors
  ["Oscar De Moya"]
end

.available_optionsObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/fastlane/plugin/trello/actions/trello_move_card.rb', line 86

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :api_key,
                                 env_name: "TRELLO_API_KEY",
                                 description: "Trello API Key (get one at: https://trello.com/app-key)",
                                 optional: false,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :api_token,
                                 env_name: "TRELLO_API_TOKEN",
                                 description: "Trello API Token (get one at: https://trello.com/app-key)",
                                 optional: false,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :board_id,
                                 env_name: "TRELLO_BOARD_ID",
                                 description: "The ID of the Trello board. You can find it in the trello board URL",
                                 optional: false,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :list_name,
                                 env_name: "TRELLO_LIST_NAME",
                                 description: "The name of the list to move the card",
                                 optional: false,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :card_number,
                                 env_name: "TRELLO_CARD_NUMBER",
                                 description: "The number of the card to be moved the given list",
                                 optional: false,
                                 type: Integer)
  ]
end

.descriptionObject



70
71
72
# File 'lib/fastlane/plugin/trello/actions/trello_move_card.rb', line 70

def self.description
  "Trello plugin for Fastlane"
end

.detailsObject



82
83
84
# File 'lib/fastlane/plugin/trello/actions/trello_move_card.rb', line 82

def self.details
  "Plugin for moving a trello card to a given list"
end

.find_card_by(short_id:) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/fastlane/plugin/trello/actions/trello_move_card.rb', line 54

def self.find_card_by(short_id:)       
  url = URI("#{@base_path}/boards/#{@board_id}/cards/#{short_id}?fields=id%2Cname&key=#{@key}&token=#{@token}")
  request = Net::HTTP::Get.new(url)
  response = @http.request(request)
  card = JSON.parse(response.body)
  return card
end

.find_list_by(name:) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/fastlane/plugin/trello/actions/trello_move_card.rb', line 45

def self.find_list_by(name:)        
  url = URI("#{@base_path}/boards/#{@board_id}/lists?fields=id%2Cname&cards=none&card_fields=all&filter=open&key=#{@key}&token=#{@token}")
  request = Net::HTTP::Get.new(url)
  response = @http.request(request)
  lists = JSON.parse(response.body)
  list = lists.find { |list| list["name"] == name }
  return list
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/fastlane/plugin/trello/actions/trello_move_card.rb', line 116

def self.is_supported?(platform)
  true
end

.move_card(card_id:, list_id:) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/fastlane/plugin/trello/actions/trello_move_card.rb', line 62

def self.move_card(card_id:, list_id:)
  url = URI("#{@base_path}/cards/#{card_id}?idList=#{list_id}&key=#{@key}&token=#{@token}")
  request = Net::HTTP::Put.new(url)
  response = @http.request(request)
  card = JSON.parse(response.body)
  return card
end

.return_valueObject



78
79
80
# File 'lib/fastlane/plugin/trello/actions/trello_move_card.rb', line 78

def self.return_value
  # If your method provides a return value, you can describe here what it does
end

.run(params) ⇒ Object



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
# File 'lib/fastlane/plugin/trello/actions/trello_move_card.rb', line 17

def self.run(params)
  
  @key = params[:api_key]
  @token = params[:api_token]
  @board_id = params[:board_id]
  list_name = params[:list_name]
  card_number = params[:card_number]
  
  UI.message("Fetching Trello list '#{list_name}'...")
  list = find_list_by(name: list_name)
  unless list
    UI.error("List #{list_name} not found.")
    return
  end
  list_id = list["id"]
  
  UI.message("Fetching Trello card [##{card_number}]...")
  card = find_card_by(short_id: card_number)
  unless card
    UI.error("Card #{card_number} not found.")
    return
  end
  card_name = card["name"]

  UI.message("Moving card [##{card_number}] '#{card_name}' to list '#{list_name}'")
  move_card(card_id: card["id"], list_id: list_id)
end