gitlab-triage 1.10.1 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +6 -25
- data/Guardfile +1 -1
- data/README.md +15 -7
- data/lib/gitlab/triage/action/comment.rb +2 -2
- data/lib/gitlab/triage/command_builders/base_command_builder.rb +7 -3
- data/lib/gitlab/triage/command_builders/label_command_builder.rb +17 -0
- data/lib/gitlab/triage/command_builders/text_content_builder.rb +1 -5
- data/lib/gitlab/triage/engine.rb +5 -5
- data/lib/gitlab/triage/resource/base.rb +5 -1
- data/lib/gitlab/triage/resource/label.rb +15 -0
- data/lib/gitlab/triage/url_builders/url_builder.rb +1 -1
- data/lib/gitlab/triage/version.rb +1 -1
- data/support/.gitlab-ci.example.yml +2 -2
- metadata +2 -3
- data/lib/gitlab/triage/filters/forbidden_labels_conditions_filter.rb +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e02cd169e252e4656441f6e9268314c2b968935957dbcb906ae3048ee7045da4
|
4
|
+
data.tar.gz: 3b58c8b37e3f82878272641ad848239c74623499f0e309ba0ac9aaaf6803cf0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 181a6a5055a61b5d8c78f36d047dfef269a92a7d0173598a490e5420ab04fb267c9c42be2ae9bef31a815eb7730a15b921dde2b1834e49dcc20d0969d4986f54
|
7
|
+
data.tar.gz: 621d6e208ad9dcdd034931ca0656778e5247c6aa3f3e6fa8edf53ed401795452f0d136eec259df8a377e36589de866fc7ee949a792cd1fa5b2c07257cab577ee
|
data/.gitlab-ci.yml
CHANGED
@@ -2,7 +2,7 @@ stages:
|
|
2
2
|
- prepare
|
3
3
|
- test
|
4
4
|
- triage
|
5
|
-
-
|
5
|
+
- deploy
|
6
6
|
|
7
7
|
default:
|
8
8
|
image: ruby:2.7
|
@@ -38,6 +38,7 @@ workflow:
|
|
38
38
|
services:
|
39
39
|
- docker:${DOCKER_VERSION}-dind
|
40
40
|
variables:
|
41
|
+
DOCKER_VERSION: "19.03.0"
|
41
42
|
DOCKER_DRIVER: overlay2
|
42
43
|
DOCKER_HOST: tcp://docker:2375
|
43
44
|
DOCKER_TLS_CERTDIR: ""
|
@@ -118,7 +119,7 @@ dry-run:gitlab-triage:
|
|
118
119
|
- gitlab-triage --version
|
119
120
|
- gitlab-triage --help
|
120
121
|
- gitlab-triage --init
|
121
|
-
- gitlab-triage --dry-run --debug --token $
|
122
|
+
- gitlab-triage --dry-run --debug --token $GITLAB_API_TOKEN --source-id $CI_PROJECT_PATH
|
122
123
|
|
123
124
|
# This job requires allows to override the `CI_PROJECT_PATH` variable when triggered.
|
124
125
|
dry-run:custom:
|
@@ -127,26 +128,6 @@ dry-run:custom:
|
|
127
128
|
- when: manual
|
128
129
|
allow_failure: true
|
129
130
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
release:
|
134
|
-
stage: release
|
135
|
-
rules:
|
136
|
-
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push"'
|
137
|
-
changes: ["lib/gitlab/triage/version.rb"]
|
138
|
-
- if: '$CI_MERGE_REQUEST_TITLE =~ /RELEASE/'
|
139
|
-
when: manual
|
140
|
-
before_script: []
|
141
|
-
script:
|
142
|
-
- version=$(ruby -r ./lib/gitlab/triage/version -e 'puts Gitlab::Triage::VERSION' | tr -d "\n")
|
143
|
-
- tag="v${version}"
|
144
|
-
- message="Version ${version}."
|
145
|
-
# TODO: Add release notes from the Release MR?
|
146
|
-
- 'curl --request POST --header "PRIVATE-TOKEN: ${API_TOKEN}" -d "tag_name=${tag}" -d "ref=${CI_COMMIT_SHA}" -d "message=${message}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/repository/tags"'
|
147
|
-
- gem build gitlab-triage.gemspec
|
148
|
-
- gem push "gitlab-triage-${version}.gem"
|
149
|
-
artifacts:
|
150
|
-
paths:
|
151
|
-
- gitlab-triage*.gem
|
152
|
-
expire_in: 30 days
|
131
|
+
include:
|
132
|
+
- project: 'gitlab-org/quality/pipeline-common'
|
133
|
+
file: '/ci/gem-release.yml'
|
data/Guardfile
CHANGED
@@ -24,7 +24,7 @@
|
|
24
24
|
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
25
25
|
# * 'just' rspec: 'rspec'
|
26
26
|
|
27
|
-
guard :rspec, cmd: "bundle exec rspec" do
|
27
|
+
guard :rspec, cmd: "bundle exec rspec -f doc" do
|
28
28
|
require "guard/rspec/dsl"
|
29
29
|
dsl = Guard::RSpec::Dsl.new(self)
|
30
30
|
|
data/README.md
CHANGED
@@ -552,6 +552,10 @@ Adds a number of labels to the resource.
|
|
552
552
|
|
553
553
|
Accepts an array of strings. Each element is the name of a label to add.
|
554
554
|
|
555
|
+
If any of the labels doesn't exist, the automation will stop immediately so
|
556
|
+
that if a label is renamed or deleted, you'll have to explicitly update or remove
|
557
|
+
it in your policy file.
|
558
|
+
|
555
559
|
Example:
|
556
560
|
|
557
561
|
```yml
|
@@ -567,6 +571,10 @@ Removes a number of labels from the resource.
|
|
567
571
|
|
568
572
|
Accepts an array of strings. Each element is the name of a label to remove.
|
569
573
|
|
574
|
+
If any of the labels doesn't exist, the automation will stop immediately so
|
575
|
+
that if a label is renamed or deleted, you'll have to explicitly update or remove
|
576
|
+
it in your policy file.
|
577
|
+
|
570
578
|
Example:
|
571
579
|
|
572
580
|
```yml
|
@@ -1016,22 +1024,22 @@ Usage: gitlab-triage [options]
|
|
1016
1024
|
Triaging against a specific project:
|
1017
1025
|
|
1018
1026
|
```
|
1019
|
-
gitlab-triage --dry-run --token $
|
1027
|
+
gitlab-triage --dry-run --token $GITLAB_API_TOKEN --source-id gitlab-org/triage
|
1020
1028
|
```
|
1021
1029
|
|
1022
1030
|
Triaging against a whole group:
|
1023
1031
|
|
1024
1032
|
```
|
1025
|
-
gitlab-triage --dry-run --token $
|
1033
|
+
gitlab-triage --dry-run --token $GITLAB_API_TOKEN --source-id gitlab-org --source groups
|
1026
1034
|
```
|
1027
1035
|
|
1028
1036
|
Triaging against an entire instance:
|
1029
1037
|
|
1030
1038
|
```
|
1031
|
-
gitlab-triage --dry-run --token $
|
1039
|
+
gitlab-triage --dry-run --token $GITLAB_API_TOKEN --all-projects
|
1032
1040
|
```
|
1033
1041
|
|
1034
|
-
> **Note:** The `--all-projects` option will process all resources for all projects visible to the specified `$
|
1042
|
+
> **Note:** The `--all-projects` option will process all resources for all projects visible to the specified `$GITLAB_API_TOKEN`
|
1035
1043
|
|
1036
1044
|
#### Running on GitLab CI pipeline
|
1037
1045
|
|
@@ -1042,7 +1050,7 @@ run:triage:triage:
|
|
1042
1050
|
stage: triage
|
1043
1051
|
script:
|
1044
1052
|
- gem install gitlab-triage
|
1045
|
-
- gitlab-triage --token $
|
1053
|
+
- gitlab-triage --token $GITLAB_API_TOKEN --source-id $CI_PROJECT_PATH
|
1046
1054
|
only:
|
1047
1055
|
- schedules
|
1048
1056
|
```
|
@@ -1056,7 +1064,7 @@ Yes, you can override the host url using the following options:
|
|
1056
1064
|
##### CLI
|
1057
1065
|
|
1058
1066
|
```
|
1059
|
-
gitlab-triage --dry-run --token $
|
1067
|
+
gitlab-triage --dry-run --token $GITLAB_API_TOKEN --source-id gitlab-org/triage --host-url https://gitlab.host.com
|
1060
1068
|
```
|
1061
1069
|
|
1062
1070
|
##### Policy file
|
@@ -1093,7 +1101,7 @@ Gitlab::Triage::Resource::Context.include MyPlugin
|
|
1093
1101
|
And then run it with:
|
1094
1102
|
|
1095
1103
|
```shell
|
1096
|
-
gitlab-triage -r ./my_plugin.rb --token $
|
1104
|
+
gitlab-triage -r ./my_plugin.rb --token $GITLAB_API_TOKEN --source-id gitlab-org/triage
|
1097
1105
|
```
|
1098
1106
|
|
1099
1107
|
This allows you to use `has_severity_label?` in the Ruby condition:
|
@@ -41,8 +41,8 @@ module Gitlab
|
|
41
41
|
CommandBuilders::CommentCommandBuilder.new(
|
42
42
|
[
|
43
43
|
CommandBuilders::TextContentBuilder.new(policy.actions[:comment], resource: resource, network: network).build_command,
|
44
|
-
CommandBuilders::LabelCommandBuilder.new(policy.actions[:labels]).build_command,
|
45
|
-
CommandBuilders::RemoveLabelCommandBuilder.new(policy.actions[:remove_labels]).build_command,
|
44
|
+
CommandBuilders::LabelCommandBuilder.new(policy.actions[:labels], resource: resource, network: network).build_command,
|
45
|
+
CommandBuilders::RemoveLabelCommandBuilder.new(policy.actions[:remove_labels], resource: resource, network: network).build_command,
|
46
46
|
CommandBuilders::CcCommandBuilder.new(policy.actions[:mention]).build_command,
|
47
47
|
CommandBuilders::MoveCommandBuilder.new(policy.actions[:move]).build_command,
|
48
48
|
CommandBuilders::StatusCommandBuilder.new(policy.actions[:status]).build_command
|
@@ -2,13 +2,15 @@ module Gitlab
|
|
2
2
|
module Triage
|
3
3
|
module CommandBuilders
|
4
4
|
class BaseCommandBuilder
|
5
|
-
def initialize(items)
|
5
|
+
def initialize(items, resource: nil, network: nil)
|
6
6
|
@items = Array.wrap(items)
|
7
7
|
@items.delete('')
|
8
|
+
@resource = resource&.with_indifferent_access
|
9
|
+
@network = network
|
8
10
|
end
|
9
11
|
|
10
12
|
def build_command
|
11
|
-
if
|
13
|
+
if items.any?
|
12
14
|
[slash_command_string, content_string].compact.join(separator)
|
13
15
|
else
|
14
16
|
""
|
@@ -17,6 +19,8 @@ module Gitlab
|
|
17
19
|
|
18
20
|
private
|
19
21
|
|
22
|
+
attr_reader :items, :resource, :network
|
23
|
+
|
20
24
|
def separator
|
21
25
|
' '
|
22
26
|
end
|
@@ -26,7 +30,7 @@ module Gitlab
|
|
26
30
|
end
|
27
31
|
|
28
32
|
def content_string
|
29
|
-
|
33
|
+
items.map do |item|
|
30
34
|
format_item(item)
|
31
35
|
end.join(separator)
|
32
36
|
end
|
@@ -4,8 +4,25 @@ module Gitlab
|
|
4
4
|
module Triage
|
5
5
|
module CommandBuilders
|
6
6
|
class LabelCommandBuilder < BaseCommandBuilder
|
7
|
+
def build_command
|
8
|
+
ensure_labels_exist!
|
9
|
+
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
7
13
|
private
|
8
14
|
|
15
|
+
def ensure_labels_exist!
|
16
|
+
items.each do |label|
|
17
|
+
label_opts = { project_id: resource[:project_id], name: label }
|
18
|
+
|
19
|
+
unless Resource::Label.new(label_opts, network: network).exist?
|
20
|
+
raise Resource::Label::LabelDoesntExistError,
|
21
|
+
"Label `#{label}` doesn't exist!"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
9
26
|
def slash_command_string
|
10
27
|
"/label"
|
11
28
|
end
|
@@ -34,13 +34,9 @@ module Gitlab
|
|
34
34
|
}.freeze
|
35
35
|
PLACEHOLDER_REGEX = /{{([\w\.]+)}}/.freeze
|
36
36
|
|
37
|
-
attr_reader :resource, :network
|
38
|
-
|
39
37
|
def initialize(
|
40
38
|
items, resource: nil, network: nil, redact_confidentials: true)
|
41
|
-
super(items)
|
42
|
-
@resource = resource&.with_indifferent_access
|
43
|
-
@network = network
|
39
|
+
super(items, resource: resource, network: network)
|
44
40
|
@redact_confidentials = redact_confidentials
|
45
41
|
end
|
46
42
|
|
data/lib/gitlab/triage/engine.rb
CHANGED
@@ -4,7 +4,6 @@ require 'active_support/inflector'
|
|
4
4
|
require_relative 'expand_condition'
|
5
5
|
require_relative 'filters/merge_request_date_conditions_filter'
|
6
6
|
require_relative 'filters/votes_conditions_filter'
|
7
|
-
require_relative 'filters/forbidden_labels_conditions_filter'
|
8
7
|
require_relative 'filters/no_additional_labels_conditions_filter'
|
9
8
|
require_relative 'filters/author_member_conditions_filter'
|
10
9
|
require_relative 'filters/assignee_member_conditions_filter'
|
@@ -202,10 +201,6 @@ module Gitlab
|
|
202
201
|
results << Filters::VotesConditionsFilter.new(resource, conditions[:upvotes]).calculate
|
203
202
|
end
|
204
203
|
|
205
|
-
if conditions[:forbidden_labels]
|
206
|
-
results << Filters::ForbiddenLabelsConditionsFilter.new(resource, conditions[:forbidden_labels]).calculate
|
207
|
-
end
|
208
|
-
|
209
204
|
if conditions[:no_additional_labels]
|
210
205
|
results << Filters::NoAdditionalLabelsConditionsFilter.new(resource, conditions.fetch(:labels) { [] }).calculate
|
211
206
|
end
|
@@ -244,6 +239,11 @@ module Gitlab
|
|
244
239
|
|
245
240
|
condition_builders = []
|
246
241
|
condition_builders << APIQueryBuilders::MultiQueryParamBuilder.new('labels', conditions[:labels], ',') if conditions[:labels]
|
242
|
+
|
243
|
+
if conditions[:forbidden_labels]
|
244
|
+
condition_builders << APIQueryBuilders::MultiQueryParamBuilder.new('not[labels]', conditions[:forbidden_labels], ',')
|
245
|
+
end
|
246
|
+
|
247
247
|
condition_builders << APIQueryBuilders::SingleQueryParamBuilder.new('state', conditions[:state]) if conditions[:state]
|
248
248
|
condition_builders << APIQueryBuilders::SingleQueryParamBuilder.new('milestone', Array(conditions[:milestone])[0]) if conditions[:milestone]
|
249
249
|
condition_builders << APIQueryBuilders::SingleQueryParamBuilder.new('source_branch', conditions[:source_branch]) if conditions[:source_branch]
|
@@ -58,11 +58,15 @@ module Gitlab
|
|
58
58
|
build_url(params: params)
|
59
59
|
end
|
60
60
|
|
61
|
+
def resource_id
|
62
|
+
resource[:iid]
|
63
|
+
end
|
64
|
+
|
61
65
|
def resource_url(params: {}, sub_resource_type: nil)
|
62
66
|
build_url(
|
63
67
|
params: params,
|
64
68
|
options: {
|
65
|
-
resource_id:
|
69
|
+
resource_id: resource_id,
|
66
70
|
sub_resource_type: sub_resource_type
|
67
71
|
}
|
68
72
|
)
|
@@ -8,6 +8,8 @@ module Gitlab
|
|
8
8
|
module Triage
|
9
9
|
module Resource
|
10
10
|
class Label < Base
|
11
|
+
LabelDoesntExistError = Class.new(StandardError)
|
12
|
+
|
11
13
|
FIELDS = %i[
|
12
14
|
id
|
13
15
|
project_id
|
@@ -35,6 +37,19 @@ module Gitlab
|
|
35
37
|
Time.parse(value) if value
|
36
38
|
end
|
37
39
|
end
|
40
|
+
|
41
|
+
def exist?
|
42
|
+
label = network.query_api_cached(resource_url).first
|
43
|
+
return false unless label
|
44
|
+
|
45
|
+
label[:name] == name
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def resource_id
|
51
|
+
name
|
52
|
+
end
|
38
53
|
end
|
39
54
|
end
|
40
55
|
end
|
@@ -8,7 +8,7 @@ dry-run:triage:
|
|
8
8
|
script:
|
9
9
|
- gem install gitlab-triage
|
10
10
|
- gitlab-triage --help
|
11
|
-
- gitlab-triage --dry-run --token $
|
11
|
+
- gitlab-triage --dry-run --token $GITLAB_API_TOKEN --source projects --source-id $CI_PROJECT_PATH
|
12
12
|
when: manual
|
13
13
|
except:
|
14
14
|
- schedules
|
@@ -17,6 +17,6 @@ run:triage:
|
|
17
17
|
stage: triage
|
18
18
|
script:
|
19
19
|
- gem install gitlab-triage
|
20
|
-
- gitlab-triage --token $
|
20
|
+
- gitlab-triage --token $GITLAB_API_TOKEN --source projects --source-id $CI_PROJECT_PATH
|
21
21
|
only:
|
22
22
|
- schedules
|
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.11.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-07-
|
11
|
+
date: 2020-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -158,7 +158,6 @@ files:
|
|
158
158
|
- lib/gitlab/triage/filters/assignee_member_conditions_filter.rb
|
159
159
|
- lib/gitlab/triage/filters/author_member_conditions_filter.rb
|
160
160
|
- lib/gitlab/triage/filters/base_conditions_filter.rb
|
161
|
-
- lib/gitlab/triage/filters/forbidden_labels_conditions_filter.rb
|
162
161
|
- lib/gitlab/triage/filters/member_conditions_filter.rb
|
163
162
|
- lib/gitlab/triage/filters/merge_request_date_conditions_filter.rb
|
164
163
|
- lib/gitlab/triage/filters/name_conditions_filter.rb
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require_relative 'base_conditions_filter'
|
2
|
-
|
3
|
-
module Gitlab
|
4
|
-
module Triage
|
5
|
-
module Filters
|
6
|
-
class ForbiddenLabelsConditionsFilter < BaseConditionsFilter
|
7
|
-
def validate_condition(condition)
|
8
|
-
raise ArgumentError, 'condition must be an array containing forbidden label values' unless condition.is_a?(Array)
|
9
|
-
end
|
10
|
-
|
11
|
-
def initialize_variables(forbidden_labels)
|
12
|
-
@attribute = :labels
|
13
|
-
@forbidden_labels = forbidden_labels
|
14
|
-
end
|
15
|
-
|
16
|
-
def resource_value
|
17
|
-
@resource[@attribute]
|
18
|
-
end
|
19
|
-
|
20
|
-
def calculate
|
21
|
-
label_intersection.empty?
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def label_intersection
|
27
|
-
resource_value & @forbidden_labels
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|