gitlab-triage 1.1.0 → 1.1.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
  SHA256:
3
- metadata.gz: 743f14cae78b04f7df22e21ef0ce1f75a17c7d12e7b40376334f12c92f236fb9
4
- data.tar.gz: 38d6dafa53eaacf4daecd70eb22cf726862955a2d0d37f92fcdf3e975c10ba95
3
+ metadata.gz: da8631c8e4a01092f91bba3be37db11cbadee2e321c62922f1a2a27ea3a98e41
4
+ data.tar.gz: cc565d9cc79cbdfdbabaa5f86880172cd5ef711b3d8ac2286476a045ae1510fe
5
5
  SHA512:
6
- metadata.gz: e0e1e9ff19465cfe990d392ea6a1332a2be2c021a9fa7bdf91af55e0c74ec1ea4d48fe7f7c7067c16fda1a34d56f69c5685d9c64a6fcf75e6a759a24e2b5f204
7
- data.tar.gz: 452730d44ec1dd9880c57fb077411003e25988727c4eb04d277ef04229092ef04748582e6bb4f0c9008ba38cf38b99ef119e452a7e7742436a755275524747f4
6
+ metadata.gz: e2b39262189075194795e05df1adf15eaa86a987731834f821f3daa24e06642cbcc9b97a918cdae7827d4a89d29c204c4f6c939a1cdb597d8a665c0971116a4f
7
+ data.tar.gz: 13aeac661214408c2584a6b41b9bbf9a69f1fb68e620f5f5fea08a9f74635315a0e8e03c84f86ab5ce84b71a32b206f368b433dfff90e2903d0e2eba625da4a2
@@ -13,6 +13,8 @@ require_relative 'limiters/date_field_limiter'
13
13
  require_relative 'action'
14
14
  require_relative 'policies/rule_policy'
15
15
  require_relative 'policies/summary_policy'
16
+ require_relative 'policies_resources/rule_resources'
17
+ require_relative 'policies_resources/summary_resources'
16
18
  require_relative 'api_query_builders/single_query_param_builder'
17
19
  require_relative 'api_query_builders/multi_query_param_builder'
18
20
  require_relative 'url_builders/url_builder'
@@ -120,9 +122,9 @@ module Gitlab
120
122
  puts Gitlab::Triage::UI.header("Processing summary: **#{summary[:name]}**", char: '~')
121
123
  puts
122
124
 
123
- summary_parts_for_rules(resource_type, summary[:rules]) do |parts|
125
+ summary_parts_for_rules(resource_type, summary[:rules]) do |resources|
124
126
  policy = Policies::SummaryPolicy.new(
125
- resource_type, summary, parts, network)
127
+ resource_type, summary, resources, network)
126
128
 
127
129
  process_action(policy)
128
130
  end
@@ -141,7 +143,7 @@ module Gitlab
141
143
  end
142
144
  end
143
145
 
144
- yield(parts)
146
+ yield(PoliciesResources::SummaryResources.new(parts))
145
147
  end
146
148
 
147
149
  def resources_for_rule(resource_type, rule)
@@ -163,7 +165,7 @@ module Gitlab
163
165
  puts "\n* Total after limiting: #{resources.count} resources"
164
166
  puts
165
167
 
166
- yield(resources, conditions)
168
+ yield(PoliciesResources::RuleResources.new(resources), conditions)
167
169
  end
168
170
  end
169
171
 
@@ -6,8 +6,11 @@ module Gitlab
6
6
  module Triage
7
7
  module EntityBuilders
8
8
  class IssueBuilder
9
- def initialize(type:, action:, resources:, network:, separator: "\n")
9
+ def initialize(
10
+ type:, action:, resources:, network:,
11
+ policy_spec: {}, separator: "\n")
10
12
  @type = type
13
+ @policy_spec = policy_spec
11
14
  @item_template = action[:item]
12
15
  @title_template = action[:title]
13
16
  @summary_template = action[:summary]
@@ -9,8 +9,7 @@ module Gitlab
9
9
  def initialize(type, policy_spec, resources, network)
10
10
  @type = type
11
11
  @policy_spec = policy_spec
12
- # In some filters/actions we want to know which resource type it is
13
- @resources = attach_resource_type(resources, type)
12
+ @resources = resources
14
13
  @network = network
15
14
  end
16
15
 
@@ -34,14 +33,6 @@ module Gitlab
34
33
  def build_issue
35
34
  raise NotImplementedError
36
35
  end
37
-
38
- private
39
-
40
- # We don't have to do this once the response will contain the type
41
- # of the resource. For now let's just attach it.
42
- def attach_resource_type(resources, type)
43
- resources.map { |resource| resource.reverse_merge(type: type) }
44
- end
45
36
  end
46
37
  end
47
38
  end
@@ -13,8 +13,9 @@ module Gitlab
13
13
 
14
14
  EntityBuilders::IssueBuilder.new(
15
15
  type: type,
16
+ policy_spec: policy_spec,
16
17
  action: action,
17
- resources: resources,
18
+ resources: resources.resources,
18
19
  network: network)
19
20
  end
20
21
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'base_policy'
4
- require_relative 'rule_policy'
5
4
  require_relative '../entity_builders/issue_builder'
6
5
 
7
6
  module Gitlab
@@ -11,13 +10,11 @@ module Gitlab
11
10
  # Build an issue from several rules policies
12
11
  def build_issue
13
12
  action = actions[:summarize]
14
-
15
- issues =
16
- resources.map do |inner_policy_spec, inner_resources|
17
- Policies::RulePolicy.new(
18
- type, inner_policy_spec, inner_resources, network)
19
- .build_issue
20
- end
13
+ issues = resources.build_issues do |inner_policy_spec, inner_resources|
14
+ Policies::RulePolicy.new(
15
+ type, inner_policy_spec, inner_resources, network)
16
+ .build_issue
17
+ end
21
18
 
22
19
  EntityBuilders::IssueBuilder.new(
23
20
  type: type,
@@ -26,20 +23,6 @@ module Gitlab
26
23
  network: network,
27
24
  separator: "\n\n")
28
25
  end
29
-
30
- # Due to resources is a different type, this will never work
31
- # FIXME: We should try to make sure type is consistent for resources
32
- def comment?
33
- false
34
- end
35
-
36
- private
37
-
38
- def attach_resource_type(resources, type)
39
- resources.each_with_object({}) do |(rule, rule_resources), result|
40
- result[rule] = super(rule_resources, type)
41
- end
42
- end
43
26
  end
44
27
  end
45
28
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gitlab
4
+ module Triage
5
+ module PoliciesResources
6
+ class RuleResources
7
+ attr_reader :resources
8
+
9
+ def initialize(new_resources)
10
+ @resources = new_resources
11
+ end
12
+
13
+ def each
14
+ resources.each do |resource|
15
+ yield(resource)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gitlab
4
+ module Triage
5
+ module PoliciesResources
6
+ class SummaryResources
7
+ attr_reader :rule_to_resources
8
+
9
+ def initialize(new_rule_to_resources)
10
+ @rule_to_resources = new_rule_to_resources
11
+ end
12
+
13
+ def build_issues
14
+ rule_to_resources.map do |inner_policy_spec, inner_resources|
15
+ yield(inner_policy_spec, inner_resources)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,5 @@
1
1
  module Gitlab
2
2
  module Triage
3
- VERSION = '1.1.0'.freeze
3
+ VERSION = '1.1.1'.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: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitLab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-19 00:00:00.000000000 Z
11
+ date: 2019-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -172,6 +172,8 @@ files:
172
172
  - lib/gitlab/triage/policies/base_policy.rb
173
173
  - lib/gitlab/triage/policies/rule_policy.rb
174
174
  - lib/gitlab/triage/policies/summary_policy.rb
175
+ - lib/gitlab/triage/policies_resources/rule_resources.rb
176
+ - lib/gitlab/triage/policies_resources/summary_resources.rb
175
177
  - lib/gitlab/triage/resource/base.rb
176
178
  - lib/gitlab/triage/resource/context.rb
177
179
  - lib/gitlab/triage/resource/instance_version.rb