gitlab-triage 1.7.1 → 1.11.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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.gitlab-ci.yml +57 -41
  4. data/.gitlab/merge_request_templates/Release.md +35 -0
  5. data/.rubocop.yml +3 -0
  6. data/Gemfile +1 -1
  7. data/Guardfile +1 -1
  8. data/README.md +105 -8
  9. data/gitlab-triage.gemspec +1 -1
  10. data/lib/gitlab/triage/action/comment.rb +16 -3
  11. data/lib/gitlab/triage/api_query_builders/date_query_param_builder.rb +78 -0
  12. data/lib/gitlab/triage/command_builders/base_command_builder.rb +7 -3
  13. data/lib/gitlab/triage/command_builders/label_command_builder.rb +17 -0
  14. data/lib/gitlab/triage/command_builders/move_command_builder.rb +19 -0
  15. data/lib/gitlab/triage/command_builders/text_content_builder.rb +18 -6
  16. data/lib/gitlab/triage/engine.rb +42 -17
  17. data/lib/gitlab/triage/errors.rb +1 -1
  18. data/lib/gitlab/triage/filters/merge_request_date_conditions_filter.rb +51 -5
  19. data/lib/gitlab/triage/option_parser.rb +10 -0
  20. data/lib/gitlab/triage/options.rb +2 -0
  21. data/lib/gitlab/triage/policies/rule_policy.rb +1 -1
  22. data/lib/gitlab/triage/policies/summary_policy.rb +1 -1
  23. data/lib/gitlab/triage/policies_resources/rule_resources.rb +5 -6
  24. data/lib/gitlab/triage/policies_resources/summary_resources.rb +5 -6
  25. data/lib/gitlab/triage/resource/base.rb +10 -1
  26. data/lib/gitlab/triage/resource/label.rb +15 -0
  27. data/lib/gitlab/triage/resource/merge_request.rb +9 -0
  28. data/lib/gitlab/triage/url_builders/url_builder.rb +10 -9
  29. data/lib/gitlab/triage/validators/limiter_validator.rb +3 -1
  30. data/lib/gitlab/triage/validators/params_validator.rb +5 -3
  31. data/lib/gitlab/triage/version.rb +3 -1
  32. data/support/.gitlab-ci.example.yml +2 -2
  33. data/support/.triage-policies.example.yml +2 -2
  34. metadata +6 -5
  35. data/lib/gitlab/triage/filters/forbidden_labels_conditions_filter.rb +0 -32
  36. data/lib/gitlab/triage/filters/issuable_date_conditions_filter.rb +0 -65
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c67fa47a534d7f13d781966693423d4916292ec9924e4913492e63eb00a5f5a
4
- data.tar.gz: ecd0946de096e97fd73ca3b7aa243842b3bf2cdccff9b6746b4034893789d672
3
+ metadata.gz: e02cd169e252e4656441f6e9268314c2b968935957dbcb906ae3048ee7045da4
4
+ data.tar.gz: 3b58c8b37e3f82878272641ad848239c74623499f0e309ba0ac9aaaf6803cf0f
5
5
  SHA512:
6
- metadata.gz: cc9bc7902d7e3e96186d2f2593c76ef64bd74005857548e6b8d5014a70e3be1d75447083b06de4e7bb923651b0d9696029dfdf64ef3011672fc8a1ffbb4d8ca4
7
- data.tar.gz: aa02ac6fbefebc75589e4da546c52e48150408aebdacd34fc83f0cf24a373d19c3e63de52cbfba6847bcc778b285ba21e9c4ea037d886d36122998d2bebbf9d7
6
+ metadata.gz: 181a6a5055a61b5d8c78f36d047dfef269a92a7d0173598a490e5420ab04fb267c9c42be2ae9bef31a815eb7730a15b921dde2b1834e49dcc20d0969d4986f54
7
+ data.tar.gz: 621d6e208ad9dcdd034931ca0656778e5247c6aa3f3e6fa8edf53ed401795452f0d136eec259df8a377e36589de866fc7ee949a792cd1fa5b2c07257cab577ee
data/.gitignore CHANGED
@@ -6,7 +6,6 @@
6
6
  /Gemfile.lock
7
7
  /_yardoc/
8
8
  /coverage/
9
- /doc/
10
9
  /pkg/
11
10
  /spec/reports/
12
11
  /tmp/
