Skip to content

Commit 9e17ee3

Browse files
committed
feat: Add badge setting in README
Check README for a specific comment and if found replace badge URLs based on module settings. Refs: voxpupuli/plumbing#84
1 parent b179087 commit 9e17ee3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib/modulesync.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,24 @@ def self.manage_file(puppet_module, filename, settings, options)
116116
end
117117
end
118118

119+
def self.update_readme_badges(puppet_module)
120+
return unless File.exist?(puppet_module.path('README.md'))
121+
122+
content = File.read(puppet_module.path('README.md'))
123+
badge_regex = %r{^\[//\]: # \(modulesync badge placeholder, do not remove\)$}
124+
125+
build_status = "![Build Status](https://github.com/voxpupuli/#{puppet_module.repository_name}/actions/workflows/ci.yml/badge.svg?branch=master)\n"
126+
code_coverage = "[![Code Coverage](https://coveralls.io/repos/github/voxpupuli/#{puppet_module.repository_name}/badge.svg?branch=master)](https://coveralls.io/github/voxpupuli/#{puppet_module.repository_name})\n"
127+
license = "[![License](https://img.shields.io/github/license/voxpupuli/#{puppet_module.repository_name}.svg)](LICENSE)\n"
128+
129+
badges = build_status
130+
badges << license
131+
badges << code_coverage if Dir.exist?(File.expand_path('./lib', puppet_module.path))
132+
content.gsub!(badge_regex, badges.chomp)
133+
134+
File.write(puppet_module.path('README.md'), content)
135+
end
136+
119137
def self.manage_module(puppet_module, module_files, defaults)
120138
puts "Syncing '#{puppet_module.given_name}'"
121139
# NOTE: #prepare_workspace now supports to execute only offline operations
@@ -140,6 +158,7 @@ def self.manage_module(puppet_module, module_files, defaults)
140158

141159
files_to_manage = settings.managed_files(module_files)
142160
files_to_manage.each { |filename| manage_file(puppet_module, filename, settings, options) }
161+
update_readme_badges(puppet_module)
143162

144163
if options[:noop]
145164
puts "Using no-op. Files in '#{puppet_module.given_name}' may be changed but will not be committed."

0 commit comments

Comments
 (0)