easy-auto 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +39 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +27 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +55 -0
  7. data/Rakefile +11 -0
  8. data/bin/create-branch +8 -0
  9. data/bin/create-repo +5 -0
  10. data/bin/easy-authorize +5 -0
  11. data/bin/easy-setup +5 -0
  12. data/bin/pull-request +5 -0
  13. data/easy-auto.gemspec +25 -0
  14. data/lib/easy_auto.rb +13 -0
  15. data/lib/easy_auto/authorize.rb +49 -0
  16. data/lib/easy_auto/client_wrapper.rb +21 -0
  17. data/lib/easy_auto/config_manager.rb +60 -0
  18. data/lib/easy_auto/config_manager_wrapper.rb +9 -0
  19. data/lib/easy_auto/create_branch.rb +53 -0
  20. data/lib/easy_auto/create_repo.rb +75 -0
  21. data/lib/easy_auto/easy_setup.rb +58 -0
  22. data/lib/easy_auto/easy_utilities.rb +14 -0
  23. data/lib/easy_auto/git.rb +57 -0
  24. data/lib/easy_auto/git_wrapper.rb +9 -0
  25. data/lib/easy_auto/pull_request.rb +68 -0
  26. data/lib/easy_auto/set_upstream.rb +16 -0
  27. data/lib/easy_auto/system_helper.rb +29 -0
  28. data/lib/easy_auto/version.rb +3 -0
  29. data/test/lib/easy_auto/authorize_test.rb +17 -0
  30. data/test/lib/easy_auto/create_branch_test.rb +74 -0
  31. data/test/lib/easy_auto/create_repo_test.rb +51 -0
  32. data/test/lib/easy_auto/easy_setup_test.rb +32 -0
  33. data/test/lib/easy_auto/easy_utilities_test.rb +20 -0
  34. data/test/lib/easy_auto/git_test.rb +69 -0
  35. data/test/lib/easy_auto/git_wrapper_test.rb +20 -0
  36. data/test/lib/easy_auto/pull_request_test.rb +78 -0
  37. data/test/lib/easy_auto/set_upstream_test.rb +41 -0
  38. data/test/lib/easy_auto/version_test.rb +7 -0
  39. data/test/test_helper.rb +3 -0
  40. data/todo.md +3 -0
  41. metadata +141 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 302736908a8008b2d9d655b7938cd7690848358f
4
+ data.tar.gz: c3c942cad430f85b818fdfd40f771d39b5a76232
5
+ SHA512:
6
+ metadata.gz: d5b11abe9489b52174b7fd341049e80a1d9aec6a65ca2d03edd1620ff2191450b8acd6ab14c8f6461240b17628c437a421992ffd8ba8df59e02b69bb58700a4a
7
+ data.tar.gz: 2591f2414be1ea0112b7c4422c898429394879ce09c5b5f4a49c8f48d95827819db7b8cc091adc25baee7ec02a4cd28c710d5d47ea133d00efc8c28bf2d19231
@@ -0,0 +1,39 @@
1
+ *.gem
2
+ # Compiled source #
3
+ ###################
4
+ *.com
5
+ *.class
6
+ *.dll
7
+ *.exe
8
+ *.o
9
+ *.so
10
+
11
+ # Packages #
12
+ ############
13
+ # it's better to unpack these files and commit the raw source
14
+ # git has its own built in compression methods
15
+ *.7z
16
+ *.dmg
17
+ *.gz
18
+ *.iso
19
+ *.jar
20
+ *.rar
21
+ *.tar
22
+ *.zip
23
+
24
+ # Logs and databases #
25
+ ######################
26
+ *.log
27
+ *.sql
28
+ *.sqlite
29
+
30
+ # OS generated files #
31
+ ######################
32
+ .DS_Store
33
+ .DS_Store?
34
+ ._*
35
+ .Spotlight-V100
36
+ .Trashes
37
+ Icon?
38
+ ehthumbs.db
39
+ Thumbs.db
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in easy-auto.gemspec
4
+ gemspec
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ easy-auto (0.0.1)
5
+ octokit (~> 2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ faraday (0.8.8)
11
+ multipart-post (~> 1.2.0)
12
+ multipart-post (1.2.0)
13
+ octokit (2.0.0)
14
+ sawyer (~> 0.3.0)
15
+ rake (10.1.0)
16
+ sawyer (0.3.0)
17
+ faraday (~> 0.8, < 0.10)
18
+ uri_template (~> 0.5.0)
19
+ uri_template (0.5.3)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler (~> 1.3)
26
+ easy-auto!
27
+ rake
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Stuart Nelson
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.
@@ -0,0 +1,55 @@
1
+ # EasyAuto
2
+
3
+ Simple CLI for git and github
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'easy-auto'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install easy-auto
18
+
19
+ ## Setup
20
+
21
+ Configure your computer for easy-auto:
22
+
23
+ $ easy-authorize
24
+
25
+ Follow the prompts, then confirm the install worked:
26
+
27
+ $ easy-setup
28
+
29
+ ## Usage
30
+
31
+ To create a repo on github from your current project:
32
+
33
+ $ create-repo
34
+
35
+ Follow the instructions.
36
+
37
+ Create a new branch:
38
+
39
+ $ create-branch <new-branch-name> <OPTIONAL: branch-to-track>
40
+
41
+ The new branch is made from master if no second branch name is given.
42
+
43
+ To open a pull-request:
44
+
45
+ $ pull-request
46
+
47
+ Follow the prompts.
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create new Pull Request
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'lib/easy_auto'
7
+ t.test_files = FileList['test/lib/easy_auto/*_test.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,8 @@
1
+ #! usr/bin/env ruby
2
+
3
+ require 'easy_auto'
4
+
5
+ new_branch = ARGV.pop
6
+ origin_branch = ARGV.pop
7
+
8
+ EasyAuto::CreateBranch.new(new_branch, origin_branch).run
@@ -0,0 +1,5 @@
1
+ #! usr/bin/env ruby
2
+
3
+ require 'easy_auto'
4
+
5
+ EasyAuto::CreateRepo.new.run
@@ -0,0 +1,5 @@
1
+ #! usr/bin/env ruby
2
+
3
+ require 'easy_auto'
4
+
5
+ EasyAuto::Authorize.new.run
@@ -0,0 +1,5 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'easy_auto'
4
+
5
+ EasyAuto::EasySetup.new.run
@@ -0,0 +1,5 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'easy_auto'
4
+
5
+ EasyAuto::PullRequest.new.run
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'easy_auto/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "easy-auto"
8
+ spec.version = EasyAuto::VERSION
9
+ spec.authors = ["Stuart Nelson"]
10
+ spec.email = ["stuartnelson3@gmail.com"]
11
+ spec.description = %q{Easy access to git commands}
12
+ spec.summary = %q{Use the command line to simplify interacting with git}
13
+ spec.homepage = "https://github.com/stuartnelson3/easy-auto"
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "octokit", "~> 2.0"
25
+ end
@@ -0,0 +1,13 @@
1
+ require 'octokit'
2
+
3
+ trap("INT") { puts "\nexiting"; exit 1 }
4
+
5
+ module EasyAuto; end
6
+
7
+ require "easy_auto/version"
8
+ require "easy_auto/create_repo"
9
+ require "easy_auto/pull_request"
10
+ require "easy_auto/set_upstream"
11
+ require "easy_auto/create_branch"
12
+ require "easy_auto/authorize"
13
+ require "easy_auto/easy_setup"
@@ -0,0 +1,49 @@
1
+ require 'json'
2
+ require 'easy_auto/system_helper'
3
+ require 'easy_auto/config_manager_wrapper'
4
+ require 'easy_auto/easy_utilities'
5
+
6
+ module EasyAuto
7
+ class Authorize
8
+ include EasyUtilities
9
+ include SystemHelper
10
+ include ConfigManagerWrapper
11
+ attr_accessor :email
12
+ attr_accessor :password
13
+ attr_accessor :token
14
+
15
+ def run
16
+ get_credentials
17
+ generate_token
18
+ store_token
19
+ end
20
+
21
+ def store_token
22
+ config_manager.set :github_email, email
23
+ config_manager.set :github_token, token
24
+ end
25
+
26
+ def get_credentials
27
+ self.email = get_email
28
+ self.password = get_password
29
+ end
30
+
31
+ def get_email
32
+ puts "what is your github email account?"
33
+ gets.strip
34
+ end
35
+
36
+ def get_password
37
+ puts "enter your password for #{email}. this will not be stored."
38
+ hidden_input
39
+ end
40
+
41
+ def generate_token
42
+ self.token = JSON.parse(github_curl)['token']
43
+ end
44
+
45
+ def github_curl
46
+ cli_send %Q(curl -u '#{email}:#{password}' -d '{"scopes": ["repo"], "notes": "Easy Auto"}' https://api.github.com/authorizations)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,21 @@
1
+ require 'easy_auto/config_manager_wrapper'
2
+
3
+ module EasyAuto
4
+ class Github
5
+ extend ConfigManagerWrapper
6
+
7
+ def self.client
8
+ Octokit::Client.new login: config_manager.github_email, access_token: config_manager.github_token
9
+ end
10
+ end
11
+
12
+ module ClientWrapper
13
+ def client
14
+ Github.client
15
+ end
16
+
17
+ def username
18
+ client.login.split('@').first
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,60 @@
1
+ require 'yaml'
2
+
3
+ module EasyAuto
4
+ class ConfigManager
5
+ attr_accessor :config
6
+ attr_accessor :github_email
7
+ attr_accessor :github_token
8
+
9
+ def initialize config_contents
10
+ self.config = config_contents
11
+ config.each do |k,v|
12
+ # e.g., foo: "bar" translates to self.foo = "bar"
13
+ setter = "#{k}="
14
+ send(setter, v) if respond_to? setter
15
+ end
16
+ end
17
+
18
+ def self.read_yml
19
+ new load_config
20
+ end
21
+
22
+ def set key, value
23
+ send("#{key}=", value)
24
+ config.merge!(key => value)
25
+ File.write self.class.config_file, YAML.dump(config)
26
+ end
27
+
28
+ def self.load_config
29
+ YAML.load_file config_file
30
+ rescue Errno::ENOENT
31
+ create_config_file
32
+ {}
33
+ end
34
+
35
+ def self.create_config_file
36
+ check_dir_existence
37
+ check_file_existence
38
+ end
39
+
40
+ def self.check_dir_existence
41
+ unless Dir.exists? config_dir
42
+ Dir.mkdir config_dir
43
+ end
44
+ end
45
+
46
+ def self.config_dir
47
+ File.expand_path "~/.easy-auto"
48
+ end
49
+
50
+ def self.check_file_existence
51
+ unless File.exists? config_file
52
+ File.write config_file, YAML.dump({})
53
+ end
54
+ end
55
+
56
+ def self.config_file
57
+ File.join config_dir, "config.yml"
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,9 @@
1
+ require 'easy_auto/config_manager'
2
+
3
+ module EasyAuto
4
+ module ConfigManagerWrapper
5
+ def config_manager
6
+ @config_manager ||= ConfigManager.read_yml
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,53 @@
1
+ require 'easy_auto/set_upstream'
2
+ require 'easy_auto/git'
3
+ require 'easy_auto/easy_utilities'
4
+
5
+ module EasyAuto
6
+ class CreateBranch
7
+ include GitWrapper
8
+ include EasyUtilities
9
+ attr_reader :new_branch
10
+ attr_reader :origin_branch
11
+
12
+ def initialize new_branch = nil, origin_branch = nil
13
+ @new_branch = new_branch
14
+ @origin_branch = origin_branch
15
+ end
16
+
17
+ def run
18
+ return usage if wrong_usage || help_request?
19
+ checkout_master
20
+ pull
21
+ git.create_and_switch_to new_branch, origin_branch
22
+ new_branch_message if set_upstream
23
+ end
24
+
25
+ def wrong_usage
26
+ [new_branch, origin_branch].all?(&:nil?)
27
+ end
28
+
29
+ def help_request?
30
+ %w{-h --help}.include? new_branch
31
+ end
32
+
33
+ def usage
34
+ puts 'usage: create-branch <new-branch> <OPTIONAL: branch-to-track>.'
35
+ end
36
+
37
+ def checkout_master
38
+ git.checkout_master
39
+ end
40
+
41
+ def pull
42
+ git.pull
43
+ end
44
+
45
+ def set_upstream
46
+ SetUpstream.new(new_branch).set
47
+ end
48
+
49
+ def new_branch_message
50
+ puts "successfully created branch and set upstream remote!"
51
+ end
52
+ end
53
+ end