Skip to content

Commit e369228

Browse files
committed
Refactor PR/MR related code (2/3)
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 voxpupuli#158)
1 parent c373a04 commit e369228

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

lib/modulesync/git_service.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ def self.instantiate(type:, options:)
88
endpoint = options[:base_url] || ENV.fetch('GITHUB_BASE_URL', 'https://api.github.com')
99
token = options[:token] || ENV['GITHUB_TOKEN']
1010
raise ModuleSync::Error, 'No GitHub token specified to create a pull request' if token.nil?
11-
require 'modulesync/pr/github'
12-
return ModuleSync::PR::GitHub.new(token, endpoint)
11+
require 'modulesync/git_service/github'
12+
ModuleSync::GitService::GitHub.new(token, endpoint)
1313
when :gitlab
1414
endpoint = options[:base_url] || ENV.fetch('GITLAB_BASE_URL', 'https://gitlab.com/api/v4')
1515
token = options[:token] || ENV['GITLAB_TOKEN']
1616
raise ModuleSync::Error, 'No GitLab token specified to create a merge request' if token.nil?
17-
require 'modulesync/pr/gitlab'
18-
return ModuleSync::PR::GitLab.new(token, endpoint)
17+
require 'modulesync/git_service/gitlab'
18+
ModuleSync::GitService::GitLab.new(token, endpoint)
1919
else
2020
raise ModuleSync::Error, "Unable to manage a PR/MR for Git service: '#{type}'"
2121
end

lib/modulesync/pr/github.rb renamed to lib/modulesync/git_service/github.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require 'modulesync/util'
55

66
module ModuleSync
7-
module PR
7+
module GitService
88
# GitHub creates and manages pull requests on github.com or GitHub
99
# Enterprise installations.
1010
class GitHub

lib/modulesync/pr/gitlab.rb renamed to lib/modulesync/git_service/gitlab.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require 'modulesync/util'
55

66
module ModuleSync
7-
module PR
7+
module GitService
88
# GitLab creates and manages merge requests on gitlab.com or private GitLab
99
# installations.
1010
class GitLab

spec/unit/modulesync/pr/github_spec.rb renamed to spec/unit/modulesync/git_service/github_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
require 'spec_helper'
2-
require 'modulesync/pr/github'
32

4-
describe ModuleSync::PR::GitHub do
3+
require 'modulesync/git_service/github'
4+
5+
describe ModuleSync::GitService::GitHub do
56
context '::open_pull_request' do
67
before(:each) do
78
@git_repo = 'test/modulesync'
@@ -16,7 +17,7 @@
1617

1718
@client = double()
1819
allow(Octokit::Client).to receive(:new).and_return(@client)
19-
@it = ModuleSync::PR::GitHub.new('test', 'https://api.github.com')
20+
@it = ModuleSync::GitService::GitHub.new('test', 'https://api.github.com')
2021
end
2122

2223
it 'submits PR when --pr is set' do

spec/unit/modulesync/pr/gitlab_spec.rb renamed to spec/unit/modulesync/git_service/gitlab_spec.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
require 'spec_helper'
2-
require 'modulesync/pr/gitlab'
32

4-
describe ModuleSync::PR::GitLab do
3+
require 'modulesync/git_service/gitlab'
4+
5+
describe ModuleSync::GitService::GitLab do
56
context '::open_pull_request' do
67
before(:each) do
78
@git_repo = 'test/modulesync'
89
@namespace, @repo_name = @git_repo.split('/')
910
@options = {
1011
:pr => true,
11-
:pr_title => 'Test PR is submitted',
12+
:pr_title => 'Test MR is submitted',
1213
:branch => 'test',
1314
:message => 'Hello world',
1415
:pr_auto_merge => false,
1516
}
1617

1718
@client = double()
1819
allow(Gitlab::Client).to receive(:new).and_return(@client)
19-
@it = ModuleSync::PR::GitLab.new('test', 'https://gitlab.com/api/v4')
20+
@it = ModuleSync::GitService::GitLab.new('test', 'https://gitlab.com/api/v4')
2021
end
2122

2223
it 'submits MR when --pr is set' do

0 commit comments

Comments
 (0)