gitlab-triage 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b9611f0a3f4f58779cf16cfa76d2dc93889646dc7566b8dc75116838f362940
4
- data.tar.gz: 6d8c4675ead2c209ab18df6f8bb6068cf9c2a80f262d7d6759921f90679f1e47
3
+ metadata.gz: 9d589eb58296c263748c53e0888e6eb3368bb02328c74245f5d25055a2ca7a37
4
+ data.tar.gz: 3e6d2b8e2536016b933b7d31a73781474fa772c7346dbb6ce76f10554196a1dc
5
5
  SHA512:
6
- metadata.gz: 521a204ed0b650f6f31d8cb78583525ea58f2fb9378db976bf1a1e42af3a58b475480c8128cc59f43fdf065214e23557356502c4ee2340d444806fe56a3cfe33
7
- data.tar.gz: a9d972bdd97dc71c4759849ec6b17a6a0f1f0bfc634c3aaf9c895b1f5e7e53a119642ebad19b39ffb156a583efaf06c0ce6a5b5cfb6f27cb384fc963252e215b
6
+ metadata.gz: 0fb236cfb7041f4e91e3b7a92cd4a4da95fce95a516c078e1737f6b2178f93c7e8e54463b3090ad0ae87c255c67b379547d767ec50fe8e0b04203d2d78762ea6
7
+ data.tar.gz: 8f23c54a9b1412b5588ef77a0a6d2e64ef2e6a0b489aeaa24746c870f816ec6b6bf7a3d2be506bf85956f4e0fabb2807c73861c008cc5cade1fddcfb47bee0be
data/.gitlab-ci.yml CHANGED
@@ -34,8 +34,6 @@ setup-test-env:
34
34
  paths:
35
35
  - vendor/cache/
36
36
  - Gemfile.lock
37
- except:
38
- - schedules
39
37
 
40
38
  ################
41
39
  ## Test stage ##
@@ -45,8 +43,6 @@ styles:
45
43
  stage: test
46
44
  script:
47
45
  - bundle exec rubocop
48
- except:
49
- - schedules
50
46
 
51
47
  specs:
52
48
  <<: *pull-cache
@@ -75,59 +71,32 @@ codequality:
75
71
  artifacts:
76
72
  paths:
77
73
  - codeclimate.json
78
- except:
79
- - schedules
80
74
 
81
75
  ##################
82
76
  ## Triage stage ##
83
77
  ##################
84
- dry-run:bin:gitlab-org/triage:
78
+ dry-run:bin:gitlab-triage:
85
79
  <<: *pull-cache
86
80
  stage: triage
87
81
  script:
88
82
  - bundle exec rake install:local
89
83
  - gitlab-triage --help
90
- - gitlab-triage --dry-run --token $API_TOKEN --project-id $CI_PROJECT_PATH
91
- except:
92
- - schedules
84
+ - gitlab-triage --dry-run --debug --token $API_TOKEN --project-id $CI_PROJECT_PATH
93
85
 
94
- dry-run:bin:gitlab-org/gitlab-ce:
86
+ dry-run:bin:gitlab-ce:
95
87
  <<: *pull-cache
96
88
  stage: triage
97
89
  script:
98
90
  - bundle exec rake install:local
99
91
  - gitlab-triage --help
100
- - gitlab-triage --dry-run --token $API_TOKEN --project-id gitlab-org/gitlab-ce
92
+ - gitlab-triage --dry-run --debug --token $API_TOKEN --project-id gitlab-org/gitlab-ce
101
93
  when: manual
102
- except:
103
- - schedules
104
94
 
105
- dry-run:gem:gitlab-org/triage:
95
+ dry-run:gem:gitlab-triage:
106
96
  <<: *pull-cache
107
97
  stage: triage
108
98
  script:
109
99
  - gem install gitlab-triage
110
100
  - gitlab-triage --help
111
- - gitlab-triage --dry-run --token $API_TOKEN --project-id $CI_PROJECT_PATH
101
+ - gitlab-triage --dry-run --debug --token $API_TOKEN --project-id $CI_PROJECT_PATH
112
102
  when: manual
