-
-
Notifications
You must be signed in to change notification settings - Fork 56
Split generic and specific code #215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ekohl
merged 7 commits into
voxpupuli:master
from
opus-codium:split_generic_n_specific_code
Apr 23, 2021
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e313f91
Make room for puppet modules specific methods
neomilium ed5a02d
Move Puppet module specific code into dedicated class
neomilium 9b36991
Make SourceCode the owner of its repository
neomilium 1cda568
SourceCode: Write options initialization in one-line style
neomilium 722a744
SourceCode: Provide #path that computes the absolute filename of a file
neomilium 5813e92
PuppetCode: Use SourceCode#path when relevant
neomilium 4e9f330
Rubocop: Update autogenerated todo file
neomilium File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,49 +1,37 @@ | ||
| require 'modulesync' | ||
| require 'modulesync/util' | ||
| require 'puppet_blacksmith' | ||
|
|
||
| module ModuleSync | ||
| # Provide methods to retrieve puppet module attributes | ||
| class PuppetModule | ||
| attr_reader :given_name | ||
| attr_reader :options | ||
|
|
||
| def initialize(given_name, options) | ||
| options ||= {} | ||
| @options = Util.symbolize_keys(options) | ||
|
|
||
| @given_name = given_name | ||
|
|
||
| return unless given_name.include?('/') | ||
|
|
||
| @repository_name = given_name.split('/').last | ||
| @repository_namespace = given_name.split('/')[0...-1].join('/') | ||
| end | ||
|
|
||
| def repository_name | ||
| @repository_name ||= given_name | ||
| end | ||
| require 'modulesync/source_code' | ||
|
|
||
| def repository_namespace | ||
| @repository_namespace ||= @options[:namespace] || ModuleSync.options[:namespace] | ||
| end | ||
|
|
||
| def repository_path | ||
| @repository_path ||= "#{repository_namespace}/#{repository_name}" | ||
| end | ||
|
|
||
| def repository_remote | ||
| @repository_remote ||= @options[:remote] || _repository_remote | ||
| end | ||
|
|
||
| def working_directory | ||
| @working_directory ||= File.join(ModuleSync.options[:project_root], repository_path) | ||
| module ModuleSync | ||
| # Provide methods to manipulate puppet module code | ||
| class PuppetModule < SourceCode | ||
| def update_changelog(version, message) | ||
| changelog = path('CHANGELOG.md') | ||
| if File.exist?(changelog) | ||
| puts "Updating #{changelog} for version #{version}" | ||
| changes = File.readlines(changelog) | ||
| File.open(changelog, 'w') do |f| | ||
| date = Time.now.strftime('%Y-%m-%d') | ||
| f.puts "## #{date} - Release #{version}\n\n" | ||
| f.puts "#{message}\n\n" | ||
| # Add old lines again | ||
| f.puts changes | ||
| end | ||
| repository.git.add('CHANGELOG.md') | ||
| else | ||
| puts 'No CHANGELOG.md file found, not updating.' | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def _repository_remote | ||
| git_base = ModuleSync.options[:git_base] | ||
| git_base.start_with?('file://') ? "#{git_base}#{repository_path}" : "#{git_base}#{repository_path}.git" | ||
| def bump(message, changelog = false) | ||
| m = Blacksmith::Modulefile.new path('metadata.json') | ||
| new = m.bump! | ||
| puts "Bumped to version #{new}" | ||
| repository.git.add('metadata.json') | ||
| update_changelog(new, message) if changelog | ||
| repository.git.commit("Release version #{new}") | ||
| repository.git.push | ||
| new | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| require 'modulesync' | ||
| require 'modulesync/repository' | ||
| require 'modulesync/util' | ||
|
|
||
| module ModuleSync | ||
| # Provide methods to retrieve source code attributes | ||
| class SourceCode | ||
| attr_reader :given_name | ||
| attr_reader :options | ||
|
|
||
| def initialize(given_name, options) | ||
| @options = Util.symbolize_keys(options || {}) | ||
|
|
||
| @given_name = given_name | ||
|
|
||
| return unless given_name.include?('/') | ||
|
|
||
| @repository_name = given_name.split('/').last | ||
| @repository_namespace = given_name.split('/')[0...-1].join('/') | ||
| end | ||
|
|
||
| def repository | ||
| @repository ||= Repository.new directory: working_directory, remote: repository_remote | ||
| end | ||
|
|
||
| def repository_name | ||
| @repository_name ||= given_name | ||
| end | ||
|
|
||
| def repository_namespace | ||
| @repository_namespace ||= @options[:namespace] || ModuleSync.options[:namespace] | ||
| end | ||
|
|
||
| def repository_path | ||
| @repository_path ||= "#{repository_namespace}/#{repository_name}" | ||
| end | ||
|
|
||
| def repository_remote | ||
| @repository_remote ||= @options[:remote] || _repository_remote | ||
| end | ||
|
|
||
| def working_directory | ||
| @working_directory ||= File.join(ModuleSync.options[:project_root], repository_path) | ||
| end | ||
|
|
||
| def path(*parts) | ||
| File.join(working_directory, *parts) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def _repository_remote | ||
| git_base = ModuleSync.options[:git_base] | ||
| git_base.start_with?('file://') ? "#{git_base}#{repository_path}" : "#{git_base}#{repository_path}.git" | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.