codebot 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/ISSUE_TEMPLATE.md +32 -0
- data/.github/ISSUE_TEMPLATE/formatter_issue.md +20 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +13 -0
- data/.gitignore +10 -0
- data/.rspec +1 -0
- data/.rubocop.yml +11 -0
- data/.travis.yml +26 -0
- data/CODE_OF_CONDUCT.md +46 -0
- data/CONTRIBUTING.md +15 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +75 -0
- data/LICENSE +21 -0
- data/README.md +230 -0
- data/Rakefile +29 -0
- data/bin/console +8 -0
- data/codebot.gemspec +49 -0
- data/exe/codebot +7 -0
- data/lib/codebot.rb +8 -0
- data/lib/codebot/channel.rb +134 -0
- data/lib/codebot/command_error.rb +17 -0
- data/lib/codebot/config.rb +125 -0
- data/lib/codebot/configuration_error.rb +17 -0
- data/lib/codebot/core.rb +76 -0
- data/lib/codebot/cryptography.rb +38 -0
- data/lib/codebot/event.rb +62 -0
- data/lib/codebot/ext/cinch/ssl_extensions.rb +37 -0
- data/lib/codebot/formatter.rb +242 -0
- data/lib/codebot/formatters.rb +109 -0
- data/lib/codebot/formatters/.rubocop.yml +2 -0
- data/lib/codebot/formatters/commit_comment.rb +43 -0
- data/lib/codebot/formatters/fork.rb +40 -0
- data/lib/codebot/formatters/gitlab_issue_hook.rb +56 -0
- data/lib/codebot/formatters/gitlab_job_hook.rb +77 -0
- data/lib/codebot/formatters/gitlab_merge_request_hook.rb +57 -0
- data/lib/codebot/formatters/gitlab_note_hook.rb +119 -0
- data/lib/codebot/formatters/gitlab_pipeline_hook.rb +51 -0
- data/lib/codebot/formatters/gitlab_push_hook.rb +83 -0
- data/lib/codebot/formatters/gitlab_wiki_page_hook.rb +56 -0
- data/lib/codebot/formatters/gollum.rb +67 -0
- data/lib/codebot/formatters/issue_comment.rb +41 -0
- data/lib/codebot/formatters/issues.rb +41 -0
- data/lib/codebot/formatters/ping.rb +79 -0
- data/lib/codebot/formatters/public.rb +30 -0
- data/lib/codebot/formatters/pull_request.rb +71 -0
- data/lib/codebot/formatters/pull_request_review_comment.rb +49 -0
- data/lib/codebot/formatters/push.rb +172 -0
- data/lib/codebot/formatters/watch.rb +38 -0
- data/lib/codebot/integration.rb +195 -0
- data/lib/codebot/integration_manager.rb +225 -0
- data/lib/codebot/ipc_client.rb +83 -0
- data/lib/codebot/ipc_server.rb +79 -0
- data/lib/codebot/irc_client.rb +102 -0
- data/lib/codebot/irc_connection.rb +156 -0
- data/lib/codebot/message.rb +37 -0
- data/lib/codebot/metadata.rb +15 -0
- data/lib/codebot/network.rb +240 -0
- data/lib/codebot/network_manager.rb +181 -0
- data/lib/codebot/options.rb +49 -0
- data/lib/codebot/options/base.rb +55 -0
- data/lib/codebot/options/core.rb +126 -0
- data/lib/codebot/options/integration.rb +101 -0
- data/lib/codebot/options/network.rb +109 -0
- data/lib/codebot/payload.rb +32 -0
- data/lib/codebot/request.rb +51 -0
- data/lib/codebot/sanitizers.rb +130 -0
- data/lib/codebot/serializable.rb +101 -0
- data/lib/codebot/shortener.rb +43 -0
- data/lib/codebot/thread_controller.rb +70 -0
- data/lib/codebot/user_error.rb +13 -0
- data/lib/codebot/validation_error.rb +17 -0
- data/lib/codebot/web_listener.rb +107 -0
- data/lib/codebot/web_server.rb +58 -0
- data/webhook.png +0 -0
- metadata +249 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Portions (c) 2008 Logical Awesome, LLC (released under the MIT license).
|
4
|
+
# See the LICENSE file for the full MIT license text.
|
5
|
+
|
6
|
+
module Codebot
|
7
|
+
module Formatters
|
8
|
+
# This class formats commit_comment events.
|
9
|
+
class CommitComment < Formatter
|
10
|
+
# Formats IRC messages for a commit_comment event.
|
11
|
+
#
|
12
|
+
# @return [Array<String>] the formatted messages
|
13
|
+
def format
|
14
|
+
["#{summary}: #{format_url url}"]
|
15
|
+
end
|
16
|
+
|
17
|
+
def summary
|
18
|
+
default_format % {
|
19
|
+
repository: format_repository(repository_name),
|
20
|
+
sender: format_user(sender_name),
|
21
|
+
hash: format_hash(commit_id),
|
22
|
+
summary: prettify(comment_body)
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def default_format
|
27
|
+
'[%<repository>s] %<sender>s commented on commit %<hash>s: %<summary>s'
|
28
|
+
end
|
29
|
+
|
30
|
+
def summary_url
|
31
|
+
extract(:comment, :html_url).to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
def comment_body
|
35
|
+
extract(:comment, :body).to_s
|
36
|
+
end
|
37
|
+
|
38
|
+
def commit_id
|
39
|
+
extract(:comment, :commit_id)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Codebot
|
4
|
+
module Formatters
|
5
|
+
# This class formats fork events.
|
6
|
+
class Fork < Formatter
|
7
|
+
# Formats IRC messages for a fork event.
|
8
|
+
#
|
9
|
+
# @return [Array<String>] the formatted messages
|
10
|
+
def format
|
11
|
+
["#{summary}: #{format_url url}"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def summary
|
15
|
+
default_format % {
|
16
|
+
repository: format_repository(repository_name),
|
17
|
+
sender: format_user(sender_name),
|
18
|
+
fork_owner: format_user(fork_owner_login),
|
19
|
+
fork_name: format_repository(fork_name)
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def default_format
|
24
|
+
'[%<repository>s] %<sender>s created fork %<fork_owner>s/%<fork_name>s'
|
25
|
+
end
|
26
|
+
|
27
|
+
def fork_owner_login
|
28
|
+
extract(:forkee, :owner, :login)
|
29
|
+
end
|
30
|
+
|
31
|
+
def fork_name
|
32
|
+
extract(:forkee, :name)
|
33
|
+
end
|
34
|
+
|
35
|
+
def summary_url
|
36
|
+
extract(:forkee, :html_url).to_s
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Codebot
|
4
|
+
module Formatters
|
5
|
+
module Gitlab
|
6
|
+
# This class formats issues events.
|
7
|
+
class IssueHook < Formatter
|
8
|
+
def issue_action
|
9
|
+
extract(:object_attributes, :action)
|
10
|
+
end
|
11
|
+
|
12
|
+
def format_issue_action
|
13
|
+
case issue_action
|
14
|
+
when 'open' then 'opened'
|
15
|
+
when 'close' then 'closed'
|
16
|
+
when 'reopen' then 'reopened'
|
17
|
+
when 'update', nil then 'updated'
|
18
|
+
else issue_action
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def repo_url
|
23
|
+
extract(:project, :web_url)
|
24
|
+
end
|
25
|
+
|
26
|
+
def repo_name
|
27
|
+
extract(:project, :path_with_namespace)
|
28
|
+
end
|
29
|
+
|
30
|
+
def issue_url
|
31
|
+
shorten_url extract(:object_attributes, :url)
|
32
|
+
end
|
33
|
+
|
34
|
+
def user_name
|
35
|
+
extract(:user, :name)
|
36
|
+
end
|
37
|
+
|
38
|
+
def default_format
|
39
|
+
'[%<repository>s] %<sender>s %<action>s issue #%<number>s:' \
|
40
|
+
' %<title>s: %<url>s'
|
41
|
+
end
|
42
|
+
|
43
|
+
def format
|
44
|
+
[default_format % {
|
45
|
+
repository: format_repository(repo_name),
|
46
|
+
sender: format_user(user_name),
|
47
|
+
action: format_issue_action,
|
48
|
+
number: extract(:object_attributes, :iid),
|
49
|
+
title: extract(:object_attributes, :title),
|
50
|
+
url: issue_url
|
51
|
+
}]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Codebot
|
4
|
+
module Formatters
|
5
|
+
module Gitlab
|
6
|
+
# Triggers on a Job or Build event
|
7
|
+
class JobHook < Formatter
|
8
|
+
def format_job_status # rubocop:disable Metrics/MethodLength
|
9
|
+
case extract(:build_status)
|
10
|
+
when 'created'
|
11
|
+
'was created from commit:'
|
12
|
+
when 'success'
|
13
|
+
'succeeded'
|
14
|
+
when 'skipped'
|
15
|
+
'was skipped'
|
16
|
+
when /^fail/, /^err/
|
17
|
+
"failed: #{extract(:build_failure_reason)}"
|
18
|
+
else
|
19
|
+
"did something: #{extract(:build_status)}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def repo_url
|
24
|
+
extract(:repository, :homepage)
|
25
|
+
end
|
26
|
+
|
27
|
+
def repo_name
|
28
|
+
extract(:repository, :name)
|
29
|
+
end
|
30
|
+
|
31
|
+
def job_url
|
32
|
+
shorten_url "#{repo_url}/-/jobs/#{extract(:build_id)}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def job_description
|
36
|
+
'[%<repository>s] job \'%<build>s\' (%<url>s) %<status>s' % {
|
37
|
+
repository: format_repository(repo_name),
|
38
|
+
build: extract(:build_name),
|
39
|
+
url: job_url,
|
40
|
+
status: format_job_status
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def format
|
45
|
+
if extract(:build_status) == 'created'
|
46
|
+
[job_description] + [format_commit(extract(:commit))]
|
47
|
+
else
|
48
|
+
[job_description]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def author(commit)
|
53
|
+
return nil unless commit['author'].is_a? Hash
|
54
|
+
|
55
|
+
commit['author']['name']
|
56
|
+
end
|
57
|
+
|
58
|
+
def branch
|
59
|
+
pieces = extract(:ref).split('/')
|
60
|
+
return pieces[0] if pieces.length == 1
|
61
|
+
|
62
|
+
pieces[2..-1].join('/')
|
63
|
+
end
|
64
|
+
|
65
|
+
def format_commit(commit)
|
66
|
+
'%<repository>s/%<branch>s %<hash>s %<author>s: %<title>s' % {
|
67
|
+
repository: format_repository(repo_name),
|
68
|
+
branch: format_branch(branch),
|
69
|
+
hash: format_hash(commit['id']),
|
70
|
+
author: format_user(author(commit)),
|
71
|
+
title: prettify(commit['message'])
|
72
|
+
}
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Codebot
|
4
|
+
module Formatters
|
5
|
+
module Gitlab
|
6
|
+
# Triggers on a Merge Request Hook event
|
7
|
+
class MergeRequestHook < Formatter
|
8
|
+
def format
|
9
|
+
["#{summary}: #{format_url url}"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def summary
|
13
|
+
default_format % {
|
14
|
+
repository: format_repository(repository_name),
|
15
|
+
sender: format_user(sender_name),
|
16
|
+
action: action,
|
17
|
+
title: pull_title
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def default_format
|
22
|
+
'[%<repository>s] %<sender>s %<action>s merge request \'%<title>s\''
|
23
|
+
end
|
24
|
+
|
25
|
+
def repository_name
|
26
|
+
extract(:project, :path_with_namespace)
|
27
|
+
end
|
28
|
+
|
29
|
+
def sender_name
|
30
|
+
extract(:user, :name)
|
31
|
+
end
|
32
|
+
|
33
|
+
def summary_url
|
34
|
+
extract(:object_attributes, :url)
|
35
|
+
end
|
36
|
+
|
37
|
+
def action
|
38
|
+
case pull_action
|
39
|
+
when 'open' then 'opened'
|
40
|
+
when 'close' then 'closed'
|
41
|
+
when 'reopen' then 'reopened'
|
42
|
+
when 'update', nil then 'updated'
|
43
|
+
else pull_action
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def pull_action
|
48
|
+
extract(:object_attributes, :action)
|
49
|
+
end
|
50
|
+
|
51
|
+
def pull_title
|
52
|
+
extract(:object_attributes, :title)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Codebot
|
4
|
+
module Formatters
|
5
|
+
module Gitlab
|
6
|
+
# Triggers on a Note Hook event
|
7
|
+
class NoteHook < Formatter
|
8
|
+
def format
|
9
|
+
["#{summary}: #{format_url url}"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def summary
|
13
|
+
case note_type
|
14
|
+
when 'Issue'
|
15
|
+
issue_summary
|
16
|
+
when 'Snippet'
|
17
|
+
snippet_summary
|
18
|
+
when 'MergeRequest'
|
19
|
+
merge_request_summary
|
20
|
+
when 'Commit'
|
21
|
+
commit_summary
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def issue_summary
|
26
|
+
issue_default_format % {
|
27
|
+
repository: format_repository(repository_name),
|
28
|
+
sender: format_user(sender_name),
|
29
|
+
number: issue_number,
|
30
|
+
summary: prettify(comment_body)
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def snippet_summary
|
35
|
+
snippet_default_format % {
|
36
|
+
repository: format_repository(repository_name),
|
37
|
+
sender: format_user(sender_name),
|
38
|
+
snippet: snippet_title,
|
39
|
+
summary: prettify(comment_body)
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def merge_request_summary
|
44
|
+
merge_request_default_format % {
|
45
|
+
repository: format_repository(repository_name),
|
46
|
+
sender: format_user(sender_name),
|
47
|
+
mr: merge_request_title,
|
48
|
+
summary: prettify(comment_body)
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def commit_summary
|
53
|
+
commit_default_format % {
|
54
|
+
repository: format_repository(repository_name),
|
55
|
+
sender: format_user(sender_name),
|
56
|
+
hash: format_hash(commit_id),
|
57
|
+
summary: prettify(comment_body)
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
def issue_default_format
|
62
|
+
'[%<repository>s] %<sender>s commented on issue' \
|
63
|
+
' #%<number>s: %<summary>s'
|
64
|
+
end
|
65
|
+
|
66
|
+
def snippet_default_format
|
67
|
+
'[%<repository>s] %<sender>s commented on code snippet' \
|
68
|
+
' \'%<snippet>s\': %<summary>s'
|
69
|
+
end
|
70
|
+
|
71
|
+
def merge_request_default_format
|
72
|
+
'[%<repository>s] %<sender>s commented on merge request' \
|
73
|
+
' \'%<mr>s\': %<summary>s'
|
74
|
+
end
|
75
|
+
|
76
|
+
def commit_default_format
|
77
|
+
'[%<repository>s] %<sender>s commented on commit' \
|
78
|
+
' %<hash>s: %<summary>s'
|
79
|
+
end
|
80
|
+
|
81
|
+
def note_type
|
82
|
+
extract(:object_attributes, :noteable_type)
|
83
|
+
end
|
84
|
+
|
85
|
+
def repository_name
|
86
|
+
extract(:project, :path_with_namespace)
|
87
|
+
end
|
88
|
+
|
89
|
+
def sender_name
|
90
|
+
extract(:user, :name)
|
91
|
+
end
|
92
|
+
|
93
|
+
def summary_url
|
94
|
+
extract(:object_attributes, :url)
|
95
|
+
end
|
96
|
+
|
97
|
+
def comment_body
|
98
|
+
extract(:object_attributes, :note)
|
99
|
+
end
|
100
|
+
|
101
|
+
def snippet_title
|
102
|
+
extract(:snippet, :title)
|
103
|
+
end
|
104
|
+
|
105
|
+
def merge_request_title
|
106
|
+
extract(:merge_request, :title)
|
107
|
+
end
|
108
|
+
|
109
|
+
def issue_number
|
110
|
+
extract(:issue, :iid)
|
111
|
+
end
|
112
|
+
|
113
|
+
def commit_id
|
114
|
+
extract(:commit, :id)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Codebot
|
4
|
+
module Formatters
|
5
|
+
module Gitlab
|
6
|
+
# Triggered on status change of pipeline
|
7
|
+
class PipelineHook < Formatter
|
8
|
+
def pipeline_status
|
9
|
+
extract(:object_attributes, :status)
|
10
|
+
end
|
11
|
+
|
12
|
+
def format_job_status # rubocop:disable Metrics/MethodLength
|
13
|
+
case pipeline_status
|
14
|
+
when 'created'
|
15
|
+
'was created from commit'
|
16
|
+
when 'success'
|
17
|
+
'succeeded'
|
18
|
+
when 'skipped'
|
19
|
+
'was skipped'
|
20
|
+
when /^fail/, /^err/
|
21
|
+
"failed: #{extract(:object_attributes, :detailed_status)}"
|
22
|
+
else
|
23
|
+
"did something: #{pipeline_status}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def pipeline_id
|
28
|
+
extract(:object_attributes, :id)
|
29
|
+
end
|
30
|
+
|
31
|
+
def format # rubocop:disable Metrics/MethodLength
|
32
|
+
repo_url = extract(:project, :web_url)
|
33
|
+
repo_name = extract(:project, :path_with_namespace)
|
34
|
+
|
35
|
+
pipeline_url = shorten_url "#{repo_url}/pipelines/#{pipeline_id}"
|
36
|
+
reply = '[%<repository>s] pipeline %<status>s (%<url>s)' % {
|
37
|
+
repository: format_repository(repo_name),
|
38
|
+
status: format_job_status,
|
39
|
+
url: pipeline_url
|
40
|
+
}
|
41
|
+
|
42
|
+
if pipeline_status == 'created'
|
43
|
+
[reply + ':'] + [format_commit(extract(:commit))]
|
44
|
+
else
|
45
|
+
[reply]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|