easy-auto 0.0.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.
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,75 @@
1
+ require 'easy_auto/easy_utilities'
2
+ require 'easy_auto/client_wrapper'
3
+ require 'easy_auto/git_wrapper'
4
+
5
+ module EasyAuto
6
+ class CreateRepo
7
+ include EasyUtilities
8
+ include ClientWrapper
9
+ include GitWrapper
10
+ attr_accessor :repo_name
11
+ attr_reader :password
12
+
13
+ def run
14
+ if remote_exists?
15
+ puts "remote already exists!", "aborting!"
16
+ else
17
+ create_remote
18
+ end
19
+ end
20
+
21
+ def login
22
+ client.login
23
+ end
24
+
25
+ def remote_exists?
26
+ !git.remote.empty?
27
+ end
28
+
29
+ def create_remote
30
+ git_init
31
+ create_repo
32
+ set_remote
33
+ end
34
+
35
+ def git_init
36
+ git.init
37
+ end
38
+
39
+ def add_files
40
+ git.perform "add -A"
41
+ end
42
+
43
+ def first_commit
44
+ git.perform "commit -m 'first commit'"
45
+ end
46
+
47
+ def add_remote
48
+ git.perform "remote add origin git@github.com:#{username}/#{repo_name}.git"
49
+ end
50
+
51
+ def first_push
52
+ git.perform "push -u origin master"
53
+ end
54
+
55
+ def set_remote
56
+ add_files
57
+ first_commit
58
+ add_remote
59
+ first_push
60
+ end
61
+
62
+ def create_repo
63
+ puts "creating repo for username: #{login}"
64
+ client.create_repo get_repo_name
65
+ end
66
+
67
+ def get_repo_name
68
+ self.repo_name = ask_repo_name
69
+ end
70
+
71
+ def ask_repo_name
72
+ ask 'what would you like to name the remote repo?'
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,58 @@
1
+ require 'easy_auto/config_manager_wrapper'
2
+ require 'easy_auto/system_helper'
3
+
4
+ module EasyAuto
5
+ class EasySetup
6
+ include ConfigManagerWrapper
7
+ include SystemHelper
8
+ attr_accessor :email
9
+ attr_accessor :password
10
+
11
+ def run
12
+ setup_message
13
+ os_check
14
+ check_git_install
15
+ check_git_extras_install
16
+ check_authorization
17
+ success_message
18
+ end
19
+
20
+ def system_exit
21
+ exit 1
22
+ end
23
+
24
+ def check_authorization
25
+ Octokit::Client.new(login: config_manager.github_email, access_token: config_manager.github_token).user
26
+ rescue Faraday::Error::ConnectionFailed => e
27
+ p e
28
+ rescue
29
+ puts "make sure you have octokit installed and have run easy-authorize!"
30
+ system_exit
31
+ end
32
+
33
+ def success_message
34
+ puts "all set!"
35
+ end
36
+
37
+ def check_git_install
38
+ check_install "git"
39
+ end
40
+
41
+ def check_git_extras_install
42
+ check_install "git-extras"
43
+ end
44
+
45
+ def os_check
46
+ if os == "Linux" || os == "Darwin"
47
+ puts "You have an acceptable os!"
48
+ else
49
+ puts "Sorry, your OS isn't supported."
50
+ system_exit
51
+ end
52
+ end
53
+
54
+ def setup_message
55
+ puts "this will check to make sure your computer is set up!"
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,14 @@
1
+ require 'io/console'
2
+
3
+ module EasyAuto
4
+ module EasyUtilities
5
+ def hidden_input
6
+ $stdin.noecho(&:gets).strip
7
+ end
8
+
9
+ def ask string
10
+ puts string
11
+ gets.strip
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,57 @@
1
+ require 'easy_auto/system_helper'
2
+
3
+ module EasyAuto
4
+ class Git
5
+ extend SystemHelper
6
+
7
+ def self.perform command
8
+ cli_send "git #{command}"
9
+ end
10
+
11
+ def self.init
12
+ perform "init"
13
+ end
14
+
15
+ def self.abbrev_ref
16
+ "rev-parse --abbrev-ref"
17
+ end
18
+
19
+ def self.current_branch_name
20
+ perform "#{abbrev_ref} HEAD"
21
+ end
22
+
23
+ def self.remote_branch
24
+ perform "#{abbrev_ref} --symbolic-full-name @{u}"
25
+ end
26
+
27
+ def self.delete_local_branch branch_name
28
+ checkout_master
29
+ perform "branch -D #{branch_name}"
30
+ end
31
+
32
+ def self.delete_local_and_remote_branch branch_name
33
+ delete_local_branch branch_name
34
+ delete_remote_branch branch_name
35
+ end
36
+
37
+ def self.delete_remote_branch branch_name
38
+ perform "push origin :#{branch_name}"
39
+ end
40
+
41
+ def self.remote
42
+ perform "remote"
43
+ end
44
+
45
+ def self.checkout_master
46
+ perform "checkout master"
47
+ end
48
+
49
+ def self.pull
50
+ perform "pull"
51
+ end
52
+
53
+ def self.create_and_switch_to branch_name, tracking_branch = nil
54
+ perform "checkout -b #{branch_name} #{tracking_branch}"
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,9 @@
1
+ require 'easy_auto/git'
2
+
3
+ module EasyAuto
4
+ module GitWrapper
5
+ def git
6
+ @git ||= Git
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,68 @@
1
+ require 'easy_auto/easy_utilities'
2
+ require 'easy_auto/git_wrapper'
3
+ require 'easy_auto/client_wrapper'
4
+
5
+ module EasyAuto
6
+ class PullRequest
7
+ include EasyUtilities
8
+ include GitWrapper
9
+ include ClientWrapper
10
+ include SystemHelper
11
+ attr_accessor :title, :body
12
+
13
+ def run
14
+ state_merge_intent
15
+ ask_title
16
+ ask_body
17
+ push_changes
18
+ resp = client.create_pull_request(repo_path, base, head, title, body)
19
+ pr_number = resp.attrs[:number]
20
+ open_in_browser pr_number
21
+ end
22
+
23
+ def open_in_browser pr_number
24
+ cli_send "open 'https://github.com/#{repo_path}/pull/#{pr_number}'"
25
+ end
26
+
27
+ def state_merge_intent
28
+ puts "Preparing pull request:"
29
+ puts "#{repo_owner}/#{repo_name}/#{head} -> #{repo_owner}/#{repo_name}/master"
30
+ end
31
+
32
+ def ask_title
33
+ self.title = ask "Title:"
34
+ end
35
+
36
+ def ask_body
37
+ self.body = ask "Description:"
38
+ end
39
+
40
+ def base
41
+ 'master'
42
+ end
43
+
44
+ def head
45
+ git.current_branch_name
46
+ end
47
+
48
+ def repo_name
49
+ remote_paths.match(/\/(.+)\.git/)[1]
50
+ end
51
+
52
+ def repo_owner
53
+ remote_paths.match(/:(.+)\//)[1]
54
+ end
55
+
56
+ def repo_path
57
+ "#{repo_owner}/#{repo_name}"
58
+ end
59
+
60
+ def push_changes
61
+ git.perform "push"
62
+ end
63
+
64
+ def remote_paths
65
+ git.perform "remote -v"
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,16 @@
1
+ require 'easy_auto/git_wrapper'
2
+
3
+ module EasyAuto
4
+ class SetUpstream
5
+ include GitWrapper
6
+ attr_reader :upstream_branch
7
+
8
+ def initialize upstream_branch
9
+ @upstream_branch = upstream_branch
10
+ end
11
+
12
+ def set
13
+ git.perform "push --set-upstream origin #{upstream_branch}"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ require 'open3'
2
+
3
+ module EasyAuto
4
+ module SystemHelper
5
+ def cli_send command
6
+ output, error, status = Open3.capture3 command
7
+ output.strip
8
+ end
9
+
10
+ def os
11
+ cli_send "uname"
12
+ end
13
+
14
+ def check_install software_name
15
+ software_path = cli_send "which #{software_name}"
16
+ if software_path.empty?
17
+ puts "no #{software_name} detected!"
18
+ if os == "Darwin"
19
+ puts "installing with brew.."
20
+ cli_send "brew install #{software_name}"
21
+ puts "installed #{software_name}!"
22
+ else
23
+ puts "install #{software_name} and try again!"
24
+ exit 1
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module EasyAuto
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,17 @@
1
+ require_relative '../../test_helper'
2
+
3
+ AuthMock = Class.new(EasyAuto::Authorize) do
4
+ def github_curl
5
+ "{\"token\": \"token123\"}"
6
+ end
7
+ end
8
+
9
+ describe EasyAuto::Authorize do
10
+
11
+ subject { AuthMock.new }
12
+
13
+ it "should set the token correctly" do
14
+ subject.generate_token
15
+ subject.token.must_equal "token123"
16
+ end
17
+ end
@@ -0,0 +1,74 @@
1
+ require_relative '../../test_helper'
2
+
3
+ CBMock = Class.new(EasyAuto::CreateBranch) do
4
+ def set_upstream
5
+ true
6
+ end
7
+
8
+ def pull; end
9
+ def checkout_master; end
10
+ def new_branch_message; end
11
+ end
12
+
13
+ describe EasyAuto::CreateBranch do
14
+
15
+ subject { CBMock.new 'test-123' }
16
+ let(:git) { subject.git }
17
+
18
+ after do
19
+ git.checkout_master
20
+ git.delete_local_branch 'test-123'
21
+ end
22
+
23
+ it 'has easy utilities included' do
24
+ subject.must_respond_to :ask
25
+ end
26
+
27
+ describe 'usage' do
28
+ it 'should acknowledge -h' do
29
+ subject = CBMock.new '-h'
30
+ subject.help_request?.must_equal true
31
+ end
32
+
33
+ it 'should acknowledge --help' do
34
+ subject = CBMock.new '--help'
35
+ subject.help_request?.must_equal true
36
+ end
37
+
38
+ it 'should accept branch names' do
39
+ subject = CBMock.new 'new-branch-name'
40
+ subject.help_request?.must_equal false
41
+ end
42
+ end
43
+
44
+ describe 'command line invocation' do
45
+ # add webmock to stop network io
46
+ # do stuff with ARGV in create-branch bin script
47
+ # get up the nerve to dm bernhardt on twitter to pair with you
48
+
49
+ it 'should return usage when invoked without arguments' do
50
+ -> { CBMock.new(nil, nil).run }.must_output "usage: create-branch <new-branch> <OPTIONAL: branch-to-track>.\n"
51
+ end
52
+
53
+ # it 'should return usage when invoked with too many arguments' do
54
+ # subject = CBMock.new 'arg', 'too', 'many'
55
+ # -> { subject.run }.must_output "usage: create-branch <new-branch> <OPTIONAL: branch-to-track>.\n"
56
+ # end
57
+
58
+ it 'should return usage when invoked with -h' do
59
+ subject = CBMock.new '-h'
60
+ -> { subject.run }.must_output "usage: create-branch <new-branch> <OPTIONAL: branch-to-track>.\n"
61
+ end
62
+
63
+ it 'should return usage when invoked with --help' do
64
+ subject = CBMock.new '--help'
65
+ -> { subject.run }.must_output "usage: create-branch <new-branch> <OPTIONAL: branch-to-track>.\n"
66
+ end
67
+
68
+ it 'should accept one param and set the branch to that' do
69
+ subject = CBMock.new 'test-123'
70
+ subject.run
71
+ git.current_branch_name.must_equal 'test-123'
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,51 @@
1
+ require_relative '../../test_helper'
2
+
3
+ Client = Class.new do
4
+ def login
5
+ 'test-user@example.com'
6
+ end
7
+ end
8
+
9
+ CreateRepoMock = Class.new(EasyAuto::CreateRepo) do
10
+ def initialize mock
11
+ @mock = mock
12
+ end
13
+
14
+ def git
15
+ @mock
16
+ end
17
+
18
+ def client
19
+ Client.new
20
+ end
21
+
22
+ def repo_name
23
+ 'test-repo'
24
+ end
25
+ end
26
+
27
+ describe EasyAuto::CreateRepo do
28
+ before do
29
+ @mock = MiniTest::Mock.new
30
+ end
31
+ subject { CreateRepoMock.new @mock }
32
+
33
+ it 'gets the username from the client' do
34
+ subject.client.login.must_equal 'test-user@example.com'
35
+ end
36
+
37
+ it 'gets the user name correctly' do
38
+ subject.username.must_equal 'test-user'
39
+ end
40
+
41
+ it 'sends the right cli_send messages in #set_remote' do
42
+ username = 'test-user'
43
+ repo_name = 'test-repo'
44
+ @mock.expect :perform, true, ["add -A"]
45
+ @mock.expect :perform, true, ["commit -m 'first commit'"]
46
+ @mock.expect :perform, true, ["remote add origin git@github.com:#{username}/#{repo_name}.git"]
47
+ @mock.expect :perform, true, ["push -u origin master"]
48
+ subject.set_remote
49
+ @mock.verify
50
+ end
51
+ end