Module: Kettle::Dev::CIMonitor

Defined in:
lib/kettle/dev/ci_monitor.rb,
sig/kettle/dev.rbs

Overview

CIMonitor centralizes CI monitoring logic (GitHub Actions and GitLab pipelines) so it can be reused by both kettle-release and Rake tasks (e.g., ci:act).

Public API is intentionally small and based on environment/project introspection via CIHelpers, matching the behavior historically implemented in ReleaseCLI.

Class Method Summary collapse

Class Method Details

.abort(msg) ⇒ Object

Abort helper (delegates through ExitAdapter so specs can trap exits)



20
21
22
# File 'lib/kettle/dev/ci_monitor.rb', line 20

def abort(msg)
  Kettle::Dev::ExitAdapter.abort(msg)
end

.collect_allHash

Non-aborting collection across GH and GL, returning a compact results hash. Results format:

  {
    github: [ {workflow: "file.yml", status: "completed", conclusion: "success"|"failure"|nil, url: String} ],
    gitlab: { status: "success"|"failed"|"blocked"|"unknown"|nil, url: String }
  }

Returns:

  • (Hash)


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/kettle/dev/ci_monitor.rb', line 77

def collect_all
  results = {github: [], gitlab: nil}
  begin
    gh = collect_github
    results[:github] = gh if gh
  rescue => e
    Kettle::Dev.debug_error(e, __method__)
  end
  begin
    gl = collect_gitlab
    results[:gitlab] = gl if gl
  rescue => e
    Kettle::Dev.debug_error(e, __method__)
  end
  results
end

.collect_githubArray[untyped]?

--- Collectors ---

Returns:

  • (Array[untyped], nil)


167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/kettle/dev/ci_monitor.rb', line 167

def collect_github
  root = Kettle::Dev::CIHelpers.project_root
  workflows = Kettle::Dev::CIHelpers.workflows_list(root)
  gh_remote = preferred_github_remote
  return unless gh_remote && !workflows.empty?

  branch = Kettle::Dev::CIHelpers.current_branch
  abort("Could not determine current branch for CI checks.") unless branch

  url = remote_url(gh_remote)
  owner, repo = parse_github_owner_repo(url)
  return unless owner && repo

  total = workflows.size
  return [] if total.zero?

  puts "Checking GitHub Actions workflows on #{branch} (#{owner}/#{repo}) via remote '#{gh_remote}'"
  pbar = if defined?(ProgressBar)
    ProgressBar.create(title: "GHA", total: total, format: "%t %b %c/%C", length: 30)
  end
  # Initial sleep same as aborting path
  begin
    initial_sleep = Integer(ENV["K_RELEASE_CI_INITIAL_SLEEP"])
  rescue
    initial_sleep = nil
  end
  sleep((initial_sleep && initial_sleep >= 0) ? initial_sleep : 3)

  results = {}
  idx = 0
  loop do
    wf = workflows[idx]
    run = Kettle::Dev::CIHelpers.latest_run(owner: owner, repo: repo, workflow_file: wf, branch: branch)
    if run
      if Kettle::Dev::CIHelpers.success?(run)
        unless results[wf]
          status = run["status"] || "completed"
          conclusion = run["conclusion"] || "success"
          results[wf] = {workflow: wf, status: status, conclusion: conclusion, url: run["html_url"]}
          pbar&.increment
        end
      elsif Kettle::Dev::CIHelpers.failed?(run)
        unless results[wf]
          results[wf] = {workflow: wf, status: run["status"], conclusion: run["conclusion"] || "failure", url: run["html_url"] || "https://github.com/#{owner}/#{repo}/actions/workflows/#{wf}"}
          pbar&.increment
        end
      end
    end
    break if results.size == total

    idx = (idx + 1) % total
    sleep(1)
  end
  pbar&.finish unless pbar&.finished?
  results.values
end

.collect_gitlab{ status: String, url: String? }?

Returns:

  • ({ status: String, url: String? }, nil)


225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/kettle/dev/ci_monitor.rb', line 225

