pivotal-cli 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ /.idea
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ /pmip
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Omar Skalli
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,34 @@
1
+ # Pivotal-cli
2
+
3
+ Simple command line tool for working with pivotal stories.
4
+
5
+ # Installing
6
+
7
+ To install the gem:
8
+
9
+ ```bash
10
+ gem install pivotal_cli
11
+ ```
12
+
13
+ # Usage
14
+
15
+ ```
16
+ NAME
17
+ pivotal - Pivotal Tracker CLI
18
+
19
+ SYNOPSIS
20
+ pivotal_cli [global options] command [command options] [arguments...]
21
+
22
+ VERSION
23
+ 0.0.1
24
+
25
+ GLOBAL OPTIONS
26
+ --help - Show this message
27
+ --version - Display the program version
28
+
29
+ COMMANDS
30
+ branch - Start a pivotal task, and create a branch for it
31
+ help - Shows a list of commands or help for one command
32
+ list - Display pivotal items assigned to you
33
+ setup - Setup your pivotal account, by creating a config file in ~/.pivotal_cli
34
+ ```
data/bin/pivotal ADDED
@@ -0,0 +1,154 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gli'
3
+ require 'rainbow'
4
+ require 'pivotal_cli'
5
+ require 'highline/import'
6
+
7
+ # Application high level settings
8
+
9
+ include GLI::App
10
+ program_desc 'Pivotal Tracker CLI'
11
+ version PivotalCli::VERSION
12
+
13
+ # Shared re-usable actions
14
+
15
+ def setup_config
16
+ username = ask("What's your full name? ")
17
+ project_id = ask("Project Id? ", Integer)
18
+ token = ask("API Token? (Available at https://www.pivotaltracker.com/profile) ") {|q| q.validate = /\A[A-Za-z0-9]{32}\z/ }
19
+
20
+ @tracker.setup(username, project_id, token)
21
+ puts Rainbow("Configuration has been saved to `#{@tracker.config_file}`.").yellow
22
+ end
23
+
24
+ def ensure_setup_complete
25
+ unless @tracker.setup_complete?
26
+ puts Rainbow("Missing configuration file `#{@tracker.config_file}`. Let's get you setup.").yellow
27
+ setup_config
28
+ end
29
+ @tracker.load_configuration
30
+ end
31
+
32
+ def formatted_story(story, index = nil)
33
+ estimate = (1..8).map { |i| i <= story.estimate.to_i ? '*' : ' ' }.join
34
+
35
+ output = ' '
36
+ output << "#{index.to_s.rjust(2)}: " unless index.nil?
37
+ output << Rainbow("#{story.id} ").yellow
38
+ output << Rainbow("#{story.current_state.rjust(11)} [#{estimate}] ").blue
39
+ output << story.name
40
+ output
41
+ end
42
+
43
+ # CLI entry points
44
+
45
+ desc 'Display pivotal items assigned to you'
46
+ command :list do |c|
47
+ c.action do |global_options,options,args|
48
+ ensure_setup_complete
49
+ stories = @tracker.my_stories
50
+ puts Rainbow("\n You have #{stories.length} stories assigned to you.\n").green
51
+
52
+ stories.each_with_index do |story, index|
53
+ puts formatted_story(story)
54
+ end
55
+ end
56
+ end
57
+
58
+ desc 'Start a pivotal task, and create a branch for it'
59
+ arg_name '<branchname> [task id]'
60
+ command :branch do |c|
61
+ c.action do |global_options,options,args|
62
+ ensure_setup_complete
63
+ if args.length < 1
64
+ puts Rainbow("\n Please specify a branch name to create.\n").red
65
+ next
66
+ end
67
+
68
+ stories = @tracker.my_stories
69
+ branch_name = args[0]
70
+ task_id = args[1].to_i
71
+ story = task_id && stories.find { |story| story.id == task_id }
72
+ new_story = PivotalTracker::Story.new(name: '<Create a new story>', id: '????????', current_state: '', estimate: -1)
73
+
74
+ # Ask the user to select a task from the menu
75
+ if story.nil?
76
+ puts Rainbow("\n You have #{stories.length} stories assigned to you.\n").green
77
+
78
+ # Create a dummy new story
79
+ stories << new_story
80
+ stories.each_with_index do |story, index|
81
+ puts formatted_story(story, index + 1)
82
+ end
83
+
84
+ question = Rainbow("\nWhich of the #{stories.length} stories are you starting? ").green
85
+ task_index = ask(question, Integer) { |q| q.in = 1..(stories.length) }
86
+ story = stories[task_index - 1]
87
+ end
88
+
89
+ # Create the new story on the fly
90
+ if story == new_story
91
+ story_name = ask(Rainbow('Story name? ').green)
92
+ story_description = ask(Rainbow('Story description? ').green)
93
+ story = @tracker.create_story(story_name, story_description)
94
+ if story.errors && story.errors.count > 0
95
+ puts Rainbow("Whoops, something went wrong when creating the story:").red
96
+ story.errors.each do |error|
97
+ puts " * #{error}"
98
+ end
99
+ next
100
+ end
101
+ end
102
+
103
+ # Make sure feature is estimated (can't start otherwise)
104
+ if story.estimate < 0
105
+ question = Rainbow("How many points in the story (0-8)? ").green
106
+ points = ask(question, Integer) { |q| q.in = 0..8 }
107
+ @tracker.set_points(story, points)
108
+ end
109
+
110
+ # Checkout branch
111
+ branch_name = "pv-#{story.id}-#{branch_name}"
112
+ command = "git checkout -b #{branch_name}"
113
+ puts "Executing: #{command}"
114
+ success = system(command)
115
+
116
+ # Update status
117
+ if success
118
+ @tracker.start(story)
119
+ puts Rainbow("Set story #{story.id} as 'Started'\n").green
120
+ else
121
+ puts Rainbow("^ Whoops, something went wrong...").red
122
+ end
123
+ end
124
+ end
125
+
126
+ desc 'Setup your pivotal account, by creating a config file in ~/.pivotal_cli'
127
+ command :setup do |c|
128
+ c.action do |global_options,options,args|
129
+
130
+ if @tracker.setup_complete?
131
+ puts Rainbow("Looks like you already have an existing `#{@tracker.config_file}` config file.").yellow
132
+ answer = ask('Overwrite file? [y, n]') { |q| q.in = ['y', 'n']; q.default = 'n' }
133
+ next if answer == 'n'
134
+ end
135
+
136
+ # Required information for the API
137
+ setup_config
138
+ end
139
+ end
140
+
141
+ pre do |global,command,options,args|
142
+ @tracker = PivotalCli::Tracker.new
143
+ true
144
+ end
145
+
146
+ post do |global,command,options,args|
147
+ puts ""
148
+ end
149
+
150
+ on_error do |exception|
151
+ true
152
+ end
153
+
154
+ exit run(ARGV)
@@ -0,0 +1,59 @@
1
+ require 'pivotal-tracker'
2
+
3
+ module PivotalCli
4
+ class Tracker
5
+ attr_accessor :project, :username
6
+
7
+ def config_file
8
+ @config_file ||= "#{ENV['HOME']}/.pivotal"
9
+ end
10
+
11
+ def setup_complete?
12
+ File.exists?(config_file)
13
+ end
14
+
15
+ def setup(username, project_id, token)
16
+ username = username.strip
17
+ File.open(config_file, 'w') do |file|
18
+ file.puts(username)
19
+ file.puts(project_id)
20
+ file.puts(token)
21
+ end
22
+ end
23
+
24
+ def my_stories
25
+ @project.stories.all(owned_by: username).reject { |s| s.current_state =~ /accepted/ }
26
+ end
27
+
28
+ def create_story(name, description)
29
+ attributes = {
30
+ story_type: 'feature',
31
+ name: name,
32
+ description: description,
33
+ owned_by: username
34
+ }
35
+ @project.stories.create(attributes)
36
+ end
37
+
38
+ def set_points(story, points)
39
+ story.update(estimate: points)
40
+ end
41
+
42
+ def start(story)
43
+ story.update(current_state: 'started')
44
+ end
45
+
46
+ def load_configuration
47
+ File.open(config_file, 'r') do |file|
48
+ lines = file.readlines
49
+ @username = lines[0].strip
50
+ token = lines[2].strip
51
+ project_id = lines[1].strip
52
+
53
+ PivotalTracker::Client.token = token
54
+ PivotalTracker::Client.use_ssl = true
55
+ @project = PivotalTracker::Project.find(project_id)
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,3 @@
1
+ module PivotalCli
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,2 @@
1
+ require 'pivotal_cli/version.rb'
2
+ require 'pivotal_cli/tracker.rb'
@@ -0,0 +1,20 @@
1
+ # Ensure we require the local version and not one we might have installed already
2
+ require File.join([File.dirname(__FILE__),'lib','pivotal_cli','version.rb'])
3
+ spec = Gem::Specification.new do |s|
4
+ s.name = 'pivotal-cli'
5
+ s.version = PivotalCli::VERSION
6
+ s.author = 'Omar Skalli'
7
+ s.email = 'chetane@gmail.com'
8
+ s.platform = Gem::Platform::RUBY
9
+ s.summary = 'Simple command line tool for working with Pivotal Stories'
10
+ s.homepage = 'https://github.com/chetane/pivotal-cli'
11
+ s.license = 'MIT'
12
+ s.files = `git ls-files`.split($/)
13
+ s.require_paths << 'lib'
14
+ s.bindir = 'bin'
15
+ s.executables << 'pivotal'
16
+ s.add_runtime_dependency('gli','2.11.0')
17
+ s.add_runtime_dependency('rainbow', '2.0.0')
18
+ s.add_runtime_dependency('highline','1.6.21')
19
+ s.add_runtime_dependency('pivotal-tracker', '0.5.12')
20
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pivotal-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Omar Skalli
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-07-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: gli
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.11.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.11.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rainbow
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - '='
36
+ - !ruby/object:Gem::Version
37
+ version: 2.0.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - '='
44
+ - !ruby/object:Gem::Version
45
+ version: 2.0.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: highline
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - '='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.6.21
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.6.21
62
+ - !ruby/object:Gem::Dependency
63
+ name: pivotal-tracker
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.5.12
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.5.12
78
+ description:
79
+ email: chetane@gmail.com
80
+ executables:
81
+ - pivotal
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - bin/pivotal
90
+ - lib/pivotal_cli.rb
91
+ - lib/pivotal_cli/tracker.rb
92
+ - lib/pivotal_cli/version.rb
93
+ - pivotal_cli.gemspec
94
+ homepage: https://github.com/chetane/pivotal-cli
95
+ licenses:
96
+ - MIT
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 1.8.24
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Simple command line tool for working with Pivotal Stories
120
+ test_files: []