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
3 changed files
with
78 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,56 @@ | ||
# frozen_string_literal: true | ||
|
||
module Codebot | ||
module Formatters | ||
module Gitlab | ||
# Triggers on a Wiki Page Hook event | ||
class WikiPageHook < 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: wiki_title | ||
} | ||
end | ||
|
||
def default_format | ||
'[%<repository>s] %<sender>s %<action>s page \'%<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 wiki_action | ||
when 'create' then 'created' | ||
when 'delete' then 'deleted' | ||
when 'update', nil then 'updated' | ||
else wiki_action | ||
end | ||
end | ||
|
||
def wiki_action | ||
extract(:object_attributes, :action) | ||
end | ||
|
||
def wiki_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 |
---|---|---|
@@ -1 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'codebot/formatters/gitlab_helpers' | ||
|
||
RSpec.describe Codebot::Formatters::Gitlab::WikiPageHook do | ||
describe '.format' do | ||
it 'formats correctly one entry' do | ||
result = do_format_test('gitlab_wiki_page_hook_1', | ||
Codebot::Formatters::Gitlab::WikiPageHook) | ||
expect(result).to eq ['[root/awesome-project] Administrator created page \'Awesome\': shortened://http://example.com/root/awesome-project/wikis/awesome'] | ||
end | ||
|
||
it 'formats correctly another entry' do | ||
result = do_format_test('gitlab_wiki_page_hook_2', | ||
Codebot::Formatters::Gitlab::WikiPageHook) | ||
expect(result).to eq ['[infrastructure/management] Ola Bini created page \'Infrastructure Onboarding\': shortened://https://gitlab.autonomia.digital/infrastructure/management/wikis/Infrastructure-Onboarding'] | ||
end | ||
end | ||
end |