def collect_gitlab
  root = Kettle::Dev::CIHelpers.project_root
  gitlab_ci = File.exist?(File.join(root, ".gitlab-ci.yml"))
  gl_remote = gitlab_remote_candidates.first
  return unless gitlab_ci && gl_remote

  branch = Kettle::Dev::CIHelpers.current_branch
  abort("Could not determine current branch for CI checks.") unless branch

  owner, repo = Kettle::Dev::CIHelpers.repo_info_gitlab
  return unless owner && repo

  puts "Checking GitLab pipeline on #{branch} (#{owner}/#{repo}) via remote '#{gl_remote}'"
  pbar = if defined?(ProgressBar)
    ProgressBar.create(title: "GL", total: 1, format: "%t %b %c/%C", length: 30)
  end
  result = {status: "unknown", url: nil}
  loop do
    pipe = Kettle::Dev::CIHelpers.gitlab_latest_pipeline(owner: owner, repo: repo, branch: branch)
    if pipe
      result[:url] ||= pipe["web_url"] || "https://gitlab.com/#{owner}/#{repo}/-/pipelines"
      if Kettle::Dev::CIHelpers.gitlab_success?(pipe)
        result[:status] = "success"
        pbar&.increment unless pbar&.finished?
      elsif Kettle::Dev::CIHelpers.gitlab_failed?(pipe)
        reason = (pipe["failure_reason"] || "").to_s
        if /insufficient|quota|minute/i.match?(reason)
          result[:status] = "unknown"
          pbar&.finish unless pbar&.finished?
        else
          result[:status] = "failed"
          pbar&.increment unless pbar&.finished?
        end
      elsif pipe["status"] == "blocked"
        result[:status] = "blocked"
        pbar&.finish unless pbar&.finished?
      end
      break
    end
    sleep(1)
  end
  pbar&.finish unless pbar&.finished?
  result
end

.emit_ci_monitor_event(event_recorder, action:, status:, provider:, **payload) ⇒ Object



619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
# File 'lib/kettle/dev/ci_monitor.rb', line 619

def emit_ci_monitor_event(event_recorder, action:, status:, provider:, **payload)
  mark = case status.to_s
  when "started"
    ">"
  when "ok", "skipped"
    "."
  when "failed"
    "!"
  else
    "?"
  end
  Kettle::Ndjson.emit_event(
    event_recorder,
    "ci_monitor",
    payload.merge(
      action: action,
      phase: "release",
      provider: provider,
      status: status,
      mark: mark
    )
  )
end

.github_poll_intervalFloat

Returns:

  • (Float)


470
471
472
473
474
475
476
477
# File 'lib/kettle/dev/ci_monitor.rb', line 470

def github_poll_interval
  seconds = begin
    Float(ENV["K_RELEASE_CI_POLL_INTERVAL"])
  rescue
    nil
  end
  (seconds && seconds >= 0) ? seconds : 1
end

.github_remote_candidatesObject



655
656
657
# File 'lib/kettle/dev/ci_monitor.rb', line 655

def github_remote_candidates
  remotes_with_urls.select { |n, u| u.include?("github.com") }.keys
end

.github_start_timeoutInteger

Returns:

  • (Integer)


460
461
462
463
464
465
466
467
# File 'lib/kettle/dev/ci_monitor.rb', line 460

def github_start_timeout
  seconds = begin
    Integer(ENV["K_RELEASE_CI_START_TIMEOUT"])
  rescue
    nil
  end
  (seconds && seconds >= 0) ? seconds : 300
end

.gitlab_remote_candidatesObject



660
661
662
# File 'lib/kettle/dev/ci_monitor.rb', line 660

def gitlab_remote_candidates
  remotes_with_urls.select { |n, u| u.include?("gitlab.com") }.keys
end

.keepalive_intervalObject



495
496
497
498
499
500
501
502
# File 'lib/kettle/dev/ci_monitor.rb', line 495

def keepalive_interval
  seconds = begin
    Float(ENV["KETTLE_RELEASE_SECRET_KEEPALIVE_INTERVAL"])
  rescue
    nil
  end
  (seconds && seconds >= 0) ? seconds : 240.0
end

.keepalive_timer(keepalive) ⇒ Object



480
481
482
483
484
485
486
487
488
489
490
491
492
# File 'lib/kettle/dev/ci_monitor.rb', line 480

def keepalive_timer(keepalive)
  interval = keepalive_interval
  last_run = nil
  lambda do
    if keepalive
      now = monotonic_time
      if !last_run || (now - last_run) >= interval
        keepalive.call
        last_run = now
      end
    end
  end
end

.monitor_all!(restart_hint: "bundle exec kettle-release start_step=10", workflows: nil, keepalive: nil, event_recorder: nil, **options) ⇒ void

This method returns an undefined value.

