-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #215 from opus-codium/split_generic_n_specific_code
Split generic and specific code
- Loading branch information
Showing
5 changed files
with
102 additions
and
95 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |