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
-
#pull_request_branch_ready? ⇒ Boolean
This method checks if the pull request branch is ready to be opened.
-
#pull_request_source_branch ⇒ Object
This method returns the source branch for the pull request.
-
#pull_request_target_branch ⇒ Object
This method returns the target branch for the pull request.
- #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.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/modulesync/source_code.rb', line 14 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.
12 13 14 |
# File 'lib/modulesync/source_code.rb', line 12 def given_name @given_name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/modulesync/source_code.rb', line 12 def @options end |
Instance Method Details
#git_service ⇒ Object
53 54 55 56 57 |
# File 'lib/modulesync/source_code.rb', line 53 def git_service return nil if git_service_configuration.nil? @git_service ||= GitService::Factory.instantiate(**git_service_configuration) end |
#git_service_configuration ⇒ Object
59 60 61 62 63 |
# File 'lib/modulesync/source_code.rb', line 59 def git_service_configuration @git_service_configuration ||= GitService.configuration_for(sourcecode: self) rescue GitService::UnguessableTypeError nil end |
#open_pull_request ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/modulesync/source_code.rb', line 65 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: pull_request_source_branch, target_branch: pull_request_target_branch, labels: ModuleSync::Util.parse_list(ModuleSync.[:pr_labels]), noop: ModuleSync.[:noop], ) end |
#path(*parts) ⇒ Object
49 50 51 |
# File 'lib/modulesync/source_code.rb', line 49 def path(*parts) File.join(working_directory, *parts) end |
#pull_request_branch_ready? ⇒ Boolean
This method checks if the pull request branch is ready to be opened. It does this by checking if the source branch is ahead of the target branch in the remote repository.
80 81 82 |
# File 'lib/modulesync/source_code.rb', line 80 def pull_request_branch_ready? repository.remote_branch_ahead?(pull_request_source_branch, pull_request_target_branch) end |
#pull_request_source_branch ⇒ Object
This method returns the source branch for the pull request.
It first checks if the remote_branch option is set, then checks if the branch option is set, and finally defaults to the repository's default branch.
86 87 88 |
# File 'lib/modulesync/source_code.rb', line 86 def pull_request_source_branch ModuleSync.[:remote_branch] || ModuleSync.[:branch] || repository.default_branch end |
#pull_request_target_branch ⇒ Object
This method returns the target branch for the pull request.
It first checks if the pr_target_branch option is set, and if not, it defaults to the repository's default branch.
92 93 94 |
# File 'lib/modulesync/source_code.rb', line 92 def pull_request_target_branch ModuleSync.[:pr_target_branch] || repository.default_branch end |
#repository ⇒ Object
25 26 27 |
# File 'lib/modulesync/source_code.rb', line 25 def repository @repository ||= Repository.new directory: working_directory, remote: repository_remote end |
#repository_name ⇒ Object
29 30 31 |
# File 'lib/modulesync/source_code.rb', line 29 def repository_name @repository_name ||= given_name end |
#repository_namespace ⇒ Object
33 34 35 |
# File 'lib/modulesync/source_code.rb', line 33 def repository_namespace @repository_namespace ||= @options[:namespace] || ModuleSync.[:namespace] end |
#repository_path ⇒ Object
37 38 39 |
# File 'lib/modulesync/source_code.rb', line 37 def repository_path @repository_path ||= "#{repository_namespace}/#{repository_name}" end |
#repository_remote ⇒ Object
41 42 43 |
# File 'lib/modulesync/source_code.rb', line 41 def repository_remote @repository_remote ||= @options[:remote] || _repository_remote end |
#working_directory ⇒ Object
45 46 47 |
# File 'lib/modulesync/source_code.rb', line 45 def working_directory @working_directory ||= File.join(ModuleSync.[:project_root], repository_path) end |