pgit 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/README.markdown +3 -0
  4. data/bin/pgit +1 -1
  5. data/lib/pgit.rb +11 -1
  6. data/lib/pgit/configuration.rb +2 -43
  7. data/lib/pgit/configuration/layout_error.rb +9 -0
  8. data/lib/pgit/configuration/missing_attributes_error.rb +10 -0
  9. data/lib/pgit/configuration/not_found_error.rb +10 -0
  10. data/lib/pgit/configuration/project_missing_error.rb +10 -0
  11. data/lib/pgit/configuration/validator.rb +41 -0
  12. data/lib/pgit/current_project.rb +1 -7
  13. data/lib/pgit/current_project/no_paths_match_working_dir_error.rb +10 -0
  14. data/lib/pgit/current_project/validator.rb +11 -0
  15. data/lib/pgit/error.rb +4 -0
  16. data/lib/pgit/external_error.rb +9 -0
  17. data/lib/pgit/installer/configuration.rb +34 -0
  18. data/lib/pgit/pivotal_request_validator.rb +27 -0
  19. data/lib/pgit/story.rb +2 -6
  20. data/lib/pgit/version.rb +1 -1
  21. data/pgit.gemspec +2 -0
  22. data/spec/pgit/configuration/missing_attributes_error_spec.rb +30 -0
  23. data/spec/pgit/configuration/not_found_error_spec.rb +17 -0
  24. data/spec/pgit/configuration/project_missing_error_spec.rb +30 -0
  25. data/spec/pgit/configuration/validator_spec.rb +79 -0
  26. data/spec/pgit/configuration_spec.rb +22 -124
  27. data/spec/pgit/current_branch_spec.rb +1 -1
  28. data/spec/pgit/current_project/no_paths_match_working_dir_error_spec.rb +17 -0
  29. data/spec/pgit/current_project/validator_spec.rb +11 -0
  30. data/spec/pgit/current_project_spec.rb +17 -18
  31. data/spec/pgit/external_error_spec.rb +21 -0
  32. data/spec/pgit/installer/configuration_spec.rb +162 -0
  33. data/spec/pgit/pgit_spec.rb +2 -0
  34. data/spec/pgit/pivotal_request_validator_spec.rb +86 -0
  35. data/spec/pgit/story_branch/application_spec.rb +1 -1
  36. data/spec/pgit/story_branch_spec.rb +1 -1
  37. data/spec/pgit/story_spec.rb +1 -20
  38. data/spec/spec_helper.rb +101 -0
  39. metadata +52 -5
  40. data/lib/pgit/installer.rb +0 -32
  41. data/spec/pgit/application_spec.rb +0 -16
  42. data/spec/pgit/installer_spec.rb +0 -158
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e11d6044b7f8bd8030a10c3e563eafbf594a498f
4
- data.tar.gz: 517300daf5c4126e417940f0af925e669a65f0bb
3
+ metadata.gz: d736adc51cc2cda472f63edadcddd766f7ad22a2
4
+ data.tar.gz: 2b7e43a567cb947507d4d1d1cd4c0704a02af14c
5
5
  SHA512:
6
- metadata.gz: 4649d681d4b7e8dbbfcfe33e6ce55ae113bf4ec7e8bbef9db81f5944738a1b196f36ab9d14971892d38a6d2c3e52d314393a7d02f692d558cc07c360ed55c7f7
7
- data.tar.gz: 32e1abf53d85783fa22004377823035bc0ac6ca527d5c2a45af4befceb28b17eec0324ed8269d78014d00dda283750aebf21c547619e1e9392421b4025dc3c07
6
+ metadata.gz: 7c30a313b05b8940dc915c14f13c9e36621c7c876dd1b8121d23d16d0a7d2bc74d39062e1543184cb3fd5bf9f2bfdb7c39cb81184a42aa48f0a2cc4292a67a72
7
+ data.tar.gz: e811579cab502fd70ed1dda709637222f42036e04fd8702636da4d99319236d27876a2bc44302adf9cb6b0d66a159bf1501e5c6a12183c5eab4170fa6c3e93e1
@@ -0,0 +1 @@
1
+ service_name: travis-ci
@@ -1,7 +1,10 @@
1
1
  # PGit
2
2
 