@@ -1,49 +1,68 @@
1
- image: ruby:2.6
2
-
3
1
  stages:
4
2
  - prepare
5
3
  - test
6
4
  - triage
5
+ - deploy
7
6
 
8
- .default-only:
9
- only:
10
- refs:
11
- - master
12
- - merge_requests
13
- - tags
14
-
15
- .default-before_script:
7
+ default:
8
+ image: ruby:2.7
9
+ tags:
10
+ - gitlab-org
11
+ cache:
12
+ key:
13
+ files:
14
+ - Gemfile
15
+ - gitlab-triage.gemspec
16
+ paths:
17
+ - vendor/ruby
18
+ - Gemfile.lock
19
+ policy: pull
16
20
  before_script:
21
+ - ruby --version
17
22
  - gem install bundler --no-document --version 2.0.2
18
- - bundle install --jobs $(nproc) --retry 3 --quiet
23
+ - bundle --version
24
+ - bundle install --jobs $(nproc) --path=vendor --retry 3 --quiet
25
+ - bundle check
26
+
27
+ workflow:
28
+ rules:
29
+ # For merge requests, create a pipeline.
30
+ - if: '$CI_MERGE_REQUEST_IID'
31
+ # For `master` branch, create a pipeline (this includes on schedules, pushes, merges, etc.).
32
+ - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
33
+ # For tags, create a pipeline.
34
+ - if: '$CI_COMMIT_TAG'
35
+
36
+ .use-docker-in-docker:
37
+ image: docker:${DOCKER_VERSION}
38
+ services:
39
+ - docker:${DOCKER_VERSION}-dind
40
+ variables:
41
+ DOCKER_VERSION: "19.03.0"
42
+ DOCKER_DRIVER: overlay2
43
+ DOCKER_HOST: tcp://docker:2375
44
+ DOCKER_TLS_CERTDIR: ""
45
+ tags:
46
+ # See https://gitlab.com/gitlab-com/www-gitlab-com/-/issues/7019 for tag descriptions
47
+ - gitlab-org-docker
19
48
 
20
49
  ###################
21
50
  ## Prepare stage ##
22
51
  ###################
23
52
  setup-test-env:
24
- extends: .default-only
25
53
  stage: prepare
26
54
  script:
27
- - ruby --version
28
- - gem install bundler --no-document
29
- - bundle --version
30
- - bundle install --clean --jobs $(nproc) --path=vendor --retry=3 --quiet
31
- - bundle check
55
+ - echo "Setup done!"
32
56
  cache:
33
- key: "$CI_JOB_NAME-ruby-2.6"
34
- paths:
35
- - vendor/ruby
36
- - Gemfile.lock
57
+ policy: pull-push
37
58
  artifacts:
38
59
  paths:
39
- - vendor/ruby
40
60
  - Gemfile.lock
41
61
 
42
62
  ################
43
63
  ## Test stage ##
44
64
  ################
45
65
  rubocop:
46
- extends: [".default-only", ".default-before_script"]
47
66
  stage: test
48
67
  needs: ["setup-test-env"]
49
68
  dependencies: ["setup-test-env"]
@@ -55,20 +74,15 @@ rubocop:
55
74
  - .cache/rubocop_cache/
56
75
 
57
76
  # We need to copy this job's definition from the Code-Quality.gitlab-ci.yml
58
- # template because `only` is set without `refs`, so it takes precedence over `.default-only`.
77
+ # template because `only` is set without `refs`, so it takes precedence over default workflow rules.
59
78
  # See https://gitlab.com/gitlab-org/gitlab-ce/issues/66767.
60
79
  code_quality:
61
- extends: .default-only
62
- needs: ["setup-test-env"]
63
- dependencies: ["setup-test-env"]
80
+ extends: .use-docker-in-docker
64
81
  stage: test
65
- image: docker:stable
66
82
  allow_failure: true
67
- services:
68
- - docker:stable-dind
69
83
  variables:
70
- DOCKER_DRIVER: overlay2
71
84
  DOCKER_TLS_CERTDIR: ""
85
+ before_script: []
72
86
  script:
73
87
  - |
74
88
  if ! docker info &>/dev/null; then
@@ -85,14 +99,9 @@ code_quality:
85
99
  reports:
86
100
  codequality: gl-code-quality-report.json
87
101
  expire_in: 1 week
88
- except:
89
- variables:
90
- - $CODE_QUALITY_DISABLED
91
102
 
