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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.gitlab-ci.yml +75 -40
  4. data/.gitlab/merge_request_templates/Release.md +35 -0
  5. data/.rubocop.yml +3 -0
  6. data/Gemfile +1 -1
  7. data/README.md +95 -4
  8. data/gitlab-triage.gemspec +1 -1
  9. data/lib/gitlab/triage/action/comment.rb +14 -1
  10. data/lib/gitlab/triage/api_query_builders/date_query_param_builder.rb +78 -0
  11. data/lib/gitlab/triage/command_builders/move_command_builder.rb +19 -0
  12. data/lib/gitlab/triage/command_builders/text_content_builder.rb +17 -1
  13. data/lib/gitlab/triage/engine.rb +41 -16
  14. data/lib/gitlab/triage/errors.rb +1 -1
  15. data/lib/gitlab/triage/filters/merge_request_date_conditions_filter.rb +51 -5
  16. data/lib/gitlab/triage/network.rb +2 -1
  17. data/lib/gitlab/triage/network_adapters/httparty_adapter.rb +13 -1
  18. data/lib/gitlab/triage/option_parser.rb +10 -0
  19. data/lib/gitlab/triage/options.rb +2 -0
  20. data/lib/gitlab/triage/policies/rule_policy.rb +1 -1
  21. data/lib/gitlab/triage/policies/summary_policy.rb +1 -1
  22. data/lib/gitlab/triage/policies_resources/rule_resources.rb +5 -6
  23. data/lib/gitlab/triage/policies_resources/summary_resources.rb +5 -6
  24. data/lib/gitlab/triage/resource/base.rb +5 -0
  25. data/lib/gitlab/triage/resource/issue.rb +4 -0
  26. data/lib/gitlab/triage/resource/merge_request.rb +13 -0
  27. data/lib/gitlab/triage/resource/shared/issuable.rb +26 -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/.triage-policies.example.yml +2 -2
  33. metadata +6 -4
  34. 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: 403aa273677c675e590d5c2a46c0feb1d5087e1369532cb7c3b063e79191bc8c
4
- data.tar.gz: 2f25cbdcad4c7b8ddd861d026711e396d8c1f9cc01f489a65166954694bc344c
3
+ metadata.gz: 9ac5f595e5dffde9a3135eec982d931510615517b7512168291944252cd6f2ed
4
+ data.tar.gz: 3336902a5864b878ad60091442fd2047eeef620981ae4d8e40c73c0ca2394cb1
5
5
  SHA512:
6
- metadata.gz: 27804c7a88c2079a8559593381e4aa6a0a94bbc6b0d5f23e4624227953fb75b57d177f79b86dbb09ee0836c2be0f9637ac7f762da80f955ae88294943cd1d6fa
7
- data.tar.gz: 5ba384a4eb246540da8d23250240af00f4bdc30aa16e1dc17a1fbd4c294f3463e0a9cfefdce653d942ae738c7abc90ad55c28aff95f4c820247d027a18f2459b
6
+ metadata.gz: a5669015087540e47ea682b07a3282a7fbb49e3206cb635e71086fa180f82084908dc964c659d7faeca8e0a8cabe83a0b296e7835ea161f43c26887aa5066ec6
7
+ data.tar.gz: b6f348f4d5adf7e7685f97d10fdaf0545e0952a91ee74b0997cdcba10b7a0c0a9823ed14dde92188f749731fd7b870cc8700d3fbc7733128b219a51287504517
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,67 @@
1
- image: ruby:2.6
2
-
3
1
  stages:
4
2
  - prepare
5
3
  - test
6
4
  - triage
5
+ - release
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_DRIVER: overlay2
42
+ DOCKER_HOST: tcp://docker:2375
43
+ DOCKER_TLS_CERTDIR: ""
44
+ tags:
45
+ # See https://gitlab.com/gitlab-com/www-gitlab-com/-/issues/7019 for tag descriptions
46
+ - gitlab-org-docker
19
47
 
20
48
  ###################
21
49
  ## Prepare stage ##
22
50
  ###################
23
51
  setup-test-env:
24
- extends: .default-only
25
52
  stage: prepare
26
53
  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
54
+ - echo "Setup done!"
32
55
  cache:
33
- key: "$CI_JOB_NAME-ruby-2.6"
34
- paths:
35
- - vendor/ruby
36
- - Gemfile.lock
56
+ policy: pull-push
37
57
  artifacts:
38
58
  paths:
39
- - vendor/ruby
40
59
  - Gemfile.lock
41
60
 
42
61
  ################
43
62
  ## Test stage ##
44
63
  ################
45
64
  rubocop:
