module Arfor::GithubModule
Constants
- PUPPET_METADATA
- README_ERB
- README_FILE
Public Class Methods
create()
click to toggle source
# File lib/arfor/github_module.rb, line 27 def self.create() # http://stackoverflow.com/a/2889747/3441106 forge_name = ask("#{Arfor::QUESTION} Forge module name: ") do |q| q.validate = /[\w_]+-[\w_]+/ end description = ask("#{Arfor::QUESTION} Module description: ") forge_name_split = forge_name.split('-') forge_user = forge_name_split[0] module_name = forge_name_split[1] git_name = "puppet-#{module_name}" git_opts = { :description => description, } # Step 1 - generate puppet module if system("puppet module generate --skip-interview #{forge_name}") Dir.chdir(module_name) { # temporary ;-) fix for needing to replace the Gemfile File.delete('Gemfile') # Step 2 - install PDQtest system("pdqtest init") # Step 3 - make remote git repo begin resp = Arfor::Util::Github::create_repository(git_name, git_opts) full_name = resp.full_name rescue Octokit::UnprocessableEntity => e raise "Repository creation error: #{e.message}" end # Step 4 - doco template template = File.read(File.join(File.dirname(File.expand_path(__FILE__)), README_ERB)) content = ERB.new(template, nil, '-').result(binding) File.write(README_FILE, content) # Step 5 - checkout local copy of git repo, merge changes and upload system("git init && git remote add origin #{resp.clone_url}") # Step 6 - update puppet metdata.json with settings from git metadata = JSON.parse(File.read(PUPPET_METADATA)) metadata['source'] = resp.clone_url metadata['project_url'] = resp.clone_url metadata['issues_url'] = resp.issues_url metadata['summary'] = description File.write(PUPPET_METADATA, JSON.pretty_generate(metadata)) # Step 7 - cleanup backup crud files Dir.glob("**/*.pdqtest_old").each { |f| File.delete(f) } # Step 8 - Enable travis (you need to have already logged yourself in) # the sleep is to allow time for the apis to settle before travis does # its scans puts "sleep for sync" sleep(30) system("travis enable --no-interactive") # Step 9 - initial git commit and upload changes system("git add -A && git commit -m 'initial' && git push origin master") } else raise "module generation error" end Arfor::OK end