gitlab-triage 1.14.1 → 1.17.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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.gitlab/merge_request_templates/Release.md +1 -1
  3. data/README.md +75 -4
  4. data/bin/gitlab-triage +5 -2
  5. data/lib/gitlab/triage/action.rb +8 -4
  6. data/lib/gitlab/triage/action/comment.rb +7 -4
  7. data/lib/gitlab/triage/action/comment_on_summary.rb +83 -0
  8. data/lib/gitlab/triage/action/summarize.rb +7 -1
  9. data/lib/gitlab/triage/api_query_builders/base_query_param_builder.rb +11 -2
  10. data/lib/gitlab/triage/api_query_builders/date_query_param_builder.rb +13 -50
  11. data/lib/gitlab/triage/api_query_builders/multi_query_param_builder.rb +10 -2
  12. data/lib/gitlab/triage/engine.rb +52 -11
  13. data/lib/gitlab/triage/errors/network.rb +2 -0
  14. data/lib/gitlab/triage/filters/discussions_conditions_filter.rb +1 -3
  15. data/lib/gitlab/triage/graphql_network.rb +28 -1
  16. data/lib/gitlab/triage/graphql_queries/query_builder.rb +72 -16
  17. data/lib/gitlab/triage/graphql_queries/query_param_builders/base_param_builder.rb +25 -0
  18. data/lib/gitlab/triage/graphql_queries/query_param_builders/date_param_builder.rb +35 -0
  19. data/lib/gitlab/triage/graphql_queries/query_param_builders/labels_param_builder.rb +18 -0
  20. data/lib/gitlab/triage/network.rb +9 -3
  21. data/lib/gitlab/triage/network_adapters/graphql_adapter.rb +33 -10
  22. data/lib/gitlab/triage/network_adapters/httparty_adapter.rb +10 -0
  23. data/lib/gitlab/triage/option_parser.rb +2 -0
  24. data/lib/gitlab/triage/param_builders/date_param_builder.rb +58 -0
  25. data/lib/gitlab/triage/policies/base_policy.rb +30 -1
  26. data/lib/gitlab/triage/resource/context.rb +1 -0
  27. data/lib/gitlab/triage/resource/epic.rb +24 -0
  28. data/lib/gitlab/triage/retryable.rb +7 -5
  29. data/lib/gitlab/triage/utils.rb +13 -0
  30. data/lib/gitlab/triage/validators/params_validator.rb +1 -1
  31. data/lib/gitlab/triage/version.rb +1 -1
  32. metadata +10 -5
  33. data/lib/gitlab/triage/graphql_queries/threads_query.rb +0 -31
  34. data/lib/gitlab/triage/graphql_queries/user_notes_query.rb +0 -23
@@ -19,6 +19,7 @@ module Gitlab
19
19
 
20
20
  raise_on_unauthorized_error!(response)
21
21
  raise_on_internal_server_error!(response)
22
+ raise_on_too_many_requests!(response)
22
23
 
23
24
  {
24
25
  more_pages: (response.headers["x-next-page"].to_s != ""),
@@ -41,6 +42,7 @@ module Gitlab
41
42
 
42
43
  raise_on_unauthorized_error!(response)
43
44
  raise_on_internal_server_error!(response)
45
+ raise_on_too_many_requests!(response)
44
46
 
45
47
  {
46
48
  results: response.parsed_response,
@@ -67,6 +69,14 @@ module Gitlab
67
69
  raise Errors::Network::InternalServerError, 'Internal server error encountered!'
68
70
  end
69
71
 
72
+ def raise_on_too_many_requests!(response)
73
+ return unless response.response.is_a?(Net::HTTPTooManyRequests)
74
+
75
+ puts Gitlab::Triage::UI.debug response.inspect if options.debug
76
+
77
+ raise Errors::Network::TooManyRequests, 'Too many requests made!'
78
+ end
79
+
70
80
  def next_page_url(url, response)
71
81
  return unless response.headers['x-next-page'].present?
72
82
 
@@ -88,6 +88,8 @@ module Gitlab
88
88
 
89
89
  parser.parse!(argv)
90
90
 
91
+ options.source = nil if options.all
92
+
91
93
  options
92
94
  end
93
95
  end
@@ -0,0 +1,58 @@
1
+ require_relative '../validators/params_validator'
2
+
3
+ module Gitlab
4
+ module Triage
5
+ module ParamBuilders
6
+ class DateParamBuilder
7
+ CONDITIONS = %w[older_than newer_than].freeze
8
+ INTERVAL_TYPES = %w[days weeks months years].freeze
9
+
10
+ def initialize(allowed_attributes, condition_hash)
11
+ @allowed_attributes = allowed_attributes
12
+ @attribute = condition_hash[:attribute].to_s
13
+ @interval_condition = condition_hash[:condition].to_sym
14
+ @interval_type = condition_hash[:interval_type]
15
+ @interval = condition_hash[:interval]
16
+
17
+ validate_condition(condition_hash)
18
+ end
19
+
20
+ def param_content
21
+ interval.public_send(interval_type).ago.to_date # rubocop:disable GitlabSecurity/PublicSend
22
+ end
23
+
24
+ private
25
+
26
+ attr_reader :allowed_attributes, :attribute, :interval_condition, :interval_type, :interval
27
+
28
+ def validate_condition(condition)
29
+ ParamsValidator.new(filter_parameters, condition).validate!
30
+ end
31
+
32
+ def filter_parameters
33
+ [
34
+ {
35
+ name: :attribute,
36
+ type: String,
37
+ values: allowed_attributes
38
+ },
39
+ {
40
+ name: :condition,
41
+ type: String,
42
+ values: CONDITIONS
43
+ },
44
+ {
45
+ name: :interval_type,
46
+ type: String,
47
+ values: INTERVAL_TYPES
48
+ },
49
+ {
50
+ name: :interval,
51
+ type: Numeric
52
+ }
53
+ ]
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -4,7 +4,10 @@ module Gitlab
4
4
  module Triage
5
5
  module Policies
6
6
  class BasePolicy
7
+ InvalidPolicyError = Class.new(StandardError)
8
+
7
9
  attr_reader :type, :policy_spec, :resources, :network
10
+ attr_accessor :summary
8
11
 
9
12
  def initialize(type, policy_spec, resources, network)
10
13
  @type = type
@@ -13,10 +16,32 @@ module Gitlab
13
16
  @network = network
14
17
  end
15
18
 
19
+ def validate!
20
+ raise InvalidPolicyError, 'Policies that comment_on_summary must include summarize action' if comment_on_summary? && !summarize?
21
+ end
22
+
16
23
  def name
17
24
  @name ||= (policy_spec[:name] || "#{type}-#{object_id}")
18
25
  end
19
26
 
27
+ def source
28
+ case type
29
+ when 'epics'
30
+ 'groups'
31
+ else
32
+ 'projects'
33
+ end
34
+ end
35
+
36
+ def source_id_sym
37
+ case type
38
+ when 'epics'
39
+ :group_id
40
+ else
41
+ :project_id
42
+ end
43
+ end
44
+
20
45
  def actions
21
46
  @actions ||= policy_spec.fetch(:actions) { {} }
22
47
  end
@@ -25,9 +50,13 @@ module Gitlab
25
50
  actions.key?(:summarize)
26
51
  end
27
52
 
53
+ def comment_on_summary?
54
+ actions.key?(:comment_on_summary)
55
+ end
56
+
28
57
  def comment?
29
58
  # The actual keys are strings
30
- (actions.keys.map(&:to_sym) - [:summarize]).any?
59
+ (actions.keys.map(&:to_sym) - [:summarize, :comment_on_summary]).any?
31
60
  end
32
61
 
33
62
  def build_issue
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'base'
4
+ require_relative 'epic'
4
5
  require_relative 'issue'
5
6
  require_relative 'merge_request'
6
7
  require_relative 'instance_version'
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+ require_relative 'shared/issuable'
5
+
6
+ module Gitlab
7
+ module Triage
8
+ module Resource
9
+ class Epic < Base
10
+ include Shared::Issuable
11
+
12
+ def project_path
13
+ @project_path ||=
14
+ request_group(resource[:group_id])[:full_path]
15
+ end
16
+ alias_method :group_path, :project_path
17
+
18
+ def reference
19
+ '&'
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -2,23 +2,25 @@ module Gitlab
2
2
  module Triage
3
3
  module Retryable
4
4
  MAX_RETRIES = 3
5
+ BACK_OFF_SECONDS = 10
5
6
 
6
7
  attr_accessor :tries
7
8
 
8
- def execute_with_retry(exception_types = [StandardError])
9
+ def execute_with_retry(exception_types: [StandardError], backoff_exceptions: [])
9
10
  @tries = 0
10
11
 
11
12
  until maximum_retries_reached?
12
13
  begin
13
14
  @tries += 1
14
- result = yield
15
- break
15
+ return yield
16
16
  rescue *exception_types
17
17
  raise if maximum_retries_reached?
18
+ rescue *backoff_exceptions
19
+ raise if maximum_retries_reached?
20
+
21
+ sleep(BACK_OFF_SECONDS)
18
22
  end
19
23
  end
20
-
21
- result
22
24
  end
23
25
 
24
26
  private
@@ -0,0 +1,13 @@
1
+ module Gitlab
2
+ module Triage
3
+ module Utils
4
+ module_function
5
+
6
+ def graphql_quote(string)
7
+ contents = string.to_s.gsub('"', '\\"')
8
+
9
+ %("#{contents}")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -34,7 +34,7 @@ module Gitlab
34
34
  def validate_parameter_content(value)
35
35
  @parameter_definitions.each do |param|
36
36
  if param[:values]
37
- raise InvalidParameter, "#{param[:name]} must be of one of #{param[:values].join(',')}" unless param[:values].include?(value[param[:name]])
37
+ raise InvalidParameter, "#{param[:name]} must be one of #{param[:values].join(',')}" unless param[:values].include?(value[param[:name]])
38
38
  end
39
39
  end
40
40
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Gitlab
4
4
  module Triage
5
- VERSION = '1.14.1'
5
+ VERSION = '1.17.0'
6
6
  end
7
7
  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.14.1
4
+ version: 1.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitLab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-27 00:00:00.000000000 Z
11
+ date: 2021-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -162,6 +162,7 @@ files:
162
162
  - lib/gitlab/triage/action.rb
163
163
  - lib/gitlab/triage/action/base.rb
164
164
  - lib/gitlab/triage/action/comment.rb
165
+ - lib/gitlab/triage/action/comment_on_summary.rb
165
166
  - lib/gitlab/triage/action/summarize.rb
166
167
  - lib/gitlab/triage/api_query_builders/base_query_param_builder.rb
167
168
  - lib/gitlab/triage/api_query_builders/date_query_param_builder.rb
@@ -195,8 +196,9 @@ files:
195
196
  - lib/gitlab/triage/filters/votes_conditions_filter.rb
196
197
  - lib/gitlab/triage/graphql_network.rb
197
198
  - lib/gitlab/triage/graphql_queries/query_builder.rb
198
- - lib/gitlab/triage/graphql_queries/threads_query.rb
199
- - lib/gitlab/triage/graphql_queries/user_notes_query.rb
199
+ - lib/gitlab/triage/graphql_queries/query_param_builders/base_param_builder.rb
200
+ - lib/gitlab/triage/graphql_queries/query_param_builders/date_param_builder.rb
201
+ - lib/gitlab/triage/graphql_queries/query_param_builders/labels_param_builder.rb
200
202
  - lib/gitlab/triage/limiters/base_limiter.rb
201
203
  - lib/gitlab/triage/limiters/date_field_limiter.rb
202
204
  - lib/gitlab/triage/network.rb
@@ -206,6 +208,7 @@ files:
206
208
  - lib/gitlab/triage/network_adapters/test_adapter.rb
207
209
  - lib/gitlab/triage/option_parser.rb
208
210
  - lib/gitlab/triage/options.rb
211
+ - lib/gitlab/triage/param_builders/date_param_builder.rb
209
212
  - lib/gitlab/triage/policies/base_policy.rb
210
213
  - lib/gitlab/triage/policies/rule_policy.rb
211
214
  - lib/gitlab/triage/policies/summary_policy.rb
@@ -213,6 +216,7 @@ files:
213
216
  - lib/gitlab/triage/policies_resources/summary_resources.rb
214
217
  - lib/gitlab/triage/resource/base.rb
215
218
  - lib/gitlab/triage/resource/context.rb
219
+ - lib/gitlab/triage/resource/epic.rb
216
220
  - lib/gitlab/triage/resource/instance_version.rb
217
221
  - lib/gitlab/triage/resource/issue.rb
218
222
  - lib/gitlab/triage/resource/label.rb
@@ -223,6 +227,7 @@ files:
223
227
  - lib/gitlab/triage/retryable.rb
224
228
  - lib/gitlab/triage/ui.rb
225
229
  - lib/gitlab/triage/url_builders/url_builder.rb
230
+ - lib/gitlab/triage/utils.rb
226
231
  - lib/gitlab/triage/validators/limiter_validator.rb
227
232
  - lib/gitlab/triage/validators/params_validator.rb
228
233
  - lib/gitlab/triage/version.rb
@@ -247,7 +252,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
247
252
  - !ruby/object:Gem::Version
248
253
  version: '0'
249
254
  requirements: []
250
- rubygems_version: 3.1.4
255
+ rubygems_version: 3.1.6
251
256
  signing_key:
252
257
  specification_version: 4
253
258
  summary: GitLab triage automation project.
@@ -1,31 +0,0 @@
1
- module Gitlab
2
- module Triage
3
- module GraphqlQueries
4
- ThreadsQuery = <<-GRAPHQL.freeze # rubocop:disable Naming/ConstantName
5
- query($source: ID!, $after: String, $iids: [String!]) {
6
- %{source_type}(fullPath: $source) {
7
- id
8
- %{resource_type}(after: $after, iids: $iids%{group_query}) {
9
- pageInfo {
10
- hasNextPage
11
- endCursor
12
- }
13
- nodes {
14
- id
15
- discussions {
16
- nodes {
17
- notes {
18
- nodes {
19
- system
20
- }
21
- }
22
- }
23
- }
24
- }
25
- }
26
- }
27
- }
28
- GRAPHQL
29
- end
30
- end
31
- end
@@ -1,23 +0,0 @@
1
- module Gitlab
2
- module Triage
3
- module GraphqlQueries
4
- UserNotesQuery = <<-GRAPHQL.freeze # rubocop:disable Naming/ConstantName
5
- query($source: ID!, $after: String, $iids: [String!]) {
6
- %{source_type}(fullPath: $source) {
7
- id
8
- %{resource_type}(after: $after, iids: $iids%{group_query}) {
9
- pageInfo {
10
- hasNextPage
11
- endCursor
12
- }
13
- nodes {
14
- id
15
- userNotesCount
16
- }
17
- }
18
- }
19
- }
20
- GRAPHQL
21
- end
22
- end
23
- end