From 55f6257d88151e2044a777b7cc5e9ce64bdec78b Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Fri, 1 Jan 2021 12:20:15 +0100 Subject: [PATCH] Refactor PR/MR related code (2/2) This commit renames ModuleSync::PR module to ModuleSync::GitService. Git service classes (ie. GitHub and GitLab) can now be used to implement more features than PR/MR opening. (e.g #158) --- lib/modulesync/git_service.rb | 8 ++++---- lib/modulesync/{pr => git_service}/github.rb | 2 +- lib/modulesync/{pr => git_service}/gitlab.rb | 2 +- spec/unit/modulesync/{pr => git_service}/github_spec.rb | 7 ++++--- spec/unit/modulesync/{pr => git_service}/gitlab_spec.rb | 9 +++++---- 5 files changed, 15 insertions(+), 13 deletions(-) rename lib/modulesync/{pr => git_service}/github.rb (99%) rename lib/modulesync/{pr => git_service}/gitlab.rb (99%) rename spec/unit/modulesync/{pr => git_service}/github_spec.rb (92%) rename spec/unit/modulesync/{pr => git_service}/gitlab_spec.rb (92%) diff --git a/lib/modulesync/git_service.rb b/lib/modulesync/git_service.rb index 21911230..1a512939 100644 --- a/lib/modulesync/git_service.rb +++ b/lib/modulesync/git_service.rb @@ -8,14 +8,14 @@ def self.instantiate(type:, options:) 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) + require 'modulesync/git_service/github' + ModuleSync::GitService::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) + require 'modulesync/git_service/gitlab' + ModuleSync::GitService::GitLab.new(token, endpoint) else raise ModuleSync::Error, "Unable to manage a PR/MR for Git service: '#{type}'" end diff --git a/lib/modulesync/pr/github.rb b/lib/modulesync/git_service/github.rb similarity index 99% rename from lib/modulesync/pr/github.rb rename to lib/modulesync/git_service/github.rb index 9726068f..dfa1105e 100644 --- a/lib/modulesync/pr/github.rb +++ b/lib/modulesync/git_service/github.rb @@ -4,7 +4,7 @@ require 'modulesync/util' module ModuleSync - module PR + module GitService # GitHub creates and manages pull requests on github.com or GitHub # Enterprise installations. class GitHub diff --git a/lib/modulesync/pr/gitlab.rb b/lib/modulesync/git_service/gitlab.rb similarity index 99% rename from lib/modulesync/pr/gitlab.rb rename to lib/modulesync/git_service/gitlab.rb index 658cc75f..6ada5559 100644 --- a/lib/modulesync/pr/gitlab.rb +++ b/lib/modulesync/git_service/gitlab.rb @@ -4,7 +4,7 @@ require 'modulesync/util' module ModuleSync - module PR + module GitService # GitLab creates and manages merge requests on gitlab.com or private GitLab # installations. class GitLab diff --git a/spec/unit/modulesync/pr/github_spec.rb b/spec/unit/modulesync/git_service/github_spec.rb similarity index 92% rename from spec/unit/modulesync/pr/github_spec.rb rename to spec/unit/modulesync/git_service/github_spec.rb index 5660f86e..f66c574b 100644 --- a/spec/unit/modulesync/pr/github_spec.rb +++ b/spec/unit/modulesync/git_service/github_spec.rb @@ -1,7 +1,8 @@ require 'spec_helper' -require 'modulesync/pr/github' -describe ModuleSync::PR::GitHub do +require 'modulesync/git_service/github' + +describe ModuleSync::GitService::GitHub do context '::open_pull_request' do before(:each) do @git_repo = 'test/modulesync' @@ -16,7 +17,7 @@ @client = double() allow(Octokit::Client).to receive(:new).and_return(@client) - @it = ModuleSync::PR::GitHub.new('test', 'https://api.github.com') + @it = ModuleSync::GitService::GitHub.new('test', 'https://api.github.com') end it 'submits PR when --pr is set' do diff --git a/spec/unit/modulesync/pr/gitlab_spec.rb b/spec/unit/modulesync/git_service/gitlab_spec.rb similarity index 92% rename from spec/unit/modulesync/pr/gitlab_spec.rb rename to spec/unit/modulesync/git_service/gitlab_spec.rb index 53420b0a..29008f6b 100644 --- a/spec/unit/modulesync/pr/gitlab_spec.rb +++ b/spec/unit/modulesync/git_service/gitlab_spec.rb @@ -1,14 +1,15 @@ require 'spec_helper' -require 'modulesync/pr/gitlab' -describe ModuleSync::PR::GitLab do +require 'modulesync/git_service/gitlab' + +describe ModuleSync::GitService::GitLab do context '::open_pull_request' do before(:each) do @git_repo = 'test/modulesync' @namespace, @repo_name = @git_repo.split('/') @options = { :pr => true, - :pr_title => 'Test PR is submitted', + :pr_title => 'Test MR is submitted', :branch => 'test', :message => 'Hello world', :pr_auto_merge => false, @@ -16,7 +17,7 @@ @client = double() allow(Gitlab::Client).to receive(:new).and_return(@client) - @it = ModuleSync::PR::GitLab.new('test', 'https://gitlab.com/api/v4') + @it = ModuleSync::GitService::GitLab.new('test', 'https://gitlab.com/api/v4') end it 'submits MR when --pr is set' do