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.
This commit starts the refactoring of PR/MR feature code. It provides a more readable code by: - renaming method #manage for GitHub and GitLab class to open_pull_request - extracting the credentials and endpoints to use in only one method: GitService#instantiate It also provides a more understandable messages: - `msync` does not warn anymore if no environmment variables are sets, but correctly configured in module options - when no tokens are provided, the message now only contains the service that requires to specify token Note: This message could be improved to help the user to setup its modules configuration or ask him to set the environment variable.
- Loading branch information
Showing
10 changed files
with
75 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module ModuleSync | ||
# Namespace for Git service classes (ie. GitHub, GitLab) | ||
module GitService | ||
def self.instantiate(type:, options:) | ||
options ||= {} | ||
case type | ||
when :github | ||
endpoint = options[:base_url] || ENV.fetch('GITHUB_BASE_URL', 'https://api.github.com') | ||
token = options[:token] || ENV['GITHUB_TOKEN'] | ||
raise ModuleSync::Error, 'No GitHub token specified to create a pull request' if token.nil? | ||
require 'modulesync/pr/github' | ||
return ModuleSync::PR::GitHub.new(token, endpoint) | ||
when :gitlab | ||
endpoint = options[:base_url] || ENV.fetch('GITLAB_BASE_URL', 'https://gitlab.com/api/v4') | ||
token = options[:token] || ENV['GITLAB_TOKEN'] | ||
raise ModuleSync::Error, 'No GitLab token specified to create a merge request' if token.nil? | ||
require 'modulesync/pr/gitlab' | ||
return ModuleSync::PR::GitLab.new(token, endpoint) | ||
else | ||
raise ModuleSync::Error, "Unable to manage a PR/MR for Git service: '#{type}'" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'modulesync/git_service' | ||
|
||
describe ModuleSync::GitService do | ||
context 'when instantiate a GitHub service without credentials' do | ||
it 'raises an error' do | ||
expect { ModuleSync::GitService.instantiate(type: :github, options: nil) }.to raise_error(ModuleSync::Error, 'No GitHub token specified to create a pull request') | ||
end | ||
end | ||
|
||
context 'when instantiate a GitLab service without credentials' do | ||
it 'raises an error' do | ||
expect { ModuleSync::GitService.instantiate(type: :gitlab, options: nil) }.to raise_error(ModuleSync::Error, 'No GitLab token specified to create a merge request') | ||
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