Skip to main content

Vine/Server/Notification/
RegisterScmResourceGroup.rs

1//! Cocoon → `register_scm_resource_group` notification.
2//!
3//! Pairs with `RegisterScmProvider`. An SCM provider creates one or more
4//! resource groups (Git's "Changes", "Staged Changes", "Merge Changes").
5//! Two side effects:
6//! 1. `VineHost::UpdateSourceControlGroup` seeds the group with an empty
7//!    `resourceStates` list so subsequent `update_scm_group` calls find it.
8//! 2. `sky://scm/registerGroup` renderer event materialises the group header
9//!    row in the SCM viewlet.
10
11use serde_json::{Value, json};
12
13use crate::{Host::VineHost, dev_log};
14
15pub async fn RegisterScmResourceGroup(Host:&dyn VineHost, Parameter:&Value) {
16	let ScmHandle = Parameter
17		.get("scmHandle")
18		.or_else(|| Parameter.get("scm_handle"))
19		.and_then(Value::as_u64)
20		.unwrap_or(0) as u32;
21
22	let GroupHandleStr = Parameter
23		.get("groupHandle")
24		.or_else(|| Parameter.get("group_handle"))
25		.and_then(Value::as_str)
26		.unwrap_or("")
27		.to_string();
28
29	let GroupId = Parameter
30		.get("groupId")
31		.or_else(|| Parameter.get("group_id"))
32		.and_then(Value::as_str)
33		.unwrap_or("")
34		.to_string();
35
36	let Label = Parameter.get("label").and_then(Value::as_str).unwrap_or(&GroupId).to_string();
37
38	if GroupId.is_empty() {
39		dev_log!("provider-register", "[ProviderRegister] scm-group skip: missing group_id");
40
41		return;
42	}
43
44	// Field names match `SourceControlGroupUpdateDTO`'s camelCase wire shape.
45	let GroupData = json!({
46		"providerHandle": ScmHandle,
47		"groupId": &GroupId,
48		"label": &Label,
49		"resourceStates": [],
50	});
51
52	// Side effect 1 - seed group state (upsert on first call).
53	Host.UpdateSourceControlGroup(ScmHandle, GroupData).await;
54
55	// Side effect 2 - renderer materialises the group header row.
56	Host.EmitToRenderer(
57		"sky://scm/registerGroup",
58		json!({
59			"scmHandle": ScmHandle,
60			"groupHandle": &GroupHandleStr,
61			"groupId": &GroupId,
62			"label": &Label,
63		}),
64	);
65
66	dev_log!(
67		"grpc",
68		"[Scm] register group scm_handle={} group_id={} label={}",
69		ScmHandle,
70		GroupId,
71		Label
72	);
73}