toolshed 0.0.4 → 0.0.5

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: 8d7f36f7fce51b7916aad6741cf12e62ed18aebd
4
- data.tar.gz: 9e1784114b5981be500e3b21a919f7d7c6ea6e3d
3
+ metadata.gz: b797dd6cddae38cc2f9e8c1f7916108727dac003
4
+ data.tar.gz: 1a39f45e8b150de27a7c6eecbc5fdf9668644b8f
5
5
  SHA512:
6
- metadata.gz: 50b81af0fbc10f5f14c453e61a841ec36f14283b6eb3792034175bddc681c0b4e33c8d3793149bb7a886e3ea7155d10323e98f907b2fe3b8b8c90b0cfb05f288
7
- data.tar.gz: d19487356cfdebde1a0dfeca6c2008dda41de775ce9c5ee2e9dcd6e8ffac15c2bf5631d15ea1fa5e7c5b3c399533a8810ca3dee1a459f81d7d569c7957ce451c
6
+ metadata.gz: 09b0e55117a1bc5bc9d62464a26b576576040ef8be4ecf3b6e6b44e3f5d847aebaf9784437f0b125957fae55b07880bf7eeec2ec292d93c5ef08ec999f68eb40
7
+ data.tar.gz: f5782e3a4ebbb447f45b83544e962c101e2cb6991e737d9b7c5fc081de15a7f2300bb6af34392e9b547539ed8518b29dc494877ef181c69d3baf38aea225756c
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Toolshed
2
2
 
3
- TODO: Write a gem description
3
+ Toolshed is a utility gem meant to make small tasks faster. This includes things like making a pull request up to Github all the way to creating a branch. This gem can be extended to used else where also.
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,7 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ After install the gem run toolshed for help menu. It will list the available commands.
22
22
 
23
23
  ## Contributing
24
24
 
data/bin/toolshed.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  $:.unshift(File.dirname(__FILE__) + '/../lib')
4
-
5
4
  require 'toolshed'
6
5
  require 'toolshed/cli'
7
6
 
@@ -11,23 +10,24 @@ require 'optparse'
11
10
 
12
11
  def usage
13
12
  $stderr.puts <<EOF
14
- This is the command line tool for toolshed. More information about toolshed can
13
+ Command line tool for toolshed. More information about toolshed can
15
14
  be found at https://github.com/wallerjake/toolshed
16
15
 
17
- Before using this tool you should create a file called .toolshed in your home directory
18
- and add the following to that file:
16
+ Before using this tool you should create a file called .toolshedrc in your projects directory or home directory if you want to use the settings globally.
17
+ Note that it will only read one file which ever file is closest to the directory you are in. Then and add the following to that file:
19
18
 
20
- use_pivotal_tracker: true
21
- pivotal_tracker_username: [pivotal_tracker_username]
22
- pivotal_tracker_password: [pivotal_tracker_password]
23
- default_pivotal_tracker_project_id: [project_id]
24
- github_username: [github_username]
25
- github_password: [github_password]
26
- branched_from_remote_name: [branched_from_remote_name]
27
- branched_from_user: [branched_from_username]
28
- branched_from_repo_name: [branched_from_repo_name]
29
- push_from_user: [push_from_yourself]
30
- push_to_myself: [push_to_yourself]
19
+ use_pivotal_tracker: true (required)
20
+ pivotal_tracker_username: [pivotal_tracker_username] (optional)
21
+ pivotal_tracker_password: [pivotal_tracker_password] (optional)
22
+ default_pivotal_tracker_project_id: [project_id] (optional)
23
+ github_username: [github_username] (optional)
24
+ github_password: [github_password] (optional)
25
+ branched_from_remote_name: [branched_from_remote_name] (required)
26
+ branched_from_user: [branched_from_username] (required)
27
+ branched_from_repo_name: [branched_from_repo_name] (required)
28
+ push_from_user: [push_from_yourself] (required)
29
+ push_to_myself: [push_to_yourself] (required)
30
+ use_git_submodules: false (optional)
31
31
 
32
32
  == Commands
33
33
 
@@ -40,6 +40,9 @@ create_github_pull_request # create a github pull request based on
40
40
  get_pivotal_tracker_story_information # Get the ticket information from a PivotalTracker story based on project_id and story_id
41
41
  create_pivotal_tracker_note # Create a note for a specific PivotalTracker story based on project_id and story_id
42
42
  update_pivotal_tracker_story_status # Update the status of PivotalTracker story
43
+ create_git_branch # Create a git branch and push it to your local repository
44
+ checkout_git_branch # Checkout a git branch and update the submodules if you use them
45
+ push_git_branch # Push your current working branch to your own repository
43
46
  EOF
44
47
  end
45
48
 
@@ -47,19 +50,29 @@ if $0.split("/").last == 'toolshed'
47
50
  options = {}
48
51
 
49
52
  global = OptionParser.new do |opts|
50
- opts.on("-u", "--username [ARG]") do |username|
51
- # Set username here
53
+ opts.on("-u", "--github_username [ARG]") do |username|
54
+ Toolshed::Client.github_username = username
55
+ end
56
+ opts.on("-p", "--github_password [ARG]") do |password|
57
+ Toolshed::Client.github_password = password
58
+ end
59
+ opts.on("-u", "--pivotal_tracker_username [ARG]") do |username|
60
+ Toolshed::Client.pivotal_tracker_username = username
61
+ end
62
+ opts.on("-p", "--pivotal_tracker_password [ARG]") do |password|
63
+ Toolshed::Client.pivotal_tracker_password = password
52
64
  end
53
- opts.on("-p", "--password [ARG]") do |password|
54
- # Set password here
65
+ opts.on("-d", "--debug [ARG]") do
66
+ Toolshed::Client.debug = true
55
67
  end
56
- opts.on("-d") do
57
- # Set debug here
68
+ opts.on("-h", "--help", "Help") do
69
+ usage
58
70
  end
59
71
  end
60
72
 
61
- subcommands = { }
73
+ subcommands = {}
62
74
 
75
+ global.order!
63
76
  command = ARGV.shift
64
77
  if command.nil? || command == 'help'
65
78
  usage
data/lib/toolshed/cli.rb CHANGED
@@ -25,13 +25,18 @@ module Toolshed
25
25
  'create_pivotal_tracker_note' => Toolshed::Commands::CreatePivotalTrackerNote,
26
26
  'get_pivotal_tracker_story_information' => Toolshed::Commands::GetPivotalTrackerStoryInformation,
27
27
  'update_pivotal_tracker_story_status' => Toolshed::Commands::UpdatePivotalTrackerStoryStatus,
28
+ 'create_git_branch' => Toolshed::Commands::CreateGitBranch,
29
+ 'checkout_git_branch' => Toolshed::Commands::CheckoutGitBranch,
30
+ 'push_git_branch' => Toolshed::Commands::PushGitBranch,
28
31
  }
29
32
  end
30
33
  end
31
-
32
34
  end
33
35
 
34
36
  require 'toolshed/commands/create_github_pull_request'
35
37
  require 'toolshed/commands/create_pivotal_tracker_note'
36
38
  require 'toolshed/commands/get_pivotal_tracker_story_information'
37
39
  require 'toolshed/commands/update_pivotal_tracker_story_status'
40
+ require 'toolshed/commands/create_git_branch'
41
+ require 'toolshed/commands/checkout_git_branch'
42
+ require 'toolshed/commands/push_git_branch'
@@ -72,6 +72,14 @@ module Toolshed
72
72
  @push_to_myself = push_to_myself
73
73
  end
74
74
 
75
+ def self.use_git_submodules
76
+ @use_git_submodules
77
+ end
78
+
79
+ def self.use_git_submodules=(use_git_submodules)
80
+ @use_git_submodules = use_git_submodules
81
+ end
82
+
75
83
 
76
84
 
77
85
  # pivotal tracker config
@@ -126,7 +134,21 @@ module Toolshed
126
134
 
127
135
  def self.load_credentials(path = config_path)
