toolshed 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 60c7e0e08aaa4ed44d9a1ff43d2a0080867aca0c
4
+ data.tar.gz: d566228c12d47d61cac671a9ff9d9599daab3c41
5
+ SHA512:
6
+ metadata.gz: 51cecf93cbeacd06c6874b637f357462f82224c88d242595cb2d61c630aee7298b4397dd9cdb32a15558903d0bdf2f2adfa8e7fd4de0ffda460c2a0af168a5e4
7
+ data.tar.gz: f69d816eead865e7d817379ac4d779a12151a449fd77e42120ed3ab330fa8b5f488081f77b274c2be7fb898449dfb3b0bf033bb8c34e2ba6e366be662fa15bdd
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in toolshed.gemspec
4
+ gemspec
5
+
6
+ gem 'toolshed', :path => "/Users/jakewaller/development/toolshed"
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 wallerjake
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Toolshed
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'toolshed'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install toolshed
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/toolshed ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'rubygems'
5
+ require 'toolshed'
6
+ gem 'rake'
7
+ rescue LoadError
8
+ end
9
+
10
+ require 'rake'
11
+ require File.dirname(__FILE__) + '/toolshed'
data/bin/toolshed.rb ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
4
+
5
+ require 'toolshed'
6
+ require 'toolshed/cli'
7
+
8
+ cli = Toolshed::CLI.new
9
+
10
+ require 'optparse'
11
+
12
+ def usage
13
+ $stderr.puts <<EOF
14
+ This is the command line tool for toolshed. More information about toolshed can
15
+ be found at https://github.com/wallerjake/toolshed
16
+
17
+ Before using this tool you should create a file called .toolshed in your home directory
18
+ and add the following to that file:
19
+
20
+ == Commands
21
+
22
+ All commands are executed as toolshed [options] command [command-options] args
23
+
24
+ The following commands are available:
25
+
26
+ help # show this usage
27
+ create_github_pull_request # create a github pull request based on the branch you currently have checked out
28
+ get_pivotal_tracker_story_information # Get the ticket information from a PivotalTracker story based on project_id and story_id
29
+ create_pivotal_tracker_note # Create a note for a specific PivotalTracker story based on project_id and story_id
30
+ update_pivotal_tracker_story_status # Update the status of PivotalTracker story
31
+ EOF
32
+ end
33
+
34
+ if $0.split("/").last == 'toolshed'
35
+ options = {}
36
+
37
+ global = OptionParser.new do |opts|
38
+ opts.on("-u", "--username [ARG]") do |username|
39
+ # Set username here
40
+ end
41
+ opts.on("-p", "--password [ARG]") do |password|
42
+ # Set password here
43
+ end
44
+ opts.on("-d") do
45
+ # Set debug here
46
+ end
47
+ end
48
+
49
+ subcommands = { }
50
+
51
+ command = ARGV.shift
52
+ if command.nil? || command == 'help'
53
+ usage
54
+ else
55
+ options_parser = subcommands[command]
56
+ options_parser.order! if options_parser
57
+ begin
58
+ cli.execute(command, ARGV, options)
59
+ rescue Toolshed::CommandNotFound => e
60
+ puts e.message
61
+ end
62
+ end
63
+ end
data/lib/toolshed.rb ADDED
@@ -0,0 +1,25 @@
1
+ require "toolshed/version"
2
+ require 'httparty'
3
+ require 'pivotal-tracker'
4
+
5
+ module Toolshed
6
+ BLANK_REGEX = /\S+/
7
+
8
+ # Echoes a deprecation warning message.
9
+ #
10
+ # @param [String] message The message to display.
11
+ # @return [void]
12
+ #
13
+ # @api internal
14
+ # @private
15
+ def self.deprecate(message = nil)
16
+ message ||= "You are using deprecated behavior which will be removed from the next major or minor release."
17
+ warn("DEPRECATION WARNING: #{message}")
18
+ end
19
+ end
20
+
21
+ require 'toolshed/base'
22
+ require 'toolshed/client'
23
+ require 'toolshed/github'
24
+ require 'toolshed/pivotal_tracker'
25
+ require 'toolshed/error'
@@ -0,0 +1,5 @@
1
+ module Toolshed
2
+ class Base
3
+ # implement base methods here
4
+ end
5
+ end
@@ -0,0 +1,37 @@
1
+ module Toolshed
2
+ class CommandNotFound < RuntimeError
3
+ end
4
+
5
+ class CLI
6
+ def execute(command_name, args, options={})
7
+ Toolshed::Client.load_credentials_if_necessary
8
+ command = commands[command_name]
9
+ if command
10
+ begin
11
+ command.new.execute(args, options)
12
+ rescue Toolshed::Error => e
13
+ puts "An error occurred: #{e.message}"
14
+ rescue RuntimeError => e
15
+ puts "An error occurred: #{e.message}"
16
+ end
17
+ else
18
+ raise CommandNotFound, "Unknown command: #{command_name}"
19
+ end
20
+ end
21
+
22
+ def commands
23
+ {
24
+ 'create_github_pull_request' => Toolshed::Commands::CreateGithubPullRequest,
25
+ 'create_pivotal_tracker_note' => Toolshed::Commands::CreatePivotalTrackerNote,
26
+ 'get_pivotal_tracker_story_information' => Toolshed::Commands::GetPivotalTrackerStoryInformation,
27
+ 'update_pivotal_tracker_story_status' => Toolshed::Commands::UpdatePivotalTrackerStoryStatus,
28
+ }
29
+ end
30
+ end
31
+
32
+ end
33
+
34
+ require 'toolshed/commands/create_github_pull_request'
35
+ require 'toolshed/commands/create_pivotal_tracker_note'
36
+ require 'toolshed/commands/get_pivotal_tracker_story_information'
37
+ require 'toolshed/commands/update_pivotal_tracker_story_status'
@@ -0,0 +1,201 @@
1
+ require 'toolshed/version'
2
+ require 'yaml'
3
+
4
+ module Toolshed
5
+ class Client
6
+ GITHUB_BASE_API_URL = "https://api.github.com/"
7
+ PIVOTAL_TRACKER_BASE_API_URL = "https://www.pivotaltracker.com/services/v5/"
8
+
9
+ def self.debug?
10
+ @debug
11
+ end
12
+
13
+ def self.debug=(debug)
14
+ @debug = debug
15
+ end
16
+
17
+
18
+ # github config settings
19
+ def self.github_username
20
+ @github_username
21
+ end
22
+
23
+ def self.github_username=(username)
24
+ @github_username = username
25
+ end
26
+
27
+ def self.github_password
28
+ @github_password
29
+ end
30
+
31
+ def self.github_password=(password)
32
+ @github_password = password
33
+ end
34
+
35
+ def self.branched_from_remote_name
36
+ @branched_from_remote_name
37
+ end
38
+
39
+ def self.branched_from_remote_name=(branched_from_remote_name)
40
+ @branched_from_remote_name = branched_from_remote_name
41
+ end
42
+
43
+ def self.branched_from_user
44
+ @branched_from_user
45
+ end
46
+
47
+ def self.branched_from_user=(branched_from_user)
48
+ @branched_from_user = branched_from_user
49
+ end
50
+
51
+ def self.branched_from_repo_name
52
+ @branched_from_repo_name
53
+ end
54
+
55
+ def self.branched_from_repo_name=(branched_from_repo_name)
56
+ @branched_from_repo_name = branched_from_repo_name
57
+ end
58
+
59
+ def self.push_from_user
60
+ @push_from_user
61
+ end
62
+
63
+ def self.push_from_user=(push_from_user)
64
+ @push_from_user = push_from_user
65
+ end
66
+
67
+ def self.push_to_myself
68
+ @push_to_myself
69
+ end
70
+
71
+ def self.push_to_myself=(push_to_myself)
72
+ @push_to_myself = push_to_myself
73
+ end
74
+
75
+
76
+
77
+ # pivotal tracker config
78
+ def self.pivotal_tracker_username
79
+ @pivotal_tracker_username
80
+ end
81
+
82
+ def self.pivotal_tracker_username=(username)
83
+ @pivotal_tracker_username = username
84
+ end
85
+
86
+ def self.pivotal_tracker_password
87
+ @pivotal_tracker_password
88
+ end
89
+
90
+ def self.pivotal_tracker_password=(password)
91
+ @pivotal_tracker_password = password
92
+ end
93
+
94
+ def self.default_pivotal_tracker_project_id
95
+ @default_pivotal_tracker_project_id
96
+ end
97
+
98
+ def self.default_pivotal_tracker_project_id=(default_pivotal_tracker_project_id)
99
+ @default_pivotal_tracker_project_id = default_pivotal_tracker_project_id
100
+ end
101
+
102
+ def self.use_pivotal_tracker
103
+ @use_pivotal_tracker
104
+ end
105
+
106
+ def self.use_pivotal_tracker=(use_pivotal_tracker)
107
+ @use_pivotal_tracker = use_pivotal_tracker
108
+ end
109
+
110
+
111
+ def self.http_proxy
112
+ @http_proxy
113
+ end
114
+
115
+ def self.http_proxy=(http_proxy)
116
+ @http_proxy = http_proxy
117
+ end
118
+
119
+ def self.load_credentials_if_necessary
120
+ load_credentials unless credentials_loaded?
121
+ end
122
+
123
+ def self.config_path
124
+ ENV['TOOLSHED_CONFIG'] || '~/.toolshed'
125
+ end
126
+
127
+ def self.load_credentials(path = config_path)
128
+ begin
129
+ credentials = YAML.load_file(File.expand_path(path))
130
+ self.github_username ||= credentials['github_username']
131
+ self.github_password ||= credentials['github_password']
132
+ self.pivotal_tracker_username ||= credentials['pivotal_tracker_username']
133
+ self.pivotal_tracker_password ||= credentials['pivotal_tracker_password']
134
+ self.default_pivotal_tracker_project_id ||= credentials['default_pivotal_tracker_project_id']
135
+ self.branched_from_remote_name ||= credentials['branched_from_remote_name']
136
+ self.branched_from_user ||= credentials['branched_from_user']
137
+ self.branched_from_repo_name ||= credentials['branched_from_repo_name']
138
+ self.push_from_user ||= credentials['push_from_user']
139
+ self.push_to_myself ||= credentials['push_to_myself']
140
+ self.use_pivotal_tracker ||= credentials['use_pivotal_tracker']
141
+ @credentials_loaded = true
142
+ puts "Credentials loaded from #{path}"
143
+ rescue => error
144
+ puts "Error loading your credentials: #{error.message}"
145
+ exit 1
146
+ end
147
+ end
148
+
149
+ def self.credentials_loaded?
150
+ (@credentials_loaded ||= false) or (github_username and github_password and pivotal_tracker_username and pivotal_tracker_password)
151
+ end
152
+
153
+ def self.base_options
154
+ options = {
155
+ :format => :json,
156
+ :headers => { 'Accept' => 'application/json', 'User-Agent' => "toolshed-ruby/#{Toolshed::VERSION}" },
157
+ }
158
+
159
+ if http_proxy
160
+ options.merge!(
161
+ :http_proxyaddr => self.http_proxy[:addr],
162
+ :http_proxyport => self.http_proxy[:port]
163
+ )
164
+ end
165
+
166
+ if password
167
+ options[:basic_auth] = { :username => username, :password => password }
168
+ else
169
+ raise Error, 'A password is required for all API requests.'
170
+ end
171
+
172
+ options
173
+ end
174
+
175
+ def self.get(path, options = {})
176
+ request :get, path, options
177
+ end
178
+
179
+ def self.post(path, options = {})
180
+ request :post, path, options
181
+ end
182
+
183
+ def self.put(path, options = {})
184
+ request :put, path, options
185
+ end
186
+
187
+ def self.delete(path, options = {})
188
+ request :delete, path, options
189
+ end
190
+
191
+ def self.request(method, path, options)
192
+ response = HTTParty.send(method, "#{base_uri}#{path}", base_options.merge(options))
193
+
194
+ if response.code == 401
195
+ raise AuthenticationFailed
196
+ end
197
+
198
+ response
199
+ end
200
+ end
201
+ end
@@ -0,0 +1,76 @@
1
+ module Toolshed
2
+ module Commands
3
+ class CreateGithubPullRequest
4
+ def execute(args, options = {})
5
+ pivotal_tracker = nil
6
+ if (Toolshed::Client.use_pivotal_tracker)
7
+ # load up the project information for pivotal tracker
8
+ print "Project ID (Default: #{Toolshed::Client.default_pivotal_tracker_project_id})? "
9
+ project_id = $stdin.gets.chomp.strip
10
+ if (project_id == '')
11
+ project_id = Toolshed::Client.default_pivotal_tracker_project_id
12
+ end
13
+
14
+ pivotal_tracker = Toolshed::PivotalTracker.new({ project_id: project_id})
15
+ end
16
+
17
+ github = Toolshed::Github.new
18
+
19
+ # see what branch is checked out and where we are branched from
20
+ puts "Current Branch: #{github.branch_name}"
21
+ puts "Branched From: #{github.branched_from}"
22
+
23
+ pt_ticket_title = ''
24
+ if (Toolshed::Client.use_pivotal_tracker)
25
+ # load up the story information from PivotalTracker
26
+ default_story_id = Toolshed::PivotalTracker::story_id_from_branch_name(github.branch_name)
27
+ print "Story ID (Default: #{default_story_id})? "
28
+ story_id = $stdin.gets.chomp.strip
29
+ if (story_id == '')
30
+ story_id = default_story_id
31
+ end
32
+
33
+ pivotal_tracker_result = pivotal_tracker.story_information(story_id)
34
+
35
+ pt_ticket_title = pivotal_tracker_result.name
36
+ pt_ticket_title = pt_ticket_title.gsub("'", "").gsub("\"", "")
37
+ end
38
+
39
+ # github pull request fields
40
+ print "Github Pull Request Title (Default: #{pt_ticket_title})? "
41
+ github_pull_request_title = $stdin.gets.chomp.strip
42
+ if (github_pull_request_title == '')
43
+ github_pull_request_title = pt_ticket_title
44
+ end
45
+
46
+ github_pull_request_default_body = ''
47
+ if (Toolshed::Client.use_pivotal_tracker)
48
+ github_pull_request_default_body = pivotal_tracker_result.url
49
+ end
50
+ print "Body (Default: #{github_pull_request_default_body})? "
51
+ github_pull_request_body = $stdin.gets.chomp.strip
52
+ if (github_pull_request_body == '')
53
+ github_pull_request_body = github_pull_request_default_body
54
+ end
55
+
56
+ # create the pull request
57
+ begin
58
+ github_pull_request_result = github.create_pull_request(github_pull_request_title, github_pull_request_body)
59
+ rescue => e
60
+ puts e.message
61
+ exit
62
+ end
63
+
64
+ if (Toolshed::Client.use_pivotal_tracker)
65
+ print "Would you like to add a note to PivotalTracker with the pull request URL(y/n)? "
66
+ update_pt_info = $stdin.gets.chomp.strip
67
+
68
+ if (update_pt_info == 'y')
69
+ result = pivotal_tracker.add_note(story_id, JSON.parse(github_pull_request_result.body["html_url"]))
70
+ result = pivotal_tracker.update_story_state(story_id, Toolshed::PivotalTracker::STORY_STATUS_DEFAULT)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,34 @@
1
+ module Toolshed
2
+ module Commands
3
+ class CreatePivotalTrackerNote
4
+ def execute(args, options = {})
5
+ print "Project ID (Default: #{Toolshed::Client.default_pivotal_tracker_project_id})? "
6
+ project_id = $stdin.gets.chomp.strip
7
+ if (project_id == '')
8
+ project_id = Toolshed::Client.default_pivotal_tracker_project_id
9
+ end
10
+
11
+ pivotal_tracker = Toolshed::PivotalTracker.new({ project_id: project_id})
12
+ github = Toolshed::Github.new
13
+
14
+ default_story_id = Toolshed::PivotalTracker::story_id_from_branch_name(github.branch_name)
15
+ print "Story ID (Default: #{default_story_id})? "
16
+ story_id = $stdin.gets.chomp.strip
17
+ if (story_id == '')
18
+ story_id = default_story_id
19
+ end
20
+
21
+ print "Note? "
22
+ note_text = $stdin.gets.chomp.strip
23
+
24
+ begin
25
+ result = pivotal_tracker.add_note(story_id, note_text)
26
+ puts result.inspect
27
+ rescue => e
28
+ puts e.message
29
+ exit
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ module Toolshed
2
+ module Commands
3
+ class GetPivotalTrackerStoryInformation
4
+ def execute(args, options = {})
5
+ begin
6
+ print "Project ID (Default: #{Toolshed::Client.default_pivotal_tracker_project_id})? "
7
+ project_id = $stdin.gets.chomp.strip
8
+ if (project_id == '')
9
+ project_id = Toolshed::Client.default_pivotal_tracker_project_id
10
+ end
11
+
12
+ pivotal_tracker = Toolshed::PivotalTracker.new({ project_id: project_id})
13
+ github = Toolshed::Github.new
14
+
15
+ default_story_id = Toolshed::PivotalTracker::story_id_from_branch_name(github.branch_name)
16
+ print "Story ID (Default: #{default_story_id})? "
17
+ story_id = $stdin.gets.chomp.strip
18
+ if (story_id == '')
19
+ story_id = default_story_id
20
+ end
21
+
22
+ result = pivotal_tracker.story_information(story_id)
23
+ puts "Name: #{result.name}"
24
+ puts "Url: #{result.url}"
25
+ puts "Description: #{result.description}"
26
+ exit
27
+ rescue => e
28
+ puts e.message
29
+ exit
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,39 @@
1
+ module Toolshed
2
+ module Commands
3
+ class UpdatePivotalTrackerStoryStatus
4
+ STORY_STATUS_DEFAULT = 'finished'
5
+
6
+ def execute(args, options = {})
7
+ print "Project ID (Default: #{Toolshed::Client.default_pivotal_tracker_project_id})? "
8
+ project_id = $stdin.gets.chomp.strip
9
+ if (project_id == '')
10
+ project_id = Toolshed::Client.default_pivotal_tracker_project_id
11
+ end
12
+
13
+ pivotal_tracker = Toolshed::PivotalTracker.new({ project_id: project_id})
14
+ github = Toolshed::Github.new
15
+
16
+ default_story_id = Toolshed::PivotalTracker::story_id_from_branch_name(github.branch_name)
17
+ print "Story ID (Default: #{default_story_id})? "
18
+ story_id = $stdin.gets.chomp.strip
19
+ if (story_id == '')
20
+ story_id = default_story_id
21
+ end
22
+
23
+ print "Status (Default: #{Toolshed::PivotalTracker::STORY_STATUS_DEFAULT})? "
24
+ story_status = $stdin.gets.chomp.strip
25
+ if (story_status == '')
26
+ story_status = Toolshed::PivotalTracker::STORY_STATUS_DEFAULT
27
+ end
28
+
29
+ begin
30
+ result = pivotal_tracker.update_story_state(story_id, story_status)
31
+ puts "Story Status Updated At: #{result["created_at"]}"
32
+ rescue => e
33
+ puts e.message
34
+ exit
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,13 @@
1
+ module Toolshed
2
+ class Error < StandardError
3
+ end
4
+
5
+ class RecordExists < Error
6
+ end
7
+
8
+ class RecordNotFoundError < Error
9
+ end
10
+
11
+ class AuthenticationFailed < Error
12
+ end
13
+ end
@@ -0,0 +1,54 @@
1
+ module Toolshed
2
+ class Github
3
+ include HTTParty
4
+
5
+ def initialize(options={})
6
+ @auth = { username: Toolshed::Client::github_username, password: Toolshed::Client::github_password }
7
+ @default_options = {
8
+ :headers => {
9
+ "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"
10
+ },
11
+ basic_auth: @auth,
12
+ }
13
+ end
14
+
15
+ def create_pull_request(title, body, options={})
16
+ options.merge!(@default_options)
17
+ options.merge!({
18
+ body: {
19
+ title: title,
20
+ body: body,
21
+ head: "#{Toolshed::Client.github_username}:#{self.branch_name}",
22
+ base: self.branched_from
23
+ }.to_json
24
+ })
25
+
26
+ response = HTTParty.post("#{Toolshed::Client::GITHUB_BASE_API_URL}repos/#{Toolshed::Client.github_username}/#{Toolshed::Client.branched_from_remote_name}/pulls", options).response
27
+ response = JSON.parse(response.body)
28
+
29
+ if (response["errors"].nil?)
30
+ response
31
+ else
32
+ raise "validation errors #{response.inspect}"
33
+ end
34
+ end
35
+
36
+ def list_branches(options={})
37
+ options.merge!(@default_options)
38
+
39
+ response = HTTParty.get("#{Toolshed::Client::GITHUB_BASE_API_URL}repos/#{Toolshed::Client.github_username}/toolshed/branches", options).response
40
+ JSON.parse(response.body).each do |branch|
41
+ puts branch.inspect
42
+ end
43
+ end
44
+
45
+ def branch_name
46
+ # branch information
47
+ branch_name = `git rev-parse --abbrev-ref HEAD`.strip
48
+ end
49
+
50
+ def branched_from
51
+ branched_from = `git rev-parse --abbrev-ref --symbolic-full-name @{u}`.split('/')[-1].strip
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,51 @@
1
+ module Toolshed
2
+ class PivotalTracker
3
+ include HTTParty
4
+
5
+ STORY_STATUS_DEFAULT = 'finished'
6
+
7
+ attr_accessor :project_id, :token
8
+
9
+ def initialize(options={})
10
+ self.token = ::PivotalTracker::Client.token(Toolshed::Client.pivotal_tracker_username, Toolshed::Client.pivotal_tracker_password)
11
+
12
+ self.project_id = (options[:project_id].nil?) ? Toolshed::Client.default_pivotal_tracker_project_id : options[:project_id]
13
+ @pt_project = ::PivotalTracker::Project.find(self.project_id)
14
+ end
15
+
16
+ def self.story_id_from_branch_name(branch_name)
17
+ story_id = branch_name.split("_")[0]
18
+ end
19
+
20
+ def story_information(story_id)
21
+ return @pt_project.stories.find(story_id)
22
+ end
23
+
24
+ def add_note(story_id, note_text)
25
+ story = @pt_project.stories.find(story_id)
26
+ results = story.notes.create(text: note_text)
27
+ end
28
+
29
+ def update_story_state(story_id, current_state, options={})
30
+ options.merge!({
31
+ :headers => {
32
+ "X-TrackerToken" => self.token,
33
+ "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",
34
+ "Content-Type" => "application/json",
35
+ },
36
+ body: {
37
+ current_state: current_state
38
+ }.to_json
39
+ })
40
+
41
+ response = HTTParty.put("#{Toolshed::Client::PIVOTAL_TRACKER_BASE_API_URL}projects/#{self.project_id}/stories/#{story_id}", options).response
42
+ response = JSON.parse(response.body)
43
+
44
+ if (response["error"].nil?)
45
+ response
46
+ else
47
+ raise "validation errors #{response.inspect}"
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module Toolshed
2
+ VERSION = "0.0.1"
3
+ end
data/toolshed.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'toolshed/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "toolshed"
8
+ spec.version = Toolshed::VERSION
9
+ spec.authors = ["test"]
10
+ spec.email = ["test@gmail.com"]
11
+ spec.description = %q{Utility that will automate simple daily tasks developers perform like creating a Github pull request}
12
+ spec.summary = %q{Create a Github pull request with minimal work. Will automatically read ticket information from pivotal tracker if you use that.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = ["toolshed"]
18
+ #spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "httparty"
25
+ spec.add_development_dependency "json"
26
+ spec.add_development_dependency "nokogiri"
27
+ spec.add_development_dependency "pivotal-tracker"
28
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: toolshed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - test
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pivotal-tracker
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Utility that will automate simple daily tasks developers perform like
98
+ creating a Github pull request
99
+ email:
100
+ - test@gmail.com
101
+ executables:
102
+ - toolshed
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - .gitignore
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/toolshed
112
+ - bin/toolshed.rb
113
+ - lib/toolshed.rb
114
+ - lib/toolshed/base.rb
115
+ - lib/toolshed/cli.rb
116
+ - lib/toolshed/client.rb
117
+ - lib/toolshed/commands/create_github_pull_request.rb
118
+ - lib/toolshed/commands/create_pivotal_tracker_note.rb
119
+ - lib/toolshed/commands/get_pivotal_tracker_story_information.rb
120
+ - lib/toolshed/commands/update_pivotal_tracker_story_status.rb
121
+ - lib/toolshed/error.rb
122
+ - lib/toolshed/github.rb
123
+ - lib/toolshed/pivotal_tracker.rb
124
+ - lib/toolshed/version.rb
125
+ - toolshed.gemspec
126
+ homepage: ''
127
+ licenses:
128
+ - MIT
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 2.1.11
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Create a Github pull request with minimal work. Will automatically read ticket
150
+ information from pivotal tracker if you use that.
151
+ test_files: []