-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathprepare_commit_message.rb
More file actions
42 lines (33 loc) · 934 Bytes
/
Copy pathprepare_commit_message.rb
File metadata and controls
42 lines (33 loc) · 934 Bytes
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
require "git_tracker/branch"
require "git_tracker/commit_message"
module GitTracker
class PrepareCommitMessage
attr_reader :file, :source, :commit_sha
def self.call(file, source = nil, commit_sha = nil)
new(file, source, commit_sha).call
end
def initialize(file, source = nil, commit_sha = nil)
@file = file
@source = source
@commit_sha = commit_sha
end
def call
exit_when_commit_exists
story = story_number_from_branch
message = CommitMessage.new(file)
exit if message.mentions_story?(story)
keyword = message.keyword
message_addition = [keyword, "##{story}"].compact.join(" ")
message.append("[#{message_addition}]")
end
private
def exit_when_commit_exists
exit if source == "commit"
end
def story_number_from_branch
story = Branch.story_number
exit unless story
story
end
end
end