128
136
  begin
129
- credentials = YAML.load_file(File.expand_path(path))
137
+ dir = Dir.pwd
138
+ while File.expand_path(dir) != '/' do
139
+ if (File.exists? "#{dir}/.toolshedrc")
140
+ loaded_from_path = "#{dir}/.toolshedrc"
141
+ break
142
+ elsif (File.exists? "#{dir}/.toolshed")
143
+ loaded_from_path = "#{dir}/.toolshed"
144
+ warn "[DEPRECATION] `.toolshed` file is being deprecated. Please use a `.toolshedrc` file instead."
145
+ break
146
+ end
147
+
148
+ dir = File.join dir, '..'
149
+ end
150
+
151
+ credentials = YAML.load_file(File.expand_path(loaded_from_path))
130
152
  self.github_username ||= credentials['github_username']
131
153
  self.github_password ||= credentials['github_password']
132
154
  self.pivotal_tracker_username ||= credentials['pivotal_tracker_username']
@@ -138,8 +160,9 @@ module Toolshed
138
160
  self.push_from_user ||= credentials['push_from_user']
139
161
  self.push_to_myself ||= credentials['push_to_myself']
140
162
  self.use_pivotal_tracker ||= credentials['use_pivotal_tracker']
163
+ self.use_git_submodules ||= credentials['use_git_submodules']
141
164
  @credentials_loaded = true
142
- puts "Credentials loaded from #{path}"
165
+ puts "Credentials loaded from #{File.absolute_path(loaded_from_path)}"
143
166
  rescue => error
144
167
  puts "Error loading your credentials: #{error.message}"
145
168
  exit 1
@@ -0,0 +1,23 @@
1
+ module Toolshed
2
+ module Commands
3
+ class CheckoutGitBranch
4
+ def execute(args, options = {})
5
+ print "Ticket ID or Branch Name? "
6
+ ticket_id = $stdin.gets.chomp
7
+
8
+ branch_name = `git branch | grep \"#{ticket_id}\"`.gsub("*", "").strip
9
+
10
+ git_submodule_command = ''
11
+ if (Toolshed::Client.use_git_submodules)
12
+ print "Update Submodules (y/n)? "
13
+ update_submodules = $stdin.gets.chomp
14
+ if (update_submodules == 'y')
15
+ git_submodule_command = "git submodule update --init;"
16
+ end
17
+ end
18
+
19
+ system("git checkout #{branch_name}; #{git_submodule_command}")
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ module Toolshed
2
+ module Commands
3
+ class CreateGitBranch
4
+ def execute(args, options = {})
5
+ print "Branch text? "
6
+ branch_name = $stdin.gets.chomp
7
+
8
+ print "Branch from? "
9
+ branch_from = $stdin.gets.chomp
10
+
11
+ git_submodule_command = ''
12
+ if (Toolshed::Client.use_git_submodules)
13
+ print "Update Submodules (y/n)? "
14
+ update_submodules = $stdin.gets.chomp
15
+ if (update_submodules == 'y')
16
+ git_submodule_command = "git submodule update --init;"
17
+ end
18
+ end
19
+
20
+ branch_name = branch_name.strip.downcase.tr(" ", "_").gsub("-", "").gsub("&", "").gsub("/", "_").gsub(".", "_").gsub("'", "").gsub("__", "_").gsub(":", "")
21
+ output_text = "git remote update; git checkout -b #{branch_name} #{Toolshed::Client.branched_from_remote_name}/#{branch_from}; #{git_submodule_command} git push #{Toolshed::Client.push_to_myself} #{branch_name}"
22
+
23
+ puts "Creating branch.."
24
+ system(output_text)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -10,11 +10,10 @@ module Toolshed
10
10
  if (project_id == '')
11
11
  project_id = Toolshed::Client.default_pivotal_tracker_project_id
12
12
  end
13
-
14
- pivotal_tracker = Toolshed::PivotalTracker.new({ project_id: project_id})
13
+ pivotal_tracker = Toolshed::PivotalTracker.new({ project_id: project_id, username: Toolshed::PivotalTracker.username, password: Toolshed::PivotalTracker.password })
15
14
  end