46
- extends: [".default-only", ".default-before_script"]
47
65
  stage: test
48
66
  needs: ["setup-test-env"]
49
67
  dependencies: ["setup-test-env"]
@@ -55,20 +73,15 @@ rubocop:
55
73
  - .cache/rubocop_cache/
56
74
 
57
75
  # 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`.
76
+ # template because `only` is set without `refs`, so it takes precedence over default workflow rules.
59
77
  # See https://gitlab.com/gitlab-org/gitlab-ce/issues/66767.
60
78
  code_quality:
61
- extends: .default-only
62
- needs: ["setup-test-env"]
63
- dependencies: ["setup-test-env"]
79
+ extends: .use-docker-in-docker
64
80
  stage: test
65
- image: docker:stable
66
81
  allow_failure: true
67
- services:
68
- - docker:stable-dind
69
82
  variables:
70
- DOCKER_DRIVER: overlay2
71
83
  DOCKER_TLS_CERTDIR: ""
84
+ before_script: []
72
85
  script:
73
86
  - |
74
87
  if ! docker info &>/dev/null; then
@@ -85,14 +98,9 @@ code_quality:
85
98
  reports:
86
99
  codequality: gl-code-quality-report.json
87
100
  expire_in: 1 week
88
- except:
89
- variables:
90
- - $CODE_QUALITY_DISABLED
91
101
 
92
102
  specs:
93
- extends: [".default-only", ".default-before_script"]
94
103
  needs: ["setup-test-env"]
95
- dependencies: ["setup-test-env"]
96
104
  stage: test
97
105
  script:
98
106
  - bundle exec rake spec
@@ -101,12 +109,13 @@ specs:
101
109
  ## Triage stage ##
102
110
  ##################
103
111
  dry-run:gitlab-triage:
104
- extends: [".default-only", ".default-before_script"]
105
112
  needs: ["setup-test-env"]
106
- dependencies: ["setup-test-env"]
107
113
  stage: triage
108
114
  script:
