Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
module Codebot | ||
module Formatters | ||
module Gitlab | ||
# Triggers on a Merge Request Hook event | ||
class MergeRequestHook < Formatter | ||
def format | ||
["#{summary}: #{format_url url}"] | ||
end | ||
|
||
def summary | ||
default_format % { | ||
repository: format_repository(repository_name), | ||
sender: format_user(sender_name), | ||
action: action, | ||
title: pull_title | ||
} | ||
end | ||
|
||
def default_format | ||
'[%<repository>s] %<sender>s %<action>s merge request \'%<title>s\'' | ||
end | ||
|
||
def repository_name | ||
extract(:project, :path_with_namespace) | ||
end | ||
|
||
def sender_name | ||
extract(:user, :name) | ||
end | ||
|
||
def summary_url | ||
extract(:object_attributes, :url) | ||
end | ||
|
||
def action | ||
case pull_action | ||
when 'open' then 'opened' | ||
when 'close' then 'closed' | ||
when 'reopen' then 'reopened' | ||
when 'update', nil then 'updated' | ||
else pull_action | ||
end | ||
end | ||
|
||
def pull_action | ||
extract(:object_attributes, :action) | ||
end | ||
|
||
def pull_title | ||
extract(:object_attributes, :title) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'codebot/formatters/gitlab_helpers' | ||
|
||
RSpec.describe Codebot::Formatters::Gitlab::MergeRequestHook do | ||
describe '.format' do | ||
it 'formats correctly one entry' do | ||
result = do_format_test('gitlab_merge_request_hook_1', | ||
Codebot::Formatters::Gitlab::MergeRequestHook) | ||
expect(result).to eq ['[gitlabhq/gitlab-test] Administrator opened merge request \'MS-Viewport\': shortened://http://example.com/diaspora/merge_requests/1'] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|