Class: Codebot::Formatters::Gitlab::PushHook
Overview
This class formats Push events from Gitlab
Instance Attribute Summary
#payload
Instance Method Summary
collapse
#abbreviate, #action, #ary_to_sentence, #closed?, #extract, #format_branch, #format_dangerous, #format_event, #format_hash, #format_number, #format_repository, #format_url, #format_user, #gitlab_action, #gitlab_closed?, #gitlab_opened?, #gitlab_repository_url, #gitlab_url, #initialize, #opened?, #prettify, #sanitize, #sender_name, #shorten_url, #url
Instance Method Details
#after_commit ⇒ Object
12
13
14
|
# File 'lib/codebot/formatters/gitlab_push_hook.rb', line 12
def after_commit
(:after)
end
|
#before_commit ⇒ Object
8
9
10
|
# File 'lib/codebot/formatters/gitlab_push_hook.rb', line 8
def before_commit
(:before)
end
|
#branch ⇒ Object
49
50
51
|
# File 'lib/codebot/formatters/gitlab_push_hook.rb', line 49
def branch
(:ref).split('/')[2..-1].join('/')
end
|
#commit_author(commit) ⇒ Object
33
34
35
36
37
|
# File 'lib/codebot/formatters/gitlab_push_hook.rb', line 33
def commit_author(commit)
return nil unless commit['author'].is_a? Hash
commit['author']['name']
end
|
29
30
31
|
# File 'lib/codebot/formatters/gitlab_push_hook.rb', line 29
def commit_default_format
'%<repository>s/%<branch>s %<hash>s %<author>s: %<title>s'
end
|
#commit_summary(commit) ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/codebot/formatters/gitlab_push_hook.rb', line 39
def commit_summary(commit)
commit_default_format % {
repository: format_repository(repository_name),
branch: format_branch(branch),
hash: format_hash(commit['id']),
author: format_user(commit_author(commit)),
title: prettify(commit['message'])
}
end
|
#compare_url ⇒ Object
24
25
26
27
|
# File 'lib/codebot/formatters/gitlab_push_hook.rb', line 24
def compare_url
commits = "#{before_commit}...#{before_commit}"
shorten_url "#{repository_url}/compare/#{commits}"
end
|
#default_summary ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/codebot/formatters/gitlab_push_hook.rb', line 63
def default_summary
user_name = (:user_name)
summary_format % {
repository: format_repository(repository_name),
user: format_user(user_name),
num_commits: num_commits,
branch: format_branch(branch),
url: compare_url
}
end
|
75
76
77
78
79
|
# File 'lib/codebot/formatters/gitlab_push_hook.rb', line 75
def format
[default_summary] + (:commits).map do |commit|
commit_summary(commit)
end
end
|
#num_commits ⇒ Object
53
54
55
56
|
# File 'lib/codebot/formatters/gitlab_push_hook.rb', line 53
def num_commits
format_number((:total_commits_count).to_i,
'new commit', 'new commits')
end
|
#repository_name ⇒ Object
16
17
18
|
# File 'lib/codebot/formatters/gitlab_push_hook.rb', line 16
def repository_name
(:repository, :name)
end
|
#repository_url ⇒ Object
20
21
22
|
# File 'lib/codebot/formatters/gitlab_push_hook.rb', line 20
def repository_url
(:repository, :homepage)
end
|
58
59
60
61
|
# File 'lib/codebot/formatters/gitlab_push_hook.rb', line 58
def summary_format
'[%<repository>s] %<user>s pushed %<num_commits>s ' \
'to %<branch>s: %<url>s'
end
|