dri 0.2.0 → 0.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: 3ae68ce5f20bab397121604708b813e8f488316559f82392a389f1750e57c89c
4
- data.tar.gz: 30b16b0291beb7e18cc74acb9c54100c869544bba883c79729f577c8bda5dd7f
3
+ metadata.gz: ebb53c09c3a4e7f7c6daa06acd9e8fb1be1c5aef4fffb97db6e84029aafe481e
4
+ data.tar.gz: f7cb0fc63042a33766c02a787cb10af4188839fb9f96d9aa650f5addc279cac9
5
5
  SHA512:
6
- metadata.gz: ad35cf45172de050ecd86c376527abc98ba535f9ad97f54f84f7be3875882c46ae897039d26a4c9f4db3c7df598608c81e8613518b7c7eeb44b7903610899406
7
- data.tar.gz: a790667c5528fc3ad94f610b2add55b36a4fb5efd9bad3e8e10a78d44e58a8140721d4717a75def60ca829715389bebf001704a38a1a8127e1e6872228dd0fe6
6
+ metadata.gz: 01f7bbef2920e466cde321720d210541cbb60b377240ae28a74e6fdd66bd89f70a5b4aba5e69d622466d5379ed6e59adce3933844d08171449496b9638dfe1f6
7
+ data.tar.gz: c263146aa4a230cab0b8cdebc7c2a6b1d278baa3cf63b5d356fa7c8ee3143472c0e69ec3eaa7006317f74249c66167f4e03a72dfccab0f2d52ea5fde4e1d972f
data/README.md CHANGED
@@ -65,7 +65,8 @@ $ dri profile
65
65
  - emoji
66
66
  - profile
67
67
  - reports