Monitor both GitHub and GitLab CI for the current project/branch. This mirrors ReleaseCLI behavior and aborts on first failure.

Parameters:

  • restart_hint (String) (defaults to: "bundle exec kettle-release start_step=10")

    guidance command shown on failure

  • restart_hint: (String) (defaults to: "bundle exec kettle-release start_step=10")
  • workflows: (Array[String], nil) (defaults to: nil)
  • (Object)


51
52
53
54
55
56
# File 'lib/kettle/dev/ci_monitor.rb', line 51

def monitor_all!(restart_hint: "bundle exec kettle-release start_step=10", workflows: nil, keepalive: nil, event_recorder: nil, **options)
  checks_any = false
  checks_any |= monitor_github_internal!(restart_hint: restart_hint, workflows: workflows, keepalive: keepalive, event_recorder: event_recorder)
  checks_any |= monitor_gitlab_internal!(restart_hint: restart_hint, keepalive: keepalive, event_recorder: event_recorder)
  abort("CI configuration not detected (GitHub or GitLab). Ensure CI is configured and remotes point to the correct hosts.") unless checks_any
end

.monitor_and_prompt_for_release!(restart_hint: "bundle exec kettle-release start_step=10") ⇒ void

This method returns an undefined value.

Prompt user to continue or quit when failures are present; otherwise return. Designed for kettle-release.

Parameters:

  • restart_hint (String) (defaults to: "bundle exec kettle-release start_step=10")
  • restart_hint: (String) (defaults to: "bundle exec kettle-release start_step=10")


131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/kettle/dev/ci_monitor.rb', line 131

def monitor_and_prompt_for_release!(restart_hint: "bundle exec kettle-release start_step=10")
  results = collect_all
  any_checks = !(results[:github].nil? || results[:github].empty?) || !!results[:gitlab]
  abort("CI configuration not detected (GitHub or GitLab). Ensure CI is configured and remotes point to the correct hosts.") unless any_checks

  ok = summarize_results(results)
  return if ok

  # Non-interactive environments default to quitting unless explicitly allowed
  env_val = ENV.fetch("K_RELEASE_CI_CONTINUE", "false")
  non_interactive_continue = !!(Kettle::Dev::ENV_TRUE_RE =~ env_val)
  if !$stdin.tty?
    abort("CI checks reported failures. Fix and restart from CI validation (#{restart_hint}).") unless non_interactive_continue
    puts "CI checks reported failures, but continuing due to K_RELEASE_CI_CONTINUE=true."
    return
  end

  # Prompt exactly once; avoid repeated printing in case of unexpected input buffering.
  # Accept c/continue to proceed or q/quit to abort. Any other input defaults to quit with a message.
  print("One or more CI checks failed. (c)ontinue or (q)uit? ")
  ans = Kettle::Dev::InputAdapter.gets
  if ans.nil?
    abort("Aborting (no input available). Fix CI, then restart with: #{restart_hint}")
  end
  ans = ans.strip.downcase
  if ans == "c" || ans == "continue"
    puts "Continuing release despite CI failures."
  elsif ans == "q" || ans == "quit"
    abort("Aborting per user choice. Fix CI, then restart with: #{restart_hint}")
  else
    abort("Unrecognized input '#{ans}'. Aborting. Fix CI, then restart with: #{restart_hint}")
  end
end

.monitor_github_internal!(restart_hint:, workflows: nil, keepalive: nil, event_recorder: nil) ⇒ Object



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# File 'lib/kettle/dev/ci_monitor.rb', line 271

