toolshed 1.0.2 → 1.0.3
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/.gitignore +2 -0
- data/.rubocop.yml +11 -0
- data/.toolshedrc.sample +32 -0
- data/README.md +159 -2
- data/Rakefile +3 -3
- data/bin/toolshed +6 -1
- data/lib/toolshed.rb +38 -28
- data/lib/toolshed/base.rb +33 -11
- data/lib/toolshed/cli.rb +30 -38
- data/lib/toolshed/client.rb +87 -293
- data/lib/toolshed/commands/base.rb +65 -23
- data/lib/toolshed/commands/checkout_branch.rb +15 -2
- data/lib/toolshed/commands/create_branch.rb +34 -29
- data/lib/toolshed/commands/create_pivotal_tracker_note.rb +9 -3
- data/lib/toolshed/commands/create_pull_request.rb +115 -68
- data/lib/toolshed/commands/create_ticket_comment.rb +17 -1
- data/lib/toolshed/commands/delete_branch.rb +34 -3
- data/lib/toolshed/commands/get_daily_time_update.rb +20 -3
- data/lib/toolshed/commands/list_branches.rb +16 -5
- data/lib/toolshed/commands/push_branch.rb +28 -9
- data/lib/toolshed/commands/rename_branch.rb +29 -0
- data/lib/toolshed/commands/ssh.rb +44 -3
- data/lib/toolshed/commands/ticket_information.rb +30 -4
- data/lib/toolshed/commands/update_pivotal_tracker_story_status.rb +9 -3
- data/lib/toolshed/commands/update_ticket_status.rb +8 -2
- data/lib/toolshed/entry_point.rb +89 -0
- data/lib/toolshed/git.rb +59 -0
- data/lib/toolshed/git/branch.rb +224 -0
- data/lib/toolshed/git/github.rb +45 -57
- data/lib/toolshed/git/validator.rb +14 -0
- data/lib/toolshed/logger.rb +46 -0
- data/lib/toolshed/password.rb +11 -6
- data/lib/toolshed/server_administration/ssh.rb +4 -2
- data/lib/toolshed/ticket_tracking/jira.rb +8 -6
- data/lib/toolshed/ticket_tracking/pivotal_tracker.rb +8 -6
- data/lib/toolshed/time_tracking/harvest.rb +8 -14
- data/lib/toolshed/version.rb +25 -1
- data/test/commands/checkout_branch_test.rb +11 -7
- data/test/commands/create_branch_test.rb +29 -24
- data/test/commands/create_pull_request_test.rb +39 -31
- data/test/commands/delete_branch_test.rb +35 -25
- data/test/commands/get_daily_time_update_test.rb +8 -8
- data/test/commands/push_branch_test.rb +27 -15
- data/test/commands/rename_branch_test.rb +59 -0
- data/test/git/git_helper.rb +5 -5
- data/test/git/git_test.rb +36 -31
- data/test/git/github_test.rb +9 -46
- data/test/helper.rb +11 -11
- data/test/server_administration/ssh_test.rb +1 -0
- data/test/ticket_tracking/jira_test.rb +18 -16
- data/test/time_tracking/harvest_test.rb +8 -6
- data/toolshed.gemspec +23 -20
- metadata +95 -46
- data/bin/toolshed.rb +0 -261
- data/lib/toolshed/git/git.rb +0 -119
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'toolshed/password'
|
2
|
+
|
1
3
|
require 'net/ssh'
|
2
4
|
|
3
5
|
module Toolshed
|
@@ -81,8 +83,8 @@ module Toolshed
|
|
81
83
|
end
|
82
84
|
|
83
85
|
def set_ssh_options
|
84
|
-
self.ssh_options.merge!({ keys: [self.keys] }) unless
|
85
|
-
self.ssh_options.merge!({ password: self.password.read_user_input_password('password') }) if
|
86
|
+
self.ssh_options.merge!({ keys: [self.keys] }) unless keys.nil? || keys.empty?
|
87
|
+
self.ssh_options.merge!({ password: self.password.read_user_input_password('password') }) if keys.nil? || keys.empty?
|
86
88
|
end
|
87
89
|
end
|
88
90
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'jira'
|
2
|
+
|
1
3
|
module Toolshed
|
2
4
|
module TicketTracking
|
3
5
|
class Jira < Base
|
@@ -8,11 +10,11 @@ module Toolshed
|
|
8
10
|
attr_accessor :project, :client, :owner, :ticket, :default_pull_request_title_format
|
9
11
|
|
10
12
|
def initialize(options={})
|
11
|
-
username = (options[:username].nil?) ? Toolshed::Client
|
12
|
-
password = (options[:password].nil?) ? Toolshed::Client
|
13
|
+
username = (options[:username].nil?) ? Toolshed::Client.instance.ticket_tracker_username : options[:username]
|
14
|
+
password = (options[:password].nil?) ? Toolshed::Client.instance.ticket_tracker_password : options[:password]
|
13
15
|
|
14
|
-
self.owner = Toolshed::Client.ticket_tracker_owner
|
15
|
-
self.default_pull_request_title_format = Toolshed::Client.default_pull_request_title_format ||= "[summary]"
|
16
|
+
self.owner = Toolshed::Client.instance.ticket_tracker_owner
|
17
|
+
self.default_pull_request_title_format = Toolshed::Client.instance.default_pull_request_title_format ||= "[summary]"
|
16
18
|
|
17
19
|
self.client = JIRA::Client.new({
|
18
20
|
username: username,
|
@@ -71,7 +73,7 @@ module Toolshed
|
|
71
73
|
|
72
74
|
class << self
|
73
75
|
def username
|
74
|
-
return Toolshed::Client
|
76
|
+
return Toolshed::Client.instance.ticket_tracker_username unless Toolshed::Client.instance.ticket_tracker_username.nil?
|
75
77
|
|
76
78
|
# prompt to ask for username
|
77
79
|
puts "Jira username? "
|
@@ -79,7 +81,7 @@ module Toolshed
|
|
79
81
|
end
|
80
82
|
|
81
83
|
def password
|
82
|
-
return Toolshed::Client
|
84
|
+
return Toolshed::Client.instance.ticket_tracker_password unless Toolshed::Client.instance.ticket_tracker_password.nil?
|
83
85
|
|
84
86
|
# prompt to ask for password
|
85
87
|
system "stty -echo"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'pivotal-tracker'
|
2
|
+
|
1
3
|
module Toolshed
|
2
4
|
module TicketTracking
|
3
5
|
class PivotalTracker < Base
|
@@ -9,9 +11,9 @@ module Toolshed
|
|
9
11
|
attr_accessor :project_id, :token, :story, :default_pull_request_title_format
|
10
12
|
|
11
13
|
def initialize(options={})
|
12
|
-
username = Toolshed::Client
|
13
|
-
password = Toolshed::Client
|
14
|
-
self.default_pull_request_title_format = Toolshed::Client.default_pull_request_title_format ||= "[title]"
|
14
|
+
username = Toolshed::Client.instance.pivotal_tracker_username
|
15
|
+
password = Toolshed::Client.instance.pivotal_tracker_password
|
16
|
+
self.default_pull_request_title_format = Toolshed::Client.instance.default_pull_request_title_format ||= "[title]"
|
15
17
|
|
16
18
|
unless (options[:username].nil?)
|
17
19
|
username = options[:username]
|
@@ -23,7 +25,7 @@ module Toolshed
|
|
23
25
|
|
24
26
|
self.token = ::PivotalTracker::Client.token(username, password)
|
25
27
|
|
26
|
-
self.project_id = (options[:project_id].nil?) ? Toolshed::Client.default_pivotal_tracker_project_id : options[:project_id]
|
28
|
+
self.project_id = (options[:project_id].nil?) ? Toolshed::Client.instance.default_pivotal_tracker_project_id : options[:project_id]
|
27
29
|
@pt_project = ::PivotalTracker::Project.find(self.project_id)
|
28
30
|
self.story = @pt_project.stories.find(options[:ticket_id])
|
29
31
|
end
|
@@ -74,7 +76,7 @@ module Toolshed
|
|
74
76
|
|
75
77
|
class << self
|
76
78
|
def username
|
77
|
-
username = Toolshed::Client
|
79
|
+
username = Toolshed::Client.instance.pivotal_tracker_username
|
78
80
|
if (username.nil?)
|
79
81
|
# prompt to ask for username
|
80
82
|
puts "PivotalTracker username? "
|
@@ -85,7 +87,7 @@ module Toolshed
|
|
85
87
|
end
|
86
88
|
|
87
89
|
def password
|
88
|
-
password = Toolshed::Client
|
90
|
+
password = Toolshed::Client.instance.pivotal_tracker_password
|
89
91
|
if (password.nil?)
|
90
92
|
# prompt to ask for password
|
91
93
|
system "stty -echo"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'harvested'
|
2
|
+
|
1
3
|
module Toolshed
|
2
4
|
module TimeTracking
|
3
5
|
class Harvest
|
@@ -9,21 +11,13 @@ module Toolshed
|
|
9
11
|
attr_accessor :harvest_client, :project_id, :line_break, :start_list_item, :end_list_item, :start_unorder_list, :end_unorder_list, :format
|
10
12
|
|
11
13
|
def initialize(options={})
|
12
|
-
username = Toolshed::Client
|
13
|
-
password = Toolshed::Client
|
14
|
-
owner = Toolshed::Client.time_tracking_owner
|
15
|
-
|
16
|
-
unless (options[:username].nil?)
|
17
|
-
username = options[:username]
|
18
|
-
end
|
14
|
+
username = Toolshed::Client.instance.time_tracking_username
|
15
|
+
password = Toolshed::Client.instance.time_tracking_password
|
16
|
+
owner = Toolshed::Client.instance.time_tracking_owner
|
19
17
|
|
20
|
-
unless
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
unless (options[:sub_domain].nil?)
|
25
|
-
owner = options[:sub_domain]
|
26
|
-
end
|
18
|
+
username = options[:username] unless options[:username].nil?
|
19
|
+
password = options[:password] unless options[:password].nil?
|
20
|
+
owner = options[:sub_domain] unless options[:sub_domain].nil?
|
27
21
|
|
28
22
|
self.harvest_client = ::Harvest.client(subdomain: owner, username: username, password: password)
|
29
23
|
self.project_id = options[:project_id] unless !options.has_key?(:project_id)
|
data/lib/toolshed/version.rb
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Module for toolshed
|
1
4
|
module Toolshed
|
2
|
-
VERSION =
|
5
|
+
VERSION = '1.0.3'
|
6
|
+
|
7
|
+
# Display the version information with the toolshed banner
|
8
|
+
class Version
|
9
|
+
def self.banner
|
10
|
+
formatted_version = format('%80s', "Version: #{Toolshed::VERSION}")
|
11
|
+
formatted_authors_string = format('%80s', 'Authors: Jake Waller')
|
12
|
+
puts <<-EOS
|
13
|
+
______ ___ ___ _ _____ __ __ ___ ___
|
14
|
+
| | / \ / \ | | / ___/| | | / _]| \
|
15
|
+
| || || || | ( \_ | | | / [_ | \
|
16
|
+
|_| |_|| O || O || |___ \__ || _ || _]| D |
|
17
|
+
| | | || || | / \ || | || [_ | |
|
18
|
+
| | | || || | \ || | || || |
|
19
|
+
|__| \___/ \___/ |_____| \___||__|__||_____||_____|
|
20
|
+
|
21
|
+
#{formatted_version}
|
22
|
+
#{formatted_authors_string}
|
23
|
+
EOS
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
end
|
3
27
|
end
|
@@ -2,19 +2,23 @@ require 'commands/commands_helper'
|
|
2
2
|
require 'toolshed/commands/checkout_branch'
|
3
3
|
|
4
4
|
class CheckoutBranchTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@branch = Toolshed::Git::Branch.new
|
7
|
+
Toolshed.expects(:die).at_least(0).returns('die')
|
8
|
+
end
|
9
|
+
|
5
10
|
def test_checkout_branch
|
6
|
-
current_branch =
|
11
|
+
current_branch = @branch.name
|
7
12
|
|
8
13
|
new_branch_name = random_branch_name
|
9
14
|
create_and_checkout_branch(new_branch_name)
|
10
15
|
|
11
|
-
|
12
|
-
|
13
|
-
assert_match /Switched to 'master'/, output
|
16
|
+
results = Toolshed::Commands::CheckoutBranch.new.execute({}, { branch_name: current_branch })
|
17
|
+
assert_equal 'die', results
|
14
18
|
end
|
15
19
|
|
16
20
|
def test_checkout_branch_prompt
|
17
|
-
current_branch =
|
21
|
+
current_branch = @branch.name
|
18
22
|
|
19
23
|
new_branch_name = random_branch_name
|
20
24
|
create_and_checkout_branch(new_branch_name)
|
@@ -22,7 +26,7 @@ class CheckoutBranchTest < Test::Unit::TestCase
|
|
22
26
|
# stub the possible input
|
23
27
|
Toolshed::Commands::CheckoutBranch.any_instance.stubs(:read_user_input).returns(current_branch)
|
24
28
|
|
25
|
-
|
26
|
-
|
29
|
+
results = Toolshed::Commands::CheckoutBranch.new.execute({})
|
30
|
+
assert_equal 'die', results
|
27
31
|
end
|
28
32
|
end
|
@@ -2,63 +2,68 @@ require 'commands/commands_helper'
|
|
2
2
|
require 'toolshed/commands/create_branch'
|
3
3
|
|
4
4
|
class CreateBranchTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@branch = Toolshed::Git::Branch.new
|
7
|
+
Toolshed.expects(:die).at_least(0).returns('die')
|
8
|
+
end
|
9
|
+
|
5
10
|
def test_create_new_branch_passing_in_branch_name_branch_from
|
6
|
-
Toolshed::Client.pull_from_remote_name = 'origin'
|
7
|
-
Toolshed::Client.push_to_remote_name = 'origin'
|
11
|
+
Toolshed::Client.instance.pull_from_remote_name = 'origin'
|
12
|
+
Toolshed::Client.instance.push_to_remote_name = 'origin'
|
8
13
|
|
9
|
-
current_branch =
|
14
|
+
current_branch = @branch.name
|
10
15
|
new_branch_name = ::Faker::Lorem.word.downcase
|
11
16
|
|
12
|
-
output =
|
17
|
+
output = Toolshed::Commands::CreateBranch.new.execute({}, { branch_name: new_branch_name, branch_from: 'development' })
|
13
18
|
|
14
|
-
assert_match
|
19
|
+
assert_match 'die', output
|
15
20
|
|
16
|
-
assert_equal new_branch_name,
|
17
|
-
assert_equal 'development', Toolshed::Git::
|
21
|
+
assert_equal new_branch_name, @branch.name
|
22
|
+
assert_equal 'development', Toolshed::Git::Branch.from
|
18
23
|
|
19
|
-
Toolshed::Git::
|
24
|
+
Toolshed::Git::Branch.checkout(current_branch)
|
20
25
|
delete_branch(new_branch_name)
|
21
26
|
end
|
22
27
|
|
23
28
|
def test_create_new_branch_not_passing_in_branch_name_or_branch_from
|
24
|
-
Toolshed::Client.pull_from_remote_name = 'origin'
|
25
|
-
Toolshed::Client.push_to_remote_name = 'origin'
|
29
|
+
Toolshed::Client.instance.pull_from_remote_name = 'origin'
|
30
|
+
Toolshed::Client.instance.push_to_remote_name = 'origin'
|
26
31
|
|
27
|
-
current_branch =
|
32
|
+
current_branch = @branch.name
|
28
33
|
new_branch_name = ::Faker::Lorem.word.downcase
|
29
34
|
|
30
35
|
# stub the possible input
|
31
36
|
Toolshed::Commands::CreateBranch.any_instance.stubs(:read_user_input_branch_name).returns(new_branch_name)
|
32
37
|
Toolshed::Commands::CreateBranch.any_instance.stubs(:read_user_input_branch_from).returns('development')
|
33
38
|
|
34
|
-
output =
|
39
|
+
output = Toolshed::Commands::CreateBranch.new.execute({})
|
35
40
|
|
36
|
-
assert_match
|
41
|
+
assert_match 'die', output
|
37
42
|
|
38
|
-
assert_equal new_branch_name,
|
39
|
-
assert_equal 'development', Toolshed::Git::
|
43
|
+
assert_equal new_branch_name, @branch.name
|
44
|
+
assert_equal 'development', Toolshed::Git::Branch.from
|
40
45
|
|
41
|
-
Toolshed::Git::
|
46
|
+
Toolshed::Git::Branch.checkout(current_branch)
|
42
47
|
delete_branch(new_branch_name)
|
43
48
|
end
|
44
49
|
|
45
50
|
def test_create_new_branch_without_passing_in_branch_from
|
46
|
-
Toolshed::Client.pull_from_remote_name = 'origin'
|
47
|
-
Toolshed::Client.push_to_remote_name = 'origin'
|
51
|
+
Toolshed::Client.instance.pull_from_remote_name = 'origin'
|
52
|
+
Toolshed::Client.instance.push_to_remote_name = 'origin'
|
48
53
|
|
49
|
-
current_branch =
|
54
|
+
current_branch = @branch.name
|
50
55
|
new_branch_name = ::Faker::Lorem.word.downcase
|
51
56
|
|
52
57
|
# stub the possible input
|
53
58
|
Toolshed::Commands::CreateBranch.any_instance.stubs(:read_user_input_branch_name).returns(new_branch_name)
|
54
59
|
|
55
|
-
output =
|
60
|
+
output = Toolshed::Commands::CreateBranch.new.execute({}, { branch_name: new_branch_name })
|
56
61
|
|
57
|
-
assert_match
|
58
|
-
assert_equal new_branch_name,
|
59
|
-
assert_equal 'master', Toolshed::Git::
|
62
|
+
assert_match 'die', output
|
63
|
+
assert_equal new_branch_name, @branch.name
|
64
|
+
assert_equal 'master', Toolshed::Git::Branch.from
|
60
65
|
|
61
|
-
Toolshed::Git::
|
66
|
+
Toolshed::Git::Branch.checkout(current_branch)
|
62
67
|
delete_branch(new_branch_name)
|
63
68
|
end
|
64
69
|
end
|
@@ -1,15 +1,23 @@
|
|
1
1
|
require 'commands/commands_helper'
|
2
2
|
require 'toolshed/commands/create_pull_request'
|
3
|
+
require 'toolshed/git/github'
|
4
|
+
require 'toolshed/ticket_tracking/pivotal_tracker'
|
5
|
+
require 'toolshed/git/branch'
|
3
6
|
|
4
7
|
class CreatePullRequestTest < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
@branch = Toolshed::Git::Branch.new
|
10
|
+
Toolshed.expects(:die).at_least(0).returns('Exiting')
|
11
|
+
end
|
12
|
+
|
5
13
|
def test_create_github_pull_request_no_ticket_tracking
|
6
|
-
Toolshed::Client.ticket_tracking_tool = ''
|
7
|
-
Toolshed::Client.git_tool = 'github'
|
8
|
-
Toolshed::Client.github_username = 'sample'
|
9
|
-
Toolshed::Client.github_password = 'sample'
|
14
|
+
Toolshed::Client.instance.ticket_tracking_tool = ''
|
15
|
+
Toolshed::Client.instance.git_tool = 'github'
|
16
|
+
Toolshed::Client.instance.github_username = 'sample'
|
17
|
+
Toolshed::Client.instance.github_password = 'sample'
|
10
18
|
|
11
|
-
Toolshed::Client.pull_from_repository_user = 'sample'
|
12
|
-
Toolshed::Client.pull_from_repository_name = 'sample_repo'
|
19
|
+
Toolshed::Client.instance.pull_from_repository_user = 'sample'
|
20
|
+
Toolshed::Client.instance.pull_from_repository_name = 'sample_repo'
|
13
21
|
|
14
22
|
# mock up the pull request
|
15
23
|
expected_result = {
|
@@ -29,34 +37,34 @@ class CreatePullRequestTest < Test::Unit::TestCase
|
|
29
37
|
body: {
|
30
38
|
title: 'Sample',
|
31
39
|
body: 'Sample Body',
|
32
|
-
head: "#{Toolshed::Client.github_username}:#{
|
33
|
-
base: Toolshed::Git::
|
40
|
+
head: "#{Toolshed::Client.instance.github_username}:#{@branch.name}",
|
41
|
+
base: Toolshed::Git::Branch.from
|
34
42
|
}.to_json
|
35
43
|
})
|
36
44
|
|
37
45
|
HTTParty.
|
38
46
|
expects(:post).
|
39
|
-
with("#{Toolshed::Client::GITHUB_BASE_API_URL}repos/#{Toolshed::Client.pull_from_repository_user}/#{Toolshed::Client.pull_from_repository_name}/pulls", github_default_options).
|
47
|
+
with("#{Toolshed::Client::GITHUB_BASE_API_URL}repos/#{Toolshed::Client.instance.pull_from_repository_user}/#{Toolshed::Client.instance.pull_from_repository_name}/pulls", github_default_options).
|
40
48
|
returns(http_party_mock)
|
41
49
|
|
42
50
|
# stub the possible input
|
43
51
|
Toolshed::Commands::CreatePullRequest.any_instance.stubs(:read_user_input_add_note_to_ticket).returns(false)
|
44
52
|
|
45
|
-
|
46
|
-
|
53
|
+
result = Toolshed::Commands::CreatePullRequest.new.execute({}, { title: 'Sample', body: 'Sample Body' })
|
54
|
+
assert_equal 'github.com/pulls/1', result.pull_request_url
|
47
55
|
end
|
48
56
|
|
49
57
|
def test_create_github_pull_request_with_pivotal_tracker
|
50
|
-
Toolshed::Client.ticket_tracking_tool = 'pivotal_tracker'
|
51
|
-
Toolshed::Client.git_tool = 'github'
|
52
|
-
Toolshed::Client.github_username = 'sample'
|
53
|
-
Toolshed::Client.github_password = 'sample'
|
54
|
-
Toolshed::Client.pivotal_tracker_username = 'ptusername'
|
55
|
-
Toolshed::Client.pivotal_tracker_password = 'ptpassword'
|
56
|
-
Toolshed::Client.default_pivotal_tracker_project_id = '1234'
|
57
|
-
Toolshed::Client.pull_from_repository_user = 'sample'
|
58
|
-
Toolshed::Client.pull_from_repository_name = 'sample_repo'
|
59
|
-
Toolshed::Client.use_defaults = true
|
58
|
+
Toolshed::Client.instance.ticket_tracking_tool = 'pivotal_tracker'
|
59
|
+
Toolshed::Client.instance.git_tool = 'github'
|
60
|
+
Toolshed::Client.instance.github_username = 'sample'
|
61
|
+
Toolshed::Client.instance.github_password = 'sample'
|
62
|
+
Toolshed::Client.instance.pivotal_tracker_username = 'ptusername'
|
63
|
+
Toolshed::Client.instance.pivotal_tracker_password = 'ptpassword'
|
64
|
+
Toolshed::Client.instance.default_pivotal_tracker_project_id = '1234'
|
65
|
+
Toolshed::Client.instance.pull_from_repository_user = 'sample'
|
66
|
+
Toolshed::Client.instance.pull_from_repository_name = 'sample_repo'
|
67
|
+
Toolshed::Client.instance.use_defaults = true
|
60
68
|
|
61
69
|
# mock up the pull request
|
62
70
|
expected_result = {
|
@@ -76,14 +84,14 @@ class CreatePullRequestTest < Test::Unit::TestCase
|
|
76
84
|
body: {
|
77
85
|
title: 'Sample',
|
78
86
|
body: 'Sample Body',
|
79
|
-
head: "#{Toolshed::Client.github_username}:#{
|
80
|
-
base: Toolshed::Git::
|
87
|
+
head: "#{Toolshed::Client.instance.github_username}:#{@branch.name}",
|
88
|
+
base: Toolshed::Git::Branch.from
|
81
89
|
}.to_json
|
82
90
|
})
|
83
91
|
|
84
92
|
HTTParty.
|
85
93
|
expects(:post).
|
86
|
-
with("#{Toolshed::Client::GITHUB_BASE_API_URL}repos/#{Toolshed::Client.pull_from_repository_user}/#{Toolshed::Client.pull_from_repository_name}/pulls", github_default_options).
|
94
|
+
with("#{Toolshed::Client::GITHUB_BASE_API_URL}repos/#{Toolshed::Client.instance.pull_from_repository_user}/#{Toolshed::Client.instance.pull_from_repository_name}/pulls", github_default_options).
|
87
95
|
returns(http_party_mock)
|
88
96
|
|
89
97
|
# mock up the pivotal_tracker stuff
|
@@ -96,7 +104,7 @@ class CreatePullRequestTest < Test::Unit::TestCase
|
|
96
104
|
pivotal_tracker_mock.stubs(:id => '1')
|
97
105
|
|
98
106
|
PivotalTracker::Project.expects(:find).
|
99
|
-
with(Toolshed::Client.default_pivotal_tracker_project_id).
|
107
|
+
with(Toolshed::Client.instance.default_pivotal_tracker_project_id).
|
100
108
|
returns(pivotal_tracker_mock)
|
101
109
|
|
102
110
|
# mock up the story information
|
@@ -120,14 +128,14 @@ class CreatePullRequestTest < Test::Unit::TestCase
|
|
120
128
|
Toolshed::Commands::CreatePullRequest.any_instance.stubs(:read_user_input_ticket_tracker_ticket_id).returns('1')
|
121
129
|
Toolshed::Commands::CreatePullRequest.any_instance.stubs(:read_user_input_add_note_to_ticket).returns(false)
|
122
130
|
|
123
|
-
|
124
|
-
|
131
|
+
result = Toolshed::Commands::CreatePullRequest.new.execute({}, { title: 'Sample', body: 'Sample Body' })
|
132
|
+
assert_equal 'github.com/pulls/1', result.pull_request_url
|
125
133
|
end
|
126
134
|
|
127
135
|
def test_create_github_pull_request_with_invalid_ticket_tracker
|
128
|
-
Toolshed::Client.ticket_tracking_tool = 'unfuddle'
|
129
|
-
Toolshed::Client.git_tool = 'github'
|
130
|
-
|
131
|
-
|
136
|
+
Toolshed::Client.instance.ticket_tracking_tool = 'unfuddle'
|
137
|
+
Toolshed::Client.instance.git_tool = 'github'
|
138
|
+
result = Toolshed::Commands::CreatePullRequest.new.execute({}, { title: 'Sample', body: 'Sample Body' })
|
139
|
+
assert_equal nil, result.pull_request_url
|
132
140
|
end
|
133
141
|
end
|
@@ -2,72 +2,82 @@ require 'commands/commands_helper'
|
|
2
2
|
require 'toolshed/commands/delete_branch'
|
3
3
|
|
4
4
|
class DeleteBranchTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Toolshed.expects(:die).at_least(0).returns('Exiting')
|
7
|
+
@branch = Toolshed::Git::Branch.new
|
8
|
+
end
|
9
|
+
|
5
10
|
def test_delete_branch_with_branch_name_passed
|
6
|
-
current_branch =
|
11
|
+
current_branch = @branch.name
|
7
12
|
|
8
13
|
new_branch_name = random_branch_name
|
9
14
|
create_and_checkout_branch(new_branch_name, 'master')
|
10
15
|
|
11
16
|
# go to the remote repo and verify it exists
|
12
17
|
Dir.chdir(File.join(TEST_ROOT, "remote"))
|
13
|
-
remote_current_branch =
|
14
|
-
Toolshed::Git::
|
15
|
-
assert_equal new_branch_name,
|
16
|
-
Toolshed::Git::
|
18
|
+
remote_current_branch = @branch.name
|
19
|
+
Toolshed::Git::Branch.checkout(new_branch_name)
|
20
|
+
assert_equal new_branch_name, @branch.name
|
21
|
+
Toolshed::Git::Branch.checkout(remote_current_branch)
|
17
22
|
|
18
23
|
Dir.chdir(File.join(TEST_ROOT, "local"))
|
19
|
-
Toolshed::Git::
|
24
|
+
Toolshed::Git::Branch.checkout(current_branch)
|
20
25
|
|
21
|
-
|
22
|
-
|
26
|
+
delete_branch_command = Toolshed::Commands::DeleteBranch.new
|
27
|
+
delete_branch_command.expects(:confirm_delete).returns(true)
|
28
|
+
result = delete_branch_command.execute({}, { branch_name: new_branch_name })
|
29
|
+
assert_equal 'Exiting', result
|
23
30
|
|
24
31
|
branch_found = `git branch | grep #{new_branch_name}`
|
25
32
|
assert_equal '', branch_found
|
26
33
|
end
|
27
34
|
|
28
35
|
def test_delete_branch_with_ticket_id_only_passed
|
29
|
-
current_branch =
|
36
|
+
current_branch = @branch.name
|
30
37
|
|
31
38
|
new_branch_name = "1234333_#{random_branch_name}"
|
32
39
|
create_and_checkout_branch(new_branch_name, 'master')
|
33
40
|
|
34
41
|
# go to the remote repo and verify it exists
|
35
42
|
Dir.chdir(File.join(TEST_ROOT, "remote"))
|
36
|
-
remote_current_branch =
|
37
|
-
Toolshed::Git::
|
38
|
-
assert_equal new_branch_name,
|
39
|
-
Toolshed::Git::
|
43
|
+
remote_current_branch = @branch.name
|
44
|
+
Toolshed::Git::Branch.checkout(new_branch_name)
|
45
|
+
assert_equal new_branch_name, @branch.name
|
46
|
+
Toolshed::Git::Branch.checkout(remote_current_branch)
|
40
47
|
|
41
48
|
Dir.chdir(File.join(TEST_ROOT, "local"))
|
42
|
-
Toolshed::Git::
|
43
|
-
|
44
|
-
|
45
|
-
|
49
|
+
Toolshed::Git::Branch.checkout(current_branch)
|
50
|
+
delete_branch_command = Toolshed::Commands::DeleteBranch.new
|
51
|
+
delete_branch_command.expects(:confirm_delete).returns(true)
|
52
|
+
result = delete_branch_command.execute({}, { branch_name: '1234333' })
|
53
|
+
assert_equal 'Exiting', result
|
46
54
|
|
47
55
|
branch_found = `git branch | grep #{new_branch_name}`
|
48
56
|
assert_equal '', branch_found
|
49
57
|
end
|
50
58
|
|
51
59
|
def test_delete_branch_without_branch_name_passed
|
52
|
-
current_branch =
|
60
|
+
current_branch = @branch.name
|
53
61
|
|
54
62
|
new_branch_name = random_branch_name
|
55
63
|
create_and_checkout_branch(new_branch_name, 'master')
|
56
64
|
|
57
65
|
# go to the remote repo and verify it exists
|
58
66
|
Dir.chdir(File.join(TEST_ROOT, "remote"))
|
59
|
-
remote_current_branch =
|
60
|
-
Toolshed::Git::
|
61
|
-
assert_equal new_branch_name,
|
62
|
-
Toolshed::Git::
|
67
|
+
remote_current_branch = @branch.name
|
68
|
+
Toolshed::Git::Branch.checkout(new_branch_name)
|
69
|
+
assert_equal new_branch_name, @branch.name
|
70
|
+
Toolshed::Git::Branch.checkout(remote_current_branch)
|
63
71
|
|
64
72
|
Dir.chdir(File.join(TEST_ROOT, "local"))
|
65
|
-
Toolshed::Git::
|
73
|
+
Toolshed::Git::Branch.checkout(current_branch)
|
66
74
|
|
67
75
|
Toolshed::Commands::DeleteBranch.any_instance.stubs(:read_user_input).returns(new_branch_name)
|
68
76
|
|
69
|
-
|
70
|
-
|
77
|
+
delete_branch_command = Toolshed::Commands::DeleteBranch.new
|
78
|
+
delete_branch_command.expects(:confirm_delete).returns(true)
|
79
|
+
result = delete_branch_command.execute({})
|
80
|
+
assert_equal 'Exiting', result
|
71
81
|
|
72
82
|
branch_found = `git branch | grep #{new_branch_name}`
|
73
83
|
assert_equal '', branch_found
|