dri 0.1.2 → 0.1.3

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: 9dfdbd437522c61a85ee277d56572906e94f8b9c33d2b511701e5e0daa6ad576
4
- data.tar.gz: 93c8566dc5c2cc610aa181e0242562dc84db111a1bf149448032cbbba0a4ee54
3
+ metadata.gz: c1c589c770547e0142cb5b2942316e41af19cad293ed2e141d95e54a7379f741
4
+ data.tar.gz: b1cc881757273745c40485c469b34abb642a8edcda18ae1baf22bfe80ed8bacd
5
5
  SHA512:
6
- metadata.gz: 432a698eb76717876ab269523cae3377ea546103dfedaa04001ff7b07a7080ab4a069f4b795d6b949c78bca02cd500e584bccfbee8c9470bcafda2029eb095c2
7
- data.tar.gz: 152bbfc469b575c0f7e65e28ffdeba5517449b635016630d677ffded81c9e01a89acb93b0c9f6cc176b2e4226f7e1bf797505f162521a73791e5224a14462efd
6
+ metadata.gz: 0fa73e3af14a31bcf96f919c1b37465695a52a7db5d0fcaedf8ee36e51c817bf4c789c3fe24bc2169de0b385b83d0ec92ae716f8da6fbb55cb134c6219a0b26a
7
+ data.tar.gz: 880ae4a81c350dcfe7b49c9db00c3760d7f98b56383b7516d0c890dae24034fc3d8ebb86f37592c8d65655c3cbe8671bddf3c26327d49a6006b0e9f5f0313afa
data/.gitignore CHANGED
@@ -6,9 +6,11 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /vendor/bundle
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
12
13
 
13
14
  .dri_profile.yml
14
- handover_reports/*
15
+ handover_reports/*
16
+ .idea/
data/.gitlab-ci.yml CHANGED
@@ -1,28 +1,40 @@
1
- image: ruby:3.0.2
1
+ .job_base:
2
+ image: ruby:3.1
3
+ variables:
4
+ BUNDLE_PATH: vendor/bundle
5
+ BUNDLE_SUPPRESS_INSTALL_USING_MESSAGES: "true"
6
+ before_script:
7
+ - bundle install
8
+ cache:
9
+ key:
10
+ files:
11
+ - dri.gemspec
12
+ - Gemfile.lock
13
+ paths:
14
+ - vendor/bundle
15
+ rules:
16
+ - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
17
+ - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
18
+
19
+ include:
20
+ - project: gitlab-org/quality/pipeline-common
21
+ ref: 0.3.4
22
+ file:
23
+ - /ci/gem-release.yml
2
24
 
3
25
  stages:
4
26
  - build
5
27
  - test
6
28
  - deploy
7
29
 
8
- before_script:
9
- - gem install bundler:2.2.22
10
- - bundle install
11
-
12
30
  build_gem:
13
31
  stage: build
32
+ extends: .job_base
14
33
  script:
15
34
  - gem build
16
35
 
17
36
  rspec:
18
37
  stage: test
38
+ extends: .job_base
19
39
  script:
20
40
  - bundle exec rspec
21
-
22
- deploy:
23
- stage: deploy
24
- script:
25
- - gem push dri*.gem
26
- rules:
27
- - if: '$CI_COMMIT_TAG'
28
- when: always
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.0.2
data/Gemfile CHANGED
@@ -2,6 +2,3 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in dri.gemspec
4
4
  gemspec
5
-
6
- gem "rake", "~> 12.0"
7
- gem "rspec", "~> 3.0"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dri (0.1.1)
4
+ dri (0.1.2)
5
5
  httparty (~> 0.20.0)
6
6
  json (~> 2.6.1)
7
7
  markdown-tables (~> 1.1.1)
@@ -39,19 +39,19 @@ GEM
39
39
  public_suffix (4.0.6)
40
40
  rake (12.3.3)
41
41
  rexml (3.2.5)
42
- rspec (3.11.0)
43
- rspec-core (~> 3.11.0)
44
- rspec-expectations (~> 3.11.0)
45
- rspec-mocks (~> 3.11.0)
46
- rspec-core (3.11.0)
47
- rspec-support (~> 3.11.0)
48
- rspec-expectations (3.11.0)
42
+ rspec (3.10.0)
43
+ rspec-core (~> 3.10.0)
44
+ rspec-expectations (~> 3.10.0)
45
+ rspec-mocks (~> 3.10.0)
46
+ rspec-core (3.10.1)
47
+ rspec-support (~> 3.10.0)
48
+ rspec-expectations (3.10.1)
49
49
  diff-lcs (>= 1.2.0, < 2.0)
50
- rspec-support (~> 3.11.0)
51
- rspec-mocks (3.11.0)
50
+ rspec-support (~> 3.10.0)
51
+ rspec-mocks (3.10.2)
52
52
  diff-lcs (>= 1.2.0, < 2.0)
53
- rspec-support (~> 3.11.0)
54
- rspec-support (3.11.0)
53
+ rspec-support (~> 3.10.0)
54
+ rspec-support (3.10.2)
55
55
  strings (0.2.1)
56
56
  strings-ansi (~> 0.2)
57
57
  unicode-display_width (>= 1.5, < 3.0)
@@ -98,10 +98,10 @@ PLATFORMS
98
98
 
99
99
  DEPENDENCIES
100
100
  dri!
101
- rake (~> 12.0)
102
- rspec (~> 3.0)
101
+ rake
102
+ rspec (~> 3.10.0)
103
103
  timecop (~> 0.9.1)
104
104
  webmock (~> 3.5)
105
105
 
106
106
  BUNDLED WITH
107
- 2.1.4
107
+ 2.3.9
data/dri.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
 
10
10
  spec.summary = %q{CLI app to help triage GitLab QA pipelines}
11
11
  spec.homepage = 'https://gitlab.com/gitlab-org/quality/dri'
12
- spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
13
13
 
14
14
  # Specify which files should be added to the gem when it is released.
15
15
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_dependency "tty-editor", "~> 0.6"
31
31
  spec.add_dependency "pastel", "~> 0.8.0"
32
32
  spec.add_dependency "thor", "~> 1.0.1"
33
- spec.add_dependency "markdown-tables", "~> 1.1.1"
33
+ spec.add_dependency "markdown-tables", "~> 1.1.1"
34
34
  spec.add_dependency 'json', '~> 2.6.1'
35
35
  spec.add_dependency 'httparty', '~> 0.20.0'
36
36
 
@@ -3,10 +3,11 @@
3
3
  require "httparty"
4
4
  require "json"
5
5
  require "tty-config"
6
+ require 'cgi'
6
7
 
7
8
  module Dri
8
9
  class ApiClient
9
-
10
+
10
11
  API_URL = 'https://gitlab.com/api/v4'
11
12
  TESTCASES_PROJECT_ID = '11229385'
12
13
  TRIAGE_PROJECT_ID = '15291320'
@@ -50,6 +51,24 @@ module Dri
50
51
  fetch_json(url.join)
51
52
  end
52
53
 
54
+ # Fetch MRs
55
+ #
56
+ # @see https://docs.gitlab.com/ee/api/merge_requests.html for all passable options
57
+ #
58
+ # @param [Hash<String>] options
59
+ # @option options [String] state
60
+ # @option options [String] order_by
61
+ # @option options [String] sort
62
+ # @option options [String] milestone
63
+ # @option options [String] labels
64
+ def fetch_mrs(project_id:, **options)
65
+ uri = URI(API_URL)
66
+ uri.query = HTTParty::HashConversions.to_params(options)
67
+ uri.path = File.join(uri.path, 'projects', CGI.escape(project_id), 'merge_requests') # CGI.escape('gitlab-org/gitlab') => 'gitlab-org%2Fgitlab'
68
+
69
+ fetch_json(uri.to_s)
70
+ end
71
+
53
72
  def fetch_current_triage_issue
54
73
  url = ["#{API_URL}/projects/"]
55
74
  url << "#{TRIAGE_PROJECT_ID}/issues?state=opened"
@@ -97,7 +116,7 @@ module Dri
97
116
  }
98
117
  }
99
118
 
100
- response = HTTParty.post(url, options)
119
+ response = HTTParty.post(url, options)
101
120
  handle_response(response)
102
121
  end
103
122
 
@@ -122,4 +141,4 @@ module Dri
122
141
  handle_response(JSON.parse(response.body))
123
142
  end
124
143
  end
125
- end
144
+ end
data/lib/dri/command.rb CHANGED
@@ -2,6 +2,8 @@
2
2
  require_relative 'command'
3
3
  require_relative 'api_client'
4
4
 
5
+ require 'dri/refinements/truncate'
6
+
5
7
  require "tty-config"
6
8
  require "pastel"
7
9
  require 'forwardable'
@@ -8,6 +8,8 @@ module Dri
8
8
  module Commands
9
9
  class Fetch
10
10
  class Failures < Dri::Command
11
+ using Refinements
12
+
11
13
  def initialize(options)
12
14
  @options = options
13
15
  @today_iso_format = Time.now.strftime('%Y-%m-%dT00:00:00Z')
@@ -26,35 +28,38 @@ module Dri
26
28
  labels = [ title, triaged, author, url ]
27
29
  triaged_counter = 0
28
30
 
29
- logger.info "Fetching today\'s failures..."
30
-
31
- spinner.run do
31
+ logger.info "Fetching today's failures..."
32
+
33
+ spinner.run do
32
34
 
33
35
  response = api_client.fetch_failures(date: @today_iso_format, state: 'opened')
34
36
 
35
37
  if response.nil?
36
- logger.info "Life is great, there are no new failures today!"
38
+ logger.info 'Life is great, there are no new failures today!'
37
39
  exit 0
38
40
  end
39
41
 
40
42
  response.each do |failure|
41
- title = truncate(failure["title"], 60)
42
- author = failure["author"]["username"]
43
- url = failure["web_url"]
44
- award_emoji_url = failure["_links"]["award_emoji"]
43
+ title = failure['title'].truncate(60)
44
+ author = failure['author']['username']
45
+ url = failure['web_url']
46
+ award_emoji_url = failure['_links']['award_emoji']
45
47
  triaged = add_color('x', :red)
46
48
 
47
- emoji_awards = api_client.fetch_awarded_emojis(award_emoji_url)
49
+ emoji_awards = api_client.fetch_awarded_emojis(award_emoji_url).find do |e|
50
+ e['name'] == emoji && e['user']['username'] == username
51
+ end
48
52
 
49
- triaged = add_color('✓', :green) && triaged_counter += 1 if emoji_awards.find do |e|
50
- e['name'] == emoji && e['user']['username'] == @username
53
+ if emoji_awards
54
+ triaged = add_color('', :green)
55
+ triaged_counter += 1
51
56
  end
52
57
 
53
58
  if @options[:urgent]
54
- labels = failure["labels"]
59
+ labels = failure['labels']
55
60
 
56
61
  labels.each do |label|
57
- if label.include? ("found:canary.gitlab.com" && "found:canary.staging.gitlab.com")
62
+ if label.include? ('found:canary.gitlab.com' && 'found:canary.staging.gitlab.com')
58
63
  urgent << [title, triaged, author, url]
59
64
  end
60
65
  end
@@ -67,19 +72,13 @@ module Dri
67
72
  if @options[:urgent]
68
73
  table = TTY::Table.new(labels, urgent)
69
74
  puts table.render(:ascii, resize: true, alignments: [:center, :center, :center, :center])
70
- output.puts "\nFound: #{urgent.size} urgent failures, ocurring in both canary.gitlab.com and canary.staging.gitlab.com."
75
+ output.puts "\nFound: #{urgent.size} urgent failures, occurring in both canary.gitlab.com and canary.staging.gitlab.com."
71
76
  else
72
77
  table = TTY::Table.new(labels, failures)
73
78
  puts table.render(:ascii, resize: true, alignments: [:center, :center, :center, :center])
74
79
  output.puts "\nFound: #{failures.size} failures, of these #{triaged_counter} have been triaged with a #{emoji}."
75
80
  end
76
81
  end
77
-
78
- private
79
-
80
- def truncate(string, max)
81
- string.length > max ? "#{string[0...max]}..." : string
82
- end
83
82
  end
84
83
  end
85
84
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../command'
4
+
5
+ require 'tty-table'
6
+
7
+ module Dri
8
+ module Commands
9
+ class Fetch
10
+ class Quarantines < Dri::Command
11
+ using Refinements
12
+
13
+ def initialize(options)
14
+ @options = options
15
+ @today_iso_format = Time.now.strftime('%Y-%m-%dT00:00:00Z')
16
+ end
17
+
18
+ def execute(input: $stdin, output: $stdout)
19
+ verify_config_exists
20
+
21
+ title = add_color('Example name', :bright_yellow)
22
+ url = add_color('URL', :bright_yellow)
23
+
24
+ headers = [title, url]
25
+ mrs = []
26
+
27
+ logger.info 'Fetching Quarantine MRs...'
28
+
29
+ spinner.run do
30
+ response = api_client.fetch_mrs(project_id: 'gitlab-org/gitlab', labels: 'QA,Quality', search: '[QUARANTINE]', in: :title, state: :opened)
31
+
32
+ mrs = response.each_with_object([]) do |mr, found_mrs|
33
+ title = mr['title'][13..] # remove the "[QUARANTINE] " prefix
34
+ url = mr['web_url']
35
+
36
+ found_mrs << [title, url]
37
+ end
38
+ end
39
+
40
+ puts TTY::Table.new(headers, mrs).render(:ascii, resize: true, alignments: %i[left center])
41
+ output.puts "Found #{mrs.size} open Quarantine MRs"
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -20,7 +20,7 @@ module Dri
20
20
  failures_triaged = []
21
21
 
22
22
  logger.info "Fetching your triaged failures..."
23
- spinner.start
23
+ spinner.start
24
24
 
25
25
  response = api_client.fetch_triaged_failures(emoji: emoji, state: 'opened')
26
26
 
@@ -30,7 +30,7 @@ module Dri
30
30
  end
31
31
 
32
32
  response.each do |triaged|
33
- title = truncate(triaged["title"], 70)
33
+ title = triaged["title"].truncate(70)
34
34
  url = triaged["web_url"]
35
35
  labels = triaged["labels"]
36
36
  type = ""
@@ -40,7 +40,7 @@ module Dri
40
40
  end
41
41
 
42
42
  labels = triaged["labels"]
43
-
43
+
44
44
  failures_triaged << [title, url, type]
45
45
  end
46
46
 
@@ -49,12 +49,6 @@ module Dri
49
49
  table = TTY::Table.new(table_labels,failures_triaged)
50
50
  puts table.render(:ascii, resize: true, alignments: [:center, :center, :center])
51
51
  end
52
-
53
- private
54
-
55
- def truncate(string, max)
56
- string.length > max ? "#{string[0...max]}..." : string
57
- end
58
52
  end
59
53
  end
60
54
  end
@@ -46,6 +46,18 @@ module Dri
46
46
  Dri::Commands::Fetch::Failures.new(options).execute
47
47
  end
48
48
  end
49
+
50
+ desc 'quarantines', 'Display open quarantine MRs'
51
+ method_option :help, aliases: '-h', type: :boolean,
52
+ desc: 'Display usage information'
53
+ def quarantines(*)
54
+ if options[:help]
55
+ invoke :help, ['quarantines']
56
+ else
57
+ require_relative 'fetch/quarantines'
58
+ Dri::Commands::Fetch::Quarantines.new(options).execute
59
+ end
60
+ end
49
61
  end
50
62
  end
51
63
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Refinements
4
+ refine String do
5
+ # Truncate string to limit of _n_ characters
6
+ # @param [Integer] limit the limit of characters
7
+ # @return [String] the resulting string after truncation
8
+ def truncate(limit = 50)
9
+ return self.freeze if self.size <= limit
10
+
11
+ # limit - 3 for the ellipses
12
+ self[0...(limit - 3)] << '...'
13
+ end
14
+ end
15
+ end
data/lib/dri/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dri
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitLab Quality
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-16 00:00:00.000000000 Z
11
+ date: 2022-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-config
@@ -248,7 +248,7 @@ dependencies:
248
248
  - - "~>"
249
249
  - !ruby/object:Gem::Version
250
250
  version: 0.9.1
251
- description:
251
+ description:
252
252
  email:
253
253
  - quality+dri@gitlab.com
254
254
  executables:
@@ -260,6 +260,7 @@ files:
260
260
  - ".gitignore"
261
261
  - ".gitlab-ci.yml"
262
262
  - ".rspec"
263
+ - ".tool-versions"
263
264
  - Gemfile
264
265
  - Gemfile.lock
265
266
  - LICENSE.txt
@@ -275,6 +276,7 @@ files:
275
276
  - lib/dri/command.rb
276
277
  - lib/dri/commands/fetch.rb
277
278
  - lib/dri/commands/fetch/failures.rb
279
+ - lib/dri/commands/fetch/quarantines.rb
278
280
  - lib/dri/commands/fetch/testcases.rb
279
281
  - lib/dri/commands/fetch/triaged.rb
280
282
  - lib/dri/commands/init.rb
@@ -285,6 +287,7 @@ files:
285
287
  - lib/dri/commands/rm/emoji.rb
286
288
  - lib/dri/commands/rm/profile.rb
287
289
  - lib/dri/commands/rm/reports.rb
290
+ - lib/dri/refinements/truncate.rb
288
291
  - lib/dri/report.rb
289
292
  - lib/dri/utils/markdown_lists.rb
290
293
  - lib/dri/version.rb
@@ -292,7 +295,7 @@ homepage: https://gitlab.com/gitlab-org/quality/dri
292
295
  licenses:
293
296
  - MIT
294
297
  metadata: {}
295
- post_install_message:
298
+ post_install_message:
296
299
  rdoc_options: []
297
300
  require_paths:
298
301
  - lib
@@ -300,7 +303,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
300
303
  requirements:
301
304
  - - ">="
302
305
  - !ruby/object:Gem::Version
303
- version: 2.5.0
306
+ version: 2.7.0
304
307
  required_rubygems_version: !ruby/object:Gem::Requirement
305
308
  requirements:
306
309
  - - ">="
@@ -308,7 +311,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
308
311
  version: '0'
309
312
  requirements: []
310
313
  rubygems_version: 3.1.6
311
- signing_key:
314
+ signing_key:
312
315
  specification_version: 4
313
316
  summary: CLI app to help triage GitLab QA pipelines
314
317
  test_files: []