Class: Codebot::Formatters::Gitlab::JobHook
Overview
Triggers on a Job or Build event
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, #repository_name, #repository_url, #sanitize, #sender_name, #shorten_url, #url
Instance Method Details
#author(commit) ⇒ Object
52
53
54
55
56
|
# File 'lib/codebot/formatters/gitlab_job_hook.rb', line 52
def author(commit)
return nil unless commit['author'].is_a? Hash
commit['author']['name']
end
|
#branch ⇒ Object
58
59
60
61
62
63
|
# File 'lib/codebot/formatters/gitlab_job_hook.rb', line 58
def branch
pieces = (:ref).split('/')
return pieces[0] if pieces.length == 1
pieces[2..-1].join('/')
end
|
44
45
46
47
48
49
50
|
# File 'lib/codebot/formatters/gitlab_job_hook.rb', line 44
def format
if (:build_status) == 'created'
[job_description] + [format_commit((:commit))]
else
[job_description]
end
end
|
65
66
67
68
69
70
71
72
73
|
# File 'lib/codebot/formatters/gitlab_job_hook.rb', line 65
def format_commit(commit)
'%<repository>s/%<branch>s %<hash>s %<author>s: %<title>s' % {
repository: format_repository(repo_name),
branch: format_branch(branch),
hash: format_hash(commit['id']),
author: format_user(author(commit)),
title: prettify(commit['message'])
}
end
|
rubocop:disable Metrics/MethodLength
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/codebot/formatters/gitlab_job_hook.rb', line 8
def format_job_status case (:build_status)
when 'created'
'was created from commit:'
when 'success'
'succeeded'
when 'skipped'
'was skipped'
when /^fail/, /^err/
"failed: #{(:build_failure_reason)}"
else
"did something: #{(:build_status)}"
end
end
|
#job_description ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/codebot/formatters/gitlab_job_hook.rb', line 35
def job_description
'[%<repository>s] job \'%<build>s\' (%<url>s) %<status>s' % {
repository: format_repository(repo_name),
build: (:build_name),
url: job_url,
status: format_job_status
}
end
|
#job_url ⇒ Object
31
32
33
|
# File 'lib/codebot/formatters/gitlab_job_hook.rb', line 31
def job_url
shorten_url "#{repo_url}/-/jobs/#{(:build_id)}"
end
|
#repo_name ⇒ Object
27
28
29
|
# File 'lib/codebot/formatters/gitlab_job_hook.rb', line 27
def repo_name
(:repository, :name)
end
|
#repo_url ⇒ Object
23
24
25
|
# File 'lib/codebot/formatters/gitlab_job_hook.rb', line 23
def repo_url
(:repository, :homepage)
end
|