diffend 0.2.16 → 0.2.17

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d23a558405ac69141d76368e9a642d153300c2a9bb01fd67b9c8f3c949a9225b
4
- data.tar.gz: 5d74b929a8debf7c7a32aa0cb8d01e9f51c373b0859468a3936e40a1bccc1004
3
+ metadata.gz: c6a7edc516bd408637e9a48744eaa24aef9aaec48eb31c975d2640e3a222f672
4
+ data.tar.gz: ced39bedfb9898395d49657e416b09e15d0bf9f9c15dab4f042c619004bb04df
5
5
  SHA512:
6
- metadata.gz: 8fe13be65aad9dda4c8a4cf3341851d691f253e4dc2d3d4a31e1da2bba92bffb2902e69ea08f78a5d3a9c6a5fb3f233abf72dd569d732df317aa5f0d8748830b
7
- data.tar.gz: 86929a3b0259f8de839edfdd2901c203ed0e69d35a733d31860d6628c71a5874097efd3a08fb4203e4fa4768f110d5d36ec192f064b144b1a99c8c208111be0f
6
+ metadata.gz: 891292dea2577d6b6b0b3b28d96589354bb73e7ca71beba535781c5bbc2388ffa897510d9a0d1ee68643076845600715c786320f32e6ed11eb5a03807c7ec9ff
7
+ data.tar.gz: 0f84201f7550bbfa9a84e2be1c4c423087271d3b7a40b76ea9a4f0d80f50f350915dfd6500df8186a8e68861bf23f9c68d94ec3879261daa0bb8ddf0d3870b17
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- diffend (0.2.16)
4
+ diffend (0.2.17)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -5,10 +5,11 @@
5
5
  ].each(&method(:require))
6
6
 
7
7
  %w[
8
+ errors
8
9
  config/fetcher
9
10
  config/file_finder
11
+ config/validator
10
12
  commands
11
- errors
12
13
  voting
13
14
  ].each { |file| require "diffend/#{file}" }
14
15
 
@@ -21,7 +22,7 @@
21
22
  # Diffend main namespace
22
23
  module Diffend
23
24
  # Current plugin version
24
- VERSION = '0.2.16'
25
+ VERSION = '0.2.17'
25
26
  # Diffend homepage
26
27
  HOMEPAGE = 'https://diffend.io'
27
28
 
@@ -7,22 +7,105 @@ module Diffend
7
7
  module Config
8
8
  # Class responsible for fetching the config from .diffend.yml
9
9
  module Fetcher
10
+ # All the errors for missing keys in the configuration file
11
+ MISSING_KEY_ERRORS = [
12
+ Errors::ProjectIdMissingInConfigurationFile,
13
+ Errors::ShareableIdMissingInConfigurationFile,
14
+ Errors::ShareableKeyMissingInConfigurationFile,
15
+ Errors::BuildPathMissingInConfigurationFile
16
+ ].freeze
17
+
10
18
  class << self
11
19
  # @param build_path [String] path of the current build
20
+ #
12
21
  # @return [OpenStruct] open struct with config details
22
+ #
13
23
  # @example
14
24
  # details = Fetcher.new.call('./')
15
25
  # details.build_path #=> './'
16
26
  def call(build_path)
17
- OpenStruct.new(
18
- YAML.safe_load(
19
- ERB.new(
20
- File.read(
21
- FileFinder.call(build_path)
22
- )
23
- ).result
24
- ).merge(build_path: build_path)
25
- )
27
+ build(build_path)
28
+ rescue Errors::MissingConfigurationFile
29
+ Bundler.ui.error(build_missing_error_message(build_path))
30
+ exit 1
31
+ rescue Errors::EmptyConfigurationFile
32
+ Bundler.ui.error(build_empty_error_message(build_path))
33
+ exit 1
34
+ rescue Errors::MalformedConfigurationFile
35
+ Bundler.ui.error(build_malformed_error_message(build_path))
36
+ exit 1
37
+ rescue *MISSING_KEY_ERRORS => e
38
+ Bundler.ui.error(build_missing_key_error_message(e))
39
+ exit 1
40
+ end
41
+
42
+ private
43
+
44
+ # @param build_path [String] path of the current build
45
+ #
46
+ # @return [OpenStruct] open struct with config details
47
+ def build(build_path)
48
+ content = ERB.new(
49
+ File.read(
50
+ FileFinder.call(build_path)
51
+ )
52
+ ).result
53
+
54
+ raise Errors::EmptyConfigurationFile if content.empty?
55
+
56
+ OpenStruct.new(parse_file(content).merge(build_path: build_path))
57
+ .tap(&Validator.method(:call))
58
+ end
59
+
60
+ def parse_file(content)
61
+ YAML.safe_load(content)
62
+ rescue Psych::SyntaxError
63
+ raise Errors::MalformedConfigurationFile
64
+ end
65
+
66
+ # @param build_path [String] path of the current build
67
+ #
68
+ # @return [String] missing configuration file message
69
+ def build_missing_error_message(build_path)
70
+ <<~MSG
71
+ \nWe were unable to locate Diffend configuration file.\n
72
+ Please make sure that .diffend.yml is present in #{build_path} folder.\n
73
+ MSG
74
+ end
75
+
76
+ # @return [String] empty configuration file message
77
+ def build_empty_error_message
78
+ <<~MSG
79
+ \nYour Diffend configuration file is empty.\n
80
+ Please re-setup.\n
81
+ MSG
82
+ end
83
+
84
+ # @return [String] malformed configuration file message
85
+ def build_malformed_error_message
86
+ <<~MSG
87
+ \nYour Diffend configuration file is malformed.\n
88
+ Please re-setup.\n
89
+ MSG
90
+ end
91
+
92
+ # @return [String] malformed configuration file message
93
+ def build_missing_key_error_message(exception)
94
+ missing_key = missing_key_from_exception(exception)
95
+
96
+ <<~MSG
97
+ \nYour Diffend configuration file is missing #{missing_key} key.\n
98
+ Please re-setup.\n
99
+ MSG
100
+ end
101
+
102
+ def missing_key_from_exception(exception)
103
+ case exception
104
+ when Errors::ProjectIdMissingInConfigurationFile then 'project_id'
105
+ when Errors::ShareableIdMissingInConfigurationFile then 'shareable_id'
106
+ when Errors::ShareableKeyMissingInConfigurationFile then 'shareable_key'
107
+ when Errors::BuildPathMissingInConfigurationFile then 'build_path'
108
+ end
26
109
  end
27
110
  end
28
111
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Diffend
4
+ # Module for all the components related to setting up the config
5
+ module Config
6
+ # Class responsible for validating the config from .diffend.yml
7
+ module Validator
8
+ class << self
9
+ # @param config [OpenStruct] path of the current build
10
+ def call(config)
11
+ raise Errors::ProjectIdMissingInConfigurationFile if missing?(config, 'project_id')
12
+ raise Errors::ShareableIdMissingInConfigurationFile if missing?(config, 'shareable_id')
13
+ raise Errors::ShareableKeyMissingInConfigurationFile if missing?(config, 'shareable_key')
14
+ raise Errors::BuildPathMissingInConfigurationFile if missing?(config, 'build_path')
15
+ end
16
+
17
+ private
18
+
19
+ def missing?(config, key)
20
+ config.public_send(key).nil? || config.public_send(key).empty?
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -7,6 +7,18 @@ module Diffend
7
7
  BaseError = Class.new(StandardError)
8
8
  # Raised when we couldn't find a valid configuration file
9
9
  MissingConfigurationFile = Class.new(BaseError)
10
+ # Raised when configuration file is empty
11
+ EmptyConfigurationFile = Class.new(BaseError)
12
+ # Raised when configuration file is malformed
13
+ MalformedConfigurationFile = Class.new(BaseError)
14
+ # Raised when project_id is missing in configuration file
15
+ ProjectIdMissingInConfigurationFile = Class.new(BaseError)
16
+ # Raised when shareable_id is missing in configuration file
17
+ ShareableIdMissingInConfigurationFile = Class.new(BaseError)
18
+ # Raised when shareable_key is missing in configuration file
19
+ ShareableKeyMissingInConfigurationFile = Class.new(BaseError)
20
+ # Raised when build_path is missing in configuration file
21
+ BuildPathMissingInConfigurationFile = Class.new(BaseError)
10
22
  # When unsupported response returned from the endpoint
11
23
  UnsupportedResponse = Class.new(BaseError)
12
24
  # When unsupported action returned from the endpoint
@@ -164,8 +164,6 @@ module Diffend
164
164
  Config::Fetcher.call(
165
165
  File.expand_path('..', Bundler.bin_path)
166
166
  )
167
- rescue Errors::MissingConfigurationFile
168
- nil
169
167
  end
170
168
  end
171
169
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diffend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.16
4
+ version: 0.2.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomasz Pajor
@@ -34,7 +34,7 @@ cert_chain:
34
34
  9MmF6uCQa1EjK2p8tYT0MnbHrFkoehxdX4VO9y99GAkhZyJNKPYPtyAUFV27sT2V
35
35
  LfCJRk4ifKIN/FUCwDSn8Cz0m6oH265q0p6wdzI6qrWOjP8tGOMBTA==
36
36
  -----END CERTIFICATE-----
37
- date: 2020-07-28 00:00:00.000000000 Z
37
+ date: 2020-08-05 00:00:00.000000000 Z
38
38
  dependencies:
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: bundler
@@ -94,6 +94,7 @@ files:
94
94
  - lib/diffend/commands.rb
95
95
  - lib/diffend/config/fetcher.rb
96
96
  - lib/diffend/config/file_finder.rb
97
+ - lib/diffend/config/validator.rb
97
98
  - lib/diffend/errors.rb
98
99
  - lib/diffend/voting.rb
99
100
  - lib/diffend/voting/request.rb
metadata.gz.sig CHANGED
Binary file