Module: Carson::Runtime::Deliver

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

Instance Method Summary collapse

Instance Method Details

#deliver!(title: nil, body_file: nil, json_output: false) ⇒ Object

Entry point for ‘carson deliver`. Pushes the current branch, ensures a PR exists, records delivery state, and returns.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
# File 'lib/carson/runtime/deliver.rb', line 8

def deliver!( title: nil, body_file: nil, json_output: false )
	branch_name = current_branch
	main_branch = config.main_branch
	remote_name = config.git_remote
	result = { command: "deliver", branch: branch_name }

	if branch_name == main_branch
		result[ :error ] = "cannot deliver from #{main_branch}"
		result[ :recovery ] = "carson worktree create <name>"
		return deliver_finish( result: result, exit_code: EXIT_BLOCK, json_output: json_output )
	end

	sync_exit, sync_diagnostics = deliver_template_sync
	if sync_exit == EXIT_ERROR
		result[ :error ] = sync_diagnostics.to_s.strip.empty? ? "template sync failed" : sync_diagnostics.strip
		return deliver_finish( result: result, exit_code: sync_exit, json_output: json_output )
	end

	push_exit = push_branch!( branch: branch_name, remote: remote_name, result: result )
	return deliver_finish( result: result, exit_code: push_exit, json_output: json_output ) unless push_exit == EXIT_OK

	pr_number, pr_url = find_or_create_pr!(
		branch: branch_name,
		title: title,
		body_file: body_file,
		result: result
	)
	return deliver_finish( result: result, exit_code: EXIT_ERROR, json_output: json_output ) if pr_number.nil?

	branch = branch_record( name: branch_name )
	delivery = ledger.upsert_delivery(
		repository: repository_record,
		branch_name: branch.name,
		head: branch.head || current_head,
		worktree_path: branch.worktree || repo_root,
		authority: config.govern_authority,
		pr_number: pr_number,
		pr_url: pr_url,
		status: "preparing",
		summary: "delivery accepted",
		cause: nil
	)
	delivery = assess_delivery!( delivery: delivery, branch_name: branch.name )

	result[ :pr_number ] = pr_number
	result[ :pr_url ] = pr_url
	result[ :ci ] = check_pr_ci( number: pr_number ).to_s
	result[ :delivery ] = delivery_payload( delivery: delivery )
	result[ :summary ] = delivery.summary
	result[ :next_step ] = "carson status"

	deliver_finish( result: result, exit_code: EXIT_OK, json_output: json_output )
end