gitlab-triage 0.4.0 → 0.5.0

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: f135ad3ee8a932b96aa63b996b47c3dfb4c144a8294087492c75b206fd9cc0a5
4
- data.tar.gz: 0af305681bc53fdd8d3b7f0a8eb86889d1da37bef53b24d837b067c336d02142
3
+ metadata.gz: e60f60430321d0d1be1393d07613ce3e2173cdb45552a530783f797e5b8fe830
4
+ data.tar.gz: 96166faf93db799035226e0cb052bb56b50bbfb95df74c074b944b3b61a1557e
5
5
  SHA512:
6
- metadata.gz: 4e415ad62d834aaf20ca0f567bdd135fc36d8e9c8cd92251410aab5464232c227af6032adcbba9bc7ca955bbbc72e4192f495dc56ecc1f18d2fac249cc96fd42
7
- data.tar.gz: 8a6b44160f809fb5b4fc3ef5bcd0d09f7b12dba043d543a27c8b4ce31549b2b9cb32317bd205bcd23faaf445a3fca27bf80af9a937f52dfd2c96073530600ebb
6
+ metadata.gz: e6ba81eb4674a0b436b9f31079f1aa557c95b454eb1378ab9c18994ac53faf9cc51e213393c404622cf45131f06da883c7b3940bc4009dc0c1f45b564faf7fa5
7
+ data.tar.gz: 2eefc9bf80feb415a9d820009d6f58b78698be4e426247ec50356289fa8bbe668de7da03057506a0bdc35809bb99956fa868b2aae535cbafa97671575ae84ab6
data/README.md CHANGED
@@ -86,7 +86,9 @@ Available condition types:
86
86
  - [`upvotes` condition](#upvotes-condition)
87
87
  - [`labels` condition](#labels-condition)
88
88
  - [`forbidden_labels` condition](#forbidden-labels-condition)
89
+ - [`no_additional_labels` condition](#no-additional-labels-condition)
89
90
  - [`author_member` condition](#author-member-condition)
91
+ - [`assignee_member` condition](#assignee-member-condition)
90
92
 
91
93
  ##### Date condition
92
94
 
@@ -189,6 +191,20 @@ conditions:
189
191
  - awaiting feedback
190
192
  ```
191
193
 
194
+ ##### No additional labels condition
195
+
196
+ Accepts a boolean. If `true` the resource cannot have more labels than those specified by the `labels` condition.
197
+
198
+
199
+ Example:
200
+
201
+ ```yml
202
+ conditions:
203
+ labels:
204
+ - feature proposal
205
+ no_additional_labels: true
206
+ ```
207
+
192
208
  ##### Author Member condition
193
209
 
194
210
  This condition determines whether the author of a resource is a member of the specified group or project.
@@ -201,13 +217,35 @@ Accepts a hash of fields.
201
217
  | --------- | ---- | ---- | -------- |
202
218
  | `source` | string | `group`, `project` | yes |
203
219
  | `condition` | string | `member_of`, `not_member_of` | yes |
204
- | `source_id` | integer | integer | yes |
220
+ | `source_id` | integer or string | gitlab-org/gitlab-ce | yes |
221
+
222
+ Example:
223
+
224
+ ```yml
225
+ conditions:
226
+ author_member:
227
+ source: group
228
+ condition: not_member_of
229
+ source_id: 9970
230
+ ```
231
+
232
+ ##### Assignee Member condition
233
+
234
+ This condition determines whether the assignee of a resource is a member of the specified group or project.
235
+
236
+ Accepts a hash of fields.
237
+
238
+ | Field | Type | Values | Required |
239
+ | --------- | ---- | ---- | -------- |
240
+ | `source` | string | `group`, `project` | yes |
241
+ | `condition` | string | `member_of`, `not_member_of` | yes |
242
+ | `source_id` | integer or string | gitlab-org/gitlab-ce | yes |
205
243
 
206
244
  Example:
207
245
 
208
246
  ```yml
209
247
  conditions:
210
- author:
248
+ assignee_member:
211
249
  source: group
212
250
  condition: not_member_of
213
251
  source_id: 9970
@@ -3,7 +3,9 @@ require 'active_support/all'
3
3
  require_relative 'limiters/date_conditions_limiter'
4
4
  require_relative 'limiters/votes_conditions_limiter'
5
5
  require_relative 'limiters/forbidden_labels_conditions_limiter'
6
+ require_relative 'limiters/no_additional_labels_conditions_limiter'
6
7
  require_relative 'limiters/author_member_conditions_limiter'
8
+ require_relative 'limiters/assignee_member_conditions_limiter'
7
9
  require_relative 'command_builders/comment_command_builder'
8
10
  require_relative 'command_builders/label_command_builder'
9
11
  require_relative 'command_builders/remove_label_command_builder'
@@ -100,7 +102,9 @@ module Gitlab
100
102
  results << Limiters::DateConditionsLimiter.new(resource, conditions[:date]).calculate if conditions[:date]
101
103
  results << Limiters::VotesConditionsLimiter.new(resource, conditions[:upvotes]).calculate if conditions[:upvotes]
102
104
  results << Limiters::ForbiddenLabelsConditionsLimiter.new(resource, conditions[:forbidden_labels]).calculate if conditions[:forbidden_labels]
103
- results << Limiters::AuthorMemberConditionsLimiter.new(resource, conditions[:author_member], { host_url: host_url, api_version: api_version, token: options.token, network: network }).calculate if conditions[:author]
105
+ results << Limiters::NoAdditionalLabelsConditionsLimiter.new(resource, conditions.fetch(:labels) { [] }).calculate if conditions[:no_additional_labels]
106
+ results << Limiters::AuthorMemberConditionsLimiter.new(resource, conditions[:author_member], { host_url: host_url, api_version: api_version, token: options.token, network: network }).calculate if conditions[:author_member]
107
+ results << Limiters::AssigneeMemberConditionsLimiter.new(resource, conditions[:assignee_member], { host_url: host_url, api_version: api_version, token: options.token, network: network }).calculate if conditions[:assignee_member]
104
108
  !results.uniq.include?(false)
105
109
  end
106
110
  end
@@ -0,0 +1,13 @@
1
+ require_relative 'member_conditions_limiter'
2
+
3
+ module Gitlab
4
+ module Triage
5
+ module Limiters
6
+ class AssigneeMemberConditionsLimiter < MemberConditionsLimiter
7
+ def member_field
8
+ :assignee
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,82 +1,11 @@
1
- require_relative 'base_conditions_limiter'
2
- require_relative '../url_builders/url_builder'
1
+ require_relative 'member_conditions_limiter'
3
2
 
4
3
  module Gitlab
5
4
  module Triage
6
5
  module Limiters
7
- class AuthorMemberConditionsLimiter < BaseConditionsLimiter
8
- SOURCES = %w[project group].freeze
9
- CONDITIONS = %w[member_of not_member_of].freeze
10
-
11
- def initialize(resource, condition, net = {})
12
- @net = net
13
- @network = net[:network]
14
- super(resource, condition)
15
- end
16
-
17
- def self.limiter_parameters
18
- [
19
- {
20
- name: :source,
21
- type: String,
22
- values: SOURCES
23
- },
24
- {
25
- name: :condition,
26
- type: String,
27
- values: CONDITIONS
28
- },
29
- {
30
- name: :source_id,
31
- type: Numeric
32
- }
33
- ]
34
- end
35
-
36
- def initialize_variables(condition)
37
- @source = condition[:source].to_sym
38
- @condition = condition[:condition].to_sym
39
- @source_id = condition[:source_id]
40
- end
41
-
42
- def resource_value
43
- @resource[:author][:username]
44
- end
45
-
46
- def condition_value
47
- members.map do |member|
48
- member[:username]
49
- end
50
- end
51
-
52
- def calculate
53
- case @condition
54
- when :member_of
55
- condition_value.include?(resource_value)
56
- when :not_member_of
57
- !condition_value.include?(resource_value)
58
- end
59
- end
60
-
61
- def members
62
- @members ||= @network.query_api(@net[:token], member_url)
63
- end
64
-
65
- def member_url
66
- UrlBuilders::UrlBuilder.new(net_opts).build
67
- end
68
-
69
- private
70
-
71
- def net_opts
72
- {
73
- host_url: @net[:host_url],
74
- api_version: @net[:api_version],
75
- resource_type: 'members',
76
- source: @source == :group ? 'groups' : 'projects',
77
- source_id: @source_id,
78
- params: { per_page: 100 }
79
- }
6
+ class AuthorMemberConditionsLimiter < MemberConditionsLimiter
7
+ def member_field
8
+ :author
80
9
  end
81
10
  end
82
11
  end
@@ -1,3 +1,5 @@
1
+ require 'active_support/all'
2
+
1
3
  module Gitlab
2
4
  module Triage
3
5
  module Limiters
@@ -48,7 +50,8 @@ module Gitlab
48
50
 
49
51
  def validate_parameter_types(condition)
50
52
  self.class.limiter_parameters.each do |param|
51
- raise ArgumentError, "#{param[:name]} must be of type #{param[:type]}" unless condition[param[:name]].is_a?(param[:type])
53
+ param_types = Array(param[:type]).flatten
54
+ raise ArgumentError, "#{param[:name]} must be of type #{param[:type]}" unless param_types.any? { |type| condition[param[:name]].is_a?(type) }
52
55
  end
53
56
  end
54
57
 
@@ -1,5 +1,3 @@
1
- require 'active_support/all'
2
-
3
1
  require_relative 'base_conditions_limiter'
4
2
 
5
3
  module Gitlab
@@ -0,0 +1,86 @@
1
+ require_relative 'base_conditions_limiter'
2
+ require_relative '../url_builders/url_builder'
3
+
4
+ module Gitlab
5
+ module Triage
6
+ module Limiters
7
+ class MemberConditionsLimiter < BaseConditionsLimiter
8
+ SOURCES = %w[project group].freeze
9
+ CONDITIONS = %w[member_of not_member_of].freeze
10
+
11
+ def initialize(resource, condition, net = {})
12
+ @net = net
13
+ @network = net[:network]
14
+ super(resource, condition)
15
+ end
16
+
17
+ def self.limiter_parameters
18
+ [
19
+ {
20
+ name: :source,
21
+ type: String,
22
+ values: SOURCES
23
+ },
24
+ {
25
+ name: :condition,
26
+ type: String,
27
+ values: CONDITIONS
28
+ },
29
+ {
30
+ name: :source_id,
31
+ type: [Numeric, String]
32
+ }
33
+ ]
34
+ end
35
+
36
+ def initialize_variables(condition)
37
+ @source = condition[:source].to_sym
38
+ @condition = condition[:condition].to_sym
39
+ @source_id = condition[:source_id]
40
+ end
41
+
42
+ def resource_value
43
+ @resource[member_field][:username] if @resource[member_field]
44
+ end
45
+
46
+ def condition_value
47
+ members.map do |member|
48
+ member[:username]
49
+ end
50
+ end
51
+
52
+ def calculate
53
+ return false unless resource_value
54
+
55
+ case @condition
56
+ when :member_of
57
+ condition_value.include?(resource_value)
58
+ when :not_member_of
59
+ !condition_value.include?(resource_value)
60
+ end
61
+ end
62
+
63
+ def members
64
+ @members ||= @network.query_api(@net[:token], member_url)
65
+ end
66
+
67
+ def member_url
68
+ UrlBuilders::UrlBuilder.new(net_opts).build
69
+ end
70
+
71
+ private
72
+
73
+ def net_opts
74
+ {
75
+ host_url: @net[:host_url],
76
+ api_version: @net[:api_version],
77
+ resource_type: 'members',
78
+ source: @source == :group ? 'groups' : 'projects',
79
+ source_id: @source_id,
80
+ params: { per_page: 100 }
81
+ }
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,30 @@
1
+ require_relative 'base_conditions_limiter'
2
+
3
+ module Gitlab
4
+ module Triage
5
+ module Limiters
6
+ class NoAdditionalLabelsConditionsLimiter < BaseConditionsLimiter
7
+ def self.limiter_parameters
8
+ []
9
+ end
10
+
11
+ def validate_condition(condition)
12
+ raise ArgumentError, 'condition must be an array containing the only label values allowed' unless condition.is_a?(Array)
13
+ end
14
+
15
+ def initialize_variables(expected_labels)
16
+ @attribute = :labels
17
+ @expected_labels = expected_labels
18
+ end
19
+
20
+ def resource_value
21
+ @resource[@attribute]
22
+ end
23
+
24
+ def calculate
25
+ (resource_value - @expected_labels).empty?
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,5 +1,5 @@
1
1
  module Gitlab
2
2
  module Triage
3
- VERSION = '0.4.0'.freeze
3
+ VERSION = '0.5.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-triage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitLab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-13 00:00:00.000000000 Z
11
+ date: 2018-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -127,11 +127,14 @@ files:
127
127
  - lib/gitlab/triage/filter_builders/base_filter_builder.rb
128
128
  - lib/gitlab/triage/filter_builders/multi_filter_builder.rb
129
129
  - lib/gitlab/triage/filter_builders/single_filter_builder.rb
130
+ - lib/gitlab/triage/limiters/assignee_member_conditions_limiter.rb
130
131
  - lib/gitlab/triage/limiters/author_member_conditions_limiter.rb
131
132
  - lib/gitlab/triage/limiters/base_conditions_limiter.rb
132
133
  - lib/gitlab/triage/limiters/date_conditions_limiter.rb
133
134
  - lib/gitlab/triage/limiters/forbidden_labels_conditions_limiter.rb
135
+ - lib/gitlab/triage/limiters/member_conditions_limiter.rb
134
136
  - lib/gitlab/triage/limiters/name_conditions_limiter.rb
137
+ - lib/gitlab/triage/limiters/no_additional_labels_conditions_limiter.rb
135
138
  - lib/gitlab/triage/limiters/votes_conditions_limiter.rb
136
139
  - lib/gitlab/triage/network.rb
137
140
  - lib/gitlab/triage/network_adapters/base_adapter.rb