def monitor_github_internal!(restart_hint:, workflows: nil, keepalive: nil, event_recorder: nil)
  root = Kettle::Dev::CIHelpers.project_root
  workflows = Array(workflows).empty? ? Kettle::Dev::CIHelpers.workflows_list(root) : Array(workflows)
  gh_remote = preferred_github_remote
  return false unless gh_remote && !workflows.empty?

  branch = Kettle::Dev::CIHelpers.current_branch
  abort("Could not determine current branch for CI checks.") unless branch

  url = remote_url(gh_remote)
  owner, repo = parse_github_owner_repo(url)
  return false unless owner && repo

  total = workflows.size
  abort("No GitHub workflows found under .github/workflows; aborting.") if total.zero?

  head_sha = Kettle::Dev::CIHelpers.current_head_sha
  abort("Could not determine local HEAD SHA for GitHub Actions checks.") unless head_sha && !head_sha.empty?

  passed = {}
  started = {}
  emit_ci_monitor_event(
    event_recorder,
    action: "github_discover",
    status: "started",
    provider: "github",
    remote: gh_remote,
    owner: owner,
    repo: repo,
    branch: branch,
    head_sha: head_sha,
    workflows: workflows,
    total: total
  )
  puts "Ensuring GitHub Actions workflows pass on #{branch} (#{owner}/#{repo}) via remote '#{gh_remote}'"
  puts "Waiting for GitHub Actions runs to start for HEAD #{head_sha[0, 12]}."
  emit_ci_monitor_event(
    event_recorder,
    action: "github_wait",
    status: "started",
    provider: "github",
    branch: branch,
    head_sha: head_sha,
    completed: 0,
    total: total
  )
  pbar = if defined?(ProgressBar)
    ProgressBar.create(title: "CI", total: total, format: "%t %b %c/%C", length: 30)
  end
  # Small initial delay to allow GitHub to register the newly pushed commit and enqueue workflows.
  # Configurable via K_RELEASE_CI_INITIAL_SLEEP (seconds); defaults to 3s.

  initial_sleep = begin
    Integer(ENV["K_RELEASE_CI_INITIAL_SLEEP"])
  rescue
    nil
  end

  sleep((initial_sleep && initial_sleep >= 0) ? initial_sleep : 3)
  start_timeout = github_start_timeout
  poll_interval = github_poll_interval
  start_deadline = monotonic_time + start_timeout
  keepalive_timer = keepalive_timer(keepalive)
  idx = 0
  all_started_emitted = false
  loop do
    keepalive_timer.call
    wf = workflows[idx]
    run = Kettle::Dev::CIHelpers.latest_run(owner: owner, repo: repo, workflow_file: wf, branch: branch, require_head: true, head_sha: head_sha)
    completed_workflow = nil
    if run
      unless started[wf]
        started[wf] = true
        emit_ci_monitor_event(
          event_recorder,
          action: "github_workflow",
          status: "started",
          provider: "github",
          workflow: wf,
          url: run["html_url"],
          run_status: run["status"],
          conclusion: run["conclusion"],
          completed: passed.size,
          total: total
        )
      end
      if started.size == total && !all_started_emitted
        all_started_emitted = true
        emit_ci_monitor_event(
          event_recorder,
          action: "github_started",
          status: "ok",
          provider: "github",
          completed: passed.size,
          total: total,
          started: started.size
        )
      end
      if Kettle::Dev::CIHelpers.success?(run)
        unless passed[wf]
          passed[wf] = true
          completed_workflow = wf
          pbar&.increment
          emit_ci_monitor_event(
            event_recorder,
            action: "github_workflow",
            status: "ok",
            provider: "github",
            workflow: wf,
            url: run["html_url"],
            run_status: run["status"],
            conclusion: run["conclusion"],
            completed: passed.size,
            total: total
          )
        end
      elsif Kettle::Dev::CIHelpers.failed?(run)
        puts
        wf_url = run["html_url"] || "https://github.com/#{owner}/#{repo}/actions/workflows/#{wf}"
        emit_ci_monitor_event(
          event_recorder,
          action: "github_workflow",
          status: "failed",
          provider: "github",
          workflow: wf,
          url: wf_url,
          run_status: run["status"],
          conclusion: run["conclusion"],
          completed: passed.size,
          total: total,
          reason: "Workflow failed"
        )
        abort("Workflow failed: #{wf} -> #{wf_url} Fix the workflow, then restart this tool from CI validation with: #{restart_hint}")
      end
    end
    emit_ci_monitor_event(
      event_recorder,
      action: "github_tick",
      status: "started",
      provider: "github",
      workflow: wf,
      run_status: run && run["status"],
      conclusion: run && run["conclusion"],
      completed_workflow: completed_workflow,
      completed: passed.size,
      total: total,
      started: started.size
    )
    break if passed.size == total
    if started.size < total && monotonic_time >= start_deadline
      missing = (workflows - started.keys).join(", ")
      puts
      emit_ci_monitor_event(
        event_recorder,
        action: "github_timeout",
        status: "failed",
        provider: "github",
        missing: workflows - started.keys,
        head_sha: head_sha,
        total: total,
        completed: passed.size,
        reason: "Timed out waiting for workflows to start"
      )
      abort("Timed out after #{start_timeout}s waiting for GitHub Actions workflows to start for HEAD #{head_sha[0, 12]}: #{missing}. Confirm GitHub Actions started, then restart this tool from CI validation with: #{restart_hint}")
    end

    idx = (idx + 1) % total
    sleep(poll_interval)
  end
  pbar&.finish unless pbar&.finished?
  emit_ci_monitor_event(
    event_recorder,
    action: "github_complete",
    status: "ok",
    provider: "github",
    workflows: workflows,
    completed: passed.size,
    total: total
  )
  puts "\nAll GitHub workflows passing (#{passed.size}/#{total})."
  true
end

.monitor_gitlab!(restart_hint: "bundle exec kettle-release start_step=10") ⇒ Boolean

Public wrapper to monitor GitLab pipeline with abort-on-failure semantics. Matches RBS and call sites expecting ::monitor_gitlab! Returns false when GitLab is not configured for this repo/branch.

Parameters:

  • restart_hint (String) (defaults to: "bundle exec kettle-release start_step=10")
  • restart_hint: (String) (defaults to: "bundle exec kettle-release start_step=10")

Returns:

  • (Boolean)


63
64
65
# File 'lib/kettle/dev/ci_monitor.rb', line 63

def monitor_gitlab!(restart_hint: "bundle exec kettle-release start_step=10")
  monitor_gitlab_internal!(restart_hint: restart_hint)
end

.monitor_gitlab_internal!(restart_hint:, keepalive: nil, event_recorder: nil) ⇒ Object



505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
# File 'lib/kettle/dev/ci_monitor.rb', line 505

def monitor_gitlab_internal!(restart_hint:, keepalive: nil, event_recorder: nil)
  root = Kettle::Dev::CIHelpers.project_root
  gitlab_ci = File.exist?(File.join(root, ".gitlab-ci.yml"))
  gl_remote = gitlab_remote_candidates.first
  return false unless gitlab_ci && gl_remote

  branch = Kettle::Dev::CIHelpers.current_branch
  abort("Could not determine current branch for CI checks.") unless branch

  owner, repo = Kettle::Dev::CIHelpers.repo_info_gitlab
  return false unless owner && repo

  emit_ci_monitor_event(
    event_recorder,
    action: "gitlab_discover",
    status: "started",
    provider: "gitlab",
    remote: gl_remote,
    owner: owner,
    repo: repo,
    branch: branch,
    total: 1
  )
  puts "Ensuring GitLab pipeline passes on #{branch} (#{owner}/#{repo}) via remote '#{gl_remote}'"
  pbar = if defined?(ProgressBar)
    ProgressBar.create(title: "CI", total: 1, format: "%t %b %c/%C", length: 30)
  end
  keepalive_timer = keepalive_timer(keepalive)
  loop do
    keepalive_timer.call
    pipe = Kettle::Dev::CIHelpers.gitlab_latest_pipeline(owner: owner, repo: repo, branch: branch)
    if pipe
      pipe_url = pipe["web_url"] || "https://gitlab.com/#{owner}/#{repo}/-/pipelines"
      if Kettle::Dev::CIHelpers.gitlab_success?(pipe)
        pbar&.increment unless pbar&.finished?
        emit_ci_monitor_event(
          event_recorder,
          action: "gitlab_pipeline",
          status: "ok",
          provider: "gitlab",
          url: pipe_url,
          run_status: pipe["status"],
          completed: 1,
          total: 1
        )
        break
      elsif Kettle::Dev::CIHelpers.gitlab_failed?(pipe)
        # Special-case: if failure is due to exhausted minutes/insufficient quota, treat as unknown and continue
        reason = (pipe["failure_reason"] || "").to_s
        if /insufficient|quota|minute/i.match?(reason)
          puts "\nGitLab reports pipeline cannot run due to quota/minutes exhaustion. Result is unknown; continuing."
          pbar&.finish unless pbar&.finished?
          emit_ci_monitor_event(
            event_recorder,
            action: "gitlab_pipeline",
            status: "skipped",
            provider: "gitlab",
            url: pipe_url,
            run_status: pipe["status"],
            reason: reason,
            completed: 0,
            total: 1
          )
          break
        else
          puts
          emit_ci_monitor_event(
            event_recorder,
            action: "gitlab_pipeline",
            status: "failed",
            provider: "gitlab",
            url: pipe_url,
            run_status: pipe["status"],
            reason: reason,
            completed: 0,
            total: 1
          )
          url = pipe_url
          abort("Pipeline failed: #{url} Fix the pipeline, then restart this tool from CI validation with: #{restart_hint}")
        end
      elsif pipe["status"] == "blocked"
        # Blocked pipeline (e.g., awaiting approvals) — treat as unknown and continue
        puts "\nGitLab pipeline is blocked. Result is unknown; continuing."
        pbar&.finish unless pbar&.finished?
        emit_ci_monitor_event(
          event_recorder,
          action: "gitlab_pipeline",
          status: "skipped",
          provider: "gitlab",
          url: pipe_url,
          run_status: pipe["status"],
          reason: "blocked",
          completed: 0,
          total: 1
        )
        break
      end
    end
    sleep(1)
  end
  pbar&.finish unless pbar&.finished?
  emit_ci_monitor_event(
    event_recorder,
    action: "gitlab_complete",
    status: "ok",
    provider: "gitlab",
    completed: 1,
    total: 1
  )
  puts "\nGitLab pipeline passing."
  true