68
- - [6. version](#6-version)
68
+ - [6. incidents](#6-incidents)
69
+ - [7. version](#7-version)
69
70
 
70
71
  #### 1. init
71
72
 
@@ -181,7 +182,15 @@ $ dri rm profile
181
182
 
182
183
  Removes the profile currently in use.
183
184
 
184
- #### 6. version
185
+ #### 6. incidents
186
+
187
+ ```shell
188
+ $ dri incidents
189
+ ```
190
+
191
+ Have a quick look at currently active/mitigated incidents on GitLab services.
192
+
193
+ #### 7. version
185
194
 
186
195
  ```shell
187
196
  $ dri version
@@ -12,6 +12,7 @@ module Dri
12
12
  TRIAGE_PROJECT_ID = '15291320'
13
13
  GITLAB_PROJECT_ID = '278964'
14
14
  FEATURE_FLAG_LOG_PROJECT_ID = '15208716'
15
+ INFRA_TEAM_PROD_PROJECT_ID = '7444821'
15
16
 
16
17
  def initialize(config)
17
18
  profile = config.read
@@ -92,6 +93,7 @@ module Dri
92
93
  url << "&order_by=updated_at&state=#{state}"
93
94
  url << "&scope=all"
94
95
  url << "&created_after=#{date}"
96
+ url << "&per_page=100"
95
97
 
96
98
  fetch_json(url.join)
97
99
  end
@@ -118,6 +120,15 @@ module Dri
118
120
  fetch_json(url.join)
119
121
  end
120
122
 
123
+ def incidents
124
+ url = ["#{API_URL}/projects/"]
125
+ url << "#{INFRA_TEAM_PROD_PROJECT_ID}/issues"
126
+ url << "?order_by=updated_at&state=opened"
127
+ url << "&labels=incident"
128
+
129
+ fetch_json(url.join)
130
+ end
131
+
121
132
  private
122
133
 
123
134
  def post_json(url, body)
@@ -138,7 +149,6 @@ module Dri
138
149
  end
139
150
 
140
151
  def handle_response(response)
141
- # puts response.to_json
142
152
  response
143
153
  end
144
154
 
data/lib/dri/cli.rb CHANGED
@@ -34,6 +34,18 @@ module Dri
34
34
  end
35
35
  map %w[--version -v] => :version
36
36
 
37
+ desc 'incidents', 'View current incidents'
38
+ method_option :help, aliases: '-h', type: :boolean,
39
+ desc: 'Display usage information'
40
+ def incidents(*)
41
+ if options[:help]
42
+ invoke :help, ['incidents']
43
+ else
44
+ require_relative 'commands/incidents'
45
+ Dri::Commands::Incidents.new(options).execute
46
+ end
47
+ end
48
+
37
49
  require_relative 'commands/rm'
38
50
  register Dri::Commands::Rm, 'rm', 'rm [SUBCOMMAND]', 'Remove triage-related items'
39
51
 
data/lib/dri/command.rb CHANGED
@@ -123,7 +123,7 @@ module Dri
123
123
  # @api public
124
124
  def prompt(**options)
125
125
  require 'tty-prompt'
126
- TTY::Prompt.new(options)
126
+ TTY::Prompt.new(options.merge(interrupt: :exit))
127
127
  end
128
128
  end
129
129
  end
@@ -10,6 +10,13 @@ module Dri
10
10
  include Dri::Utils::Table
11
11
  using Refinements
12
12
 
13
+ SORT_BY_OPTIONS = {
14
+ title: 0,
15
+ triaged: 1,
16
+ author: 2,
17
+ url: 3
18
+ }.freeze
19
+
13
20
  def initialize(options)
14
21
  @options = options
15
22
  @today_iso_format = Time.now.strftime('%Y-%m-%dT00:00:00Z')
@@ -65,6 +72,8 @@ module Dri
65
72
  end
66
73
 
67
74
  failures << [title, triaged, author, url]
75
+
76
+ failures.sort_by! { |e| e[SORT_BY_OPTIONS[@options[:sort_by].to_sym]] } if @options[:sort_by]
68
77
  end
69
78
  end
70
79
 
@@ -17,7 +17,6 @@ module Dri
17
17
  nightly
18
18
  production
19
19
  staging-canary
20
- staging-orchestrated
21
20
  staging-ref
22
21
  staging
23
22
  ]
@@ -50,6 +50,8 @@ module Dri
50
50
  desc: 'Display usage information'
51
51
  method_option :urgent, type: :boolean,
52
52
  desc: 'Shows failures that quickly escalated'
53
+ method_option :sort_by, type: :string,
54
+ desc: 'Shows failures in specified order'
53
55
  def failures(*)
54
56
  if options[:help]
55
57
  invoke :help, ['failures']
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../command'
4
+ require_relative '../utils/table'
5
+
6
+ module Dri
7
+ module Commands
8
+ class Incidents < Dri::Command
9
+ include Dri::Utils::Table
10
+ using Refinements
11
+
12
+ def initialize(options)
13
+ @options = options
14
+ end
15
+
16
+ def execute(input: $stdin, output: $stdout) # rubocop:disable Metrics/AbcSize
17
+ verify_config_exists
18
+
19
+ incident = add_color('Incident', :bright_yellow)
20
+ service = add_color('Service', :bright_yellow)
21
+ status = add_color('Status', :bright_yellow)
22
+ url = add_color('URL', :bright_yellow)
23
+
24
+ header = [incident, service, status, url]
25
+
26
+ logger.info "Looking for open incidents..."
27
+ incidents = []
28
+
29
+ spinner.run do
30
+ response = api_client.incidents
31
+
32
+ if response.nil?
33
+ logger.info 'Hooray, no active incidents 🎉.'
34
+ exit 0
35
+ end
36
+
37
+ response.each do |incident|
38
+ title = incident['title'].truncate(70)
39
+ url = incident['web_url']
40
+ labels = incident['labels']
41
+ status = "N/A"
42
+ service = "N/A"
43
+
44
+ labels.each do |label|
45
+ status = label.gsub!('Incident::', ' ').to_s if label.include? "Incident::"
46
+ service = label.gsub!('Service::', ' ').to_s if label.include? "Service::"
47
+ end
48
+
49
+ incidents << [title, service, status, url]
50
+ end
51
+ end
52
+ print_table(header, incidents, alignments: [:left, :center, :center, :center])
53
+ output.puts(<<~MSG)
54
+ Found: #{incidents.size} incident(s).
55
+ MSG
56
+ end
57
+ end
58
+ end
59
+ end
@@ -36,7 +36,17 @@ module Dri
36
36
 
37
37
  logger.info "Assembling the report... "
38
38
  # sets each failure on the table
39
- action_options = ["pinged SET", "reproduced", "transient", "quarantined"]
39
+ action_options = [
40
+ "pinged SET",
41
+ "reproduced",
42
+ "transient",
43
+ "quarantined",
44
+ "active investigation",
45
+ "blocking pipelines",
46
+ "awaiting for a fix to merge",
47
+ "notified the team",
48
+ "due to feature flag"
49
+ ]
40
50
 
41
51
  spinner.start
42
52
  issues.each do |issue|
@@ -45,7 +55,8 @@ module Dri
45
55
  if @options[:actions]
46
56
  actions = prompt.multi_select(
47
57
  "Please mark the actions on #{add_color(issue['title'], :yellow)}: ",
48
- action_options
58
+ action_options,
59
+ per_page: 9
49
60
  )
50
61
  end
51
62
 
data/lib/dri/report.rb CHANGED
@@ -59,7 +59,7 @@ module Dri
59
59
  label_pipeline_map = {
60
60
  'gitlab.com' => '/quality/production',
61
61
  'canary.gitlab.com' => '/quality/canary',
62
- # 'canary.staging.gitlab.com' => '',
62
+ 'canary.staging.gitlab.com' => '/quality/staging-canary',
63
63
  'main' => '/gitlab-org/gitlab-qa-mirror',
64
64
  'master' => '/gitlab-org/gitlab-qa-mirror',
65
65
  'nightly' => '/quality/nightly',
@@ -102,16 +102,25 @@ module Dri
102
102
  linked.join(', ')
103
103
  end
104
104
 
105
- def actions_status_template(failure_type, assigned_status, actions_opts)
106
- notified_set = ''
105
+ def actions_status_template(failure_type, assigned_status, actions_opts) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity/MethodLength
107
106
  quarantined = ''
108
107
  reproduced = ''
109
108
  transient = ''
109
+ active_investigation = ''
110
+ blocking_pipelines = ''
111
+ wait_for_fix = ''
112
+ notified_team = ''
113
+ feature_flag = ''
110
114
 
111
115
  notified_set = '<li>[x] notified SET</li>' if actions_opts.include? 'pinged SET'
112
116
  quarantined = '<li>[x] quarantined</li>' if actions_opts.include? 'quarantined'
113
117
  reproduced = '<li>[x] reproduced</li>' if actions_opts.include? 'reproduced'
114
118
  transient = '<li>[x] transient</li>' if actions_opts.include? 'transient'
119
+ active_investigation = '<li>[x] active investigation</li>' if actions_opts.include? 'active investigation'
120
+ blocking_pipelines = '<li>[x] is blocking pipelines</li>' if actions_opts.include? 'blocking pipelines'
121
+ wait_for_fix = '<li>[x] waiting for fix to merge</li>' if actions_opts.include? 'awaiting for a fix to merge'
122
+ notified_team = '<li>[x] notified the team</li>' if actions_opts.include? 'notified the team'
123
+ feature_flag = '<li>[x] due to feature flag</li>' if actions_opts.include? 'due to feature flag'
115
124
 
116
125
  action_status = ["<i>Status:</i><ul>"]
117
126
  action_status << "<li>#{failure_type}</li>"
@@ -120,13 +129,18 @@ module Dri
120
129
  action_status << quarantined
121
130
  action_status << reproduced
122
131
  action_status << transient
132
+ action_status << active_investigation
133
+ action_status << blocking_pipelines
134
+ action_status << wait_for_fix
135
+ action_status << notified_team
136
+ action_status << feature_flag
123
137
 
124
138
  action_status.join
125
139
  end
126
140
 
127
141
  def actions_fixes_template(related_mrs)
128
142
  mrs = related_mrs.each_with_object(['<i>Potential fixes:</i><br>']) do |mr, fixes|
129
- fixes << "<li>[#{mr['title']}](#{mr['web_url']})</li>"
143
+ fixes << "<li>[#{mr['title'].truncate(40)}](#{mr['web_url']})</li>"
130
144
  end
131
145
 
132
146
  "<ul>#{mrs.join}</ul>"
@@ -0,0 +1 @@
1
+ #
data/lib/dri/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dri
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitLab Quality
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-08 00:00:00.000000000 Z
11
+ date: 2022-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -296,6 +296,7 @@ files:
296
296
  - lib/dri/commands/fetch/quarantines.rb
297
297
  - lib/dri/commands/fetch/testcases.rb
298
298
  - lib/dri/commands/fetch/triaged.rb
299
+ - lib/dri/commands/incidents.rb
299
300
  - lib/dri/commands/init.rb
300
301
  - lib/dri/commands/profile.rb
301
302
  - lib/dri/commands/publish.rb
@@ -306,6 +307,7 @@ files:
306
307
  - lib/dri/commands/rm/reports.rb
307
308
  - lib/dri/refinements/truncate.rb
308
309
  - lib/dri/report.rb
310
+ - lib/dri/templates/incidents/.gitkeep
309
311
  - lib/dri/utils/markdown_lists.rb
310
312
  - lib/dri/utils/table.rb
311
313
  - lib/dri/version.rb