-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce Pronto::Formatter.register for adding custom formatters
fixes #451
- Loading branch information
Showing
20 changed files
with
150 additions
and
31 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
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
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
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,30 +1,27 @@ | ||
module Pronto | ||
module Formatter | ||
def self.get(names) | ||
names ||= 'text' | ||
Array(names).map { |name| FORMATTERS[name.to_s] || TextFormatter } | ||
.uniq.map(&:new) | ||
end | ||
class << self | ||
def register(formatter_klass) | ||
unless formatter_klass.method_defined?(:format) | ||
raise NoMethodError, "format method is not declared in the #{formatter_klass.name} class." | ||
end | ||
|
||
def self.names | ||
FORMATTERS.keys | ||
end | ||
base = Pronto::Formatter::Base | ||
raise "#{formatter_klass.name} is not a #{base}" unless formatter_klass.ancestors.include?(base) | ||
|
||
@formatters ||= {} | ||
@formatters[formatter_klass.name] = formatter_klass | ||
end | ||
|
||
FORMATTERS = { | ||
'github' => GithubFormatter, | ||
'github_status' => GithubStatusFormatter, | ||
'github_combined_status' => GithubCombinedStatusFormatter, | ||
'github_pr' => GithubPullRequestFormatter, | ||
'github_pr_review' => GithubPullRequestReviewFormatter, | ||
'gitlab' => GitlabFormatter, | ||
'gitlab_mr' => GitlabMergeRequestReviewFormatter, | ||
'bitbucket' => BitbucketFormatter, | ||
'bitbucket_pr' => BitbucketPullRequestFormatter, | ||
'bitbucket_server_pr' => BitbucketServerPullRequestFormatter, | ||
'json' => JsonFormatter, | ||
'checkstyle' => CheckstyleFormatter, | ||
'text' => TextFormatter, | ||
'null' => NullFormatter | ||
}.freeze | ||
def get(names) | ||
names ||= 'text' | ||
Array(names).map { |name| @formatters[name.to_s] || TextFormatter } | ||
.uniq.map(&:new) | ||
end | ||
|
||
def names | ||
@formatters.keys | ||
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
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
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
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
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
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 |
---|---|---|
@@ -1,7 +1,13 @@ | ||
module Pronto | ||
module Formatter | ||
class NullFormatter < Base | ||
def self.name | ||
'null' | ||
end | ||
|
||
def format(_messages, _repo, _patches); end | ||
end | ||
end | ||
end | ||
|
||
Pronto::Formatter.register(Pronto::Formatter::NullFormatter) |
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