Class: Trellish::Card
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Campfire
#announce
Methods included from Git
#current_git_branch_is_up_to_date?, #git_create_local_branch, #git_repository_name, #git_repository_owner, #git_user_initials, #github_pull_request_url
Constructor Details
#initialize(card_id_or_url) ⇒ Card
54
55
56
57
|
# File 'lib/trellish/card.rb', line 54
def initialize(card_id_or_url)
@member = Trellish::Auth.authorize
@card = Trello::Card.find(parse_card_id(card_id_or_url))
end
|
Class Method Details
.select_from_list(list_name, assigned_to_me = false) ⇒ Object
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
|
# File 'lib/trellish/card.rb', line 12
def self.select_from_list(list_name, assigned_to_me = false)
me = Trellish::Auth.authorize
boards = me.boards(filter: :open)
current_board = boards.find { |board| board.name == Trellish.config[:board_name] }
if current_board.nil?
Trellish.logger.error "Unable to find a board named `#{Trellish.config[:board_name]}`."
exit
end
list = current_board.lists.find { |list| list.name == list_name }
if list.nil?
Trellish.logger.error "Unable to find a list named `#{list_name}` on board `#{Trellish.config[:board_name]}`."
exit
end
cards = list.cards
if assigned_to_me
cards = cards.find_all { |card| card.member_ids.include?(me.id) }
end
case cards.length
when 0
if assigned_to_me
Trellish.logger.error "There are no cards assigned to you in the list `#{list_name}`"
else
Trellish.logger.error "There are no cards in the list `#{list_name}`"
end
exit
when 1
index = 0
else
puts "\nSelect a card:"
cards.each_with_index { |card, index| puts "#{index+1}. #{card.name}" }
index = Readline.readline("> ")
exit if index.blank?
index = index.to_i - 1
end
Trellish::Card.new( cards[index].id )
end
|
Instance Method Details
#add_me_as_member ⇒ Object
59
60
61
|
# File 'lib/trellish/card.rb', line 59
def add_me_as_member
@card.add_member(@member) unless @card.member_ids.include?(@member.id)
end
|
#add_pull_request_link ⇒ Object
63
64
65
66
67
68
69
70
71
|
# File 'lib/trellish/card.rb', line 63
def add_pull_request_link
message = "Pull request is at #{github_pull_request_url}"
@card. message
end
|
#create_local_branch ⇒ Object
73
74
75
76
|
# File 'lib/trellish/card.rb', line 73
def create_local_branch
branch_name = "#{git_user_initials}-#{short_name}"
git_create_local_branch(branch_name)
end
|
#finish ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/trellish/card.rb', line 78
def finish
if !current_git_branch_is_up_to_date?
finish = Readline.readline("Your remote branch isn’t up-to-date. Finish anyway? [y,N] ")
exit unless ['y','yes'].include?(finish.strip.downcase)
end
add_pull_request_link
remove_all
move_to_qa
announce %Q([Trellish] Finished card “#{@card.name}” #{@card.url}. The pull request is at #{github_pull_request_url})
end
|
#move_to_in_progress ⇒ Object
94
95
96
|
# File 'lib/trellish/card.rb', line 94
def move_to_in_progress
move_to_list(Trellish.config[:in_progress_list_name])
end
|
#move_to_qa ⇒ Object
90
91
92
|
# File 'lib/trellish/card.rb', line 90
def move_to_qa
move_to_list(Trellish.config[:qa_list_name])
end
|
#name ⇒ Object
98
99
100
|
# File 'lib/trellish/card.rb', line 98
def name
@card.name
end
|
#remove_all ⇒ Object
102
103
104
|
# File 'lib/trellish/card.rb', line 102
def remove_all
@card.remove_all_members
end
|
#short_name ⇒ Object
106
107
108
|
# File 'lib/trellish/card.rb', line 106
def short_name
name.strip.downcase.tr(' ','-').gsub(/[^0-9A-Za-z\-]/, '')[0..30]
end
|
#start ⇒ Object
110
111
112
113
114
115
|
# File 'lib/trellish/card.rb', line 110
def start
move_to_in_progress
add_me_as_member
create_local_branch
announce %Q([Trellish] Starting card “#{@card.name}” #{@card.url})
end
|