16
15
 
17
- github = Toolshed::Github.new
16
+ github = Toolshed::Github.new({ username: Toolshed::Github.username, password: Toolshed::Github.password })
18
17
 
19
18
  # see what branch is checked out and where we are branched from
20
19
  puts "Current Branch: #{github.branch_name}"
@@ -8,7 +8,7 @@ module Toolshed
8
8
  project_id = Toolshed::Client.default_pivotal_tracker_project_id
9
9
  end
10
10
 
11
- pivotal_tracker = Toolshed::PivotalTracker.new({ project_id: project_id})
11
+ pivotal_tracker = Toolshed::PivotalTracker.new({ project_id: project_id, username: Toolshed::PivotalTracker.username, password: Toolshed::PivotalTracker.password })
12
12
  github = Toolshed::Github.new
13
13
 
14
14
  default_story_id = Toolshed::PivotalTracker::story_id_from_branch_name(github.branch_name)
@@ -9,7 +9,7 @@ module Toolshed
9
9
  project_id = Toolshed::Client.default_pivotal_tracker_project_id
10
10
  end
11
11
 
12
- pivotal_tracker = Toolshed::PivotalTracker.new({ project_id: project_id})
12
+ pivotal_tracker = Toolshed::PivotalTracker.new({ project_id: project_id, username: Toolshed::PivotalTracker.username, password: Toolshed::PivotalTracker.password })
13
13
  github = Toolshed::Github.new
14
14
 
15
15
  default_story_id = Toolshed::PivotalTracker::story_id_from_branch_name(github.branch_name)
@@ -20,9 +20,9 @@ module Toolshed
20
20
  end
21
21
 
22
22
  result = pivotal_tracker.story_information(story_id)
23
- puts "Name: #{result.name}"
24
- puts "Url: #{result.url}"
25
- puts "Description: #{result.description}"
23
+ result.instance_variables.each do |name, value|
24
+ puts "#{name}: #{result.instance_variable_get(name).inspect}"
25
+ end
26
26
  exit
27
27
  rescue => e
28
28
  puts e.message
@@ -0,0 +1,10 @@
1
+ module Toolshed
2
+ module Commands
3
+ class PushGitBranch
4
+ def execute(args, options = {})
5
+ branch_name = `git rev-parse --abbrev-ref HEAD`
6
+ system("git push #{Toolshed::Client.push_to_myself} #{branch_name}")
7
+ end
8
+ end
9
+ end
10
+ end
@@ -10,7 +10,7 @@ module Toolshed
10
10
  project_id = Toolshed::Client.default_pivotal_tracker_project_id
11
11
  end
12
12
 
13
- pivotal_tracker = Toolshed::PivotalTracker.new({ project_id: project_id})
13
+ pivotal_tracker = Toolshed::PivotalTracker.new({ project_id: project_id, username: Toolshed::PivotalTracker.username, password: Toolshed::PivotalTracker.password })
14
14
  github = Toolshed::Github.new
15
15
 
16
16
  default_story_id = Toolshed::PivotalTracker::story_id_from_branch_name(github.branch_name)
@@ -28,7 +28,9 @@ module Toolshed
28
28
 
29
29
  begin
30
30
  result = pivotal_tracker.update_story_state(story_id, story_status)
31
- puts "Story Status Updated At: #{result["created_at"]}"
31
+ result.each do |key, value|
32
+ puts "#{key}: #{value}"
33
+ end
32
34
  rescue => e
33
35
  puts e.message
34
36
  exit
@@ -3,7 +3,18 @@ module Toolshed
3
3
  include HTTParty
4
4
 
5
5
  def initialize(options={})
