Module: Bones::App::Git
- Defined in:
- lib/bones/app/git.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.initialize_git ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/bones/app/git.rb', line 6 def self.initialize_git Bones::App::Create.class_eval { include ::Bones::App::Git option option('Git Options:') option('--git', 'Initialize a git repository for the project.', lambda { config[:git] = true } ) option('--github DESCRIPTION', 'Create a new GitHub project.', 'Requires a project description.', lambda { |desc| config[:git] = true, config[:github] = true, config[:github_desc] = desc } ) in_output_directory :initialize_git, :initialize_github } end |
Instance Method Details
#github_url ⇒ Object
85 86 87 88 89 |
# File 'lib/bones/app/git.rb', line 85 def github_url user = Git.global_config['github.user'] return unless user "http://github.com/#{user}/#{name}" end |
#initialize_git ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bones/app/git.rb', line 28 def initialize_git return unless @config[:git] File.rename('.bnsignore', '.gitignore') if test ?f, '.bnsignore' = Git.global_config['user.name'] email = Git.global_config['user.email'] if test ?f, 'Rakefile' lines = File.readlines 'Rakefile' lines.each do |line| case line when %r/^\s*authors\s+/ line.replace " authors '#{}'" unless .nil? or line !~ %r/FIXME/ when %r/^\s*email\s+/ line.replace " email '#{email}'" unless email.nil? or line !~ %r/FIXME/ when %r/^\s*url\s+/ next unless @config[:github] url = github_url line.replace " url '#{url}'" unless url.nil? or line !~ %r/FIXME/ when %r/^\s*\}\s*$/ line.insert 0, " ignore_file '.gitignore'\n" if test ?f, '.gitignore' end end File.open('Rakefile', 'w') {|fd| fd.puts lines} end @git = Git.init @git.add @git.commit "Initial commit to #{name}." end |
#initialize_github ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/bones/app/git.rb', line 62 def initialize_github return unless @config[:github] user = Git.global_config['github.user'] token = Git.global_config['github.token'] raise ::Bones::App::Error, 'A GitHub username was not found in the global configuration.' unless user raise ::Bones::App::Error, 'A GitHub token was not found in the global configuration.' unless token Net::HTTP.post_form( URI.parse('http://github.com/api/v2/yaml/repos/create'), 'login' => user, 'token' => token, 'name' => name, 'description' => @config[:github_desc] ) @git.add_remote 'origin', "[email protected]:#{user}/#{name}.git" @git.config 'branch.master.remote', 'origin' @git.config 'branch.master.merge', 'refs/heads/master' @git.push 'origin' end |