Class: ModuleSync::SourceCode
- Inherits:
-
Object
- Object
- ModuleSync::SourceCode
- Defined in:
- lib/modulesync/source_code.rb
Overview
Provide methods to retrieve source code attributes
Direct Known Subclasses
Instance Attribute Summary collapse
-
#given_name ⇒ Object
readonly
Returns the value of attribute given_name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #git_service ⇒ Object
- #git_service_configuration ⇒ Object
-
#initialize(given_name, options) ⇒ SourceCode
constructor
A new instance of SourceCode.
- #open_pull_request ⇒ Object
- #path(*parts) ⇒ Object
- #repository ⇒ Object
- #repository_name ⇒ Object
- #repository_namespace ⇒ Object
- #repository_path ⇒ Object
- #repository_remote ⇒ Object
- #working_directory ⇒ Object
Constructor Details
#initialize(given_name, options) ⇒ SourceCode
Returns a new instance of SourceCode.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/modulesync/source_code.rb', line 12 def initialize(given_name, ) @options = Util.symbolize_keys( || {}) @given_name = given_name return unless given_name.include?('/') @repository_name = given_name.split('/').last @repository_namespace = given_name.split('/')[0...-1].join('/') end |
Instance Attribute Details
#given_name ⇒ Object (readonly)
Returns the value of attribute given_name.
10 11 12 |
# File 'lib/modulesync/source_code.rb', line 10 def given_name @given_name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/modulesync/source_code.rb', line 10 def @options end |
Instance Method Details
#git_service ⇒ Object
51 52 53 54 55 |
# File 'lib/modulesync/source_code.rb', line 51 def git_service return nil if git_service_configuration.nil? @git_service ||= GitService::Factory.instantiate(**git_service_configuration) end |
#git_service_configuration ⇒ Object
57 58 59 60 61 |
# File 'lib/modulesync/source_code.rb', line 57 def git_service_configuration @git_service_configuration ||= GitService.configuration_for(sourcecode: self) rescue GitService::UnguessableTypeError nil end |
#open_pull_request ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/modulesync/source_code.rb', line 63 def open_pull_request git_service.open_pull_request( repo_path: repository_path, namespace: repository_namespace, title: ModuleSync.[:pr_title], message: ModuleSync.[:message], source_branch: ModuleSync.[:remote_branch] || ModuleSync.[:branch] || repository.default_branch, target_branch: ModuleSync.[:pr_target_branch] || repository.default_branch, labels: ModuleSync::Util.parse_list(ModuleSync.[:pr_labels]), noop: ModuleSync.[:noop], ) end |
#path(*parts) ⇒ Object
47 48 49 |
# File 'lib/modulesync/source_code.rb', line 47 def path(*parts) File.join(working_directory, *parts) end |
#repository ⇒ Object
23 24 25 |
# File 'lib/modulesync/source_code.rb', line 23 def repository @repository ||= Repository.new directory: working_directory, remote: repository_remote end |
#repository_name ⇒ Object
27 28 29 |
# File 'lib/modulesync/source_code.rb', line 27 def repository_name @repository_name ||= given_name end |
#repository_namespace ⇒ Object
31 32 33 |
# File 'lib/modulesync/source_code.rb', line 31 def repository_namespace @repository_namespace ||= @options[:namespace] || ModuleSync.[:namespace] end |
#repository_path ⇒ Object
35 36 37 |
# File 'lib/modulesync/source_code.rb', line 35 def repository_path @repository_path ||= "#{repository_namespace}/#{repository_name}" end |
#repository_remote ⇒ Object
39 40 41 |
# File 'lib/modulesync/source_code.rb', line 39 def repository_remote @repository_remote ||= @options[:remote] || _repository_remote end |
#working_directory ⇒ Object
43 44 45 |
# File 'lib/modulesync/source_code.rb', line 43 def working_directory @working_directory ||= File.join(ModuleSync.[:project_root], repository_path) end |