pivo_flow 0.2.5 → 0.2.11

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.
@@ -1,12 +1,20 @@
1
1
  module PivoFlow
2
2
  class Base
3
3
  GIT_DIR = '.git'
4
- KEYS_TO_CHECK = ["test-pivotal.project-id", "test-pivotal.api-token"]
4
+ KEYS_AND_QUESTIONS = {
5
+ "pivo-flow.project-id" => "Pivotal: what is your project's ID?",
6
+ "pivo-flow.api-token" => "Pivotal: what is your pivotal tracker api-token?"
7
+ }
5
8
 
6
9
  def initialize(*args)
7
10
  @options = {}
8
11
  @current_dir = Dir.pwd
9
- return "no GIT (#{GIT_DIR}) directory found" unless File.directory?(File.join(@current_dir, GIT_DIR))
12
+
13
+ # exit if no git repo found
14
+ unless File.directory?(File.join(@current_dir, GIT_DIR))
15
+ puts("no GIT (#{GIT_DIR}) directory found")
16
+ exit(1)
17
+ end
10
18
 
11
19
  # paths
12
20
  @git_dir = File.join(@current_dir, GIT_DIR)
@@ -15,6 +23,7 @@ module PivoFlow
15
23
  @pf_git_hook_path = File.join(@git_dir, 'hooks', @pf_git_hook_name)
16
24
  @pf_git_hook_cmd = "#{@pf_git_hook_path} $1"
17
25
  @options[:repository] = Grit::Repo.new(@git_dir)
26
+
18
27
  install_git_hook if git_hook_needed?
19
28
  git_config_ok? ? parse_git_config : add_git_config
20
29
  run
@@ -42,27 +51,34 @@ module PivoFlow
42
51
  end
43
52
 
44
53
  def run
45
- raise "you should define run!"
46
54
  end
47
55
 
48
56
  def user_name
49
57
  @options[:user_name] ||= @options[:repository].config['pivotal.full-name'] || @options[:repository].config['user.name']
50
58
  end
51
59
 
60
+ def reconfig
61
+ KEYS_AND_QUESTIONS.each do |key, question|
62
+ ask_question_and_force_update_config(question, key)
63
+ end
64
+ puts "[SUCCESS] Pivotal Tracker configuration has been updated."
65
+ end
66
+
52
67
  private
53
68
 
54
69
  def git_config_ok?
55
- !KEYS_TO_CHECK.any? { |key| @options[:repository].config[key].nil? }
70
+ !KEYS_AND_QUESTIONS.keys.any? { |key| @options[:repository].config[key].nil? }
56
71
  end
57
72
 
58
73
  def add_git_config
59
- ask_question_and_update_config "Pivotal: what is your project's ID?", "test-pivotal.project-id"
60
- ask_question_and_update_config "Pivotal: what is your pivotal tracker api-token?", "test-pivotal.api-token"
74
+ KEYS_AND_QUESTIONS.each do |key, question|
75
+ ask_question_and_update_config(question, key)
76
+ end
61
77
  parse_git_config
62
78
  end
63
79
 
64
80
  def parse_git_config
65
- KEYS_TO_CHECK.each do |key|
81
+ KEYS_AND_QUESTIONS.each do |key, value|
66
82
  new_key = key.split(".").last
67
83
  @options[new_key] = @options[:repository].config[key]
68
84
  end
@@ -72,6 +88,10 @@ module PivoFlow
72
88
  @options[:repository].config[variable] ||= ask_question(question)
73
89
  end
74
90
 
91
+ def ask_question_and_force_update_config question, variable
92
+ @options[:repository].config[variable] = ask_question(question)
93
+ end
94
+
75
95
  def ask_question question, first_answer = nil
76
96
  h = HighLine.new
77
97
  h.ask("#{question}\t") do |q|
data/lib/pivo_flow/cli.rb CHANGED
@@ -6,6 +6,10 @@ module PivoFlow
6
6
  puts "You forgot method name"
7
7
  exit 1
8
8
  end
9
+ Signal.trap(2) {
10
+ puts "\nkkthxbye!"
11
+ exit(0)
12
+ }
9
13
  parse_argv(*args)
10
14
  end
11
15
 
@@ -33,6 +37,14 @@ module PivoFlow
33
37
  puts "Current pivotal story id cleared."
34
38
  end
35
39
 
40
+ def reconfig
41
+ PivoFlow::Base.new.reconfig
42
+ end
43
+
44
+ def version
45
+ puts PivoFlow::VERSION
46
+ end
47
+
36
48
  private
37
49
 
38
50
  def valid_method? method_name
@@ -10,7 +10,15 @@ module PivoFlow
10
10
  return 1 unless @options["api-token"] && @options["project-id"]
11
11
  PivotalTracker::Client.token = @options["api-token"]
12
12
  PivotalTracker::Client.use_ssl = true
13
- @options[:project] ||= PivotalTracker::Project.find(@options["project-id"])
13
+
14
+ begin
15
+ @options[:project] ||= PivotalTracker::Project.find(@options["project-id"])
16
+ rescue RestClient::Unauthorized => e
17
+ puts "[ERROR] Pivotal Tracker: #{e}\n"
18
+ puts "[TIPS] It means that your configuration is wrong. You can reset your settings by running:\npf reconfig"
19
+ exit(1)
20
+ end
21
+
14
22
  end
15
23
 
16
24
  def user_stories
@@ -1,3 +1,3 @@
1
1
  module PivoFlow
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.11"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pivo_flow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: