Module: Carson::Runtime::Govern

Included in:
Carson::Runtime
Defined in:
lib/carson/runtime/govern.rb

Constant Summary collapse

GOVERN_REPORT_MD =
"govern_latest.md".freeze
GOVERN_REPORT_JSON =
"govern_latest.json".freeze
TRIAGE_READY =
"ready".freeze
TRIAGE_CI_FAILING =
"ci_failing".freeze
TRIAGE_REVIEW_BLOCKED =
"review_blocked".freeze
TRIAGE_NEEDS_ATTENTION =
"needs_attention".freeze

Instance Method Summary collapse

Instance Method Details

#govern!(dry_run: false, json_output: false, loop_seconds: nil) ⇒ Object

Portfolio-level entry point. Scans configured repos (or current repo) and triages all open PRs. Returns EXIT_OK/EXIT_ERROR.



20
21
22
23
24
25
26
# File 'lib/carson/runtime/govern.rb', line 20

def govern!( dry_run: false, json_output: false, loop_seconds: nil )
	if loop_seconds
		govern_loop!( dry_run: dry_run, json_output: json_output, loop_seconds: loop_seconds )
	else
		govern_cycle!( dry_run: dry_run, json_output: json_output )
	end
end

#govern_cycle!(dry_run:, json_output:) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/carson/runtime/govern.rb', line 28

def govern_cycle!( dry_run:, json_output: )
	print_header "Carson Govern"
	repos = governed_repo_paths
	if repos.empty?
		puts_line "governing current repository: #{repo_root}"
		repos = [ repo_root ]
	else
		puts_line "governing #{repos.length} repo#{plural_suffix( count: repos.length )}"
	end

	portfolio_report = {
		cycle_at: Time.now.utc.iso8601,
		dry_run: dry_run,
		repos: []
	}

	repos.each do |repo_path|
		repo_report = govern_repo!( repo_path: repo_path, dry_run: dry_run )
		portfolio_report[ :repos ] << repo_report
	end

	write_govern_report( report: portfolio_report )

	if json_output
		puts_line JSON.pretty_generate( portfolio_report )
	else
		print_govern_summary( report: portfolio_report )
	end

	EXIT_OK
rescue StandardError => exception
	puts_line "ERROR: govern failed — #{exception.message}"
	EXIT_ERROR
end

#govern_loop!(dry_run:, json_output:, loop_seconds:) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/carson/runtime/govern.rb', line 63

def govern_loop!( dry_run:, json_output:, loop_seconds: )
	print_header "⧓ Carson Govern — loop mode (every #{loop_seconds}s)"
	cycle_count = 0
	loop do
		cycle_count += 1
		puts_line ""
		puts_line "── cycle #{cycle_count} at #{Time.now.utc.strftime( "%Y-%m-%d %H:%M:%S UTC" )} ──"
		begin
			govern_cycle!( dry_run: dry_run, json_output: json_output )
		rescue StandardError => exception
			puts_line "ERROR: cycle #{cycle_count} failed — #{exception.message}"
		end
		puts_line "sleeping #{loop_seconds}s until next cycle…"
		sleep loop_seconds
	end
rescue Interrupt
	puts_line ""
	puts_line "⧓ govern loop stopped after #{cycle_count} cycle#{plural_suffix( count: cycle_count )}."
	EXIT_OK
end