cid 0.1.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a650014d0d2a82c2d3426e9d9f0ba4b037595755
4
- data.tar.gz: 7acf3492622ec5d725b99b6fa1f50c586520d0a0
3
+ metadata.gz: 5dd888724adb78e68f3a6760d4cb64317ca5e3e2
4
+ data.tar.gz: 610b3445181b32b18b0007f709e77185abf297b5
5
5
  SHA512:
6
- metadata.gz: 3a96b0626ef40947282b8ed42bd977090ab973bc67b491eb88cb7a416cd97f46bdd7230bafc01a22bb742195e19376430d0a818438d88f2125f6d4763cbe9b2a
7
- data.tar.gz: ee7428fdf1fa5d1e6fe424ccac98b678ac09731cf17bce72ef99dde3922d60d86165fa32cfc0f1f55ba86a0cbaaac67a2356050c19cc8f6dac433c861272e539
6
+ metadata.gz: f599d64d955fb3cc132bfc618210041f94ab421e893364ffb7f87612c6ec280a3f1aa2b978c88f94a0ef87b129ae8a0cddd512df1d67d554934465d58029d886
7
+ data.tar.gz: 40b378091289e6a7d048a1afd7a1b66d36e4ed6fd6d7b7e85ef42974bb4919c6d0d3b62b925cd5e7435cf1aee5e3db60a6b135e21fd9ee5c057ad7d6a332fa82
@@ -10,4 +10,4 @@ notifications:
10
10
  on_failure: always
11
11
  env:
12
12
  global:
13
- secure: HZhBJjfU3C6ub01Ioong30m3NMAoT5re8XwDg3VQ86L2Z/lz/Zz7FU+cJvLcJJaO7Jj7UmZK0ov0kFxIesIJMV/KsMfmMOlJjTMz0K5g/C/NaTIKlZTY4Mg53oS4fh0ZNogtfkttOfL/JLyNS2buuSEuMtFtC0+DXlqklQ/JT3w=
13
+ - secure: KTQ83GtNJyXwTUzYKbDtX1FzA3hsBSHefOqYsZ2KzOnj1dPZpGoeb4gcjWHXvNHqmR0mToT8U7KNq8AYWwHQLYCKf2+jRayd9UAzezhcs5u0SVfE5gmZLho57TW3AQvHI/uVQi9yg9/N3uDICqBplHJ7EMeMusUBc6ACF8FRmtY=
data/bin/cid CHANGED
@@ -3,67 +3,109 @@ $:.unshift File.join( File.dirname(__FILE__), "..", "lib")
3
3
 
4
4
  require 'cid'
5
5
  require 'colorize'
6
+ require 'thor'
6
7
 
7
- def print_error(index, error, color=:red)
8
- location = ""
9
- location += error.row.to_s if error.row
10
- location += "#{error.row ? "," : ""}#{error.column.to_s}" if error.column
11
- if error.row || error.column
12
- location = "#{error.row ? "Row" : "Column"}: #{location}"
13
- end
14
- puts "#{index+1}. #{error.type}. #{location}".colorize(color)
15
- end
8
+ class CidBin < Thor
16
9
 
17
- if ARGV[0] == "validate"
10
+ desc "validate PATH", "validate a package"
11
+ long_desc <<-LONGDESC
12
+ `cid validate` will validate a datapackage containing CSVs and schemas.
18
13
 
19
- if ARGV[1]
20
- source = ARGV[1]
21
- else
22
- source = "."
23
- end
14
+ It expects CSVs of each type to be in folders, with the schema that
15
+ relates to them.
24
16
 
25
- validation = Cid::Validation.validate(source)
17
+ By default, `cid validate` will look in your current folder, but you can
18
+ also specify which folder to look in:
26
19
 
27
- code = 0
20
+ > $ cid validate /this/is/a/datapackage
21
+ LONGDESC
22
+ def validate(source = ".")
23
+ check_path(source)
28
24
 
29
- validation.each do |k,v|
25
+ validation = Cid::Validation.validate(source)
30
26
 
31
- puts "#{k} is #{(v[:errors] + v[:warnings]).count == 0 ? "VALID".green : "INVALID".red}"
27
+ code = 0
32
28
 
33
- if v[:errors].length > 0
34
- v[:errors].each_with_index do |error, i|
35
- print_error(i, error)
36
- end
37
- end
29
+ validation.each do |k,v|
30
+ puts "#{k} is #{(v[:errors] + v[:warnings]).count == 0 ? "VALID".green : "INVALID".red}"
38
31
 
39
- if v[:warnings].length > 0
40
- v[:warnings].each_with_index do |error, i|
41
- print_error(i, error)
42
- end
32
+ v[:errors].each_with_index { |error, i| print_error(i, error) } if v[:errors].length > 0
33
+ v[:warnings].each_with_index { |error, i| print_error(i, error) } if v[:warnings].length > 0
34
+
35
+ code = 1 if (v[:errors] + v[:warnings]).count > 0
43
36
  end
44
37
 
45
- code = 1 if (v[:errors] + v[:warnings]).count > 0
38
+ exit code
46
39
 
47
40
  end
48
41
 
49
- exit code
42
+ desc "publish", "Publish a package to GitHub"
43
+ long_desc <<-LONGDESC
44
+ `cid publish` will create a new datapackage.json file based on the CSVs in
45
+ the package and push them to Github (unless you specify `--skip-github`)
46
+
47
+ By default, `cid publish` will look in your current folder, but you can
48
+ also specify which folder to look in:
49
+
50
+ > $ cid validate /this/is/a/datapackage
51
+ LONGDESC
52
+ option :github_token
53
+ option :skip_github, :type => :boolean
54
+ def publish(source = ".")
55
+ check_path(source)
56
+
57
+ github_token = options[:github_token] || ENV['GITHUB_OAUTH_TOKEN']
58
+
59
+ if github_token.blank? && !options[:skip_github]
60
+ error <<-ERROR
61
+ Github token not specified. Either add GITHUB_OAUTH_TOKEN as an
62
+ environment variable or `cid publish --github_token=TOKEN`
63
+ ERROR
64
+ puts error.colorize(:red)
65
+ exit 1
66
+ end
50
67
 
51
- elsif ARGV[0] == "publish"
68
+ datapackage = Cid::Datapackage.new(source)
69
+ datapackage.create
70
+ datapackage.write
71
+ puts "Datapackage created".colorize(:green)
72
+
73
+ unless options[:skip_github]
74
+ if File.exist?("#{source}/.git")
75
+ begin
76
+ datapackage.publish(github_token)
77
+ puts "Changes pushed successfully".colorize(:green)
78
+ rescue Github::Error::NotFound
79
+ puts "Github authorisation error. Are you allowed to push to this repo?".colorize(:red)
80
+ exit 1
81
+ end
82
+ else
83
+ puts "Git repo not found".colorize(:red)
84
+ exit 1
85
+ end
86
+ end
52
87
 
53
- if ARGV[1]
54
- source = ARGV[1]
55
- else
56
- source = "."
57
88
  end
58
89
 
59
- datapackage = Cid::Datapackage.new(source)
60
- datapackage.create
61
- datapackage.write
62
- if File.exist?("#{source}/.git")
63
- datapackage.publish
64
- puts "Changes pushed successfully".colorize(:green)
65
- else
66
- puts "Git repo not found".colorize(:red)
67
- exit 1
68
- end
90
+ private
91
+
92
+ def print_error(index, error, color=:red)
93
+ location = ""
94
+ location += error.row.to_s if error.row
95
+ location += "#{error.row ? "," : ""}#{error.column.to_s}" if error.column
96
+ if error.row || error.column
97
+ location = "#{error.row ? "Row" : "Column"}: #{location}"
98
+ end
99
+ puts "#{index+1}. #{error.type}. #{location}".colorize(color)
100
+ end
101
+
102
+ def check_path(path)
103
+ if !File.directory?(path)
104
+ puts "Path doesn't exist!".colorize(:red)
105
+ exit 1
106
+ end
107
+ end
108
+
69
109
  end
110
+
111
+ CidBin.start(ARGV)
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency "github_api"
25
25
  spec.add_dependency "dotenv"
26
26
  spec.add_dependency "memoist"
27
+ spec.add_dependency "thor"
27
28
 
28
29
  spec.add_development_dependency "bundler", "~> 1.3"
29
30
  spec.add_development_dependency "rake"
@@ -5,6 +5,7 @@ Feature: Publish a datapackage
5
5
  Given I run `cp -r ../../spec/fixtures/valid valid`
6
6
  And I cd to "valid"
7
7
  When I run `cid publish`
8
+ Then the output should contain "Datapackage created"
8
9
  And I run `cat datapackage.json`
9
10
  Then the output should contain "votes/votes-1.csv"
10
11
 
@@ -12,6 +13,7 @@ Feature: Publish a datapackage
12
13
  Given I run `cp -r ../../spec/fixtures/multiple_files multiple_files`
13
14
  And I cd to "multiple_files"
14
15
  When I run `cid publish`
16
+ Then the output should contain "Datapackage created"
15
17
  And I run `cat datapackage.json`
16
18
  Then the output should contain "votes/votes-1.csv"
17
19
  And the output should contain "votes/votes-2.csv"
@@ -21,9 +23,38 @@ Feature: Publish a datapackage
21
23
  And I cd to "multiple_files"
22
24
  When I run `cid publish`
23
25
  Then the output should contain "Git repo not found"
26
+ And the exit status should be 1
24
27
 
25
28
  Scenario: Sucessfully push to Github
26
29
  Given I run `git clone https://github.com/theodi/cid-test.git`
27
30
  And I cd to "cid-test"
28
31
  When I successfully run `cid publish`
29
32
  Then the output should contain "Changes pushed successfully"
33
+
34
+ Scenario: Path doesn't exist
35
+ When I run `cid publish /this/is/fake`
36
+ Then the output should contain "Path doesn't exist!"
37
+ And the exit status should be 1
38
+
39
+ Scenario: Github token not specified
40
+ Given I set the environment variables to:
41
+ | variable | value |
42
+ | GITHUB_OAUTH_TOKEN | |
43
+ When I run `cid publish`
44
+ Then the output should contain "Github token not specified"
45
+ And the exit status should be 1
46
+
47
+ Scenario: Failed Github push
48
+ Given I run `git clone https://github.com/pezholio/cid-test.git`
49
+ And I cd to "cid-test"
50
+ When I run `cid publish`
51
+ Then the output should contain "Github authorisation error"
52
+ And the exit status should be 1
53
+
54
+ Scenario: Skip GitHub
55
+ Given I run `cp -r ../../spec/fixtures/multiple_files multiple_files`
56
+ And I cd to "multiple_files"
57
+ When I run `cid publish --skip-github`
58
+ Then the output should contain "Datapackage created"
59
+ And the output should not contain "Git repo not found"
60
+ And the exit status should be 0
@@ -28,3 +28,8 @@ Feature: Validate a datapackage
28
28
  Scenario: Specify directory
29
29
  When I run `cid validate spec/fixtures/valid`
30
30
  Then the output should contain "votes/votes-1.csv is VALID"
31
+
32
+ Scenario: Path doesn't exist
33
+ When I run `cid validate /this/is/fake`
34
+ Then the output should contain "Path doesn't exist!"
35
+ And the exit status should be 1
@@ -47,8 +47,8 @@ module Cid
47
47
  File.open("#{@path}/datapackage.json", 'w') { |f| f.write(@json) }
48
48
  end
49
49
 
50
- def publish
51
- git = Cid::Publish.new(@path, ENV['GITHUB_OAUTH_TOKEN'])
50
+ def publish(token = ENV['GITHUB_OAUTH_TOKEN'])
51
+ git = Cid::Publish.new(@path, token)
52
52
  git.publish
53
53
  end
54
54
 
@@ -1,3 +1,3 @@
1
1
  module Cid
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - pezholio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-22 00:00:00.000000000 Z
11
+ date: 2014-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: csvlint
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: thor
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: bundler
113
127
  requirement: !ruby/object:Gem::Requirement