gito 0.0.1 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e312ed2d1efb78f0803e4de8abac2d148625ed68
4
- data.tar.gz: a303804c688545c37ebed8df03eea17ba00b61c2
3
+ metadata.gz: 665348ac4df9545b7452e6c24e1ba0ce994df56d
4
+ data.tar.gz: a82f08e1a78a5e9137d599431d27a96ec7c70346
5
5
  SHA512:
6
- metadata.gz: 954b08c596f0c7974da1f7b7bf352650336bfbf28e821f40cf66b175d4c9f12bd01a06812dba9eab7d67125b248a279473a2ddbe07c9e31ff3f432ea709782e8
7
- data.tar.gz: c1a1232f1c7ee94bc4d7dc23627bc95ee5652fbec068be10cef988b04dafc3e77b6704004195c94d291c3b0413beaaf766eada427af941fcbc27d9f74dda7fbf
6
+ metadata.gz: '029a3c8dc6c9f5c4ee95c158dd605f78216bee20476b16754e4b7469c0dc76624a2f78649e97e1e140b06ff5b701a9974ffed4966885f8acd796e045c27ec6b6'
7
+ data.tar.gz: bfc82c7036abc0f2ffc7b5babd9e51c3258120ee23a7bc357a3b920dfa66fc30f27b7aca2ceab42b4b44af5a9d7858250e5b438105adb6137b659277424ea3be
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .idea/
11
+ .DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ sudo: false
3
+ rvm:
4
+ - 2.4.0
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # gito
2
+ [![Gem Version](https://badge.fury.io/rb/gito.svg)](https://badge.fury.io/rb/gito)
3
+ [![Build Status](https://travis-ci.org/cesarferreira/gito.svg?branch=master)](https://travis-ci.org/cesarferreira/gito)
4
+ [![Code Climate](https://codeclimate.com/github/cesarferreira/gito/badges/gpa.svg)](https://codeclimate.com/github/cesarferreira/gito)
5
+ [![Inline docs](http://inch-ci.org/github/cesarferreira/gito.svg?branch=master)](http://inch-ci.org/github/cesarferreira/gito)
6
+
7
+ git helper tool to **clone**/**open**/**install**/**edit** a git project with a one-liner.
8
+
9
+ -----------
10
+
11
+ <p align="center">
12
+ > <strong>gito</strong> <i>cesarferreira/dryrun</i>
13
+ </p>
14
+
15
+ <p align="center">
16
+ <img src="extras/screenshot.png" width="100%" />
17
+ </p>
18
+
19
+ ## Why?
20
+ A lot of times I find myself wanting to try some code from github and in order to do so I have to copy the git URL, go to the terminal, git clone, find out the folder name, go to the folder and based on the type of project I need to `bundle install`, `./gradlew assemble`, `npm install`... Not anymore!
21
+
22
+
23
+ ## Usage
24
+
25
+ ```bash
26
+ # git clone and enter the project folder
27
+ gito cesarferreira/dryrun
28
+
29
+ # git clone and enter the project folder and edit the project
30
+ gito cesarferreira/dryrun -e
31
+
32
+ # git clone and enter the project folder, open and edit the project
33
+ gito cesarferreira/dryrun --edit --open
34
+
35
+ # git clone from github and enter the folder
36
+ gito https://github.com/cesarferreira/dryrun
37
+
38
+ # git clone from github and enter the folder
39
+ gito https://bitbucket.org/cesarferreira/project
40
+ ```
41
+
42
+ ## Installation
43
+
44
+ $ gem install gito
45
+
46
+ ## Internally what happens?
47
+
48
+ Sample:
49
+
50
+ ```bash
51
+ # clone it
52
+ git clone http://github.com/cesarferreira/dryrun
53
+
54
+ # change directory
55
+ cd dryrun
56
+
57
+ # open an editor of choice if --editor flag
58
+ atom .
59
+
60
+ # open the folder if --open flag
61
+ open .
62
+
63
+ # find out what kind of project it is
64
+ project_type_detector
65
+
66
+ # because `ruby` was detected
67
+ bundle install
68
+ ```
69
+
70
+ ## Contributing
71
+ I welcome and encourage all pull requests. It usually will take me within 24-48 hours to respond to any issue or request. Here are some basic rules to follow to ensure timely addition of your request:
72
+ 1. If its a feature, bugfix, or anything please only change code to what you specify.
73
+ 2. Please keep PR titles easy to read and descriptive of changes, this will make them easier to merge :)
74
+ 3. Pull requests _must_ be made against `develop` branch. Any other branch (unless specified by the maintainers) will get rejected.
75
+ 4. Check for existing [issues](https://github.com/cesarferreira/gito/issues) first, before filing an issue.
76
+ 5. Have fun!
77
+
78
+ ### Created & Maintained By
79
+ [Cesar Ferreira](https://github.com/cesarferreira) ([@cesarmcferreira](https://www.twitter.com/cesarmcferreira))
data/bin/gito CHANGED
@@ -1,78 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
- require 'gli'
3
- begin # XXX: Remove this begin/rescue before distributing your app
4
- require 'gito'
5
- rescue LoadError
6
- STDERR.puts "In development, you need to use `bundle exec bin/gito` to run your app"
7
- STDERR.puts "At install-time, RubyGems will make sure lib, etc. are in the load path"
8
- STDERR.puts "Feel free to remove this message from bin/gito now"
9
- exit 64
10
- end
11
-
12
- include GLI::App
13
-
14
- program_desc 'Describe your application here'
15
-
16
- version Gito::VERSION
17
-
18
- subcommand_option_handling :normal
19
- arguments :strict
20
-
21
- desc 'Describe some switch here'
22
- switch [:s,:switch]
23
-
24
- desc 'Describe some flag here'
25
- default_value 'the default'
26
- arg_name 'The name of the argument'
27
- flag [:f,:flagname]
28
-
29
- desc 'Describe open here'
30
- arg_name 'Describe arguments to open here'
31
- command :open do |c|
32
- c.desc 'Describe a switch to open'
33
- c.switch :s
34
2
 
35
- c.desc 'Describe a flag to open'
36
- c.default_value 'default'
37
- c.flag :f
38
- c.action do |global_options,options,args|
39
-
40
- # Your command logic here
41
-
42
- # If you have any errors, just raise them
43
- # raise "that command made no sense"
44
-
45
- puts "open command ran"
46
- end
47
- end
48
-
49
- desc 'Describe edit here'
50
- arg_name 'Describe arguments to edit here'
51
- command :edit do |c|
52
- c.action do |global_options,options,args|
53
- puts "edit command ran"
54
- end
55
- end
56
-
57
- pre do |global,command,options,args|
58
- # Pre logic here
59
- # Return true to proceed; false to abort and not call the
60
- # chosen command
61
- # Use skips_pre before a command to skip this block
62
- # on that command only
63
- true
64
- end
65
-
66
- post do |global,command,options,args|
67
- # Post logic here
68
- # Use skips_post before a command to skip this
69
- # block on that command only
70
- end
71
-
72
- on_error do |exception|
73
- # Error logic here
74
- # return false to skip default error handling
75
- true
76
- end
3
+ require 'bundler/setup'
4
+ require 'gito'
77
5
 
78
- exit run(ARGV)
6
+ MainApp.new(ARGV).call
Binary file
data/gito.gemspec CHANGED
@@ -1,23 +1,22 @@
1
1
  # Ensure we require the local version and not one we might have installed already
2
2
  require File.join([File.dirname(__FILE__),'lib','gito','version.rb'])
3
- spec = Gem::Specification.new do |s|
3
+ spec = Gem::Specification.new do |s|
4
4
  s.name = 'gito'
5
5
  s.version = Gito::VERSION
6
- s.author = 'Your Name Here'
7
- s.email = 'your@email.address.com'
6
+ s.authors = ['cesar ferreira']
7
+ s.email = ['cesar.manuel.ferreira@gmail.com']
8
8
  s.homepage = 'http://your.website.com'
9
9
  s.platform = Gem::Platform::RUBY
10
- s.summary = 'A description of your project'
10
+ s.summary = 'git helper tool to clone/open/install/edit a git project with a one-liner'
11
11
  s.files = `git ls-files`.split("
12
12
  ")
13
13
  s.require_paths << 'lib'
14
- s.has_rdoc = true
15
- s.extra_rdoc_files = ['README.rdoc','gito.rdoc']
16
- s.rdoc_options << '--title' << 'gito' << '--main' << 'README.rdoc' << '-ri'
17
14
  s.bindir = 'bin'
18
15
  s.executables << 'gito'
19
- s.add_development_dependency('rake')
20
- s.add_development_dependency('rdoc')
21
- s.add_development_dependency('aruba')
22
- s.add_runtime_dependency('gli','2.16.0')
16
+ s.add_development_dependency 'rake', '~> 10.0'
17
+ s.add_development_dependency 'pry-byebug', '~> 3.2'
18
+ s.add_development_dependency 'rspec'
19
+
20
+ s.add_dependency 'bundler', '~> 1.7'
21
+ s.add_dependency 'colorize', '~> 0.7'
23
22
  end
data/lib/gito.rb CHANGED
@@ -1,4 +1,92 @@
1
- require 'gito/version.rb'
1
+ require 'colorize'
2
+ require 'tmpdir'
3
+ require 'fileutils'
4
+ require 'gito/version'
5
+ require 'gito/project'
6
+ require 'openssl'
7
+ require 'open3'
8
+ require 'optparse'
2
9
 
3
- # Add requires for other files you add to your project here, so
4
- # you just need to require this one file in your bin file
10
+ class MainApp
11
+ def initialize(arguments)
12
+
13
+ @url = %w(-h --help -v --version).include?(arguments.first) ? nil : arguments.shift
14
+
15
+ # defaults
16
+ @app_path = nil
17
+ @should_edit = false
18
+ @should_open = false
19
+ @dryrun = false
20
+
21
+ # Parse Options
22
+ create_options_parser(arguments)
23
+ end
24
+
25
+ def create_options_parser(args)
26
+ args.options do |opts|
27
+ opts.banner = 'Usage: gito GIT_URL [OPTIONS]'
28
+ opts.separator ''
29
+ opts.separator 'Options'
30
+
31
+ opts.on('-e', '--edit', 'Open the project on an editor') do |edit|
32
+ @should_edit = true
33
+ end
34
+
35
+ opts.on('-o', '--open', 'Open the project on Finder') do |edit|
36
+ @should_open = true
37
+ end
38
+
39
+ opts.on('-d', '--dryrun', 'Doesn\'t install the dependencies') do |dryrun|
40
+ @dryrun = true
41
+ end
42
+
43
+ opts.on('-h', '--help', 'Displays help') do
44
+ puts opts.help
45
+ exit
46
+ end
47
+
48
+ opts.on('-v', '--version', 'Displays the version') do
49
+ puts Gito::VERSION
50
+ exit
51
+ end
52
+
53
+ opts.parse!
54
+ end
55
+ end
56
+
57
+ def call
58
+
59
+ if @url.nil?
60
+ puts 'You need to insert a valid GIT URL/folder'
61
+ exit 1
62
+ end
63
+
64
+ project = Project.new(@url)
65
+
66
+ # Clone the repository
67
+ project.clone
68
+
69
+ # Detect project type
70
+ project.detect_project_type
71
+
72
+ unless @dryrun
73
+ # Install dependencies
74
+ project.install_dependencies
75
+ end
76
+
77
+ # Open in editor
78
+ if @should_edit
79
+ project.open_editor
80
+ end
81
+
82
+ # Open in Finder
83
+ if @should_open
84
+ project.open_folder
85
+ end
86
+
87
+ # Change to directory
88
+ project.change_directory
89
+
90
+
91
+ end
92
+ end
@@ -0,0 +1,19 @@
1
+ require 'open3'
2
+
3
+ class AppUtils
4
+
5
+ def self.execute(command)
6
+ is_success = system command
7
+ unless is_success
8
+ puts "\n\n======================================================\n\n"
9
+ puts ' Something went wrong while executing this:'.red
10
+ puts " $ #{command}\n".yellow
11
+ puts "======================================================\n\n"
12
+ exit 1
13
+ end
14
+ end
15
+
16
+ def self.is_folder? (path)
17
+ File.directory?(path)
18
+ end
19
+ end
@@ -0,0 +1,133 @@
1
+ require 'tmpdir'
2
+ require 'fileutils'
3
+ require 'uri'
4
+ require_relative './app_utils'
5
+ require 'pry'
6
+
7
+ class Project
8
+ def initialize(url)
9
+ @base_url = sanitize_url(url)
10
+ @destination_dir = nil
11
+ @destination = destination
12
+ @project_type = :unknown
13
+ end
14
+
15
+ def sanitize_url(url)
16
+ url = url.split('?').first
17
+ url.chop! if url.end_with? '/'
18
+
19
+ is_valid_url = url =~ /\A#{URI::regexp(['http', 'https'])}\z/ || url.include?('git@')
20
+
21
+ unless is_valid_url
22
+
23
+ valid_shortcut = url.split('/').size == 2
24
+
25
+ if valid_shortcut
26
+ url = 'https://github.com/' + url
27
+ else
28
+ url = nil
29
+ end
30
+ end
31
+ url
32
+ end
33
+
34
+ def destination
35
+ unless @base_url.include? 'github.com'
36
+ return Digest::SHA256.hexdigest @base_url
37
+ end
38
+
39
+ stripped_url = @base_url.gsub('.git', '')
40
+ stripped_url = stripped_url.gsub('.git', '')
41
+ stripped_url = stripped_url.gsub('git@github.com:', '')
42
+ stripped_url = stripped_url.gsub('https://github.com/', '')
43
+ stripped_url.gsub('http://github.com/', '')
44
+
45
+ stripped_url.gsub('/','-')
46
+ end
47
+
48
+ def change_directory
49
+ # TODO aparently this doesn't work because ruby forks the terminal process and cant' communicate with his father
50
+
51
+ # temp_script_name = './temp.sh'
52
+ # AppUtils::execute 'echo "cd '+@destination+'" > ' + temp_script_name
53
+ # AppUtils::execute '. '+temp_script_name
54
+ # AppUtils::execute 'rm -rf ' + temp_script_name
55
+
56
+ puts "\nPlease change directory into the project"
57
+ puts "cd #{destination.green}"
58
+ end
59
+
60
+ def detect_project_type
61
+ Dir.chdir @destination_dir
62
+
63
+ @project_type = :unknown
64
+
65
+ if File.exists?('build.gradle')
66
+ @project_type = :gradle
67
+ elsif File.exists?('package.json')
68
+ @project_type = :node
69
+ elsif File.exists?('Gemfile')
70
+ @project_type = :ruby
71
+ end
72
+ @project_type
73
+ end
74
+
75
+ def install_dependencies
76
+ case @project_type
77
+ when :gradle
78
+ go_inside_and_run('./gradlew assemble')
79
+ when :node
80
+ go_inside_and_run('npm install')
81
+ when :ruby
82
+ go_inside_and_run('bundle install')
83
+ else
84
+ puts 'Unknown project type'
85
+ end
86
+ end
87
+
88
+ def cloneable_url
89
+ starts_with_git = @base_url.split(//).first(4).join.eql? 'git@'
90
+ ends_with_git = @base_url.split(//).last(4).join.eql? '.git'
91
+
92
+ # ends with git but doesnt start with git
93
+ return @base_url if ends_with_git && !starts_with_git
94
+
95
+ # ends with git but doesnt start with git
96
+ return "#{@base_url}.git" if !ends_with_git && !starts_with_git
97
+
98
+ @base_url
99
+ end
100
+
101
+ ##
102
+ ## CLONE THE REPOSITORY
103
+ ##
104
+ def clone
105
+ cloneable = cloneable_url
106
+
107
+ @destination_dir = Dir.pwd + "/#{@destination}"
108
+
109
+ if File.directory?(@destination_dir)
110
+ puts 'The folder is not empty...'.yellow
111
+ else
112
+ AppUtils.execute("git clone --depth 1 #{cloneable} #{@destination_dir}")
113
+ end
114
+
115
+ @destination_dir
116
+ end
117
+
118
+ def open_editor
119
+ puts "Opening editor...".yellow
120
+ go_inside_and_run 'atom .'
121
+ end
122
+
123
+ def open_folder
124
+ puts 'Opening folder'.yellow
125
+ go_inside_and_run 'open .'
126
+ end
127
+
128
+ def go_inside_and_run(command)
129
+ Dir.chdir(@destination_dir) do
130
+ AppUtils::execute command
131
+ end
132
+ end
133
+ end
data/lib/gito/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gito
2
- VERSION = '0.0.1'
2
+ VERSION = '0.2.1'
3
3
  end
metadata CHANGED
@@ -1,45 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gito
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
- - Your Name Here
7
+ - cesar ferreira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-01 00:00:00.000000000 Z
11
+ date: 2017-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '10.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '10.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rdoc
28
+ name: pry-byebug
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '3.2'
34
34
  type: :development
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: '0'
40
+ version: '3.2'
41
41
  - !ruby/object:Gem::Dependency
42
- name: aruba
42
+ name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,52 +53,59 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: gli
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: colorize
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - '='
73
+ - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: 2.16.0
75
+ version: '0.7'
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - '='
80
+ - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: 2.16.0
82
+ version: '0.7'
69
83
  description:
70
- email: your@email.address.com
84
+ email:
85
+ - cesar.manuel.ferreira@gmail.com
71
86
  executables:
72
87
  - gito
73
88
  extensions: []
74
- extra_rdoc_files:
75
- - README.rdoc
76
- - gito.rdoc
89
+ extra_rdoc_files: []
77
90
  files:
91
+ - ".DS_Store"
78
92
  - ".gitignore"
93
+ - ".travis.yml"
79
94
  - Gemfile
80
- - README.rdoc
95
+ - README.md
81
96
  - Rakefile
82
97
  - bin/gito
83
- - features/gito.feature
84
- - features/step_definitions/gito_steps.rb
85
- - features/support/env.rb
98
+ - extras/screenshot.png
86
99
  - gito.gemspec
87
- - gito.rdoc
88
100
  - lib/gito.rb
101
+ - lib/gito/app_utils.rb
102
+ - lib/gito/project.rb
89
103
  - lib/gito/version.rb
90
- - test/default_test.rb
91
- - test/test_helper.rb
92
104
  homepage: http://your.website.com
93
105
  licenses: []
94
106
  metadata: {}
95
107
  post_install_message:
96
- rdoc_options:
97
- - "--title"
98
- - gito
99
- - "--main"
100
- - README.rdoc
101
- - "-ri"
108
+ rdoc_options: []
102
109
  require_paths:
103
110
  - lib
104
111
  - lib
@@ -114,8 +121,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
121
  version: '0'
115
122
  requirements: []
116
123
  rubyforge_project:
117
- rubygems_version: 2.6.10
124
+ rubygems_version: 2.6.8
118
125
  signing_key:
119
126
  specification_version: 4
120
- summary: A description of your project
127
+ summary: git helper tool to clone/open/install/edit a git project with a one-liner
121
128
  test_files: []
data/README.rdoc DELETED
@@ -1,6 +0,0 @@
1
- = gito
2
-
3
- Describe your project here
4
-
5
- :include:gito.rdoc
6
-
@@ -1,8 +0,0 @@
1
- Feature: My bootstrapped app kinda works
2
- In order to get going on coding my awesome app
3
- I want to have aruba and cucumber setup
4
- So I don't have to do it myself
5
-
6
- Scenario: App just runs
7
- When I get help for "gito"
8
- Then the exit status should be 0
@@ -1,6 +0,0 @@
1
- When /^I get help for "([^"]*)"$/ do |app_name|
2
- @app_name = app_name
3
- step %(I run `#{app_name} help`)
4
- end
5
-
6
- # Add more step definitions here
@@ -1,15 +0,0 @@
1
- require 'aruba/cucumber'
2
-
3
- ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
4
- LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
5
-
6
- Before do
7
- # Using "announce" causes massive warnings on 1.9.2
8
- @puts = true
9
- @original_rubylib = ENV['RUBYLIB']
10
- ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
11
- end
12
-
13
- After do
14
- ENV['RUBYLIB'] = @original_rubylib
15
- end
data/gito.rdoc DELETED
@@ -1,5 +0,0 @@
1
- = gito
2
-
3
- Generate this with
4
- gito rdoc
5
- After you have described your command line interface
data/test/default_test.rb DELETED
@@ -1,14 +0,0 @@
1
- require 'test_helper'
2
-
3
- class DefaultTest < Test::Unit::TestCase
4
-
5
- def setup
6
- end
7
-
8
- def teardown
9
- end
10
-
11
- def test_the_truth
12
- assert true
13
- end
14
- end
data/test/test_helper.rb DELETED
@@ -1,9 +0,0 @@
1
- require 'test/unit'
2
-
3
- # Add test libraries you want to use here, e.g. mocha
4
-
5
- class Test::Unit::TestCase
6
-
7
- # Add global extensions to the test case class here
8
-
9
- end