113
- except:
114
- - schedules
115
-
116
- ###############
117
- ## Schedules ##
118
- ###############
119
- run:triage:gitlab-ce:
120
- stage: triage
121
- script:
122
- - gem install gitlab-triage
123
- - gitlab-triage --token $API_TOKEN --project-id gitlab-org/gitlab-ce
124
- only:
125
- - schedules
126
-
127
- run:triage:triage:
128
- stage: triage
129
- script:
130
- - gem install gitlab-triage
131
- - gitlab-triage --token $API_TOKEN --project-id $CI_PROJECT_PATH
132
- only:
133
- - schedules
data/.triage-policies.yml CHANGED
@@ -99,16 +99,6 @@ resource_rules:
99
99
  labels:
100
100
  - auto updated
101
101
  - potential proposal
102
- mention:
103
- - markglenfletcher
104
- comment: |
105
- In order to get this request some attention, this issue has been marked as a potentially interesting proposal as it meets the following criteria:
106
-
107
- * Labelled as a feature proposal
108
- * More than 10 upvotes
109
- * Unscheduled (not associated with a milestone)
110
-
111
- Thanks for your proposal!
112
102
  - name: Mark unpopular, old feature proposals for closure
113
103
  conditions:
114
104
  date:
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,31 @@
1
+ ## Developer Certificate of Origin + License
2
+
3
+ By contributing to GitLab B.V., You accept and agree to the following terms and
4
+ conditions for Your present and future Contributions submitted to GitLab B.V.
5
+ Except for the license granted herein to GitLab B.V. and recipients of software
6
+ distributed by GitLab B.V., You reserve all right, title, and interest in and to
7
+ Your Contributions. All Contributions are subject to the following DCO + License
8
+ terms.
9
+
10
+ [DCO + License](https://gitlab.com/gitlab-org/dco/blob/master/README.md)
11
+
12
+ ## Style guide
13
+
14
+ This project employs [rubocop](https://github.com/bbatsov/rubocop) to enforce code styles. Check your new branch by:
15
+
16
+ ```
17
+ git checkout my_branch
18
+ bundle install --path vendor/bundle
19
+ bundle exec rubocop
20
+ ```
21
+
22
+ ## Testing
23
+
24
+ - Please consider tests for any code change that is made
25
+ - Please ensure that the existing test suite passes
26
+
27
+ ```
28
+ git checkout my_branch
29
+ bundle install --path vendor/bundle
30
+ bundle exec rake spec
31
+ ```
data/LICENSE.md ADDED
@@ -0,0 +1,25 @@
1
+ Copyright (c) 2011-2017 GitLab B.V.
2
+
3
+ With regard to the GitLab Software:
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
23
+ For all third party components incorporated into the GitLab Software, those
24
+ components are licensed under the original license provided by the owner of the
25
+ applicable component.
data/README.md CHANGED
@@ -85,6 +85,7 @@ Available condition types:
85
85
  - [`state` condition](#state-condition)
86
86
  - [`upvotes` condition](#upvotes-condition)
87
87
  - [`labels` condition](#labels-condition)
88
+ - [`forbidden_labels` condition](#forbidden-labels-condition)
88
89
 
89
90
  ##### Date condition
90
91
 
@@ -173,17 +174,31 @@ conditions:
173
174
  - feature proposal
174
175
  ```
175
176
 
177
+ ##### Forbidden labels condition
178
+
179
+ Accepts an array of strings. Each element in the array represents the name of a label to filter on.
180
+
181
+ > Note: **All** specified labels must be absent on the resource for the condition to be satisfied
182
+
183
+ Example:
184
+
185
+ ```yml
186
+ conditions:
187
+ forbidden_labels:
188
+ - awaiting feedback
189
+ ```
190
+
176
191
  #### Actions field
177
192
 
178
193
  Used to declare an action to be carried out on a resource if **all** conditions are satisfied.
179
194
 
180
195
  Available action types:
181
- - [`label` action](#label-action)
196
+ - [`labels` action](#labels-action)
182
197
  - [`status` action](#status-action)
183
198
  - [`mention` action](#mention-action)
184
199
  - [`comment` action](#comment-action)
185
200
 
186
- ##### Label action
201
+ ##### Labels action
187
202
 
188
203
  Adds a number of labels to the resource.
189
204
 
@@ -193,7 +208,7 @@ Example:
193
208
 
194
209
  ```yml
195
210
  actions:
196
- label:
211
+ labels:
197
212
  - feature proposal
198
213
  - awaiting feedback
199
214
  ```
@@ -283,3 +298,7 @@ run:triage:triage:
283
298
  ```
284
299
 
285
300
  > 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
301
+
302
+ ### Contributing
303
+
304
+ Please refer to the [Contributing Guide](CONTRIBUTING.md)
@@ -2,6 +2,7 @@ require 'active_support/all'
2
2
 
3
3
  require_relative 'limiters/date_conditions_limiter'
4
4
  require_relative 'limiters/votes_conditions_limiter'
5
+ require_relative 'limiters/forbidden_labels_conditions_limiter'
5
6
  require_relative 'command_builders/comment_command_builder'
6
7
  require_relative 'command_builders/label_command_builder'
7
8
  require_relative 'command_builders/cc_command_builder'
@@ -18,13 +19,13 @@ module Gitlab
18
19
  class Engine
19
20
  attr_reader :host_url, :api_version, :per_page, :policies, :options
20
21
 
21
- def initialize(policies:, options:, network_adapter: Gitlab::Triage::NetworkAdapters::HttpartyAdapter.new)
22
+ def initialize(policies:, options:, network_adapter_class: Gitlab::Triage::NetworkAdapters::HttpartyAdapter)
22
23
  @host_url = policies.delete(:host_url) { 'https://gitlab.com' }
23
24
  @api_version = policies.delete(:api_version) { 'v4' }
24
25
  @per_page = policies.delete(:per_page) { 100 }
25
26
  @policies = policies
26
27
  @options = options
27
- @network_adapter = network_adapter
28
+ @network_adapter_class = network_adapter_class
28
29
 
29
30
  options.dry_run = true if ENV['TEST'] == 'true'
30
31
 
@@ -65,7 +66,11 @@ module Gitlab
65
66
  end
66
67
 
67
68
  def network
68
- @network ||= Network.new(@network_adapter)
69
+ @network ||= Network.new(network_adapter, options)
70
+ end
71
+
72
+ def network_adapter
73
+ @network_adapter ||= @network_adapter_class.new(options)
69
74
  end
70
75
 
71
76
  def rule_conditions(rule)
@@ -92,6 +97,7 @@ module Gitlab
92
97
  results = []
93
98
  results << Limiters::DateConditionsLimiter.new(resource, conditions[:date]).calculate if conditions[:date]
94
99
  results << Limiters::VotesConditionsLimiter.new(resource, conditions[:upvotes]).calculate if conditions[:upvotes]
100
+ results << Limiters::ForbiddenLabelsConditionsLimiter.new(resource, conditions[:forbidden_labels]).calculate if conditions[:forbidden_labels]
95
101
  !results.uniq.include?(false)
96
102
  end
97
103
  end
@@ -0,0 +1,36 @@
1
+ require_relative 'base_conditions_limiter'
2
+
3
+ module Gitlab
4
+ module Triage
5
+ module Limiters
6
+ class ForbiddenLabelsConditionsLimiter < BaseConditionsLimiter
7
+ def self.limiter_parameters
8
+ []
9
+ end
10
+
11
+ def validate_condition(condition)
12
+ raise ArgumentError, 'condition must be an array containing forbidden label values' unless condition.is_a?(Array)
13
+ end
14
+
15
+ def initialize_variables(forbidden_labels)
16
+ @attribute = :labels
17
+ @forbidden_labels = forbidden_labels
18
+ end
19
+
20
+ def resource_value
21
+ @resource[@attribute]
22
+ end
23
+
24
+ def calculate
25
+ label_intersection.empty?
26
+ end
27
+
28
+ private
29
+
30
+ def label_intersection
31
+ resource_value & @forbidden_labels
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -2,14 +2,18 @@ require 'active_support/all'
2
2
  require 'net/protocol'
3
3
 
4
4
  require_relative 'retryable'
5
+ require_relative 'ui'
5
6
 
6
7
  module Gitlab
7
8
  module Triage
8
9
  class Network
9
10
  include Retryable
10
11
 
11
- def initialize(adapter)
12
+ attr_reader :options
13
+
14
+ def initialize(adapter, options = {})
12
15
  @adapter = adapter
16
+ @options = options
13
17
  end
14
18
 
15
19
  def query_api(token, url)
@@ -0,0 +1,15 @@
1
+ require 'httparty'
2
+
3
+ module Gitlab
4
+ module Triage
5
+ module NetworkAdapters
6
+ class BaseAdapter
7
+ attr_reader :options
8
+
9
+ def initialize(options = {})
10
+ @options = options
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,9 +1,12 @@
1
1
  require 'httparty'
2
2
 
3
+ require_relative 'base_adapter'
4
+ require_relative '../ui'
5
+
3
6
  module Gitlab
4
7
  module Triage
5
8
  module NetworkAdapters
6
- class HttpartyAdapter
9
+ class HttpartyAdapter < BaseAdapter
7
10
  def get(token, url)
8
11
  response = HTTParty.get(
9
12
  url,
@@ -13,6 +16,8 @@ module Gitlab
13
16
  }
14
17
  )
15
18
 
19
+ puts Gitlab::Triage::UI.debug "response: #{response.inspect}" if options.debug
20
+
16
21
  {
17
22
  more_pages: (response.headers["x-next-page"] != ""),
18
23
  next_page_url: url + "&page=#{response.headers['x-next-page']}",
@@ -1,9 +1,11 @@
1
1
  require 'httparty'
2
2
 
3
+ require_relative 'base_adapter'
4
+
3
5
  module Gitlab
4
6
  module Triage
5
7
  module NetworkAdapters
6
- class TestAdapter
8
+ class TestAdapter < BaseAdapter
7
9
  def get(_token, url)
8
10
  results =
9
11
  case url
@@ -1,5 +1,5 @@
1
1
  module Gitlab
2
2
  module Triage
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
5
5
  end
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitLab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-13 00:00:00.000000000 Z
11
+ date: 2017-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -108,8 +108,10 @@ files:
108
108
  - ".gitlab/issue_templates/Policy.md"
109
109
  - ".rubocop.yml"
110
110
  - ".triage-policies.yml"
111
+ - CONTRIBUTING.md
111
112
  - Gemfile
112
113
  - Guardfile
114
+ - LICENSE.md
113
115
  - README.md
114
116
  - Rakefile
115
117
  - bin/gitlab-triage
@@ -126,9 +128,11 @@ files:
126
128
  - lib/gitlab/triage/filter_builders/single_filter_builder.rb
127
129
  - lib/gitlab/triage/limiters/base_conditions_limiter.rb
128
130
  - lib/gitlab/triage/limiters/date_conditions_limiter.rb
131
+ - lib/gitlab/triage/limiters/forbidden_labels_conditions_limiter.rb
129
132
  - lib/gitlab/triage/limiters/name_conditions_limiter.rb
130
133
  - lib/gitlab/triage/limiters/votes_conditions_limiter.rb
131
134
  - lib/gitlab/triage/network.rb
135
+ - lib/gitlab/triage/network_adapters/base_adapter.rb
132
136
  - lib/gitlab/triage/network_adapters/httparty_adapter.rb
133
137
  - lib/gitlab/triage/network_adapters/test_adapter.rb
134
138
  - lib/gitlab/triage/retryable.rb
@@ -157,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
161
  version: '0'
158
162
  requirements: []
159
163
  rubyforge_project:
160
- rubygems_version: 2.7.0
164
+ rubygems_version: 2.7.2
161
165
  signing_key:
162
166
  specification_version: 4
163
167
  summary: GitLab triage automation project.