pgit 0.0.3 → 0.0.4
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 +4 -4
- data/.coveralls.yml +1 -0
- data/README.markdown +3 -0
- data/bin/pgit +1 -1
- data/lib/pgit.rb +11 -1
- data/lib/pgit/configuration.rb +2 -43
- data/lib/pgit/configuration/layout_error.rb +9 -0
- data/lib/pgit/configuration/missing_attributes_error.rb +10 -0
- data/lib/pgit/configuration/not_found_error.rb +10 -0
- data/lib/pgit/configuration/project_missing_error.rb +10 -0
- data/lib/pgit/configuration/validator.rb +41 -0
- data/lib/pgit/current_project.rb +1 -7
- data/lib/pgit/current_project/no_paths_match_working_dir_error.rb +10 -0
- data/lib/pgit/current_project/validator.rb +11 -0
- data/lib/pgit/error.rb +4 -0
- data/lib/pgit/external_error.rb +9 -0
- data/lib/pgit/installer/configuration.rb +34 -0
- data/lib/pgit/pivotal_request_validator.rb +27 -0
- data/lib/pgit/story.rb +2 -6
- data/lib/pgit/version.rb +1 -1
- data/pgit.gemspec +2 -0
- data/spec/pgit/configuration/missing_attributes_error_spec.rb +30 -0
- data/spec/pgit/configuration/not_found_error_spec.rb +17 -0
- data/spec/pgit/configuration/project_missing_error_spec.rb +30 -0
- data/spec/pgit/configuration/validator_spec.rb +79 -0
- data/spec/pgit/configuration_spec.rb +22 -124
- data/spec/pgit/current_branch_spec.rb +1 -1
- data/spec/pgit/current_project/no_paths_match_working_dir_error_spec.rb +17 -0
- data/spec/pgit/current_project/validator_spec.rb +11 -0
- data/spec/pgit/current_project_spec.rb +17 -18
- data/spec/pgit/external_error_spec.rb +21 -0
- data/spec/pgit/installer/configuration_spec.rb +162 -0
- data/spec/pgit/pgit_spec.rb +2 -0
- data/spec/pgit/pivotal_request_validator_spec.rb +86 -0
- data/spec/pgit/story_branch/application_spec.rb +1 -1
- data/spec/pgit/story_branch_spec.rb +1 -1
- data/spec/pgit/story_spec.rb +1 -20
- data/spec/spec_helper.rb +101 -0
- metadata +52 -5
- data/lib/pgit/installer.rb +0 -32
- data/spec/pgit/application_spec.rb +0 -16
- data/spec/pgit/installer_spec.rb +0 -158
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d736adc51cc2cda472f63edadcddd766f7ad22a2
|
4
|
+
data.tar.gz: 2b7e43a567cb947507d4d1d1cd4c0704a02af14c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c30a313b05b8940dc915c14f13c9e36621c7c876dd1b8121d23d16d0a7d2bc74d39062e1543184cb3fd5bf9f2bfdb7c39cb81184a42aa48f0a2cc4292a67a72
|
7
|
+
data.tar.gz: e811579cab502fd70ed1dda709637222f42036e04fd8702636da4d99319236d27876a2bc44302adf9cb6b0d66a159bf1501e5c6a12183c5eab4170fa6c3e93e1
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/README.markdown
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
# PGit
|
2
2
|
|
3
3
|

|
4
|
+
[](http://badge.fury.io/rb/pgit)
|
4
5
|
[](https://codeclimate.com/github/Edderic/pgit)
|
6
|
+
[](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
|
|
data/lib/pgit.rb
CHANGED
@@ -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'
|
data/lib/pgit/configuration.rb
CHANGED
@@ -26,52 +26,11 @@ module PGit
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def initialize(config_path = '~/.pgit.rc.yml')
|
29
|
-
@
|
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,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,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
|
data/lib/pgit/current_project.rb
CHANGED
@@ -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
|
-
|
47
|
+
PGit::CurrentProject::Validator.new(matching_projects)
|
54
48
|
find_best_match(matching_projects)
|
55
49
|
end
|
56
50
|
|
data/lib/pgit/error.rb
ADDED
@@ -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
|
data/lib/pgit/story.rb
CHANGED
data/lib/pgit/version.rb
CHANGED
data/pgit.gemspec
CHANGED
@@ -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
|