gitlab-triage 0.3.0 → 0.4.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/.gitlab-ci.yml +1 -1
- data/Gemfile +6 -0
- data/README.md +27 -2
- data/lib/gitlab/triage/engine.rb +4 -2
- data/lib/gitlab/triage/limiters/author_member_conditions_limiter.rb +84 -0
- data/lib/gitlab/triage/url_builders/url_builder.rb +3 -2
- data/lib/gitlab/triage/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f135ad3ee8a932b96aa63b996b47c3dfb4c144a8294087492c75b206fd9cc0a5
|
|
4
|
+
data.tar.gz: 0af305681bc53fdd8d3b7f0a8eb86889d1da37bef53b24d837b067c336d02142
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4e415ad62d834aaf20ca0f567bdd135fc36d8e9c8cd92251410aab5464232c227af6032adcbba9bc7ca955bbbc72e4192f495dc56ecc1f18d2fac249cc96fd42
|
|
7
|
+
data.tar.gz: 8a6b44160f809fb5b4fc3ef5bcd0d09f7b12dba043d543a27c8b4ce31549b2b9cb32317bd205bcd23faaf445a3fca27bf80af9a937f52dfd2c96073530600ebb
|
data/.gitlab-ci.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[](https://gitlab.com/gitlab-org/triage/commits/master)
|
|
1
|
+
[](https://gitlab.com/gitlab-org/gitlab-triage/commits/master)
|
|
2
2
|
|
|
3
3
|
# GitLab Triage Project
|
|
4
4
|
|
|
@@ -45,7 +45,7 @@ resource_rules:
|
|
|
45
45
|
interval: 5
|
|
46
46
|
state: opened
|
|
47
47
|
label:
|
|
48
|
-
- No
|
|
48
|
+
- No Label
|
|
49
49
|
actions:
|
|
50
50
|
labels:
|
|
51
51
|
- needs attention
|
|
@@ -86,6 +86,7 @@ Available condition types:
|
|
|
86
86
|
- [`upvotes` condition](#upvotes-condition)
|
|
87
87
|
- [`labels` condition](#labels-condition)
|
|
88
88
|
- [`forbidden_labels` condition](#forbidden-labels-condition)
|
|
89
|
+
- [`author_member` condition](#author-member-condition)
|
|
89
90
|
|
|
90
91
|
##### Date condition
|
|
91
92
|
|
|
@@ -188,6 +189,30 @@ conditions:
|
|
|
188
189
|
- awaiting feedback
|
|
189
190
|
```
|
|
190
191
|
|
|
192
|
+
##### Author Member condition
|
|
193
|
+
|
|
194
|
+
This condition determines whether the author of a resource is a member of the specified group or project.
|
|
195
|
+
|
|
196
|
+
This is useful for determining whether Issues or Merge Requests have been raised by a Community Contributor.
|
|
197
|
+
|
|
198
|
+
Accepts a hash of fields.
|
|
199
|
+
|
|
200
|
+
| Field | Type | Values | Required |
|
|
201
|
+
| --------- | ---- | ---- | -------- |
|
|
202
|
+
| `source` | string | `group`, `project` | yes |
|
|
203
|
+
| `condition` | string | `member_of`, `not_member_of` | yes |
|
|
204
|
+
| `source_id` | integer | integer | yes |
|
|
205
|
+
|
|
206
|
+
Example:
|
|
207
|
+
|
|
208
|
+
```yml
|
|
209
|
+
conditions:
|
|
210
|
+
author:
|
|
211
|
+
source: group
|
|
212
|
+
condition: not_member_of
|
|
213
|
+
source_id: 9970
|
|
214
|
+
```
|
|
215
|
+
|
|
191
216
|
#### Actions field
|
|
192
217
|
|
|
193
218
|
Used to declare an action to be carried out on a resource if **all** conditions are satisfied.
|
data/lib/gitlab/triage/engine.rb
CHANGED
|
@@ -3,6 +3,7 @@ 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/author_member_conditions_limiter'
|
|
6
7
|
require_relative 'command_builders/comment_command_builder'
|
|
7
8
|
require_relative 'command_builders/label_command_builder'
|
|
8
9
|
require_relative 'command_builders/remove_label_command_builder'
|
|
@@ -99,6 +100,7 @@ module Gitlab
|
|
|
99
100
|
results << Limiters::DateConditionsLimiter.new(resource, conditions[:date]).calculate if conditions[:date]
|
|
100
101
|
results << Limiters::VotesConditionsLimiter.new(resource, conditions[:upvotes]).calculate if conditions[:upvotes]
|
|
101
102
|
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]
|
|
102
104
|
!results.uniq.include?(false)
|
|
103
105
|
end
|
|
104
106
|
end
|
|
@@ -148,7 +150,7 @@ module Gitlab
|
|
|
148
150
|
get_url = UrlBuilders::UrlBuilder.new(
|
|
149
151
|
host_url: host_url,
|
|
150
152
|
api_version: api_version,
|
|
151
|
-
|
|
153
|
+
source_id: options.project_id,
|
|
152
154
|
resource_type: resource_type,
|
|
153
155
|
params: params
|
|
154
156
|
).build
|
|
@@ -163,7 +165,7 @@ module Gitlab
|
|
|
163
165
|
post_url = UrlBuilders::UrlBuilder.new(
|
|
164
166
|
host_url: host_url,
|
|
165
167
|
api_version: api_version,
|
|
166
|
-
|
|
168
|
+
source_id: options.project_id,
|
|
167
169
|
resource_type: resource_type,
|
|
168
170
|
resource_id: resource['iid'],
|
|
169
171
|
sub_resource_type: 'notes'
|
|
@@ -0,0 +1,84 @@
|
|
|
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 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
|
+
}
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -5,7 +5,8 @@ module Gitlab
|
|
|
5
5
|
def initialize(options)
|
|
6
6
|
@host_url = options.fetch(:host_url)
|
|
7
7
|
@api_version = options.fetch(:api_version)
|
|
8
|
-
@
|
|
8
|
+
@source = options.fetch(:source, 'projects')
|
|
9
|
+
@source_id = options.fetch(:source_id)
|
|
9
10
|
@resource_type = options.fetch(:resource_type)
|
|
10
11
|
@sub_resource_type = options.fetch(:sub_resource_type, nil)
|
|
11
12
|
@resource_id = options.fetch(:resource_id, nil)
|
|
@@ -27,7 +28,7 @@ module Gitlab
|
|
|
27
28
|
end
|
|
28
29
|
|
|
29
30
|
def base_url
|
|
30
|
-
"#{host_with_api_url}
|
|
31
|
+
"#{host_with_api_url}/#{@source}/#{CGI.escape(@source_id.to_s)}/#{@resource_type}"
|
|
31
32
|
end
|
|
32
33
|
|
|
33
34
|
def params_string
|
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
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- GitLab
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2018-06-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -127,6 +127,7 @@ 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/author_member_conditions_limiter.rb
|
|
130
131
|
- lib/gitlab/triage/limiters/base_conditions_limiter.rb
|
|
131
132
|
- lib/gitlab/triage/limiters/date_conditions_limiter.rb
|
|
132
133
|
- lib/gitlab/triage/limiters/forbidden_labels_conditions_limiter.rb
|
|
@@ -162,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
162
163
|
version: '0'
|
|
163
164
|
requirements: []
|
|
164
165
|
rubyforge_project:
|
|
165
|
-
rubygems_version: 2.7.
|
|
166
|
+
rubygems_version: 2.7.7
|
|
166
167
|
signing_key:
|
|
167
168
|
specification_version: 4
|
|
168
169
|
summary: GitLab triage automation project.
|