github-cloner 0.3.0 → 0.4.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 +4 -0
 - data/README.md +4 -4
 - data/bin/github-cloner +21 -17
 - data/lib/github_cloner/opt_parser.rb +28 -14
 - data/lib/github_cloner/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 757ebae0d662268f47ec94f7f152be783d2c5b12
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: cf8f8eaec3306e172381e77e7ea042c138a011ca
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: db4a4903f8f2a4aa6560dd893860e6e6ed338366024f231bdc59d353e0960c215295484b54b6aa12973e55aef9dcb9bb7a189c800410eea06855cf74a53d3b1a
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 02f137143ba9756709e9adbd6257766c3711213d1331f642cfea00e5a96701ad58a4340520fa1ca781c87af10375934d7107a72ca094917723aa42448cf07892
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -78,10 +78,10 @@ $github-cloner --user awesome_user --oauth-token GITHUB_TOKEN_FOR_THIS_USER 
     | 
|
| 
       78 
78 
     | 
    
         
             
            ```sh
         
     | 
| 
       79 
79 
     | 
    
         
             
            ## Clone all original (non-fork) public `JavaScript` repositores for user `awesome_user` to `~/Desktop/github`
         
     | 
| 
       80 
80 
     | 
    
         
             
            # Note: --base-dir is optional, if not specified then the current directory will be used
         
     | 
| 
       81 
     | 
    
         
            -
            #       -- 
     | 
| 
      
 81 
     | 
    
         
            +
            #       --languages must be quoted if the value include any spaces e.g. "Emacs Lisp" for this to to work properly
         
     | 
| 
       82 
82 
     | 
    
         
             
            $github-cloner --user awesome_user \
         
     | 
| 
       83 
83 
     | 
    
         
             
                           --base-dir ~/Desktop/github \
         
     | 
| 
       84 
     | 
    
         
            -
                           -- 
     | 
| 
      
 84 
     | 
    
         
            +
                           --languages "JavaScript" \
         
     | 
| 
       85 
85 
     | 
    
         
             
                           --clone
         
     | 
| 
       86 
86 
     | 
    
         | 
| 
       87 
87 
     | 
    
         
             
            ## Clone all public/private repositories for `awesome_user` which are member of `AwesomeCo` organization to `~/Desktop/github`
         
     | 
| 
         @@ -93,12 +93,12 @@ $github-cloner --user awesome_user \ 
     | 
|
| 
       93 
93 
     | 
    
         
             
                           --oauth-token GITHUB_TOKEN_FOR_AWESOME_USER \
         
     | 
| 
       94 
94 
     | 
    
         
             
                           --clone
         
     | 
| 
       95 
95 
     | 
    
         | 
| 
       96 
     | 
    
         
            -
            ## Clone specific type of  
     | 
| 
      
 96 
     | 
    
         
            +
            ## Clone specific type of projects (e.g. `Java` and `Emacs Lisp` in this case) public/private repositories for `awesome_user`
         
     | 
| 
       97 
97 
     | 
    
         
             
            ## which are member of `AwesomeCo` organization to `~/Desktop/github`
         
     | 
| 
       98 
98 
     | 
    
         
             
            $github-cloner --user awesome_user \
         
     | 
| 
       99 
99 
     | 
    
         
             
                           --org AwesomeCo \
         
     | 
| 
       100 
100 
     | 
    
         
             
                           --all-repos \
         
     | 
| 
       101 
     | 
    
         
            -
                           -- 
     | 
| 
      
 101 
     | 
    
         
            +
                           --languages "Java,Emacs Lisp" \
         
     | 
| 
       102 
102 
     | 
    
         
             
                           --base-dir ~/Desktop/github \
         
     | 
| 
       103 
103 
     | 
    
         
             
                           --oauth-token GITHUB_TOKEN_FOR_AWESOME_USER \
         
     | 
| 
       104 
104 
     | 
    
         
             
                           --clone
         
     | 
    
        data/bin/github-cloner
    CHANGED
    
    | 
         @@ -7,8 +7,6 @@ end 
     | 
|
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
            include GithubCloner
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
            # Now we are ready to take the order
         
     | 
| 
       11 
     | 
    
         
            -
            # Show help if user forgot to type anything
         
     | 
| 
       12 
10 
     | 
    
         
             
            options = OptParser.parse(ARGV)
         
     | 
| 
       13 
11 
     | 
    
         | 
| 
       14 
12 
     | 
    
         
             
            # Mandatory options
         
     | 
| 
         @@ -18,31 +16,30 @@ raise "user is required"     if options.user.nil? 
     | 
|
| 
       18 
16 
     | 
    
         
             
            # Make use of the user name
         
     | 
| 
       19 
17 
     | 
    
         
             
            gh_id = options.user
         
     | 
| 
       20 
18 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
              language = options.language #'Emacs Lisp'
         
     | 
| 
      
 19 
     | 
    
         
            +
            if options.languages
         
     | 
| 
      
 20 
     | 
    
         
            +
              languages = options.languages
         
     | 
| 
       24 
21 
     | 
    
         
             
            end
         
     | 
| 
       25 
22 
     | 
    
         | 
| 
       26 
23 
     | 
    
         
             
            args = {
         
     | 
| 
       27 
     | 
    
         
            -
              base_dir:      options.base_dir, 
     | 
| 
       28 
     | 
    
         
            -
              oauth_token:   options.oauth_token, 
     | 
| 
       29 
     | 
    
         
            -
              user:          options.user, 
     | 
| 
       30 
     | 
    
         
            -
              org:           options.org, 
     | 
| 
       31 
     | 
    
         
            -
              all_repos:     options.all_repos, 
     | 
| 
       32 
     | 
    
         
            -
              group_by_user: options.group_by_user, 
     | 
| 
       33 
     | 
    
         
            -
              clone_repos:   options.clone_repos 
     | 
| 
      
 24 
     | 
    
         
            +
              base_dir:      options.base_dir,
         
     | 
| 
      
 25 
     | 
    
         
            +
              oauth_token:   options.oauth_token,
         
     | 
| 
      
 26 
     | 
    
         
            +
              user:          options.user,
         
     | 
| 
      
 27 
     | 
    
         
            +
              org:           options.org,
         
     | 
| 
      
 28 
     | 
    
         
            +
              all_repos:     options.all_repos,
         
     | 
| 
      
 29 
     | 
    
         
            +
              group_by_user: options.group_by_user,
         
     | 
| 
      
 30 
     | 
    
         
            +
              clone_repos:   options.clone_repos
         
     | 
| 
       34 
31 
     | 
    
         
             
            }
         
     | 
| 
       35 
32 
     | 
    
         | 
| 
       36 
33 
     | 
    
         
             
            repos = GithubCloner::GithubUtils.list_all(args)
         
     | 
| 
       37 
34 
     | 
    
         | 
| 
       38 
35 
     | 
    
         
             
            # List of language that have been used by the given user/organization
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
      
 36 
     | 
    
         
            +
            repo_languages = repos.map(&:language).uniq.compact
         
     | 
| 
       40 
37 
     | 
    
         
             
            puts "------------------------------------------"
         
     | 
| 
       41 
38 
     | 
    
         
             
            puts "List of languages by #{gh_id}"
         
     | 
| 
       42 
     | 
    
         
            -
            puts  
     | 
| 
      
 39 
     | 
    
         
            +
            puts repo_languages
         
     | 
| 
       43 
40 
     | 
    
         
             
            puts "------------------------------------------"
         
     | 
| 
       44 
41 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
            repos_hash = GithubCloner::GithubUtils.repos_by_language(repos,  
     | 
| 
      
 42 
     | 
    
         
            +
            repos_hash = GithubCloner::GithubUtils.repos_by_language(repos, repo_languages)
         
     | 
| 
       46 
43 
     | 
    
         | 
| 
       47 
44 
     | 
    
         
             
            result = GithubCloner::GithubUtils.repos_as_list(repos_hash)
         
     | 
| 
       48 
45 
     | 
    
         | 
| 
         @@ -54,6 +51,13 @@ if result && !result.empty? 
     | 
|
| 
       54 
51 
     | 
    
         
             
              end
         
     | 
| 
       55 
52 
     | 
    
         
             
              puts "------------------------------------------"
         
     | 
| 
       56 
53 
     | 
    
         | 
| 
       57 
     | 
    
         
            -
               
     | 
| 
       58 
     | 
    
         
            -
               
     | 
| 
      
 54 
     | 
    
         
            +
              # Need to get this from the list of language
         
     | 
| 
      
 55 
     | 
    
         
            +
              if languages && !languages.empty?
         
     | 
| 
      
 56 
     | 
    
         
            +
                result.keep_if do |i|
         
     | 
| 
      
 57 
     | 
    
         
            +
                  lang = i.split(File::SEPARATOR)[1]
         
     | 
| 
      
 58 
     | 
    
         
            +
                  languages.include?(lang)
         
     | 
| 
      
 59 
     | 
    
         
            +
                end
         
     | 
| 
      
 60 
     | 
    
         
            +
              end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
              GithubCloner::GithubUtils.clone_all(result, args)
         
     | 
| 
       59 
63 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,6 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'optparse'
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'ostruct'
         
     | 
| 
       3 
3 
     | 
    
         
             
            module GithubCloner
         
     | 
| 
      
 4 
     | 
    
         
            +
              # See: http://ruby-doc.org/stdlib-2.3.0/libdoc/optparse/rdoc/OptionParser.html
         
     | 
| 
       4 
5 
     | 
    
         
             
              class OptParser
         
     | 
| 
       5 
6 
     | 
    
         
             
                # Return a structure describing the options.
         
     | 
| 
       6 
7 
     | 
    
         
             
                def self.parse(args)
         
     | 
| 
         @@ -8,12 +9,12 @@ module GithubCloner 
     | 
|
| 
       8 
9 
     | 
    
         
             
                  options = OpenStruct.new
         
     | 
| 
       9 
10 
     | 
    
         | 
| 
       10 
11 
     | 
    
         
             
                  # Set the sensible default for the options explicitly
         
     | 
| 
       11 
     | 
    
         
            -
                  options.base_dir 
     | 
| 
       12 
     | 
    
         
            -
                  options.all_repos 
     | 
| 
      
 12 
     | 
    
         
            +
                  options.base_dir      = "."
         
     | 
| 
      
 13 
     | 
    
         
            +
                  options.all_repos     = false
         
     | 
| 
       13 
14 
     | 
    
         
             
                  options.group_by_user = false
         
     | 
| 
       14 
     | 
    
         
            -
                  options.clone_repos 
     | 
| 
      
 15 
     | 
    
         
            +
                  options.clone_repos   = false
         
     | 
| 
      
 16 
     | 
    
         
            +
                  options.languages     = []
         
     | 
| 
       15 
17 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
                  # The parser
         
     | 
| 
       17 
18 
     | 
    
         
             
                  opt_parser = OptionParser.new do |opts|
         
     | 
| 
       18 
19 
     | 
    
         
             
                    opts.banner = "Usage: github-cloner [options]"
         
     | 
| 
       19 
20 
     | 
    
         | 
| 
         @@ -44,17 +45,17 @@ module GithubCloner 
     | 
|
| 
       44 
45 
     | 
    
         
             
                      options.oauth_token = token
         
     | 
| 
       45 
46 
     | 
    
         
             
                    end
         
     | 
| 
       46 
47 
     | 
    
         | 
| 
       47 
     | 
    
         
            -
                    opts.on("-l", "-- 
     | 
| 
       48 
     | 
    
         
            -
                             
     | 
| 
       49 
     | 
    
         
            -
                            " 
     | 
| 
       50 
     | 
    
         
            -
                      options. 
     | 
| 
      
 48 
     | 
    
         
            +
                    opts.on("-l", "--languages 'LANG1,LANG2,..,LANGn'",
         
     | 
| 
      
 49 
     | 
    
         
            +
                            Array,
         
     | 
| 
      
 50 
     | 
    
         
            +
                            "Clone all repos that in the list of languages") do |langs|
         
     | 
| 
      
 51 
     | 
    
         
            +
                      options.languages = langs
         
     | 
| 
       51 
52 
     | 
    
         
             
                    end
         
     | 
| 
       52 
53 
     | 
    
         | 
| 
       53 
54 
     | 
    
         
             
                    # Boolean switch.
         
     | 
| 
       54 
55 
     | 
    
         
             
                    opts.on("-a", "--[no-]all-repos",
         
     | 
| 
       55 
56 
     | 
    
         
             
                            "All repository only (optional)",
         
     | 
| 
       56 
     | 
    
         
            -
                            "default to original/non-forked repositories only") do | 
     | 
| 
       57 
     | 
    
         
            -
                      options.all_repos =  
     | 
| 
      
 57 
     | 
    
         
            +
                            "default to original/non-forked repositories only") do |all_repos|
         
     | 
| 
      
 58 
     | 
    
         
            +
                      options.all_repos = all_repos
         
     | 
| 
       58 
59 
     | 
    
         
             
                    end
         
     | 
| 
       59 
60 
     | 
    
         | 
| 
       60 
61 
     | 
    
         
             
                    opts.on("-g", "--[no-]group-by-user",
         
     | 
| 
         @@ -78,11 +79,20 @@ module GithubCloner 
     | 
|
| 
       78 
79 
     | 
    
         
             
                      puts ""
         
     | 
| 
       79 
80 
     | 
    
         
             
                      puts "Example Usage:"
         
     | 
| 
       80 
81 
     | 
    
         
             
                      puts ""
         
     | 
| 
       81 
     | 
    
         
            -
                      puts " 
     | 
| 
       82 
     | 
    
         
            -
                      puts "github-cloner - 
     | 
| 
      
 82 
     | 
    
         
            +
                      puts "1) List all repositories by a given user (dry-run)"
         
     | 
| 
      
 83 
     | 
    
         
            +
                      puts "$github-cloner -u awesome_user"
         
     | 
| 
       83 
84 
     | 
    
         
             
                      puts ""
         
     | 
| 
       84 
     | 
    
         
            -
                      puts " 
     | 
| 
       85 
     | 
    
         
            -
                      puts "github-cloner -b ~/Desktop/projects -u awesome_user -l  
     | 
| 
      
 85 
     | 
    
         
            +
                      puts "2) List all 'Emacs Lisp' repositories for a given user (dry-run)"
         
     | 
| 
      
 86 
     | 
    
         
            +
                      puts "$github-cloner -b ~/Desktop/projects -u awesome_user -l 'Emacs Lisp'"
         
     | 
| 
      
 87 
     | 
    
         
            +
                      puts ""
         
     | 
| 
      
 88 
     | 
    
         
            +
                      puts "3) List all 'JavaScript' and 'Emacs Lisp' repositories for a given user (dry-run)"
         
     | 
| 
      
 89 
     | 
    
         
            +
                      puts "$github-cloner -b ~/Desktop/projects -u awesome_user -l 'JavaScript,Emacs Lisp'"
         
     | 
| 
      
 90 
     | 
    
         
            +
                      puts ""
         
     | 
| 
      
 91 
     | 
    
         
            +
                      puts "4) Clone all 'JavaScript' and 'Emacs Lisp' repositories for a given user (note: --clone or -c option)"
         
     | 
| 
      
 92 
     | 
    
         
            +
                      puts "$github-cloner -b ~/Desktop/projects -u awesome_user -l 'JavaScript,Emacs Lisp' -c"
         
     | 
| 
      
 93 
     | 
    
         
            +
                      puts ""
         
     | 
| 
      
 94 
     | 
    
         
            +
                      puts "5) Clone all 'JavaScript' and 'Emacs Lisp' repositories for a given organization where a given user belongs to (include private repos)"
         
     | 
| 
      
 95 
     | 
    
         
            +
                      puts "$github-cloner -b ~/Desktop/projects -u awesome_user -o awesome_company -l -t GITHUB_TOKEN -l 'JavaScript,Emacs Lisp' -c"
         
     | 
| 
       86 
96 
     | 
    
         
             
                      puts ""
         
     | 
| 
       87 
97 
     | 
    
         
             
                      exit
         
     | 
| 
       88 
98 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -93,3 +103,7 @@ module GithubCloner 
     | 
|
| 
       93 
103 
     | 
    
         
             
                end
         
     | 
| 
       94 
104 
     | 
    
         
             
              end
         
     | 
| 
       95 
105 
     | 
    
         
             
            end
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
            # options = GithubCloner::OptParser.parse(ARGV)
         
     | 
| 
      
 108 
     | 
    
         
            +
            # puts options
         
     | 
| 
      
 109 
     | 
    
         
            +
            # puts ARGV
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: github-cloner
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.4.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-07 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: github_api
         
     |