3
3
  ![Travis CI Build](https://travis-ci.org/Edderic/pgit.svg?branch=master)
4
+ [![Gem Version](https://badge.fury.io/rb/pgit.svg)](http://badge.fury.io/rb/pgit)
4
5
  [![Code Climate](https://codeclimate.com/github/Edderic/pgit/badges/gpa.svg)](https://codeclimate.com/github/Edderic/pgit)
6
+ [![Coverage Status](https://coveralls.io/repos/Edderic/pgit/badge.png?branch=master)](https://coveralls.io/r/Edderic/pgit?branch=master)
7
+
5
8
  ## Example Usage
6
9
 
7
10
  Assuming that:
data/bin/pgit CHANGED
@@ -25,7 +25,7 @@ arguments :strict
25
25
  desc "Installs the pgit configuration file"
26
26
  command :install do |c|
27
27
  c.action do |global_options,options,args|
28
- PGit::Installer.new(global_options, options, args)
28
+ PGit::Installer::Configuration.new(global_options, options, args)
29
29
  end
30
30
  end
31
31
 
@@ -1,9 +1,19 @@
1
1
  require 'json'
2
+ require 'pgit/error'
3
+ require 'pgit/configuration/layout_error'
4
+ require 'pgit/configuration/not_found_error'
5
+ require 'pgit/configuration/project_missing_error'
6
+ require 'pgit/configuration/missing_attributes_error'
7
+ require 'pgit/configuration/validator'
2
8
  require 'pgit/configuration'
3
9
  require 'pgit/current_branch'
10
+ require 'pgit/current_project/no_paths_match_working_dir_error'
11
+ require 'pgit/current_project/validator'
4
12
  require 'pgit/current_project'
5
- require 'pgit/installer'
13
+ require 'pgit/installer/configuration'
6
14
  require 'pgit/name_parser'
15
+ require 'pgit/pivotal_request_validator'
16
+ require 'pgit/external_error'
7
17
  require 'pgit/story'
8
18
  require 'pgit/story_branch'
9
19
  require 'pgit/story_branch/application'
@@ -26,52 +26,11 @@ module PGit
26
26
  end
27
27
 
28
28
  def initialize(config_path = '~/.pgit.rc.yml')
29
- @expanded_path = File.expand_path(config_path)
30
- if File.exists? @expanded_path
31
- config_file = File.open(@expanded_path, 'r')
32
- @yaml = YAML.load(config_file)
33
-
34
- validate_existence_of_at_least_one_project
35
- validate_presence_of_items_in_each_project
36
- else
37
- raise missing_config_default
38
- end
29
+ @validator = PGit::Configuration::Validator.new(config_path)
39
30
  end
40
31
 
41
32
  def to_yaml
42
- @yaml
43
- end
44
-
45
- private
46
-
47
- def missing_config_default
48
- "Default configuration file does not exist. Please run `pgit install`"
49
- end
50
-
51
- def general_error_message
52
- "Please have the following layout:\n" + YAML.dump(PGit::Configuration.default_options)
53
- end
54
-
55
- def validate_presence_of_items_in_each_project
56
- projects = @yaml["projects"]
57
- all_present = projects.all? do |project|
58
- project["api_token"] &&
59
- project["path"] &&
60
- project["id"]
61
- end
62
-
63
- unless all_present
64
- raise "Error: Must have a path, id, and api_token for each project.\n" +
65
- general_error_message
66
- end
67
- end
68
-
69
- def validate_existence_of_at_least_one_project
70
- unless @yaml["projects"]
71
- raise "Error: #{@expanded_path} needs at least one project.\n" +
72
- general_error_message
73
-
74
- end
33
+ @validator.yaml
75
34
  end
76
35
  end
77
36
  end
@@ -0,0 +1,9 @@
1
+ module PGit
2
+ class Configuration
3
+ class LayoutError < PGit::Error
4
+ def prepend_general_message(message)
5
+ "#{message}\nPlease have the following layout:\n" + YAML.dump(PGit::Configuration.default_options)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module PGit
2
+ class Configuration
3
+ class MissingAttributesError < PGit::Configuration::LayoutError
4
+ def initialize(path)
5
+ @message = prepend_general_message "#{path} must have a path, id, and api_token for each project."
6
+ super(@message)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module PGit
2
+ class Configuration
3
+ class NotFoundError < PGit::Error
4
+ def initialize(config_path)
5
+ @message = "#{config_path} configuration file does not exist. Please run `pgit install`"
6
+ super(@message)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module PGit
2
+ class Configuration
3
+ class ProjectMissingError < PGit::Configuration::LayoutError
4
+ def initialize(path)
5
+ @message = prepend_general_message "#{path} needs at least one project."
6
+ super(@message)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,41 @@
1
+ module PGit
2
+ class Configuration
3
+ class Validator
4
+ attr_reader :yaml
5
+
6
+ def initialize(config_path)
7
+ @expanded_path = File.expand_path(config_path)
8
+ if File.exists? @expanded_path
9
+ config_file = File.open(@expanded_path, 'r')
10
+ @yaml = YAML.load(config_file)
11
+
12
+ validate_existence_of_at_least_one_project
13
+ validate_presence_of_items_in_each_project
14
+ else
15
+ raise PGit::Configuration::NotFoundError.new(@expanded_path)
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def validate_presence_of_items_in_each_project
22
+ projects = @yaml["projects"]
23
+ all_present = projects.all? do |project|
24
+ project["api_token"] &&
25
+ project["path"] &&
26
+ project["id"]
27
+ end
28
+
29
+ unless all_present
30
+ raise PGit::Configuration::MissingAttributesError.new(@expanded_path)
31
+ end
32
+ end
33
+
34
+ def validate_existence_of_at_least_one_project
35
+ unless @yaml["projects"]
36
+ raise PGit::Configuration::ProjectMissingError.new(@expanded_path)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -27,12 +27,6 @@ module PGit
27
27
 
28
28
  private
29
29
 
30
- def validate_pwd_match_at_least_one(matching_projects)
31
- if matching_projects.length == 0
32
- raise "None of the project paths matches the working directory"
33
- end
34
- end
35
-
36
30
  def escape_slashes(project_path)
37
31
  project_path.gsub('/','\/')
38
32
  end
@@ -50,7 +44,7 @@ module PGit
50
44
  projects = config_yaml["projects"]
51
45
  matching_projects = find_matching_projects(projects)
52
46
 
53
- validate_pwd_match_at_least_one(matching_projects)
47
+ PGit::CurrentProject::Validator.new(matching_projects)
54
48
  find_best_match(matching_projects)
55
49
  end
56
50
 
@@ -0,0 +1,10 @@
1
+ module PGit
2
+ class CurrentProject
3
+ class NoPathsMatchWorkingDirError < PGit::Error
4
+ def initialize
5
+ @message = "None of the project paths matches the working directory"
6
+ super(@message)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ module PGit
2
+ class CurrentProject
3
+ class Validator
4
+ def initialize(matching_projects)
5
+ if matching_projects.length == 0
6
+ raise PGit::CurrentProject::NoPathsMatchWorkingDirError.new
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ module PGit
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -0,0 +1,9 @@
1
+ module PGit
2
+ class ExternalError < PGit::Error
3
+ def initialize(message)
4
+ @message = message
5
+
6
+ super @message
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,34 @@
1
+ module PGit
2
+ module Installer
3
+ class Configuration
4
+ FILEPATH = "~/.pgit.rc.yml"
5
+ def initialize(glob_opts, opts, args)
6
+ @expanded_path = File.expand_path(FILEPATH)
7
+
8
+ if File.exists? @expanded_path
9
+ warn "#{FILEPATH} already exists"
10
+ else
11
+ ask_continue
12
+ end
13
+ end
14
+
15
+ def ask_continue
16
+ puts "*** Installing example pgit configuration file under #{FILEPATH}. Continue? [Y/n]"
17
+ if STDIN.gets.chomp.match(/y/i)
18
+ puts "Saving example pgit config in #{FILEPATH}..."
19
+ write_example_pgit_rc_file
20
+ else
21
+ puts "Aborting installation..."
22
+ end
23
+ end
24
+
25
+ def write_example_pgit_rc_file
26
+ File.open(@expanded_path, 'w') do |f|
27
+ YAML.dump(PGit::Configuration.default_options, f)
28
+ end
29
+
30
+ puts "Saved! Please edit #{FILEPATH} and add the proper Pivotal Tracker API tokens, id, and file paths for each project"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,27 @@
1
+ module PGit
2
+ class PivotalRequestValidator
3
+ attr_reader :request
4
+
5
+ def initialize(request)
6
+ @request = request
7
+
8
+ validate
9
+ end
10
+
11
+ private
12
+
13
+ def validate
14
+ if kind_error? || no_kind?
15
+ raise PGit::ExternalError.new(@request)
16
+ end
17
+ end
18
+
19
+ def kind_error?
20
+ @request.match(/"kind": "error"/)
21
+ end
22
+
23
+ def no_kind?
24
+ !@request.match(/"kind"/)
25
+ end
26
+ end
27
+ end
@@ -28,12 +28,8 @@ module PGit
28
28
  end
29
29
 
30
30
  def get!
31
- request = `#{get_request}`
32
- if request.match(/error/)
33
- raise request
34
- else
35
- request
36
- end
31
+ validator = PGit::PivotalRequestValidator.new `#{get_request}`
32
+ validator.request
37
33
  end
38
34
 
39
35
  def link
@@ -1,3 +1,3 @@
1
1
  module Pgit
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -18,6 +18,8 @@ spec = Gem::Specification.new do |s|
18
18
  s.executables << 'pgit'
19
19
  s.add_development_dependency('rake')
20
20
  s.add_development_dependency('rspec', '~> 3.1')
21
+ s.add_development_dependency('coveralls', '~> 0.7')
22
+ s.add_development_dependency('simplecov', '~> 0.9')
21
23
  s.add_runtime_dependency('gli','2.12.2')
22
24
  s.license = 'MIT'
23
25
  s.requirements << 'At least one project that uses Pivotal Tracker and Git'
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'PGit::Configuration::MissingAttributesError' do
4
+ it 'should inherit from PGit::Error' do
5
+ ancestors = PGit::Configuration::MissingAttributesError.ancestors
6
+
7
+ expect(ancestors).to include (PGit::Error)
8
+ end
9
+
10
+ it 'should complain saying that a project must exist' do
11
+ error_message = <<-ERROR
12
+ /Users/edderic/some/config/path.yml must have a path, id, and api_token for each project.
13
+ Please have the following layout:
14
+ ---
15
+ projects:
16
+ - api_token: somepivotalatoken124
17
+ id: '12345'
18
+ path: "~/some/path/to/a/pivotal-git/project"
19
+ - api_token: somepivotalatoken124
20
+ id: '23429070'
21
+ path: "~/some/other/pivotal-git/project"
22
+ ERROR
23
+ error_message.gsub!(/^\s{6}/,'')
24
+ fake_path = "/Users/edderic/some/config/path.yml"
25
+ missing_attributes_error = PGit::Configuration::MissingAttributesError.new(fake_path)
26
+ message = missing_attributes_error.instance_eval{ @message }
27
+
28
+ expect(message).to eq error_message
29
+ end
30
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'PGit::Configuration::NotFoundError' do
4
+ it 'should inherit from PGit::Error' do
5
+ ancestors = PGit::Configuration::NotFoundError.ancestors
6
+
7
+ expect(ancestors).to include (PGit::Error)
8
+ end
9
+
10
+ it 'should complain that the Configuration file does not exist' do
11
+ fake_config_path = "/Users/edderic/some/path/to/.pgit.rc.yml"
12
+ not_found_error = PGit::Configuration::NotFoundError.new(fake_config_path)
13
+ message = not_found_error.instance_eval{ @message }
14
+
15
+ expect(message).to eq "#{fake_config_path} configuration file does not exist. Please run `pgit install`"
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'PGit::Configuration::ProjectMissingError' do
4
+ it 'should inherit from PGit::Error' do
5
+ ancestors = PGit::Configuration::ProjectMissingError.ancestors
6
+
7
+ expect(ancestors).to include (PGit::Error)
8
+ end
9
+
10
+ it 'should complain saying that a project must exist' do
11
+ error_message = <<-ERROR
12
+ /Users/edderic/some/config/path.yml needs at least one project.
13
+ Please have the following layout:
14
+ ---
15
+ projects:
16
+ - api_token: somepivotalatoken124
17
+ id: '12345'
18
+ path: "~/some/path/to/a/pivotal-git/project"
19
+ - api_token: somepivotalatoken124
20
+ id: '23429070'
21
+ path: "~/some/other/pivotal-git/project"
22
+ ERROR
23
+ error_message.gsub!(/^\s{6}/,'')
24
+ fake_path = "/Users/edderic/some/config/path.yml"
25
+ project_missing_error = PGit::Configuration::ProjectMissingError.new(fake_path)
26
+ message = project_missing_error.instance_eval{ @message }
27
+
28
+ expect(message).to eq error_message
29
+ end
30
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'PGit::Configuration::Validator' do
4
+ describe '#new(configuration_path)' do
5
+ describe 'empty file' do
6
+ it 'should complain that there should be at least one project' do
7
+ fake_path = "~/some/config/path.yml"
8
+ fake_expanded_path = "/Users/edderic/some/config/path.yml"
9
+ fake_file = double('file')
10
+ fake_yaml = {}
11
+
12
+ allow(File).to receive(:expand_path).with(fake_path).and_return(fake_expanded_path)
13
+ allow(File).to receive(:expand_path).with('.')
14
+ allow(File).to receive(:exists?).with(fake_expanded_path).and_return(true)
15
+ allow(File).to receive(:open).with(fake_expanded_path, 'r').and_return(fake_file)
16
+ allow(YAML).to receive(:load).with(fake_file).and_return(fake_yaml)
17
+
18
+ expect do
19
+ PGit::Configuration::Validator.new(fake_path)
20
+ end.to raise_error(PGit::Configuration::ProjectMissingError)
21
+ end
22
+ end
23
+
24
+ describe 'has projects but is missing a token' do
25
+ it 'should raise an error' do
26
+ fake_path = "~/some/config/path.yml"
27
+ fake_expanded_path = "/Users/edderic/some/config/path.yml"
28
+ fake_file = double('file')
29
+ fake_projects = [ { path: 'fake_path',
30
+ api_token: 'fake_token'
31
+ }]
32
+ fake_yaml = { 'projects' => fake_projects }
33
+
34
+ allow(File).to receive(:expand_path).with(fake_path).and_return(fake_expanded_path)
35
+ allow(File).to receive(:expand_path).with('.')
36
+ allow(File).to receive(:exists?).with(fake_expanded_path).and_return(true)
37
+ allow(File).to receive(:open).with(fake_expanded_path, 'r').and_return(fake_file)
38
+ allow(YAML).to receive(:load).with(fake_file).and_return(fake_yaml)
39
+
40
+ expect do
41
+ PGit::Configuration::Validator.new(fake_path)
42
+ end.to raise_error(PGit::Configuration::MissingAttributesError)
43
+ end
44
+ end
45
+
46
+ describe 'configuration_path exists' do
47
+ it '#yaml should return the yaml file' do
48
+ fake_path = "~/some/config/path.yml"
49
+ fake_expanded_path = "/Users/edderic/some/config/path.yml"
50
+ fake_file = double('file')
51
+ fake_projects = [ { "path" => 'fake_path',
52
+ "id" => 'fake_id',
53
+ "api_token" => 'fake_token'
54
+ }]
55
+
56
+ fake_yaml = { 'projects' => fake_projects }
57
+
58
+ allow(File).to receive(:expand_path).with(fake_path).and_return(fake_expanded_path)
59
+ allow(File).to receive(:exists?).with(fake_expanded_path).and_return(true)
60
+ allow(File).to receive(:open).with(fake_expanded_path, 'r').and_return(fake_file)
61
+ allow(YAML).to receive(:load).with(fake_file).and_return(fake_yaml)
62
+
63
+ configuration = PGit::Configuration::Validator.new(fake_path)
64
+
65
+ expect(configuration.yaml).to eq fake_yaml
66
+ end
67
+ end
68
+
69
+ describe 'configuration path does not exist' do
70
+ it 'should throw an error' do
71
+ file_path = '~/.edderic-dotfiles/config/project.yml'
72
+ fake_expanded_path = "/home/edderic/.edderic-dotfiles/config/project.yml"
73
+ allow(File).to receive(:exists?).and_return(false)
74
+
75
+ expect{ PGit::Configuration::Validator.new(file_path) }.to raise_error(PGit::Configuration::NotFoundError)
76
+ end
77
+ end
78
+ end
79
+ end