end

.monotonic_timeFloat

Returns:

  • (Float)


455
456
457
# File 'lib/kettle/dev/ci_monitor.rb', line 455

def monotonic_time
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
end

.parse_github_owner_repo(url) ⇒ Object



677
678
679
# File 'lib/kettle/dev/ci_monitor.rb', line 677

def parse_github_owner_repo(url)
  Kettle::Dev::CIHelpers.parse_hosted_repo(url, "github.com") || [nil, nil]
end

.preferred_github_remoteObject



665
666
667
668
669
670
671
672
673
674
# File 'lib/kettle/dev/ci_monitor.rb', line 665

def preferred_github_remote
  cands = github_remote_candidates
  return if cands.empty?

  explicit = cands.find { |n| n == "github" } || cands.find { |n| n == "gh" }
  return explicit if explicit
  return "origin" if cands.include?("origin")

  cands.first
end

.remote_url(name) ⇒ Object



650
651
652
# File 'lib/kettle/dev/ci_monitor.rb', line 650

def remote_url(name)
  Kettle::Dev::GitAdapter.new.remote_url(name)
end

.remotes_with_urlsObject

-- tiny wrappers around GitAdapter-like helpers used by ReleaseCLI --



645
646
647
# File 'lib/kettle/dev/ci_monitor.rb', line 645

def remotes_with_urls
  Kettle::Dev::GitAdapter.new.remotes_with_urls
end

.status_emoji(status, conclusion) ⇒ String

Small helper to map CI run status/conclusion to an emoji. Reused by ci:act and release summary.

Parameters:

  • status (String, nil)
  • conclusion (String, nil)

Returns:

  • (String)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/kettle/dev/ci_monitor.rb', line 30

def status_emoji(status, conclusion)
  case status.to_s
  when "queued" then "⏳️"
  when "in_progress", "running" then "👟"
  when "completed"
    (conclusion.to_s == "success") ? "" : "🍅"
  else
    # Some APIs report only a final state string like "success"/"failed"
    return "" if conclusion.to_s == "success" || status.to_s == "success"
    return "🍅" if conclusion.to_s == "failure" || status.to_s == "failed"

    "⏳️"
  end
end

.summarize_results(results) ⇒ Boolean

Print a concise summary like ci:act and return whether everything is green.

Parameters:

  • results (Hash)
  • ({ github: Array[untyped], gitlab: untyped? })

Returns:

  • (Boolean)

    true when all checks passed or were unknown, false when any failed



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/kettle/dev/ci_monitor.rb', line 98

def summarize_results(results)
  all_ok = true
  gh_items = results[:github] || []
  unless gh_items.empty?
    puts "GitHub Actions:"
    gh_items.each do |item|
      emoji = status_emoji(item[:status], item[:conclusion])
      details = [item[:status], item[:conclusion]].compact.join("/")
      wf = item[:workflow]
      puts "  - #{wf}: #{emoji} (#{details}) #{"-> #{item[:url]}" if item[:url]}"
      all_ok &&= (item[:conclusion] == "success")
    end
  end
  gl = results[:gitlab]
  if gl
    status = if gl[:status] == "success"
      "success"
    else
      ((gl[:status] == "failed") ? "failure" : nil)
    end
    emoji = status_emoji(gl[:status], status)
    details = gl[:status].to_s
    puts "GitLab Pipeline: #{emoji} (#{details}) #{"-> #{gl[:url]}" if gl[:url]}"
    all_ok &&= (gl[:status] != "failed")
  end
  all_ok
end