gitlab-triage 1.6.1 → 1.10.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 +4 -4
- data/.gitignore +0 -1
- data/.gitlab-ci.yml +75 -40
- data/.gitlab/merge_request_templates/Release.md +35 -0
- data/.rubocop.yml +3 -0
- data/Gemfile +1 -1
- data/README.md +95 -4
- data/gitlab-triage.gemspec +1 -1
- data/lib/gitlab/triage/action/comment.rb +14 -1
- data/lib/gitlab/triage/api_query_builders/date_query_param_builder.rb +78 -0
- data/lib/gitlab/triage/command_builders/move_command_builder.rb +19 -0
- data/lib/gitlab/triage/command_builders/text_content_builder.rb +17 -1
- data/lib/gitlab/triage/engine.rb +41 -16
- data/lib/gitlab/triage/errors.rb +1 -1
- data/lib/gitlab/triage/filters/merge_request_date_conditions_filter.rb +51 -5
- data/lib/gitlab/triage/network.rb +2 -1
- data/lib/gitlab/triage/network_adapters/httparty_adapter.rb +13 -1
- data/lib/gitlab/triage/option_parser.rb +10 -0
- data/lib/gitlab/triage/options.rb +2 -0
- data/lib/gitlab/triage/policies/rule_policy.rb +1 -1
- data/lib/gitlab/triage/policies/summary_policy.rb +1 -1
- data/lib/gitlab/triage/policies_resources/rule_resources.rb +5 -6
- data/lib/gitlab/triage/policies_resources/summary_resources.rb +5 -6
- data/lib/gitlab/triage/resource/base.rb +5 -0
- data/lib/gitlab/triage/resource/issue.rb +4 -0
- data/lib/gitlab/triage/resource/merge_request.rb +13 -0
- data/lib/gitlab/triage/resource/shared/issuable.rb +26 -0
- data/lib/gitlab/triage/url_builders/url_builder.rb +10 -9
- data/lib/gitlab/triage/validators/limiter_validator.rb +3 -1
- data/lib/gitlab/triage/validators/params_validator.rb +5 -3
- data/lib/gitlab/triage/version.rb +3 -1
- data/support/.triage-policies.example.yml +2 -2
- metadata +6 -4
- data/lib/gitlab/triage/filters/issuable_date_conditions_filter.rb +0 -65
@@ -1,20 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'forwardable'
|
4
|
+
|
3
5
|
module Gitlab
|
4
6
|
module Triage
|
5
7
|
module PoliciesResources
|
6
8
|
class SummaryResources
|
7
|
-
|
9
|
+
include Enumerable
|
10
|
+
extend Forwardable
|
8
11
|
|
9
12
|
def initialize(new_rule_to_resources)
|
10
13
|
@rule_to_resources = new_rule_to_resources
|
11
14
|
end
|
12
15
|
|
13
|
-
|
14
|
-
rule_to_resources.map do |inner_policy_spec, inner_resources|
|
15
|
-
yield(inner_policy_spec, inner_resources)
|
16
|
-
end
|
17
|
-
end
|
16
|
+
def_delegator :@rule_to_resources, :each
|
18
17
|
end
|
19
18
|
end
|
20
19
|
end
|
@@ -41,6 +41,11 @@ module Gitlab
|
|
41
41
|
|
42
42
|
private
|
43
43
|
|
44
|
+
def expand_resource!(params: {})
|
45
|
+
resource.merge!(
|
46
|
+
network.query_api_cached(resource_url(params: params)).first)
|
47
|
+
end
|
48
|
+
|
44
49
|
def source_resource
|
45
50
|
@source_resource ||= network.query_api_cached(source_url).first
|
46
51
|
end
|
@@ -8,6 +8,19 @@ module Gitlab
|
|
8
8
|
module Resource
|
9
9
|
class MergeRequest < Base
|
10
10
|
include Shared::Issuable
|
11
|
+
|
12
|
+
def reference
|
13
|
+
'!'
|
14
|
+
end
|
15
|
+
|
16
|
+
def first_contribution?
|
17
|
+
if resource.key?(:first_contribution)
|
18
|
+
resource[:first_contribution]
|
19
|
+
else
|
20
|
+
expanded = expand_resource!
|
21
|
+
expanded[:first_contribution]
|
22
|
+
end
|
23
|
+
end
|
11
24
|
end
|
12
25
|
end
|
13
26
|
end
|
@@ -49,6 +49,20 @@ module Gitlab
|
|
49
49
|
@author ||= resource.dig(:author, :username)
|
50
50
|
end
|
51
51
|
|
52
|
+
def project_path
|
53
|
+
@project_path ||=
|
54
|
+
request_project(resource[:project_id])[:path_with_namespace]
|
55
|
+
end
|
56
|
+
|
57
|
+
def full_resource_reference
|
58
|
+
@full_resource_reference ||=
|
59
|
+
"#{project_path}#{reference}#{resource[:iid]}"
|
60
|
+
end
|
61
|
+
|
62
|
+
def reference
|
63
|
+
raise NotImplementedError
|
64
|
+
end
|
65
|
+
|
52
66
|
def root_id(
|
53
67
|
resource: source_resource,
|
54
68
|
max_levels: MAX_PARENT_LOOKUP)
|
@@ -72,6 +86,10 @@ module Gitlab
|
|
72
86
|
resource_url(sub_resource_type: 'resource_label_events'))
|
73
87
|
end
|
74
88
|
|
89
|
+
def request_project(project_id)
|
90
|
+
network.query_api_cached(project_url(project_id)).first
|
91
|
+
end
|
92
|
+
|
75
93
|
def request_group(group_id)
|
76
94
|
network.query_api_cached(group_url(group_id)).first
|
77
95
|
end
|
@@ -83,6 +101,14 @@ module Gitlab
|
|
83
101
|
source_id: group_id
|
84
102
|
).build
|
85
103
|
end
|
104
|
+
|
105
|
+
def project_url(project_id)
|
106
|
+
Gitlab::Triage::UrlBuilders::UrlBuilder.new(
|
107
|
+
network_options: network.options,
|
108
|
+
source: 'projects',
|
109
|
+
source_id: project_id
|
110
|
+
).build
|
111
|
+
end
|
86
112
|
end
|
87
113
|
end
|
88
114
|
end
|
@@ -6,6 +6,7 @@ module Gitlab
|
|
6
6
|
@network_options = options.fetch(:network_options)
|
7
7
|
@host_url = @network_options.host_url
|
8
8
|
@api_version = @network_options.api_version
|
9
|
+
@all = options.fetch(:all, false)
|
9
10
|
@source = options.fetch(:source, 'projects')
|
10
11
|
@source_id = options.fetch(:source_id)
|
11
12
|
@resource_type = options.fetch(:resource_type, nil)
|
@@ -15,11 +16,11 @@ module Gitlab
|
|
15
16
|
end
|
16
17
|
|
17
18
|
def build
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
url = base_url
|
20
|
+
url << "/#{@resource_id}" if @resource_id
|
21
|
+
url << "/#{@sub_resource_type}" if @sub_resource_type
|
22
|
+
url << params_string if @params
|
23
|
+
url
|
23
24
|
end
|
24
25
|
|
25
26
|
private
|
@@ -29,10 +30,10 @@ module Gitlab
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def base_url
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
url = host_with_api_url
|
34
|
+
url << "/#{@source}/#{CGI.escape(@source_id.to_s)}" unless @all
|
35
|
+
url << "/#{@resource_type}" if @resource_type
|
36
|
+
url
|
36
37
|
end
|
37
38
|
|
38
39
|
def params_string
|
@@ -12,7 +12,9 @@ module Gitlab
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def validate_required_parameters(value)
|
15
|
-
|
15
|
+
return if value.keys.one? { |key| params_limiter_names.include?(key.to_sym) }
|
16
|
+
|
17
|
+
raise ArgumentError, "For the limits field, please specify one of: `#{params_limiter_names.join('`, `')}`"
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Gitlab
|
2
2
|
module Triage
|
3
3
|
class ParamsValidator
|
4
|
+
InvalidParameter = Class.new(ArgumentError)
|
5
|
+
|
4
6
|
def initialize(parameter_definitions, value)
|
5
7
|
@parameter_definitions = parameter_definitions
|
6
8
|
@value = value
|
@@ -16,7 +18,7 @@ module Gitlab
|
|
16
18
|
|
17
19
|
def validate_required_parameters(value)
|
18
20
|
@parameter_definitions.each do |param|
|
19
|
-
raise
|
21
|
+
raise InvalidParameter, "#{param[:name]} is a required parameter" unless value[param[:name]]
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
@@ -24,7 +26,7 @@ module Gitlab
|
|
24
26
|
@parameter_definitions.each do |param|
|
25
27
|
if value.has_key?(param[:name])
|
26
28
|
param_types = Array(param[:type]).flatten
|
27
|
-
raise
|
29
|
+
raise InvalidParameter, "#{param[:name]} must be of type #{param[:type]}" unless param_types.any? { |type| value[param[:name]].is_a?(type) }
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
@@ -32,7 +34,7 @@ module Gitlab
|
|
32
34
|
def validate_parameter_content(value)
|
33
35
|
@parameter_definitions.each do |param|
|
34
36
|
if param[:values]
|
35
|
-
raise
|
37
|
+
raise InvalidParameter, "#{param[:name]} must be of one of #{param[:values].join(',')}" unless param[:values].include?(value[param[:name]])
|
36
38
|
end
|
37
39
|
end
|
38
40
|
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.
|
4
|
+
version: 1.10.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-
|
11
|
+
date: 2020-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- ".gitignore"
|
121
121
|
- ".gitlab-ci.yml"
|
122
122
|
- ".gitlab/CODEOWNERS"
|
123
|
+
- ".gitlab/merge_request_templates/Release.md"
|
123
124
|
- ".rubocop.yml"
|
124
125
|
- CONTRIBUTING.md
|
125
126
|
- Gemfile
|
@@ -135,12 +136,14 @@ files:
|
|
135
136
|
- lib/gitlab/triage/action/comment.rb
|
136
137
|
- lib/gitlab/triage/action/summarize.rb
|
137
138
|
- lib/gitlab/triage/api_query_builders/base_query_param_builder.rb
|
139
|
+
- lib/gitlab/triage/api_query_builders/date_query_param_builder.rb
|
138
140
|
- lib/gitlab/triage/api_query_builders/multi_query_param_builder.rb
|
139
141
|
- lib/gitlab/triage/api_query_builders/single_query_param_builder.rb
|
140
142
|
- lib/gitlab/triage/command_builders/base_command_builder.rb
|
141
143
|
- lib/gitlab/triage/command_builders/cc_command_builder.rb
|
142
144
|
- lib/gitlab/triage/command_builders/comment_command_builder.rb
|
143
145
|
- lib/gitlab/triage/command_builders/label_command_builder.rb
|
146
|
+
- lib/gitlab/triage/command_builders/move_command_builder.rb
|
144
147
|
- lib/gitlab/triage/command_builders/remove_label_command_builder.rb
|
145
148
|
- lib/gitlab/triage/command_builders/status_command_builder.rb
|
146
149
|
- lib/gitlab/triage/command_builders/text_content_builder.rb
|
@@ -156,7 +159,6 @@ files:
|
|
156
159
|
- lib/gitlab/triage/filters/author_member_conditions_filter.rb
|
157
160
|
- lib/gitlab/triage/filters/base_conditions_filter.rb
|
158
161
|
- lib/gitlab/triage/filters/forbidden_labels_conditions_filter.rb
|
159
|
-
- lib/gitlab/triage/filters/issuable_date_conditions_filter.rb
|
160
162
|
- lib/gitlab/triage/filters/member_conditions_filter.rb
|
161
163
|
- lib/gitlab/triage/filters/merge_request_date_conditions_filter.rb
|
162
164
|
- lib/gitlab/triage/filters/name_conditions_filter.rb
|
@@ -212,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
212
214
|
- !ruby/object:Gem::Version
|
213
215
|
version: '0'
|
214
216
|
requirements: []
|
215
|
-
rubygems_version: 3.
|
217
|
+
rubygems_version: 3.1.2
|
216
218
|
signing_key:
|
217
219
|
specification_version: 4
|
218
220
|
summary: GitLab triage automation project.
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require_relative 'base_conditions_filter'
|
2
|
-
|
3
|
-
module Gitlab
|
4
|
-
module Triage
|
5
|
-
module Filters
|
6
|
-
class IssuableDateConditionsFilter < BaseConditionsFilter
|
7
|
-
ATTRIBUTES = %w[updated_at created_at].freeze
|
8
|
-
CONDITIONS = %w[older_than newer_than].freeze
|
9
|
-
INTERVAL_TYPES = %w[days weeks months years].freeze
|
10
|
-
|
11
|
-
def self.allowed_attributes
|
12
|
-
self::ATTRIBUTES
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.filter_parameters
|
16
|
-
[
|
17
|
-
{
|
18
|
-
name: :attribute,
|
19
|
-
type: String,
|
20
|
-
values: allowed_attributes
|
21
|
-
},
|
22
|
-
{
|
23
|
-
name: :condition,
|
24
|
-
type: String,
|
25
|
-
values: CONDITIONS
|
26
|
-
},
|
27
|
-
{
|
28
|
-
name: :interval_type,
|
29
|
-
type: String,
|
30
|
-
values: INTERVAL_TYPES
|
31
|
-
},
|
32
|
-
{
|
33
|
-
name: :interval,
|
34
|
-
type: Numeric
|
35
|
-
}
|
36
|
-
]
|
37
|
-
end
|
38
|
-
|
39
|
-
def initialize_variables(condition)
|
40
|
-
@attribute = condition[:attribute].to_sym
|
41
|
-
@condition = condition[:condition].to_sym
|
42
|
-
@interval_type = condition[:interval_type].to_sym
|
43
|
-
@interval = condition[:interval]
|
44
|
-
end
|
45
|
-
|
46
|
-
def resource_value
|
47
|
-
@resource[@attribute].to_date
|
48
|
-
end
|
49
|
-
|
50
|
-
def condition_value
|
51
|
-
@interval.public_send(@interval_type).ago.to_date # rubocop:disable GitlabSecurity/PublicSend
|
52
|
-
end
|
53
|
-
|
54
|
-
def calculate
|
55
|
-
case @condition
|
56
|
-
when :older_than
|
57
|
-
resource_value < condition_value
|
58
|
-
when :newer_than
|
59
|
-
resource_value > condition_value
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|