gitlab-triage 1.23.1 → 1.25.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab/issue_templates/Default.md +2 -0
- data/.gitlab/merge_request_templates/Default.md +2 -0
- data/.gitlab-ci.yml +7 -0
- data/.rubocop.yml +5 -0
- data/.rubocop_todo.yml +145 -0
- data/Gemfile +1 -1
- data/README.md +115 -11
- data/lib/gitlab/triage/action/comment.rb +5 -0
- data/lib/gitlab/triage/action/delete.rb +56 -0
- data/lib/gitlab/triage/action/issue.rb +64 -0
- data/lib/gitlab/triage/action/summarize.rb +1 -1
- data/lib/gitlab/triage/action.rb +5 -1
- data/lib/gitlab/triage/command_builders/text_content_builder.rb +2 -1
- data/lib/gitlab/triage/engine.rb +27 -3
- data/lib/gitlab/triage/entity_builders/issue_builder.rb +11 -39
- data/lib/gitlab/triage/entity_builders/summary_builder.rb +82 -0
- data/lib/gitlab/triage/filters/branch_date_filter.rb +67 -0
- data/lib/gitlab/triage/filters/branch_protected_filter.rb +26 -0
- data/lib/gitlab/triage/graphql_queries/query_builder.rb +7 -7
- data/lib/gitlab/triage/network.rb +19 -91
- data/lib/gitlab/triage/network_adapters/httparty_adapter.rb +20 -0
- data/lib/gitlab/triage/policies/base_policy.rb +13 -1
- data/lib/gitlab/triage/policies/rule_policy.rb +15 -3
- data/lib/gitlab/triage/policies/summary_policy.rb +5 -5
- data/lib/gitlab/triage/resource/branch.rb +13 -0
- data/lib/gitlab/triage/resource/context.rb +2 -0
- data/lib/gitlab/triage/resource/instance_version.rb +1 -1
- data/lib/gitlab/triage/resource/issue.rb +6 -0
- data/lib/gitlab/triage/resource/linked_issue.rb +15 -0
- data/lib/gitlab/triage/rest_api_network.rb +126 -0
- data/lib/gitlab/triage/url_builders/url_builder.rb +1 -0
- data/lib/gitlab/triage/version.rb +1 -1
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42c73b8dcb5e94e895ba0daa399105f8111584523001f233a3b5344dd52e8d13
|
4
|
+
data.tar.gz: 0f9c38c9aa9de8c6210cca84d6224af7647bfeec4c7fa8a73562cb4e035205e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 264e37c9838cff91100494a72a791828e555afcac5e028a83cd0de7b86c19f9d206d1ffe0486983cd990cd51686719c660b7b04f530bd633118bc85f734a9960
|
7
|
+
data.tar.gz: dd4e5b974bdf3496ee8a40eca9d69d17a3882cf40e6ac24fb8b452c500ad2fe17c8a40bd32ff1a97ad5639f7837cbdc24c993ea96d264a07a2a58985af6744b8
|
@@ -9,3 +9,5 @@ If you are experiencing an issue when using GitLab.com, your first port of call
|
|
9
9
|
If you feel that your issue can be categorized as a reproducible bug or a feature proposal, please use one of the issue templates provided and include as much information as possible.
|
10
10
|
|
11
11
|
Thank you for helping to make GitLab a better product.
|
12
|
+
|
13
|
+
<!-- template sourced from https://gitlab.com/gitlab-org/ruby/gems/gitlab-triage/-/blob/master/.gitlab/issue_templates/Default.md -->
|
@@ -7,3 +7,5 @@ Please keep this description updated with any discussion that takes place so
|
|
7
7
|
that reviewers can understand your intent. Keeping the description updated is
|
8
8
|
especially important if they didn't participate in the discussion.
|
9
9
|
-->
|
10
|
+
|
11
|
+
<!-- template sourced from https://gitlab.com/gitlab-org/ruby/gems/gitlab-triage/-/blob/master/.gitlab/merge_request_templates/Default.md -->
|
data/.gitlab-ci.yml
CHANGED
@@ -106,6 +106,13 @@ specs:
|
|
106
106
|
script:
|
107
107
|
- bundle exec rake spec
|
108
108
|
|
109
|
+
specs ruby3.0:
|
110
|
+
image: ruby:3.0
|
111
|
+
needs: ["setup-test-env"]
|
112
|
+
stage: test
|
113
|
+
script:
|
114
|
+
- bundle exec rake spec
|
115
|
+
|
109
116
|
##################
|
110
117
|
## Triage stage ##
|
111
118
|
##################
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2022-05-26 15:15:19 UTC using RuboCop version 0.93.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 43
|
10
|
+
CodeReuse/ActiveRecord:
|
11
|
+
Exclude:
|
12
|
+
- 'lib/gitlab/triage/engine.rb'
|
13
|
+
- 'lib/gitlab/triage/graphql_network.rb'
|
14
|
+
- 'spec/gitlab/triage/engine_spec.rb'
|
15
|
+
- 'spec/gitlab/triage/graphql_network_spec.rb'
|
16
|
+
- 'spec/gitlab/triage/network_adapters/graphql_adapter_spec.rb'
|
17
|
+
- 'spec/gitlab/triage/rest_api_network_spec.rb'
|
18
|
+
- 'spec/gitlab/triage/policies/rule_policy_spec.rb'
|
19
|
+
- 'spec/gitlab/triage/resource/label_spec.rb'
|
20
|
+
- 'spec/support/expect_next_instance_of.rb'
|
21
|
+
- 'spec/support/shared_examples/issuable_shared_examples.rb'
|
22
|
+
- 'spec/support/shared_examples/label_command_shared_examples.rb'
|
23
|
+
- 'spec/support/stub_api.rb'
|
24
|
+
|
25
|
+
# Offense count: 1
|
26
|
+
# Cop supports --auto-correct.
|
27
|
+
Cop/LineBreakAroundConditionalBlock:
|
28
|
+
Exclude:
|
29
|
+
- 'lib/gitlab/triage/engine.rb'
|
30
|
+
|
31
|
+
# Offense count: 1
|
32
|
+
# Configuration parameters: Include.
|
33
|
+
# Include: **/*.gemspec
|
34
|
+
Gemspec/RequiredRubyVersion:
|
35
|
+
Exclude:
|
36
|
+
- 'gitlab-triage.gemspec'
|
37
|
+
|
38
|
+
# Offense count: 1
|
39
|
+
# Cop supports --auto-correct.
|
40
|
+
Lint/NonDeterministicRequireOrder:
|
41
|
+
Exclude:
|
42
|
+
- 'spec/spec_helper.rb'
|
43
|
+
|
44
|
+
# Offense count: 1
|
45
|
+
# Configuration parameters: IgnoredMethods.
|
46
|
+
Metrics/AbcSize:
|
47
|
+
Max: 57
|
48
|
+
|
49
|
+
# Offense count: 1
|
50
|
+
# Cop supports --auto-correct.
|
51
|
+
Performance/ConstantRegexp:
|
52
|
+
Exclude:
|
53
|
+
- 'lib/gitlab/triage/command_builders/text_content_builder.rb'
|
54
|
+
|
55
|
+
# Offense count: 2
|
56
|
+
# Cop supports --auto-correct.
|
57
|
+
# Configuration parameters: SafeMultiline.
|
58
|
+
Performance/DeleteSuffix:
|
59
|
+
Exclude:
|
60
|
+
- 'lib/gitlab/triage/api_query_builders/date_query_param_builder.rb'
|
61
|
+
- 'lib/gitlab/triage/graphql_queries/query_param_builders/date_param_builder.rb'
|
62
|
+
|
63
|
+
# Offense count: 5
|
64
|
+
Performance/MethodObjectAsBlock:
|
65
|
+
Exclude:
|
66
|
+
- 'lib/gitlab/triage/engine.rb'
|
67
|
+
- 'lib/gitlab/triage/entity_builders/issue_builder.rb'
|
68
|
+
- 'lib/gitlab/triage/expand_condition.rb'
|
69
|
+
- 'lib/gitlab/triage/expand_condition/expansion.rb'
|
70
|
+
- 'lib/gitlab/triage/limiters/date_field_limiter.rb'
|
71
|
+
|
72
|
+
# Offense count: 31
|
73
|
+
# Cop supports --auto-correct.
|
74
|
+
RSpec/EmptyLineAfterLetBlock:
|
75
|
+
Enabled: false
|
76
|
+
|
77
|
+
# Offense count: 93
|
78
|
+
# Configuration parameters: AllowSubject.
|
79
|
+
RSpec/MultipleMemoizedHelpers:
|
80
|
+
Max: 12
|
81
|
+
|
82
|
+
# Offense count: 12
|
83
|
+
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
|
84
|
+
RSpec/VerifiedDoubles:
|
85
|
+
Exclude:
|
86
|
+
- 'spec/gitlab/triage/graphql_network_spec.rb'
|
87
|
+
- 'spec/gitlab/triage/network_adapters/graphql_adapter_spec.rb'
|
88
|
+
- 'spec/gitlab/triage/rest_api_network_spec.rb'
|
89
|
+
- 'spec/support/shared_examples/label_command_shared_examples.rb'
|
90
|
+
|
91
|
+
# Offense count: 1
|
92
|
+
# Cop supports --auto-correct.
|
93
|
+
Rails/IndexBy:
|
94
|
+
Exclude:
|
95
|
+
- 'lib/gitlab/triage/engine.rb'
|
96
|
+
|
97
|
+
# Offense count: 1
|
98
|
+
# Cop supports --auto-correct.
|
99
|
+
Rails/NegateInclude:
|
100
|
+
Exclude:
|
101
|
+
- 'lib/gitlab/triage/filters/member_conditions_filter.rb'
|
102
|
+
|
103
|
+
# Offense count: 3
|
104
|
+
# Cop supports --auto-correct.
|
105
|
+
Rails/Pluck:
|
106
|
+
Exclude:
|
107
|
+
- 'lib/gitlab/triage/filters/base_conditions_filter.rb'
|
108
|
+
- 'lib/gitlab/triage/filters/member_conditions_filter.rb'
|
109
|
+
- 'lib/gitlab/triage/validators/limiter_validator.rb'
|
110
|
+
|
111
|
+
# Offense count: 2
|
112
|
+
# Cop supports --auto-correct.
|
113
|
+
Style/ArrayCoercion:
|
114
|
+
Exclude:
|
115
|
+
- 'lib/gitlab/triage/graphql_network.rb'
|
116
|
+
|
117
|
+
# Offense count: 1
|
118
|
+
# Cop supports --auto-correct.
|
119
|
+
Style/ExplicitBlockArgument:
|
120
|
+
Exclude:
|
121
|
+
- 'spec/support/expect_next_instance_of.rb'
|
122
|
+
|
123
|
+
# Offense count: 115
|
124
|
+
# Cop supports --auto-correct.
|
125
|
+
# Configuration parameters: EnforcedStyle.
|
126
|
+
# SupportedStyles: always, always_true, never
|
127
|
+
Style/FrozenStringLiteralComment:
|
128
|
+
Enabled: false
|
129
|
+
|
130
|
+
# Offense count: 5
|
131
|
+
Style/OpenStructUse:
|
132
|
+
Exclude:
|
133
|
+
- 'spec/gitlab/triage/network_adapters/httparty_adapter_spec.rb'
|
134
|
+
|
135
|
+
# Offense count: 1
|
136
|
+
# Cop supports --auto-correct.
|
137
|
+
Style/RedundantRegexpEscape:
|
138
|
+
Exclude:
|
139
|
+
- 'lib/gitlab/triage/command_builders/text_content_builder.rb'
|
140
|
+
|
141
|
+
# Offense count: 1
|
142
|
+
# Configuration parameters: AllowModifier.
|
143
|
+
Style/SoleNestedConditional:
|
144
|
+
Exclude:
|
145
|
+
- 'lib/gitlab/triage/validators/params_validator.rb'
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -21,6 +21,7 @@ Triage policies are defined on a resource level basis, resources being:
|
|
21
21
|
- Epics
|
22
22
|
- Issues
|
23
23
|
- Merge Requests
|
24
|
+
- Branches
|
24
25
|
|
25
26
|
Each policy can declare a number of conditions that must all be satisfied before
|
26
27
|
a number of actions are carried out.
|
@@ -42,6 +43,7 @@ Select which resource to add the policy to:
|
|
42
43
|
- `epics`
|
43
44
|
- `issues`
|
44
45
|
- `merge_requests`
|
46
|
+
- `branches`
|
45
47
|
|
46
48
|
And create an array of `rules` to define your policies:
|
47
49
|
|
@@ -120,6 +122,18 @@ resource_rules:
|
|
120
122
|
comment_type: thread
|
121
123
|
comment: |
|
122
124
|
{{author}} This issue is unlabelled. Please add one or more labels.
|
125
|
+
branches:
|
126
|
+
rules:
|
127
|
+
- name: My branch policy
|
128
|
+
conditions:
|
129
|
+
date:
|
130
|
+
attribute: committed_date
|
131
|
+
condition: older_than
|
132
|
+
interval_type: 6
|
133
|
+
interval: months
|
134
|
+
name: ^feature
|
135
|
+
actions:
|
136
|
+
delete: true
|
123
137
|
```
|
124
138
|
|
125
139
|
### Real world example
|
@@ -166,20 +180,23 @@ Available condition types:
|
|
166
180
|
- [`target_branch` condition](#target-branch-condition)
|
167
181
|
- [`weight` condition](#weight-condition)
|
168
182
|
- [`discussions` condition](#discussions-condition)
|
183
|
+
- [`protected` condition](#protected-condition)
|
169
184
|
- [`ruby` condition](#ruby-condition)
|
170
185
|
|
171
186
|
##### Date condition
|
172
187
|
|
173
188
|
Accepts a hash of fields.
|
174
189
|
|
175
|
-
| Field | Type | Values
|
176
|
-
| --------- | ----
|
177
|
-
| `attribute` | string | `created_at`, `updated_at`, `merged_at` | yes |
|
178
|
-
| `condition` | string | `older_than`, `newer_than`
|
179
|
-
| `interval_type` | string | `days`, `weeks`, `months`, `years`
|
180
|
-
| `interval` | integer | integer
|
181
|
-
|
182
|
-
>
|
190
|
+
| Field | Type | Values | Required |
|
191
|
+
| --------- | ---- |--------------------------------------------------------------------------| -------- |
|
192
|
+
| `attribute` | string | `created_at`, `updated_at`, `merged_at`, `authored_date`, `committed_date` | yes |
|
193
|
+
| `condition` | string | `older_than`, `newer_than` | yes |
|
194
|
+
| `interval_type` | string | `days`, `weeks`, `months`, `years` | yes |
|
195
|
+
| `interval` | integer | integer | yes |
|
196
|
+
> **Note:**
|
197
|
+
> - `merged_at` only works on merge requests.
|
198
|
+
> - `closed_at` is not supported in the GitLab API, but can be used in a [`ruby` condition](#ruby-condition).
|
199
|
+
> - `committed_date` and `authored_date` only works for branches.
|
183
200
|
|
184
201
|
Example:
|
185
202
|
|
@@ -574,6 +591,13 @@ conditions:
|
|
574
591
|
threshold: 15
|
575
592
|
```
|
576
593
|
|
594
|
+
##### Protected condition
|
595
|
+
|
596
|
+
** This condition is only applicable for branches**
|
597
|
+
|
598
|
+
Accept a boolean.
|
599
|
+
If not specified, default to `false` to filter out protected branches.
|
600
|
+
|
577
601
|
##### Ruby condition
|
578
602
|
|
579
603
|
This condition allows users to write a Ruby expression to be evaluated for
|
@@ -612,6 +636,13 @@ conditions:
|
|
612
636
|
This will make it only act on resources which have active milestones and
|
613
637
|
there exists next milestone which has already started.
|
614
638
|
|
639
|
+
Since `closed_at` is not a queryable attribute in the GitLab API, we can use a Ruby expression to filter resources like:
|
640
|
+
|
641
|
+
```yml
|
642
|
+
conditions:
|
643
|
+
ruby: resource[:closed_at] > 7.days.ago.strftime('%Y-%m-%dT00:00:00.000Z')
|
644
|
+
```
|
645
|
+
|
615
646
|
See [Ruby expression API](#ruby-expression-api) for the list of currently
|
616
647
|
available API.
|
617
648
|
|
@@ -653,6 +684,8 @@ Available action types:
|
|
653
684
|
- [`comment_type` action option](#comment-type-action-option)
|
654
685
|
- [`summarize` action](#summarize-action)
|
655
686
|
- [`comment_on_summary` action](#comment-on-summary-action)
|
687
|
+
- [`issue` action](#create-a-new-issue-from-each-resource)
|
688
|
+
- [`delete` action](#delete-action)
|
656
689
|
|
657
690
|
##### Labels action
|
658
691
|
|
@@ -984,6 +1017,70 @@ resource_rules:
|
|
984
1017
|
/label ~"needs attention"
|
985
1018
|
```
|
986
1019
|
|
1020
|
+
##### Create a new issue from each resource
|
1021
|
+
|
1022
|
+
Generates one issue for each resource, by default in the same project as the resource.
|
1023
|
+
|
1024
|
+
The use case for this is, for example, creating test issues in the same (or different)
|
1025
|
+
project for issues labeled "extended-testing"; or automatically splitting one issue with a
|
1026
|
+
certain label into multiple ones.
|
1027
|
+
|
1028
|
+
Accepts a hash of fields.
|
1029
|
+
|
1030
|
+
| Field | Type | Description | Required | Placeholders | Ruby expression | Default |
|
1031
|
+
| ---- | ---- | ---- | ---- | ---- | ---- | ---- |
|
1032
|
+
| `title` | string | The title of the generated issue | yes | yes | yes | |
|
1033
|
+
| `destination` | integer or string | The project ID or path to create the generated issue in | no | no | no | source project |
|
1034
|
+
| `description` | string | The description of the generated issue | no | yes | yes | |
|
1035
|
+
| `redact_confidential_resources` | boolean | Whether redact fields for confidential resources | no | no | no | true |
|
1036
|
+
|
1037
|
+
The placeholders available in `title` and `destination` are the properties of the resource being used to generate the issue.
|
1038
|
+
|
1039
|
+
Example
|
1040
|
+
|
1041
|
+
```yml
|
1042
|
+
resource_rules:
|
1043
|
+
issues:
|
1044
|
+
rules:
|
1045
|
+
- name: Issues requiring extra testing
|
1046
|
+
labels:
|
1047
|
+
- needs-testing
|
1048
|
+
actions:
|
1049
|
+
issue:
|
1050
|
+
title: |
|
1051
|
+
Testing: {{ title }}
|
1052
|
+
description: |
|
1053
|
+
The issue {{ full_reference }} needs testing.
|
1054
|
+
|
1055
|
+
Please take care of them before the end of #{7.days.from_now.strftime('%Y-%m-%d')}
|
1056
|
+
|
1057
|
+
/label ~"needs attention"
|
1058
|
+
```
|
1059
|
+
|
1060
|
+
##### Delete action
|
1061
|
+
|
1062
|
+
**This action is only applicable for branches.**
|
1063
|
+
|
1064
|
+
Delete the resource.
|
1065
|
+
|
1066
|
+
Accept a boolean. Set to `true` to enable.
|
1067
|
+
|
1068
|
+
Example :
|
1069
|
+
```yaml
|
1070
|
+
resource_rules:
|
1071
|
+
branches:
|
1072
|
+
rules:
|
1073
|
+
- name: My branch policy
|
1074
|
+
conditions:
|
1075
|
+
date:
|
1076
|
+
attribute: committed_date
|
1077
|
+
condition: older_than
|
1078
|
+
interval_type: months
|
1079
|
+
interval: 30
|
1080
|
+
actions:
|
1081
|
+
delete: true
|
1082
|
+
```
|
1083
|
+
|
987
1084
|
### Summary policies
|
988
1085
|
|
989
1086
|
Summary policies are special policies that join multiple rule policies together
|
@@ -1090,13 +1187,20 @@ Here's a list of currently available Ruby expression API:
|
|
1090
1187
|
| project_path | String | The path with namespace to the issues or merge requests project |
|
1091
1188
|
| full_resource_reference | String | A full reference including project path to the issue or merge request |
|
1092
1189
|
|
1093
|
-
##### Methods for `Issue` (issue context)
|
1190
|
+
##### Methods for `Issue` and `LinkedIssue` (issue context)
|
1094
1191
|
|
1095
1192
|
| Name | Return type | Description |
|
1096
1193
|
| ---- | ---- | ---- |
|
1097
1194
|
| merge_requests_count | Integer | The number of merge requests related to the issue |
|
1098
1195
|
| related_merge_requests | [MergeRequest] | The list of merge requests related to the issue |
|
1099
1196
|
| closed_by | [MergeRequest] | The list of merge requests that close the issue |
|
1197
|
+
| linked_issues | [LinkedIssue] | The list of issues that are linked to the issue |
|
1198
|
+
|
1199
|
+
##### Methods for `LinkedIssue`
|
1200
|
+
|
1201
|
+
| Method | Return type | Description |
|
1202
|
+
| ---- | ---- | ---- |
|
1203
|
+
| link_type | String | The link type of the linked issue (`blocks`, `is_blocked_by`, or `relates_to`) |
|
1100
1204
|
|
1101
1205
|
##### Methods for `MergeRequest` (merge request context)
|
1102
1206
|
|
@@ -1227,8 +1331,8 @@ run:triage:triage:
|
|
1227
1331
|
script:
|
1228
1332
|
- gem install gitlab-triage
|
1229
1333
|
- gitlab-triage --token $GITLAB_API_TOKEN --source-id $CI_PROJECT_PATH
|
1230
|
-
|
1231
|
-
-
|
1334
|
+
rules:
|
1335
|
+
- if: $CI_PIPELINE_SOURCE == "schedule"
|
1232
1336
|
```
|
1233
1337
|
|
1234
1338
|
> **Note:** You can use the [`--init-ci`](#usage) option to add an example [`.gitlab-ci.yml` file](support/.gitlab-ci.example.yml) to your project
|
@@ -28,6 +28,11 @@ module Gitlab
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def act
|
31
|
+
if policy.type == 'branches'
|
32
|
+
puts Gitlab::Triage::UI.warn "Comment actions are not available for branches. They will NOT be performed\n\n"
|
33
|
+
return
|
34
|
+
end
|
35
|
+
|
31
36
|
policy.resources.each do |resource|
|
32
37
|
comment = build_comment(resource).strip
|
33
38
|
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'base'
|
4
|
+
|
5
|
+
module Gitlab
|
6
|
+
module Triage
|
7
|
+
module Action
|
8
|
+
class Delete < Base
|
9
|
+
class Dry < Delete
|
10
|
+
def act
|
11
|
+
puts "The following resources will be deleted by the rule **#{policy.name}**:\n\n"
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def perform(resource)
|
18
|
+
puts "DELETE resource with type: #{resource[:type]} and id: #{resource_id(resource)}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def act
|
23
|
+
return unless policy.type&.to_sym == :branches
|
24
|
+
|
25
|
+
policy.resources.each do |resource|
|
26
|
+
perform(resource)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def perform(resource)
|
33
|
+
network.delete_api(build_delete_url(resource))
|
34
|
+
end
|
35
|
+
|
36
|
+
def build_delete_url(resource)
|
37
|
+
delete_url = UrlBuilders::UrlBuilder.new(
|
38
|
+
source: policy.source,
|
39
|
+
source_id: network.options.source_id,
|
40
|
+
resource_type: policy.type,
|
41
|
+
resource_id: resource_id(resource),
|
42
|
+
network_options: network.options
|
43
|
+
).build
|
44
|
+
|
45
|
+
puts Gitlab::Triage::UI.debug "delete_url: #{delete_url}" if network.options.debug
|
46
|
+
|
47
|
+
delete_url
|
48
|
+
end
|
49
|
+
|
50
|
+
def resource_id(resource)
|
51
|
+
resource[:name]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'base'
|
4
|
+
|
5
|
+
module Gitlab
|
6
|
+
module Triage
|
7
|
+
module Action
|
8
|
+
class Issue < Base
|
9
|
+
class Dry < Issue
|
10
|
+
def act
|
11
|
+
puts "The following issues would be created for the rule **#{policy.name}**:\n\n"
|
12
|
+
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def perform(resource, issue)
|
19
|
+
puts ">>>"
|
20
|
+
puts "* Project: #{issue.destination || resource[policy.source_id_sym]}"
|
21
|
+
puts "* Title: #{issue.title}"
|
22
|
+
puts "* Description: #{issue.description}"
|
23
|
+
puts ">>>"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def act
|
28
|
+
policy.resources.each do |resource|
|
29
|
+
issue = policy.build_issue(resource)
|
30
|
+
|
31
|
+
perform(resource, issue) if issue.valid?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def perform(resource, issue)
|
38
|
+
network.post_api(build_post_url(resource, issue), post_issue_body(issue))
|
39
|
+
end
|
40
|
+
|
41
|
+
def build_post_url(resource, issue)
|
42
|
+
# POST /projects/:id/issues
|
43
|
+
# https://docs.gitlab.com/ee/api/issues.html#new-issue
|
44
|
+
post_url = UrlBuilders::UrlBuilder.new(
|
45
|
+
network_options: network.options,
|
46
|
+
source_id: issue.destination || resource[policy.source_id_sym],
|
47
|
+
resource_type: 'issues'
|
48
|
+
).build
|
49
|
+
|
50
|
+
puts Gitlab::Triage::UI.debug "post_issue_url: #{post_url}" if network.options.debug
|
51
|
+
|
52
|
+
post_url
|
53
|
+
end
|
54
|
+
|
55
|
+
def post_issue_body(issue)
|
56
|
+
{
|
57
|
+
title: issue.title,
|
58
|
+
description: issue.description
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/gitlab/triage/action.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require_relative 'action/summarize'
|
2
2
|
require_relative 'action/comment'
|
3
3
|
require_relative 'action/comment_on_summary'
|
4
|
+
require_relative 'action/issue'
|
5
|
+
require_relative 'action/delete'
|
4
6
|
|
5
7
|
module Gitlab
|
6
8
|
module Triage
|
@@ -11,7 +13,9 @@ module Gitlab
|
|
11
13
|
[
|
12
14
|
[Summarize, policy.summarize?],
|
13
15
|
[Comment, policy.comment?],
|
14
|
-
[CommentOnSummary, policy.comment_on_summary?]
|
16
|
+
[CommentOnSummary, policy.comment_on_summary?],
|
17
|
+
[Issue, policy.issue?],
|
18
|
+
[Delete, policy.delete?]
|
15
19
|
].each do |action, active|
|
16
20
|
act(action: action, policy: policy, **args) if active
|
17
21
|
end
|
data/lib/gitlab/triage/engine.rb
CHANGED
@@ -3,6 +3,8 @@ require 'active_support/inflector'
|
|
3
3
|
|
4
4
|
require_relative 'expand_condition'
|
5
5
|
require_relative 'filters/merge_request_date_conditions_filter'
|
6
|
+
require_relative 'filters/branch_date_filter'
|
7
|
+
require_relative 'filters/branch_protected_filter'
|
6
8
|
require_relative 'filters/votes_conditions_filter'
|
7
9
|
require_relative 'filters/no_additional_labels_conditions_filter'
|
8
10
|
require_relative 'filters/author_member_conditions_filter'
|
@@ -21,6 +23,7 @@ require_relative 'api_query_builders/multi_query_param_builder'
|
|
21
23
|
require_relative 'url_builders/url_builder'
|
22
24
|
require_relative 'network'
|
23
25
|
require_relative 'graphql_network'
|
26
|
+
require_relative 'rest_api_network'
|
24
27
|
require_relative 'network_adapters/httparty_adapter'
|
25
28
|
require_relative 'network_adapters/graphql_adapter'
|
26
29
|
require_relative 'graphql_queries/query_builder'
|
@@ -78,7 +81,11 @@ module Gitlab
|
|
78
81
|
end
|
79
82
|
|
80
83
|
def network
|
81
|
-
@network ||= Network.new(
|
84
|
+
@network ||= Network.new(restapi: restapi_network, graphql: graphql_network)
|
85
|
+
end
|
86
|
+
|
87
|
+
def restapi_network
|
88
|
+
@restapi_network ||= RestAPINetwork.new(network_adapter)
|
82
89
|
end
|
83
90
|
|
84
91
|
def graphql_network
|
@@ -334,7 +341,16 @@ module Gitlab
|
|
334
341
|
|
335
342
|
# rubocop:disable Style/IfUnlessModifier
|
336
343
|
if conditions[:date]
|
337
|
-
|
344
|
+
case resource[:type]
|
345
|
+
when 'branches'
|
346
|
+
results << Filters::BranchDateFilter.new(resource, conditions[:date]).calculate
|
347
|
+
when 'merge_requests'
|
348
|
+
results << Filters::MergeRequestDateConditionsFilter.new(resource, conditions[:date]).calculate
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
if resource[:type] == 'branches'
|
353
|
+
results << Filters::BranchProtectedFilter.new(resource, conditions[:protected]).calculate
|
338
354
|
end
|
339
355
|
|
340
356
|
if conditions[:upvotes]
|
@@ -397,7 +413,7 @@ module Gitlab
|
|
397
413
|
|
398
414
|
condition_builders << milestone_condition_builder(resource_type, conditions[:milestone]) if conditions[:milestone]
|
399
415
|
|
400
|
-
if conditions[:date] && APIQueryBuilders::DateQueryParamBuilder.applicable?(conditions[:date])
|
416
|
+
if conditions[:date] && APIQueryBuilders::DateQueryParamBuilder.applicable?(conditions[:date]) && resource_type&.to_sym != :branches
|
401
417
|
condition_builders << APIQueryBuilders::DateQueryParamBuilder.new(conditions.delete(:date))
|
402
418
|
end
|
403
419
|
|
@@ -406,6 +422,8 @@ module Gitlab
|
|
406
422
|
condition_builders.concat(issues_resource_query(conditions))
|
407
423
|
when :merge_requests
|
408
424
|
condition_builders.concat(merge_requests_resource_query(conditions))
|
425
|
+
when :branches
|
426
|
+
condition_builders.concat(branches_resource_query(conditions))
|
409
427
|
end
|
410
428
|
|
411
429
|
condition_builders.compact.each do |condition_builder|
|
@@ -463,6 +481,12 @@ module Gitlab
|
|
463
481
|
end
|
464
482
|
end
|
465
483
|
|
484
|
+
def branches_resource_query(conditions)
|
485
|
+
[].tap do |condition_builders|
|
486
|
+
condition_builders << APIQueryBuilders::SingleQueryParamBuilder.new('search', conditions[:name]) if conditions[:name]
|
487
|
+
end
|
488
|
+
end
|
489
|
+
|
466
490
|
def draft_condition_builder(draft_condittion)
|
467
491
|
# Issues API only accepts 'yes' and 'no' as strings: https://docs.gitlab.com/ee/api/merge_requests.html
|
468
492
|
wip =
|