github_copier 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +50 -51
- data/bin/github_copier +9 -16
- data/github_copier.gemspec +5 -2
- data/lib/github_copier.rb +0 -1
- data/lib/github_copier/github_copier.rb +17 -12
- data/lib/github_copier/opt_parser.rb +30 -17
- data/lib/github_copier/version.rb +1 -1
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f65a16009f22048a6d1efb93d734bd5c936e99ec
|
4
|
+
data.tar.gz: 2d6042100d7705c19166037abd9ada3eee891618
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b45a11433cf42353184a92da6af9edb0dd983fa8ab88c1f824ab576e3df42f979b2f0d59db98877bffb1db3d1a916fee73c3b7a6f14c28df8bfbe62f7aff034c
|
7
|
+
data.tar.gz: 6c62d3a174b690fadd93d57f0c1928af00ed4031e63d9de9fe426ec6179567aa8bedb9dda55a38e9656276431eeb873d2dbea4eb812293a4c60dbdd1c700cf5d
|
data/CHANGELOG.md
CHANGED
@@ -3,3 +3,9 @@
|
|
3
3
|
#### 0.1.0
|
4
4
|
|
5
5
|
- Initial release
|
6
|
+
|
7
|
+
#### 0.2.0
|
8
|
+
- Add option to group output by language by default
|
9
|
+
- Show list of repositories in the dry-run mode (--no-clone) option
|
10
|
+
- Improve the gemspec to add more context for the user
|
11
|
+
- Add some example to default option when the user type no argument
|
data/README.md
CHANGED
@@ -38,18 +38,21 @@ You should see something like
|
|
38
38
|
Usage: github_copier [options]
|
39
39
|
|
40
40
|
Specific options:
|
41
|
-
-b, --base-dir BASE_DIR
|
42
|
-
|
43
|
-
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
41
|
+
-b, --base-dir BASE_DIR where BASE_DIR is the directory where the repositories will be cloned to (mandatory)
|
42
|
+
If not specified, current directory will be used
|
43
|
+
-u, --user USER The Github USER that will be cloned from (mandatory)
|
44
|
+
-o, --org [ORG] The Github's organization name to be used if specified (optional)
|
45
|
+
where ORG is the organization that the user belongs to
|
46
|
+
-t, --oauth-token [OAUTH_TOKEN] The Github's oauth_token for authentication (optional - only required to list/clone private repositories)
|
47
|
+
where OAUTH_TOKEN is from the user's Github setting
|
48
|
+
-l, --language [LANG] Clone only project of type LANG (optional)
|
49
|
+
where LANG is main language as shown on Github
|
49
50
|
-a, --[no-]all-repos All repository only (optional)
|
50
|
-
|
51
|
+
default to original/non-forked repositories only
|
52
|
+
-g, --[no-]group-by-user Group the output by {BASE_DIR}/{USER}/{LANG}
|
53
|
+
default to {BASE_DIR}/{LANG}/{USER}
|
51
54
|
-c, --[no-]clone Clone the repositories to the path specified (optional)
|
52
|
-
|
55
|
+
default to --no-clone e.g. dry-run only
|
53
56
|
|
54
57
|
Common options:
|
55
58
|
-h, --help Show this message
|
@@ -108,8 +111,7 @@ $github_copier --user awesome_user \
|
|
108
111
|
- List repositories by a given user (dry-run)
|
109
112
|
|
110
113
|
```
|
111
|
-
|
112
|
-
$github_copier -b ~/Desktop/projects -u littlebee -l CoffeeScript
|
114
|
+
$github_copier -b ~/Desktop/projects -u littlebee -l Ruby
|
113
115
|
------------------------------------------
|
114
116
|
List of languages by littlebee
|
115
117
|
Makefile
|
@@ -136,55 +138,52 @@ List of all repositories by littlebee
|
|
136
138
|
14/15: littlebee/JavaScript/selectable-collection
|
137
139
|
15/15: littlebee/Arduino/solar-sunflower
|
138
140
|
------------------------------------------
|
139
|
-
|
141
|
+
FYI: dry-run only, no action taken!!
|
142
|
+
Process 1 of 1 : git clone git@github.com:littlebee/got.git /Users/bchoomnuan/Desktop/projects/Ruby/littlebee/got
|
140
143
|
```
|
141
144
|
|
142
145
|
- List and clone repositories for a given user (e.g. `--clone` option used)
|
143
146
|
|
144
147
|
```
|
145
|
-
$github_copier
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
Process 2 of 11 => git clone git@github.com:littlebee/bumble-docs.git /Users/bchoomnuan/Desktop/projects/littlebee/CoffeeScript/bumble-docs
|
174
|
-
Process 3 of 11 => git clone git@github.com:littlebee/bumble-strings.git /Users/bchoomnuan/Desktop/projects/littlebee/CoffeeScript/bumble-strings
|
175
|
-
Process 4 of 11 => git clone git@github.com:littlebee/bumble-test.git /Users/bchoomnuan/Desktop/projects/littlebee/CoffeeScript/bumble-test
|
176
|
-
Process 5 of 11 => git clone git@github.com:littlebee/bumble-util.git /Users/bchoomnuan/Desktop/projects/littlebee/CoffeeScript/bumble-util
|
177
|
-
Process 6 of 11 => git clone git@github.com:littlebee/git-log-utils.git /Users/bchoomnuan/Desktop/projects/littlebee/CoffeeScript/git-log-utils
|
178
|
-
Process 7 of 11 => git clone git@github.com:littlebee/git-status-utils.git /Users/bchoomnuan/Desktop/projects/littlebee/CoffeeScript/git-status-utils
|
179
|
-
Process 8 of 11 => git clone git@github.com:littlebee/git-time-machine.git /Users/bchoomnuan/Desktop/projects/littlebee/CoffeeScript/git-time-machine
|
180
|
-
Process 9 of 11 => git clone git@github.com:littlebee/notjs.git /Users/bchoomnuan/Desktop/projects/littlebee/CoffeeScript/notjs
|
181
|
-
Process 10 of 11 => git clone git@github.com:littlebee/publish.git /Users/bchoomnuan/Desktop/projects/littlebee/CoffeeScript/publish
|
182
|
-
Process 11 of 11 => git clone git@github.com:littlebee/react-focus-trap-amd.git /Users/bchoomnuan/Desktop/projects/littlebee/CoffeeScript/react-focus-trap-amd
|
148
|
+
$github_copier -b ~/Desktop/projects -u littlebee -l Ruby -c
|
149
|
+
------------------------------------------
|
150
|
+
List of languages by littlebee
|
151
|
+
Makefile
|
152
|
+
CoffeeScript
|
153
|
+
Ruby
|
154
|
+
JavaScript
|
155
|
+
Arduino
|
156
|
+
------------------------------------------
|
157
|
+
------------------------------------------
|
158
|
+
List of all repositories by littlebee
|
159
|
+
1/15: littlebee/Makefile/arduino-mk
|
160
|
+
2/15: littlebee/CoffeeScript/bumble-build
|
161
|
+
3/15: littlebee/CoffeeScript/bumble-docs
|
162
|
+
4/15: littlebee/CoffeeScript/bumble-strings
|
163
|
+
5/15: littlebee/CoffeeScript/bumble-test
|
164
|
+
6/15: littlebee/CoffeeScript/bumble-util
|
165
|
+
7/15: littlebee/CoffeeScript/git-log-utils
|
166
|
+
8/15: littlebee/CoffeeScript/git-status-utils
|
167
|
+
9/15: littlebee/CoffeeScript/git-time-machine
|
168
|
+
10/15: littlebee/CoffeeScript/notjs
|
169
|
+
11/15: littlebee/CoffeeScript/publish
|
170
|
+
12/15: littlebee/CoffeeScript/react-focus-trap-amd
|
171
|
+
13/15: littlebee/Ruby/got
|
172
|
+
14/15: littlebee/JavaScript/selectable-collection
|
173
|
+
15/15: littlebee/Arduino/solar-sunflower
|
174
|
+
------------------------------------------
|
175
|
+
Process 1 of 1 : git clone git@github.com:littlebee/got.git /Users/bchoomnuan/Desktop/projects/Ruby/littlebee/got
|
183
176
|
```
|
184
177
|
|
185
178
|
### TODO
|
186
179
|
|
187
180
|
- Replace system call with the ruby library like [grit](https://github.com/mojombo/grit) or something similar
|
181
|
+
- Allow the `https` when performing the clone
|
182
|
+
- Implement the `FilenameCleaner.sanitize()` locally
|
183
|
+
|
184
|
+
### Related Projects
|
185
|
+
|
186
|
+
- [github_cloner](https://github.com/nashby/github_cloner) by Vasiliy Ermolovich
|
188
187
|
|
189
188
|
### Contributing
|
190
189
|
|
data/bin/github_copier
CHANGED
@@ -24,12 +24,13 @@ if options.language
|
|
24
24
|
end
|
25
25
|
|
26
26
|
args = {
|
27
|
-
base_dir:
|
28
|
-
oauth_token:
|
29
|
-
user:
|
30
|
-
org:
|
31
|
-
all_repos:
|
32
|
-
|
27
|
+
base_dir: options.base_dir, # mandatory
|
28
|
+
oauth_token: options.oauth_token, # optional required for private repos
|
29
|
+
user: options.user, # optional if org is used?
|
30
|
+
org: options.org, # optional if user is used?
|
31
|
+
all_repos: options.all_repos, # default to false
|
32
|
+
group_by_user: options.group_by_user, # default to false
|
33
|
+
clone_repos: options.clone_repos # default to false
|
33
34
|
}
|
34
35
|
|
35
36
|
repos = GithubCopier::GithubUtils.list_all(args)
|
@@ -53,14 +54,6 @@ if result && !result.empty?
|
|
53
54
|
end
|
54
55
|
puts "------------------------------------------"
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
GithubCopier::GithubUtils.clone_all(result.keep_if { |i| i.split(File::SEPARATOR)[1] == language }, options.base_dir)
|
59
|
-
else
|
60
|
-
GithubCopier::GithubUtils.clone_all(result, options.base_dir)
|
61
|
-
end
|
62
|
-
else
|
63
|
-
puts "Dry-run only, no action taken!"
|
64
|
-
puts "------------------------------------------"
|
65
|
-
end
|
57
|
+
result.keep_if { |i| i.split(File::SEPARATOR)[1] == language } if language
|
58
|
+
GithubCopier::GithubUtils.clone_all(result,args)
|
66
59
|
end
|
data/github_copier.gemspec
CHANGED
@@ -8,7 +8,10 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ['Burin Choomnuan']
|
9
9
|
spec.email = ['agilecreativity@gmail.com']
|
10
10
|
spec.summary = %q{Clone/list Github repository for a given user/organization include private/public in one go}
|
11
|
-
spec.description = %q
|
11
|
+
spec.description = %q(
|
12
|
+
Clone/list multiple Github repositories for a given user/organization including private repos easily.
|
13
|
+
e.g.$github_copier --base-dir ~/projects --user awesome_dev --language "Emacs Lisp" --clone
|
14
|
+
).gsub(/^\s+/, " ")
|
12
15
|
spec.homepage = 'https://github.com/agilecreativity/github_copier'
|
13
16
|
spec.required_ruby_version = ">= 2.0.0"
|
14
17
|
spec.license = 'MIT'
|
@@ -25,9 +28,9 @@ Gem::Specification.new do |spec|
|
|
25
28
|
spec.require_paths = ['lib']
|
26
29
|
|
27
30
|
spec.add_runtime_dependency 'github_api', '~> 0.13'
|
28
|
-
spec.add_runtime_dependency 'awesome_print', '~> 1.6'
|
29
31
|
spec.add_runtime_dependency 'filename_cleaner', '~> 0.4'
|
30
32
|
|
33
|
+
spec.add_development_dependency 'awesome_print', '~> 1.6'
|
31
34
|
spec.add_development_dependency 'bundler', '~> 1.10'
|
32
35
|
spec.add_development_dependency 'gem-ctags', '~> 1.0'
|
33
36
|
spec.add_development_dependency 'guard', '~> 2.12'
|
data/lib/github_copier.rb
CHANGED
@@ -21,6 +21,7 @@ module GithubCopier
|
|
21
21
|
|
22
22
|
# require this for only with org and with private repos
|
23
23
|
args.merge!(oauth_token: args[:oauth_token]) if args[:oauth_token]
|
24
|
+
##puts "FYI: your options #{args}"
|
24
25
|
|
25
26
|
# Only required if we use oauth_token which allow use to list private repositories
|
26
27
|
github = Github.new(args)
|
@@ -51,15 +52,14 @@ module GithubCopier
|
|
51
52
|
|
52
53
|
# Clone list of repos of the following forms
|
53
54
|
#
|
54
|
-
|
55
|
-
|
56
|
-
# @param [String] base_dir the base directory to save the clone result
|
57
|
-
# default to current directory
|
58
|
-
# The result will be saved to '/path/to/base_dir/{org_name}/{language}/{repo_name}'
|
59
|
-
def clone_all(projects, base_dir = ".")
|
60
|
-
base_path = File.expand_path(base_dir)
|
55
|
+
def clone_all(projects, args = {})
|
56
|
+
base_path = File.expand_path(args[:base_dir])
|
61
57
|
|
62
|
-
|
58
|
+
if args[:clone_repos]
|
59
|
+
FileUtils.mkdir_p(base_path)
|
60
|
+
else
|
61
|
+
puts "FYI: dry-run only, no action taken!!" unless args[:clone_repos]
|
62
|
+
end
|
63
63
|
|
64
64
|
projects.each_with_index do |project, i|
|
65
65
|
org_name, language, repo_name = project.split(File::SEPARATOR)
|
@@ -67,10 +67,15 @@ module GithubCopier
|
|
67
67
|
# Note: need to cleanup the language like 'Emacs Lisp' to 'Emacs_Lisp' or 'emacs_lisp'
|
68
68
|
language = FilenameCleaner.sanitize(language, '_', false)
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
70
|
+
if args[:group_by_user]
|
71
|
+
output_path = [base_path, org_name, language, repo_name].join(File::SEPARATOR)
|
72
|
+
else
|
73
|
+
output_path = [base_path, language, org_name, repo_name].join(File::SEPARATOR)
|
74
|
+
end
|
75
|
+
puts "Process #{i+1} of #{projects.size} : git clone git@github.com:#{[org_name, repo_name].join(File::SEPARATOR)}.git #{output_path}"
|
76
|
+
if args[:clone_repos]
|
77
|
+
system("git clone git@github.com:#{[org_name, repo_name].join(File::SEPARATOR)}.git #{output_path} 2> /dev/null")
|
78
|
+
end
|
74
79
|
end
|
75
80
|
end
|
76
81
|
|
@@ -5,14 +5,13 @@ module GithubCopier
|
|
5
5
|
# Return a structure describing the options.
|
6
6
|
def self.parse(args)
|
7
7
|
# The options specified on the command line will be collected in *options*.
|
8
|
-
# We set default values here.
|
9
8
|
options = OpenStruct.new
|
10
9
|
|
11
|
-
#
|
10
|
+
# Set the sensible default for the options explicitly
|
12
11
|
options.base_dir = "."
|
13
|
-
|
14
|
-
|
15
|
-
options.
|
12
|
+
options.all_repos = false
|
13
|
+
options.group_by_user = false
|
14
|
+
options.clone_repos = false
|
16
15
|
|
17
16
|
# The parser
|
18
17
|
opt_parser = OptionParser.new do |opts|
|
@@ -23,44 +22,50 @@ module GithubCopier
|
|
23
22
|
|
24
23
|
# Mandatory argument
|
25
24
|
opts.on("-b", "--base-dir BASE_DIR",
|
26
|
-
"
|
25
|
+
"where BASE_DIR is the directory where the repositories will be cloned to (mandatory)",
|
26
|
+
"If not specified, current directory will be used") do |dir|
|
27
27
|
options.base_dir = dir
|
28
28
|
end
|
29
29
|
|
30
30
|
opts.on("-u", "--user USER",
|
31
|
-
"The
|
32
|
-
# By default the id is assumed to be of a normal user not as organization
|
31
|
+
"The Github USER that will be cloned from (mandatory)") do |user|
|
33
32
|
options.user = user
|
34
33
|
end
|
35
34
|
|
36
35
|
opts.on("-o", "--org [ORG]",
|
37
|
-
"The Github's organization name to be used if specified",
|
38
|
-
"
|
36
|
+
"The Github's organization name to be used if specified (optional)",
|
37
|
+
"where ORG is the organization that the user belongs to") do |org|
|
39
38
|
options.org = org
|
40
39
|
end
|
41
40
|
|
42
41
|
opts.on("-t", "--oauth-token [OAUTH_TOKEN]",
|
43
|
-
"The Github's oauth_token for authentication (required to list/clone private repositories)",
|
44
|
-
"
|
42
|
+
"The Github's oauth_token for authentication (optional - only required to list/clone private repositories)",
|
43
|
+
"where OAUTH_TOKEN is from the user's Github setting") do |token|
|
45
44
|
options.oauth_token = token
|
46
45
|
end
|
47
46
|
|
48
47
|
opts.on("-l", "--language [LANG]",
|
49
|
-
"Clone only project of type LANG",
|
50
|
-
"
|
48
|
+
"Clone only project of type LANG (optional)",
|
49
|
+
"where LANG is main language as shown on Github") do |lang|
|
51
50
|
options.language = lang
|
52
51
|
end
|
53
52
|
|
54
53
|
# Boolean switch.
|
55
54
|
opts.on("-a", "--[no-]all-repos",
|
56
55
|
"All repository only (optional)",
|
57
|
-
"
|
56
|
+
"default to original/non-forked repositories only") do |a|
|
58
57
|
options.all_repos = a
|
59
58
|
end
|
60
59
|
|
60
|
+
opts.on("-g", "--[no-]group-by-user",
|
61
|
+
"Group the output by {BASE_DIR}/{USER}/{LANG}",
|
62
|
+
"default to {BASE_DIR}/{LANG}/{USER}") do |gbu|
|
63
|
+
options.group_by_user = gbu
|
64
|
+
end
|
65
|
+
|
61
66
|
opts.on( "-c", "--[no-]clone",
|
62
67
|
"Clone the repositories to the path specified (optional)",
|
63
|
-
"
|
68
|
+
"default to --no-clone e.g. dry-run only") do |c|
|
64
69
|
options.clone_repos = c
|
65
70
|
end
|
66
71
|
|
@@ -68,9 +73,17 @@ module GithubCopier
|
|
68
73
|
opts.separator "Common options:"
|
69
74
|
|
70
75
|
# No argument, shows at tail. This will print an options summary.
|
71
|
-
# Try it and see!
|
72
76
|
opts.on_tail("-h", "--help", "Show this message") do
|
73
77
|
puts opts
|
78
|
+
puts ""
|
79
|
+
puts "Example Usage:"
|
80
|
+
puts ""
|
81
|
+
puts "a) List the 'JavaScript' repositories for a given user (dry-run)"
|
82
|
+
puts "github_copier -b ~/Desktop/projects -u awesome_user -l JavaScript"
|
83
|
+
puts ""
|
84
|
+
puts "b) Clone the 'JavaScript' repositories for a given user (note: --clone or -c option)"
|
85
|
+
puts "github_copier -b ~/Desktop/projects -u awesome_user -l JavaScript -c"
|
86
|
+
puts ""
|
74
87
|
exit
|
75
88
|
end
|
76
89
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github_copier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Burin Choomnuan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: github_api
|
@@ -25,33 +25,33 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.13'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: filename_cleaner
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0.4'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0.4'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: awesome_print
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
48
|
-
type: :
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '1.6'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -206,8 +206,9 @@ dependencies:
|
|
206
206
|
- - "~>"
|
207
207
|
- !ruby/object:Gem::Version
|
208
208
|
version: '0.8'
|
209
|
-
description: Clone/list Github
|
210
|
-
|
209
|
+
description: " Clone/list multiple Github repositories for a given user/organization
|
210
|
+
including private repos easily.\n e.g.$github_copier --base-dir ~/projects --user
|
211
|
+
awesome_dev --language \"Emacs Lisp\" --clone\n "
|
211
212
|
email:
|
212
213
|
- agilecreativity@gmail.com
|
213
214
|
executables:
|