109
- - bundle exec rake install:local
115
+ - bundle exec rake build
116
+ - gem install pkg/*.gem
117
+ - which gitlab-triage
118
+ - gitlab-triage --version
110
119
  - gitlab-triage --help
111
120
  - gitlab-triage --init
112
121
  - gitlab-triage --dry-run --debug --token $API_TOKEN --source-id $CI_PROJECT_PATH
@@ -114,4 +123,30 @@ dry-run:gitlab-triage:
114
123
  # This job requires allows to override the `CI_PROJECT_PATH` variable when triggered.
115
124
  dry-run:custom:
116
125
  extends: dry-run:gitlab-triage
117
- when: manual
126
+ rules:
127
+ - when: manual
128
+ allow_failure: true
129
+
130
+ ###################
131
+ ## Release stage ##
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
@@ -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 scenarios and scenario 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 (CI, backstage)
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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # GitLab Triage Project
4
4
 
5
- This project contains the library and pipeline definition to enable automated triaging of issues in the [GitLab Project](https://gitlab.com/gitlab-org/gitlab).
5
+ This project allows to automate triaging of issues and merge requests for GitLab projects or groups.
6
6
 
7
7
  ## gitlab-triage gem
8
8
 
@@ -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
@@ -572,6 +609,19 @@ actions:
572
609
  - markglenfletcher
573
610
  ```
574
611
 
612
+ ##### Move action
613
+
614
+ Moves an issue (merge request is not supported yet) to the specified project.
615
+
616
+ Accepts a string containing the target project path.
617
+
618
+ Example:
619
+
620
+ ```yml
621
+ actions:
622
+ move: target/project_path
623
+ ```
624
+
575
625
  ##### Comment action
576
626
 
577
627
  Adds a comment to the resource.
@@ -619,6 +669,26 @@ actions:
619
669
  {{author}} Are you still interested in finishing this merge request?
620
670
  ```
621
671
 
672
+ ##### Comment type action option
673
+
674
+ Determines the type of comment to be added to the resource.
675
+
676
+ The following comment types are supported:
677
+
678
+ - `comment` (default): creates a regular comment on the resource
679
+ - `thread`: starts a resolvable thread (discussion) on the resource
680
+
681
+ 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.
682
+
683
+ Example:
684
+
685
+ ```yml
686
+ actions:
687
+ comment_type: thread
688
+ comment: |
689
+ {{author}} Are you still interested in finishing this merge request?
690
+ ```
691
+
622
692
  ###### Harnessing Quick Actions
623
693
 
624
694
  [GitLab's quick actions feature](https://docs.gitlab.com/ce/user/project/quick_actions.html) is available in Core.
@@ -839,7 +909,7 @@ Which could generate an issue like:
839
909
 
840
910
  Here's a list of currently available Ruby expression API:
841
911
 
842
- ##### API
912
+ ##### Methods for `Issue` and `MergeRequest` (the context)
843
913
 
844
914
  | Name | Return type | Description |
845
915
  | ---- | ---- | ---- |
@@ -851,6 +921,14 @@ Here's a list of currently available Ruby expression API:
851
921
  | labels_chronologically | [Label] | Same as `labels_with_details` but sorted chronologically |
852
922
  | label_events | [LabelEvent] | A list of label events on the resource |
853
923
  | instance_version | InstanceVersion | The version for the GitLab instance we're triaging with |
924
+ | project_path | String | The path with namespace to the issues or merge requests project |
925
+ | full_resource_reference | String | A full reference incuding project path to the issue or merge request |
926
+
927
+ ##### Methods for `MergeRequest` (merge request context)
928
+
929
+ | Method | Return type | Description |
930
+ | ---- | ---- | ---- |
931
+ | 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. |
854
932
 
855
933
  ##### Methods for `Milestone`
856
934
 
@@ -928,6 +1006,7 @@ Usage: gitlab-triage [options]
928
1006
  -r, --require [string] Require a file before performing
929
1007
  -d, --debug Print debug information
930
1008
  -h, --help Print help message
1009
+ --all-projects Process all projects visible to `--token`
931
1010
  --init Initialize the project with a policy file
932
1011
  --init-ci Initialize the project with a .gitlab-ci.yml file
933
1012
  ```
@@ -946,6 +1025,14 @@ Triaging against a whole group:
946
1025
  gitlab-triage --dry-run --token $API_TOKEN --source-id gitlab-org --source groups
947
1026
  ```
948
1027
 
1028
+ Triaging against an entire instance:
1029
+
1030
+ ```
1031
+ gitlab-triage --dry-run --token $API_TOKEN --all-projects
1032
+ ```
1033
+
1034
+ > **Note:** The `--all-projects` option will process all resources for all projects visible to the specified `$API_TOKEN`
1035
+
949
1036
  #### Running on GitLab CI pipeline
950
1037
 
951
1038
  You can enforce policies using a scheduled pipeline:
@@ -1028,3 +1115,7 @@ resource_rules:
1028
1115
  ### Contributing
1029
1116
 
1030
1117
  Please refer to the [Contributing Guide](CONTRIBUTING.md).
1118
+
1119
+ ## Release Process
1120
+
1121
+ Please refer to the [Release Process](docs/release_process.md).
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.license = 'MIT'
14
14
 
15
15
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
- f.match(%r{^(test|spec|features)/})
16
+ f.match(%r{^(docs|test|spec|features)/})
17
17
  end
18
18
  spec.bindir = 'bin'
19
19
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -7,6 +7,7 @@ require_relative '../command_builders/label_command_builder'
7
7
  require_relative '../command_builders/remove_label_command_builder'
8
8
  require_relative '../command_builders/cc_command_builder'
9
9
  require_relative '../command_builders/status_command_builder'
10
+ require_relative '../command_builders/move_command_builder'
10
11
 
11
12
  module Gitlab
12
13
  module Triage
@@ -43,6 +44,7 @@ module Gitlab
43
44
  CommandBuilders::LabelCommandBuilder.new(policy.actions[:labels]).build_command,
44
45
  CommandBuilders::RemoveLabelCommandBuilder.new(policy.actions[:remove_labels]).build_command,
45
46
  CommandBuilders::CcCommandBuilder.new(policy.actions[:mention]).build_command,
47
+ CommandBuilders::MoveCommandBuilder.new(policy.actions[:move]).build_command,
46
48
  CommandBuilders::StatusCommandBuilder.new(policy.actions[:status]).build_command
47
49
  ]
48
50
  ).build_command
@@ -61,13 +63,24 @@ module Gitlab
61
63
  source_id: resource[:project_id],
62
64
  resource_type: policy.type,
63
65
  resource_id: resource['iid'],
64
- sub_resource_type: 'notes'
66
+ sub_resource_type: sub_resource_type
65
67
  ).build
66
68
 
67
69
  puts Gitlab::Triage::UI.debug "post_url: #{post_url}" if network.options.debug
68
70
 
69
71
  post_url
70
72
  end
73
+
74
+ def sub_resource_type
75
+ case type = policy.actions[:comment_type]
76
+ when 'comment', nil # nil is default
77
+ 'notes'
78
+ when 'thread'
79
+ 'discussions'
80
+ else
81
+ raise ArgumentError, "Unknown comment type: #{type}"
82
+ end
83
+ end
71
84
  end
72
85
  end
73
86
  end