6
- @auth = { username: Toolshed::Client::github_username, password: Toolshed::Client::github_password }
6
+ username = Toolshed::Client::github_username
7
+ password = Toolshed::Client::github_password
8
+
9
+ unless (options[:username].nil?)
10
+ username = options[:username]
11
+ end
12
+
13
+ unless (options[:password].nil?)
14
+ password = options[:password]
15
+ end
16
+
17
+ @auth = { username: username, password: password }
7
18
  @default_options = {
8
19
  :headers => {
9
20
  "User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1309.0 Safari/537.17"
@@ -50,5 +61,29 @@ module Toolshed
50
61
  def branched_from
51
62
  branched_from = `git rev-parse --abbrev-ref --symbolic-full-name @{u}`.split('/')[-1].strip
52
63
  end
64
+
65
+ def self.username
66
+ username = Toolshed::Client::github_username
67
+ if (username.nil?)
68
+ # prompt to ask for username
69
+ puts "Github username? "
70
+ username = $stdin.gets.chomp.strip
71
+ end
72
+
73
+ return username
74
+ end
75
+
76
+ def self.password
77
+ password = Toolshed::Client::github_password
78
+ if (password.nil?)
79
+ # prompt to ask for password
80
+ system "stty -echo"
81
+ puts "Github password? "
82
+ password = $stdin.gets.chomp.strip
83
+ system "stty echo"
84
+ end
85
+
86
+ return password
87
+ end
53
88
  end
54
89
  end
@@ -7,7 +7,19 @@ module Toolshed
7
7
  attr_accessor :project_id, :token
8
8
 
9
9
  def initialize(options={})
10
- self.token = ::PivotalTracker::Client.token(Toolshed::Client.pivotal_tracker_username, Toolshed::Client.pivotal_tracker_password)
10
+ username = Toolshed::Client::pivotal_tracker_username
11
+ password = Toolshed::Client::pivotal_tracker_password
12
+
13
+ unless (options[:username].nil?)
14
+ username = options[:username]
15
+ end
16
+
17
+ unless (options[:password].nil?)
18
+ password = options[:password]
19
+ end
20
+
21
+
22
+ self.token = ::PivotalTracker::Client.token(username, password)
11
23
 
12
24
  self.project_id = (options[:project_id].nil?) ? Toolshed::Client.default_pivotal_tracker_project_id : options[:project_id]
13
25
  @pt_project = ::PivotalTracker::Project.find(self.project_id)
@@ -47,5 +59,29 @@ module Toolshed
47
59
  raise "validation errors #{response.inspect}"
48
60
  end
49
61
  end
62
+
63
+ def self.username
64
+ username = Toolshed::Client::pivotal_tracker_username
65
+ if (username.nil?)
66
+ # prompt to ask for username
67
+ puts "PivotalTracker username? "
68
+ username = $stdin.gets.chomp.strip
69
+ end
70
+
71
+ return username
72
+ end
73
+
74
+ def self.password
75
+ password = Toolshed::Client::pivotal_tracker_password
76
+ if (password.nil?)
77
+ # prompt to ask for password
78
+ system "stty -echo"
79
+ puts "PivotalTracker password? "
80
+ password = $stdin.gets.chomp.strip
81
+ system "stty echo"
82
+ end
83
+
84
+ return password
85
+ end
50
86
  end
51
87
  end
@@ -1,3 +1,3 @@
1
1
  module Toolshed
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toolshed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - test
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-31 00:00:00.000000000 Z
11
+ date: 2014-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -100,9 +100,12 @@ files:
100
100
  - lib/toolshed/base.rb
101
101
  - lib/toolshed/cli.rb
102
102
  - lib/toolshed/client.rb
103
+ - lib/toolshed/commands/checkout_git_branch.rb
104
+ - lib/toolshed/commands/create_git_branch.rb
103
105
  - lib/toolshed/commands/create_github_pull_request.rb
104
106
  - lib/toolshed/commands/create_pivotal_tracker_note.rb
105
107
  - lib/toolshed/commands/get_pivotal_tracker_story_information.rb
108
+ - lib/toolshed/commands/push_git_branch.rb
106
109
  - lib/toolshed/commands/update_pivotal_tracker_story_status.rb
107
110
  - lib/toolshed/error.rb
108
111
  - lib/toolshed/github.rb