Skip to content

Commit

Permalink
Refactor PR/MR related code (2/3)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
neomilium committed Apr 23, 2021
1 parent 0326bf9 commit c62bb6d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
8 changes: 4 additions & 4 deletions lib/modulesync/git_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
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,
}

@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
Expand Down

0 comments on commit c62bb6d

Please sign in to comment.