git_cloner 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ tudu/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+ gem "rspec", "~> 2.14.1"
5
+ gem "thor", "~> 0.18.1"
6
+ gem "simplecov", "~> 0.8.2"
7
+ gem "activesupport", "~> 4.0.1"
8
+ gem "activemodel", "~> 4.0.2"
9
+ gem "tudu", "~> 0.0.4"
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 tbpgr
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # GitCloner
2
+
3
+ GitCloner clone git repositoris from Gitclonerfile settings.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'git_cloner'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install git_cloner
18
+
19
+ ## Usage
20
+
21
+ ### generate Gitclonerfile
22
+
23
+ ~~~bash
24
+ gitcloner init
25
+ ~~~
26
+
27
+ ~~~ruby
28
+ # encoding: utf-8
29
+
30
+ # default_output place
31
+ # default_output is required
32
+ # default_output allow only String
33
+ # default_output's default value => "./"
34
+ default_output "./"
35
+
36
+ # git repositries
37
+ # repo allow only Array(in Array, Hash[:place, :output])
38
+ # repo's default value => []
39
+ repos [
40
+ {
41
+ place: 'https://github.com/tbpgr/rspec_piccolo.git',
42
+ output: './tmp'
43
+ }
44
+ ]
45
+ ~~~
46
+
47
+ ### edit Gitclonerfile manually
48
+
49
+ ~~~ruby
50
+ # encoding: utf-8
51
+ default_output "./"
52
+ repos [
53
+ {
54
+ place: "https://github.com/tbpgr/rspec_piccolo.git",
55
+ output: "./tmp",
56
+ },
57
+ {
58
+ place: "https://github.com/tbpgr/tbpgr_utils.git",
59
+ }
60
+ ]
61
+ ~~~
62
+
63
+ ### execute clone
64
+
65
+ ~~~bash
66
+ gitcloner clone
67
+ ~~~
68
+
69
+ ### confirm clone result
70
+
71
+ ~~~bash
72
+ $ tree
73
+ ├─tmp
74
+ | rspec_piccolo
75
+ └─tbpgr_utils
76
+ ~~~
77
+
78
+ ## Contributing
79
+
80
+ 1. Fork it
81
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
82
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
83
+ 4. Push to the branch (`git push origin my-new-feature`)
84
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/gitcloner ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require "git_cloner_core"
5
+ require "git_cloner/version"
6
+ require "thor"
7
+
8
+ module GitCloner
9
+ # GitCloner CLI
10
+ class CLI < Thor
11
+ class_option :help, :type => :boolean, :aliases => '-h', :desc => 'help message.'
12
+ class_option :version, :type => :boolean, :desc => 'version'
13
+
14
+ desc "clone", "clone git repositories from Gitclonerfile"
15
+ def clone
16
+ GitCloner::Core.new.execute
17
+ end
18
+
19
+ desc "init", "generate Gitclonerfile"
20
+ def init
21
+ GitCloner::Core.new.init
22
+ end
23
+
24
+ desc "version", "version"
25
+ def version
26
+ p GitCloner::VERSION
27
+ end
28
+ end
29
+ end
30
+
31
+ GitCloner::CLI.start(ARGV)
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'git_cloner/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "git_cloner"
8
+ spec.version = GitCloner::VERSION
9
+ spec.authors = ["tbpgr"]
10
+ spec.email = ["tbpgr@tbpgr.jp"]
11
+ spec.description = %q{GitCloner clone git repositoris from Gitclonerfile settings}
12
+ spec.summary = %q{GitCloner clone git repositoris from Gitclonerfile settings}
13
+ spec.homepage = "https://github.com/tbpgr/git_cloner"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "activesupport", "~> 4.0.1"
22
+ spec.add_runtime_dependency "activemodel", "~> 4.0.2"
23
+ spec.add_runtime_dependency "thor", "~> 0.18.1"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec", "~> 2.14.1"
28
+ spec.add_development_dependency "simplecov", "~> 0.8.2"
29
+ end
@@ -0,0 +1,3 @@
1
+ module GitCloner
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,90 @@
1
+ # encoding: utf-8
2
+ require 'git_cloner_dsl'
3
+ require "uri"
4
+
5
+ module GitCloner
6
+ # GitCloner Core
7
+ class Core
8
+ GIT_CLONER_FILE = "Gitclonerfile"
9
+ GIT_CLONER_TEMPLATE =<<-EOS
10
+ # encoding: utf-8
11
+
12
+ # default_output place
13
+ # default_output is required
14
+ # default_output allow only String
15
+ # default_output's default value => "./"
16
+ default_output "./"
17
+
18
+ # git repositries
19
+ # repo allow only Array(in Array, Hash[:place, :output])
20
+ # repo's default value => []
21
+ repos [
22
+ {
23
+ place: 'https://github.com/tbpgr/rspec_piccolo.git',
24
+ output: './tmp'
25
+ }
26
+ ]
27
+ EOS
28
+
29
+ #== generate Gitclonerfile to current directory.
30
+ def init
31
+ File.open(GIT_CLONER_FILE, "w") {|f|f.puts GIT_CLONER_TEMPLATE}
32
+ end
33
+
34
+ #== clone git repositories
35
+ def execute
36
+ dsl = get_dsl
37
+ base = Dir.pwd
38
+ default_output = dsl.git_cloner.default_output
39
+ tmp_repos = dsl.git_cloner.repos
40
+ fail ArgumentError, 'invalid repos. repos must be Array.' unless tmp_repos.is_a? Array
41
+ tmp_repos.each do |repo|
42
+ fail ArgumentError, 'invalid repos. repos-Array must have Hash' unless repo.is_a? Hash
43
+ fail ArgumentError, 'invalid key. Hash must contain :place key' unless repo.has_key? :place
44
+ repo_name = get_repo_name repo[:place]
45
+ target_dir = get_output(repo[:output], default_output)
46
+ FileUtils.mkdir_p(target_dir) unless Dir.exists? target_dir
47
+ Dir.chdir(target_dir)
48
+ result = system("git clone #{repo[:place]} --depth=1")
49
+ remove_dot_git_directory repo_name
50
+ show_result_message(result, repo_name)
51
+ Dir.chdir base
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ def get_dsl
58
+ src = read_dsl
59
+ dsl = GitCloner::Dsl.new
60
+ dsl.instance_eval src
61
+ dsl
62
+ end
63
+
64
+ def read_dsl
65
+ File.open(GIT_CLONER_FILE) {|f|f.read}
66
+ end
67
+
68
+ def get_repo_name(place)
69
+ uri = URI(place)
70
+ p uri.path.gsub(/.*\//, '').gsub('.git', '')
71
+ end
72
+
73
+ def get_output(output, default_output)
74
+ output.nil? ? default_output : output
75
+ end
76
+
77
+ def remove_dot_git_directory(repo_name)
78
+ Dir.chdir("./#{repo_name}")
79
+ FileUtils.rm_rf('.git') if Dir.exists? '.git'
80
+ end
81
+
82
+ def show_result_message(result, repo_name)
83
+ if result
84
+ puts "clone #{Dir.pwd}/#{repo_name} complete"
85
+ else
86
+ pust "clone #{Dir.pwd}/#{repo_name} fail"
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ require 'git_cloner_dsl_model'
3
+
4
+ module GitCloner
5
+ class Dsl
6
+ attr_accessor :git_cloner
7
+
8
+ # String Define
9
+ [:default_output].each do |f|
10
+ define_method f do |value|
11
+ eval "@git_cloner.#{f.to_s} = '#{value}'", binding
12
+ end
13
+ end
14
+
15
+ # Array/Hash/Boolean Define
16
+ [:repos].each do |f|
17
+ define_method f do |value|
18
+ eval "@git_cloner.#{f.to_s} = #{value}", binding
19
+ end
20
+ end
21
+
22
+ def initialize
23
+ @git_cloner = GitCloner::DslModel.new
24
+ @git_cloner.default_output = './'
25
+ @git_cloner.repos = []
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+ require 'active_model'
3
+
4
+ module GitCloner
5
+ class DslModel
6
+ include ActiveModel::Model
7
+
8
+ # default_output place
9
+ attr_accessor :default_output
10
+ validates :default_output, :presence => true
11
+
12
+ # git repositries
13
+ attr_accessor :repos
14
+
15
+ end
16
+ end
@@ -0,0 +1,171 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+ require "git_cloner_core"
4
+
5
+ describe GitCloner::Core do
6
+ context :init do
7
+ OUTPUT_DSL_TMP_DIR = 'generate_dsl'
8
+ cases = [
9
+ {
10
+ case_no: 1,
11
+ case_title: 'valid case',
12
+ expected_file: GitCloner::Core::GIT_CLONER_FILE,
13
+ expected_content: GitCloner::Core::GIT_CLONER_TEMPLATE,
14
+ },
15
+ ]
16
+
17
+ cases.each do |c|
18
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
19
+ begin
20
+ case_before c
21
+
22
+ # -- given --
23
+ git_cloner_core = GitCloner::Core.new
24
+
25
+ # -- when --
26
+ git_cloner_core.init
27
+
28
+ # -- then --
29
+ actual = File.read("./#{c[:expected_file]}")
30
+ expect(actual).to eq(c[:expected_content])
31
+ ensure
32
+ case_after c
33
+ end
34
+ end
35
+
36
+ def case_before(c)
37
+ Dir.mkdir(OUTPUT_DSL_TMP_DIR) unless Dir.exists? OUTPUT_DSL_TMP_DIR
38
+ Dir.chdir(OUTPUT_DSL_TMP_DIR)
39
+ end
40
+
41
+ def case_after(c)
42
+ Dir.chdir('../')
43
+ FileUtils.rm_rf(OUTPUT_DSL_TMP_DIR) if Dir.exists? OUTPUT_DSL_TMP_DIR
44
+ end
45
+ end
46
+ end
47
+
48
+ context :execute do
49
+ OUTPUT_GIT_CLONER_TMP_DIR = 'tmp_git_cloner'
50
+ GIT_CLONER_CASE1 =<<-EOF
51
+ # encoding: utf-8
52
+ default_output "./"
53
+ repos [
54
+ {
55
+ place: "https://github.com/tbpgr/rspec_piccolo.git",
56
+ output: "./tmp",
57
+ },
58
+ {
59
+ place: "https://github.com/tbpgr/tbpgr_utils.git",
60
+ }
61
+ ]
62
+ EOF
63
+
64
+ RESULT_CASE1 =<<-EOF
65
+ # encoding: utf-8
66
+ require 'templatable'
67
+
68
+ class SampleUse
69
+ include Templatable
70
+ template <<-EOS
71
+ line1:<%=placeholders[:param1]%>
72
+ line2:<%=placeholders[:param2]%>
73
+ EOS
74
+
75
+ def manufactured_param1
76
+ # TODO: implement your logic
77
+ end
78
+
79
+ def manufactured_param2
80
+ # TODO: implement your logic
81
+ end
82
+ end
83
+ EOF
84
+
85
+ GIT_CLONER_CASE2 =<<-EOF
86
+ # encoding: utf-8
87
+ default_output "./"
88
+ repos "invalid"
89
+ EOF
90
+
91
+ GIT_CLONER_CASE3 =<<-EOF
92
+ # encoding: utf-8
93
+ default_output "./"
94
+ repos ["invalid"]
95
+ EOF
96
+
97
+ GIT_CLONER_CASE4 =<<-EOF
98
+ # encoding: utf-8
99
+ default_output "./"
100
+ repos [
101
+ {
102
+ plase: "typo"
103
+ }
104
+ ]
105
+ EOF
106
+
107
+ cases = [
108
+ {
109
+ case_no: 1,
110
+ case_title: "valid case",
111
+ input: GIT_CLONER_CASE1,
112
+ expecteds: ['./tmp/rspec_piccolo', './tbpgr_utils'],
113
+ },
114
+ {
115
+ case_no: 2,
116
+ case_title: "invalid repos case(String)",
117
+ input: GIT_CLONER_CASE2,
118
+ has_error: true,
119
+ },
120
+ {
121
+ case_no: 3,
122
+ case_title: "invalid repos case(Array[Not Hash])",
123
+ input: GIT_CLONER_CASE3,
124
+ has_error: true,
125
+ },
126
+ {
127
+ case_no: 4,
128
+ case_title: "invalid repos case(Array[Hash] but invalid hash key)",
129
+ input: GIT_CLONER_CASE4,
130
+ has_error: true,
131
+ },
132
+ ]
133
+
134
+ cases.each do |c|
135
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
136
+ begin
137
+ case_before c
138
+
139
+ # -- given --
140
+ git_cloner_core = GitCloner::Core.new
141
+
142
+ # -- when --
143
+ if c[:has_error]
144
+ lambda {git_cloner_core.execute}.should raise_error(StandardError)
145
+ next
146
+ end
147
+ git_cloner_core.execute
148
+
149
+ # -- then --
150
+ c[:expecteds].each do |expected|
151
+ actual_exists = File.exists? expected
152
+ expect(actual_exists).to be_true
153
+ end
154
+ ensure
155
+ case_after c
156
+ end
157
+ end
158
+
159
+ def case_before(c)
160
+ Dir.mkdir(OUTPUT_GIT_CLONER_TMP_DIR) unless Dir.exists? OUTPUT_GIT_CLONER_TMP_DIR
161
+ Dir.chdir(OUTPUT_GIT_CLONER_TMP_DIR)
162
+ File.open(GitCloner::Core::GIT_CLONER_FILE, 'w:UTF-8') { |f|f.print c[:input] }
163
+ end
164
+
165
+ def case_after(c)
166
+ Dir.chdir('../')
167
+ FileUtils.rm_rf(OUTPUT_GIT_CLONER_TMP_DIR) if Dir.exists? OUTPUT_GIT_CLONER_TMP_DIR
168
+ end
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+ require "simplecov"
3
+ SimpleCov.start
4
+ RSpec.configure do |config|
5
+ config.treat_symbols_as_metadata_keys_with_true_values = true
6
+ config.run_all_when_everything_filtered = true
7
+ config.filter_run :focus
8
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git_cloner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - tbpgr
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-01-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: &30810744 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 4.0.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *30810744
25
+ - !ruby/object:Gem::Dependency
26
+ name: activemodel
27
+ requirement: &30810444 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 4.0.2
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *30810444
36
+ - !ruby/object:Gem::Dependency
37
+ name: thor
38
+ requirement: &30810168 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.18.1
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *30810168
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: &30809892 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *30809892
58
+ - !ruby/object:Gem::Dependency
59
+ name: rake
60
+ requirement: &30809664 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *30809664
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: &30809340 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 2.14.1
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *30809340
80
+ - !ruby/object:Gem::Dependency
81
+ name: simplecov
82
+ requirement: &30809040 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 0.8.2
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *30809040
91
+ description: GitCloner clone git repositoris from Gitclonerfile settings
92
+ email:
93
+ - tbpgr@tbpgr.jp
94
+ executables:
95
+ - gitcloner
96
+ extensions: []
97
+ extra_rdoc_files: []
98
+ files:
99
+ - .gitignore
100
+ - .rspec
101
+ - Gemfile
102
+ - LICENSE.txt
103
+ - README.md
104
+ - Rakefile
105
+ - bin/gitcloner
106
+ - git_cloner.gemspec
107
+ - lib/git_cloner/version.rb
108
+ - lib/git_cloner_core.rb
109
+ - lib/git_cloner_dsl.rb
110
+ - lib/git_cloner_dsl_model.rb
111
+ - spec/git_cloner_core_spec.rb
112
+ - spec/spec_helper.rb
113
+ homepage: https://github.com/tbpgr/git_cloner
114
+ licenses:
115
+ - MIT
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 1.8.11
135
+ signing_key:
136
+ specification_version: 3
137
+ summary: GitCloner clone git repositoris from Gitclonerfile settings
138
+ test_files:
139
+ - spec/git_cloner_core_spec.rb
140
+ - spec/spec_helper.rb
141
+ has_rdoc: