gitlab-triage 1.2.0 → 1.3.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: cd48e4232bda87bda7044a5453a42c0a39b29ebe69cd5953048df8dd577c872f
4
- data.tar.gz: d14d0e432023d50f6a11fcf3ff8ec223c3235ac5c53191cf2dd5babfbaeaa10b
3
+ metadata.gz: 3ce7441fc645df64325c4061299790c590bfbdcdb979dd53369f55231479f346
4
+ data.tar.gz: 3ca3d8cb0d811e5d3e32e2870c0aaf0d671ba5b51fd819341eae831894b131e4
5
5
  SHA512:
6
- metadata.gz: 9aa0e6f1062e6c39785b020c23c0c382a2387446fe77e29dd154cbe6530ee4cd6f873da842ab1abae04e2516cd4a7a2c070019ef8ebdce63b16eeb9becb5b5cb
7
- data.tar.gz: 67fbbe46988133f88de13d8e066eb61da9cfbf025d1c4cd622a97e4c41420838a4d27ce1300fc88cacbb70a2447c46b3af84d342405206cd578c40b59d250dd0
6
+ metadata.gz: 92e7edefb97e7849ff2228ab4d842a04583b11a4d24a1f64f553e58b8a850bfc17f1f5fd00e18b436bb2ad6e0b0558cff6e1ff5f98c7fea6cee398b6ced715bc
7
+ data.tar.gz: 13bc2c8ac796534550dcef8164cd3ace9e5e99757f2f007e5c87c63b67943545ca4800a214798bd4387374b7fa3c3e49cd85682bc5db80665ce52ca1e22d61a8
data/bin/gitlab-triage CHANGED
@@ -5,9 +5,13 @@ require_relative '../lib/gitlab/triage/option_parser'
5
5
  require_relative '../lib/gitlab/triage/engine'
6
6
 
7
7
  options = Gitlab::Triage::OptionParser.parse(ARGV)
8
- policies_file = options.policies_file || '.triage-policies.yml'
9
- policies = HashWithIndifferentAccess.new(YAML.load_file(policies_file))
10
8
 
11
- Gitlab::Triage::Engine
12
- .new(policies: policies, options: options)
13
- .perform
9
+ policies_files = options.policies_files || ['.triage-policies.yml']
10
+
11
+ policies_files.each do |policies_file|
12
+ policies = HashWithIndifferentAccess.new(YAML.load_file(policies_file))
13
+
14
+ Gitlab::Triage::Engine
15
+ .new(policies: policies, options: options)
16
+ .perform
17
+ end
@@ -21,7 +21,7 @@ module Gitlab
21
21
  end
22
22
 
23
23
  opts.on('-f', '--policies-file [string]', String, 'A valid policies YML file') do |value|
24
- options.policies_file = value
24
+ options.policies_files << value
25
25
  end
26
26
 
27
27
  opts.on('-s', '--source [type]', [:projects, :groups], 'The source type between [ projects or groups ], default value: projects') do |value|
@@ -2,7 +2,7 @@ module Gitlab
2
2
  module Triage
3
3
  Options = Struct.new(
4
4
  :dry_run,
5
- :policies_file,
5
+ :policies_files,
6
6
  :source,
7
7
  :source_id,
8
8
  :token,
@@ -19,6 +19,7 @@ module Gitlab
19
19
  self.api_version ||= 'v4'
20
20
  self.source ||= 'projects'
21
21
  self.require_files ||= []
22
+ self.policies_files ||= Set.new
22
23
  end
23
24
  end
24
25
  end
@@ -41,6 +41,14 @@ module Gitlab
41
41
 
42
42
  private
43
43
 
44
+ def source_resource
45
+ @source_resource ||= network.query_api_cached(source_url).first
46
+ end
47
+
48
+ def source_url
49
+ build_url(options: { resource_type: nil })
50
+ end
51
+
44
52
  def url(params = {})
45
53
  build_url(params: params)
46
54
  end
@@ -9,6 +9,9 @@ module Gitlab
9
9
  module Resource
10
10
  module Shared
11
11
  module Issuable
12
+ SourceTooDeep = Class.new(RuntimeError)
13
+ MAX_PARENT_LOOKUP = 10
14
+
12
15
  def milestone
13
16
  @milestone ||=
14
17
  resource[:milestone] &&
@@ -42,12 +45,40 @@ module Gitlab
42
45
  @labels_chronologically ||= labels_with_details.sort_by(&:added_at)
43
46
  end
44
47
 
48
+ def root_id(
49
+ namespace: source_resource[:namespace],
50
+ max_levels: MAX_PARENT_LOOKUP)
51
+ raise SourceTooDeep if max_levels <= 0
52
+
53
+ parent_id = namespace[:parent_id]
54
+
55
+ if parent_id
56
+ root_id(
57
+ namespace: request_group(parent_id)[:namespace],
58
+ max_levels: max_levels - 1)
59
+ else
60
+ namespace[:id]
61
+ end
62
+ end
63
+
45
64
  private
46
65
 
47
66
  def query_label_events
48
67
  network.query_api_cached(
49
68
  resource_url(sub_resource_type: 'resource_label_events'))
50
69
  end
70
+
71
+ def request_group(group_id)
72
+ network.query_api_cached(group_url(group_id)).first
73
+ end
74
+
75
+ def group_url(group_id)
76
+ Gitlab::Triage::UrlBuilders::UrlBuilder.new(
77
+ network_options: network.options,
78
+ source: 'groups',
79
+ source_id: group_id
80
+ ).build
81
+ end
51
82
  end
52
83
  end
53
84
  end
@@ -8,7 +8,7 @@ module Gitlab
8
8
  @api_version = @network_options.api_version
9
9
  @source = options.fetch(:source, 'projects')
10
10
  @source_id = options.fetch(:source_id)
11
- @resource_type = options.fetch(:resource_type)
11
+ @resource_type = options.fetch(:resource_type, nil)
12
12
  @sub_resource_type = options.fetch(:sub_resource_type, nil)
13
13
  @resource_id = options.fetch(:resource_id, nil)
14
14
  @params = options.fetch(:params, [])
@@ -29,7 +29,10 @@ module Gitlab
29
29
  end
30
30
 
31
31
  def base_url
32
- "#{host_with_api_url}/#{@source}/#{CGI.escape(@source_id.to_s)}/#{@resource_type}"
32
+ "#{host_with_api_url}/#{@source}/#{CGI.escape(@source_id.to_s)}"
33
+ .tap do |url|
34
+ url << "/#{@resource_type}" if @resource_type
35
+ end
33
36
  end
34
37
 
35
38
  def params_string
@@ -1,5 +1,5 @@
1
1
  module Gitlab
2
2
  module Triage
3
- VERSION = '1.2.0'.freeze
3
+ VERSION = '1.3.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: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitLab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-09 00:00:00.000000000 Z
11
+ date: 2019-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport