forked from voxpupuli/modulesync
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GitService: Move factory part into dedicated module
- Loading branch information
Showing
5 changed files
with
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module ModuleSync | ||
module GitService | ||
module Factory | ||
def self.instantiate(type:, endpoint:, token:) | ||
raise MissingCredentialsError, <<~MESSAGE if token.nil? | ||
A token is required to use services from #{type}: | ||
Please set environment variable: "#{type.upcase}_TOKEN" or set the token entry in module options. | ||
MESSAGE | ||
|
||
case type | ||
when :github | ||
require 'modulesync/git_service/github' | ||
ModuleSync::GitService::GitHub.new(token, endpoint) | ||
when :gitlab | ||
require 'modulesync/git_service/gitlab' | ||
ModuleSync::GitService::GitLab.new(token, endpoint) | ||
else | ||
raise NotImplementedError, "Unable to manage a PR/MR for Git service: '#{type}'" | ||
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
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,16 @@ | ||
require 'modulesync' | ||
require 'modulesync/git_service/factory' | ||
|
||
describe ModuleSync::GitService::Factory do | ||
context 'when instantiate a GitHub service without credentials' do | ||
it 'raises an error' do | ||
expect { ModuleSync::GitService::Factory.instantiate(type: :github, endpoint: nil, token: nil) }.to raise_error(ModuleSync::GitService::MissingCredentialsError) | ||
end | ||
end | ||
|
||
context 'when instantiate a GitLab service without credentials' do | ||
it 'raises an error' do | ||
expect { ModuleSync::GitService::Factory.instantiate(type: :gitlab, endpoint: nil, token: nil) }.to raise_error(ModuleSync::GitService::MissingCredentialsError) | ||
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