92
103
  specs:
93
- extends: [".default-only", ".default-before_script"]
94
104
  needs: ["setup-test-env"]
95
- dependencies: ["setup-test-env"]
96
105
  stage: test
97
106
  script:
98
107
  - bundle exec rake spec
@@ -101,17 +110,24 @@ specs:
101
110
  ## Triage stage ##
102
111
  ##################
103
112
  dry-run:gitlab-triage:
104
- extends: [".default-only", ".default-before_script"]
105
113
  needs: ["setup-test-env"]
106
- dependencies: ["setup-test-env"]
107
114
  stage: triage
108
115
  script:
109
- - bundle exec rake install:local
116
+ - bundle exec rake build
117
+ - gem install pkg/*.gem
118
+ - which gitlab-triage
119
+ - gitlab-triage --version
110
120
  - gitlab-triage --help
111
121
  - gitlab-triage --init
112
- - gitlab-triage --dry-run --debug --token $API_TOKEN --source-id $CI_PROJECT_PATH
122
+ - gitlab-triage --dry-run --debug --token $GITLAB_API_TOKEN --source-id $CI_PROJECT_PATH
113
123
 
114
124
  # This job requires allows to override the `CI_PROJECT_PATH` variable when triggered.
115
125
  dry-run:custom:
116
126
  extends: dry-run:gitlab-triage
117
- when: manual
127
+ rules:
128
+ - when: manual
129
+ allow_failure: true
130
+
131
+ include:
132
+ - project: 'gitlab-org/quality/pipeline-common'
133
+ file: '/ci/gem-release.yml'
@@ -0,0 +1,35 @@
1
+ <!-- Replace `v4.5.0` with the previous release here, and `e18d76b309e42888759c1effe96767f13e34ae55`
2
+ with the latest commit from https://gitlab.com/gitlab-org/gitlab-triage/commits/master that will be included in the release. -->
3
+ - Diff: https://gitlab.com/gitlab-org/gitlab-triage/compare/v4.5.0...e18d76b309e42888759c1effe96767f13e34ae55
4
+
5
+ - Release notes:
6
+
7
+ <!-- Keep the sections order but remove the empty sections -->
8
+
9
+ ```markdown
10
+ ### New features and features updates
11
+
12
+ - !aaa <Title of the aaa MR>.
13
+
14
+ ### Fixes
15
+
16
+ - !bbb <Title of the bbb MR>.
17
+
18
+ ### Doc changes
19
+
20
+ - !ccc <Title of the ccc MR>.
21
+
22
+ ### Other changes (tooling, technical debt)
23
+
24
+ - !ddd <Title of the ddd MR>.
25
+ ```
26
+
27
+ - Checklist before merging:
28
+ - [ ] Diff link is up-to-date.
29
+ - [ ] Based on the diff, `lib/gitlab/triage/version.rb` is updated, according to [SemVer](https://semver.org).
30
+ - [ ] Release notes are accurate.
31
+
32
+ - Checklist after merging:
33
+ - [ ] [Update the release notes for the newly created tag](docs/release_process.md#how-to).
34
+
35
+ /label ~"Engineering Productivity" ~"ep::triage" ~"tooling::workflow"
@@ -11,3 +11,6 @@ AllCops:
11
11
 
12
12
  Rails/Output:
13
13
  Enabled: false
14
+
15
+ Metrics/LineLength:
16
+ Max: 152
data/Gemfile CHANGED
@@ -4,5 +4,5 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :test do
7
- gem 'gitlab-styles', '~> 3.0'
7
+ gem 'gitlab-styles', '~> 3.3.0'
8
8
  end
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
@@ -58,7 +58,7 @@ resource_rules:
58
58
  interval: 5
59
59
  state: opened
60
60
  labels:
61
- - No Label
61
+ - None
62
62
  limits:
63
63
  most_recent: 50
64
64
  actions:
@@ -66,6 +66,7 @@ resource_rules:
66
66
  - needs attention
67
67
  mention:
68
68
  - markglenfletcher
69
+ move: gitlab-org/backlog
69
70
  comment: |
70
71
  {{author}} This issue is unlabelled after 5 days. It needs attention. Please take care of this before the end of #{2.days.from_now.strftime('%Y-%m-%d')}
71
72
  summarize:
@@ -85,9 +86,27 @@ resource_rules:
85
86
  /label ~"needs attention"
86
87
  merge_requests:
87
88
  rules:
88
- []
89
+ - name: My policy
90
+ conditions:
91
+ state: opened
92
+ labels:
93
+ - None
94
+ limits:
95
+ most_recent: 50
96
+ actions:
97
+ labels:
98
+ - needs attention
99
+ comment_type: thread
100
+ comment: |
101
+ {{author}} This issue is unlabelled. Please add one or more labels.
89
102
  ```
90
103
 
104
+ ### Real world example
105
+
106
+ We're enforcing multiple polices with pipeline schedules at [triage-ops](
107
+ https://gitlab.com/gitlab-org/quality/triage-ops), where we're also
108
+ extensively utilizing the [plugins system](#can-i-customize).
109
+
91
110
  ### Fields
92
111
 
93
112
  A policy consists of the following fields:
@@ -210,6 +229,22 @@ conditions:
210
229
  - feature proposal
211
230
  ```
212
231
 
232
+ ###### Predefined special label names
233
+
234
+ Basing on the [issues API](https://docs.gitlab.com/ee/api/issues.html), there
235
+ are two special predefined label names we can use here:
236
+
237
+ * `None`: This indicates that no labels were present
238
+ * `Any`: This indicates that any labels were presented
239
+
240
+ Example:
241
+
242
+ ```yml
243
+ conditions:
244
+ labels:
245
+ - None
246
+ ```
247
+
213
248
  ###### Labels brace expansion
214
249
 
215
250
  We could expand the labels by using brace expansion, which is a pattern
@@ -506,7 +541,9 @@ Available action types:
506
541
  - [`remove_labels` action](#remove-labels-action)
507
542
  - [`status` action](#status-action)
508
543
  - [`mention` action](#mention-action)
544
+ - [`move` action](#move-action)
509
545
  - [`comment` action](#comment-action)
546
+ - [`comment_type` action option](#comment-type-action-option)
510
547
  - [`summarize` action](#summarize-action)
511
548
 
512
549
  ##### Labels action
@@ -515,6 +552,10 @@ Adds a number of labels to the resource.
515
552
 
516
553
  Accepts an array of strings. Each element is the name of a label to add.
517
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
+
518
559
  Example:
519
560
 
520
561
  ```yml
@@ -530,6 +571,10 @@ Removes a number of labels from the resource.
530
571
 
531
572
  Accepts an array of strings. Each element is the name of a label to remove.
532
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
+
533
578
  Example:
534
579
 
535
580
  ```yml
@@ -572,6 +617,19 @@ actions:
572
617
  - markglenfletcher
573
618
  ```
574
619
 
620
+ ##### Move action
621
+
622
+ Moves an issue (merge request is not supported yet) to the specified project.
623
+
624
+ Accepts a string containing the target project path.
625
+
626
+ Example:
627
+
628
+ ```yml
629
+ actions:
630
+ move: target/project_path
631
+ ```
632
+
575
633
  ##### Comment action
576
634
 
577
635
  Adds a comment to the resource.
@@ -619,6 +677,26 @@ actions:
619
677
  {{author}} Are you still interested in finishing this merge request?
620
678
  ```
621
679
 
680
+ ##### Comment type action option
681
+
682
+ Determines the type of comment to be added to the resource.
683
+
684
+ The following comment types are supported:
685
+
686
+ - `comment` (default): creates a regular comment on the resource
687
+ - `thread`: starts a resolvable thread (discussion) on the resource
688
+
689
+ For merge requests, if `comment_type` is set to `thread`, we can also configure that [all threads should be resolved before merging](https://docs.gitlab.com/ee/user/discussions/#only-allow-merge-requests-to-be-merged-if-all-threads-are-resolved), therefore this comment can prevent it from merging.
690
+
691
+ Example:
692
+
693
+ ```yml
694
+ actions:
695
+ comment_type: thread
696
+ comment: |
697
+ {{author}} Are you still interested in finishing this merge request?
698
+ ```
699
+
622
700
  ###### Harnessing Quick Actions
623
701
 
624
702
  [GitLab's quick actions feature](https://docs.gitlab.com/ce/user/project/quick_actions.html) is available in Core.
@@ -839,7 +917,7 @@ Which could generate an issue like:
839
917
 
840
918
  Here's a list of currently available Ruby expression API:
841
919
 
842
- ##### API
920
+ ##### Methods for `Issue` and `MergeRequest` (the context)
843
921
 
844
922
  | Name | Return type | Description |
845
923
  | ---- | ---- | ---- |
@@ -854,6 +932,12 @@ Here's a list of currently available Ruby expression API:
854
932
  | project_path | String | The path with namespace to the issues or merge requests project |
855
933
  | full_resource_reference | String | A full reference incuding project path to the issue or merge request |
856
934
 
935
+ ##### Methods for `MergeRequest` (merge request context)
936
+
937
+ | Method | Return type | Description |
938
+ | ---- | ---- | ---- |
939
+ | first_contribution? | Boolean | `true` if it's the author's first contribution to the project; `false` otherwise. This API requires an additional API request for the merge request, thus would be slower. |
940
+
857
941
  ##### Methods for `Milestone`
858
942
 
859
943
  | Method | Return type | Description |
@@ -930,6 +1014,7 @@ Usage: gitlab-triage [options]
930
1014
  -r, --require [string] Require a file before performing
931
1015
  -d, --debug Print debug information
932
1016
  -h, --help Print help message
1017
+ --all-projects Process all projects visible to `--token`
933
1018
  --init Initialize the project with a policy file
934
1019
  --init-ci Initialize the project with a .gitlab-ci.yml file
935
1020
  ```
@@ -939,15 +1024,23 @@ Usage: gitlab-triage [options]
939
1024
  Triaging against a specific project:
940
1025
 
941
1026
  ```
942
- gitlab-triage --dry-run --token $API_TOKEN --source-id gitlab-org/triage
1027
+ gitlab-triage --dry-run --token $GITLAB_API_TOKEN --source-id gitlab-org/triage
943
1028
  ```
944
1029
 
945
1030
  Triaging against a whole group:
946
1031
 
947
1032
  ```
948
- gitlab-triage --dry-run --token $API_TOKEN --source-id gitlab-org --source groups
1033
+ gitlab-triage --dry-run --token $GITLAB_API_TOKEN --source-id gitlab-org --source groups
949
1034
  ```
950
1035
 
1036
+ Triaging against an entire instance:
1037
+
1038
+ ```
1039
+ gitlab-triage --dry-run --token $GITLAB_API_TOKEN --all-projects
1040
+ ```
1041
+
1042
+ > **Note:** The `--all-projects` option will process all resources for all projects visible to the specified `$GITLAB_API_TOKEN`
1043
+
951
1044
  #### Running on GitLab CI pipeline
952
1045
 
953
1046
  You can enforce policies using a scheduled pipeline:
@@ -957,7 +1050,7 @@ run:triage:triage:
957
1050
  stage: triage
958
1051
  script:
959
1052
  - gem install gitlab-triage
960
- - gitlab-triage --token $API_TOKEN --source-id $CI_PROJECT_PATH
1053
+ - gitlab-triage --token $GITLAB_API_TOKEN --source-id $CI_PROJECT_PATH
961
1054
  only:
962
1055
  - schedules
963
1056
  ```
@@ -971,7 +1064,7 @@ Yes, you can override the host url using the following options:
971
1064
  ##### CLI
972
1065
 
973
1066
  ```
974
- gitlab-triage --dry-run --token $API_TOKEN --source-id gitlab-org/triage --host-url https://gitlab.host.com
1067
+ gitlab-triage --dry-run --token $GITLAB_API_TOKEN --source-id gitlab-org/triage --host-url https://gitlab.host.com
975
1068
  ```
976
1069
 
977
1070
  ##### Policy file
@@ -1008,7 +1101,7 @@ Gitlab::Triage::Resource::Context.include MyPlugin
1008
1101
  And then run it with:
1009
1102
 
1010
1103
  ```shell
1011
- gitlab-triage -r ./my_plugin.rb --token $API_TOKEN --source-id gitlab-org/triage
1104
+ gitlab-triage -r ./my_plugin.rb --token $GITLAB_API_TOKEN --source-id gitlab-org/triage
1012
1105
  ```
1013
1106
 
1014
1107
  This allows you to use `has_severity_label?` in the Ruby condition:
@@ -1030,3 +1123,7 @@ resource_rules:
1030
1123
  ### Contributing
1031
1124
 
1032
1125
  Please refer to the [Contributing Guide](CONTRIBUTING.md).
1126
+
1127
+ ## Release Process
1128
+
1129
+ Please refer to the [Release Process](docs/release_process.md).