Skip to content

Commit 85076d1

Browse files
authored
Merge branch 'main' into ref/buck2
Signed-off-by: Aid_C <57825561+AidCheng@users.noreply.github.com>
2 parents 11ef287 + 71a8bd6 commit 85076d1

32 files changed

Lines changed: 1084 additions & 269 deletions

File tree

ceres/src/api_service/mono_api_service.rs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,37 +1160,23 @@ impl MonoApiService {
11601160
}
11611161
}
11621162

1163-
/// Triggers a build for the specified Change List (CL).
1164-
/// It spawns a background task to handle the build process, ensuring that the main application flow remains responsive.
1165-
/// # Arguments
1166-
/// * `cl_link` - The unique identifier (link) of the CL for which the build is to be triggered.
1163+
/// Triggers a build for the specified CL in a background task.
11671164
///
1168-
/// # Returns
1169-
/// A `Result` indicating success or failure. Returns `Ok(())` if the build was successfully triggered,
1170-
/// or a `GitError` if an error occurred during the process.
1165+
/// This is a best-effort operation: the build runs asynchronously to keep the API responsive,
1166+
/// and any failures are logged but do not propagate to the caller.
11711167
async fn trigger_build_for_cl(&self, cl_link: &str) -> Result<(), GitError> {
11721168
let config = self.storage.config();
1173-
let bellatrix = Bellatrix::new(config.build.clone());
1174-
let cl = self
1175-
.storage
1176-
.cl_storage()
1177-
.get_cl(cl_link)
1178-
.await
1179-
.map_err(|e| GitError::CustomError(format!("Failed to get CL: {}", e)))?
1180-
.ok_or_else(|| GitError::CustomError("CL not found".to_string()))?;
1181-
1169+
let bellatrix = Arc::new(Bellatrix::new(config.build.clone()));
11821170
let storage = self.storage.clone();
11831171
let git_cache = self.git_object_cache.clone();
1172+
let cl_link = cl_link.to_string();
11841173

11851174
// Spawn a background task to handle the build process
11861175
tokio::spawn(async move {
1187-
let _ = BuildTriggerService::build_by_context(
1188-
storage,
1189-
git_cache,
1190-
Arc::new(bellatrix),
1191-
cl.into(),
1192-
)
1193-
.await;
1176+
let service = BuildTriggerService::new(storage, git_cache, bellatrix);
1177+
if let Err(e) = service.trigger_for_cl(&cl_link).await {
1178+
tracing::warn!("Build trigger failed for CL {}: {}", cl_link, e);
1179+
}
11941180
});
11951181

11961182
Ok(())

ceres/src/build_trigger/dispatcher.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ impl BuildDispatcher {
3636
BuildTriggerPayload::Webhook(p) => (&p.cl_link, &p.repo, &p.builds, p.cl_id),
3737
BuildTriggerPayload::Schedule(p) => (&p.cl_link, &p.repo, &p.builds, p.cl_id),
3838
BuildTriggerPayload::WebEdit(p) => (&p.cl_link, &p.repo, &p.builds, p.cl_id),
39+
BuildTriggerPayload::BuckFileUpload(p) => (&p.cl_link, &p.repo, &p.builds, p.cl_id),
3940
};
4041

4142
let builds: Vec<SerializableBuildInfo> = serde_json::from_value(builds_json.clone())

ceres/src/build_trigger/model.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub enum BuildTriggerType {
1414
Webhook,
1515
Schedule,
1616
WebEdit,
17+
BuckFileUpload,
1718
}
1819

1920
impl fmt::Display for BuildTriggerType {
@@ -25,6 +26,7 @@ impl fmt::Display for BuildTriggerType {
2526
BuildTriggerType::Webhook => "webhook",
2627
BuildTriggerType::Schedule => "schedule",
2728
BuildTriggerType::WebEdit => "webedit",
29+
BuildTriggerType::BuckFileUpload => "buck_file_upload",
2830
};
2931
write!(f, "{}", s)
3032
}
@@ -160,6 +162,26 @@ pub struct WebEditPayload {
160162
pub triggered_by: Option<String>,
161163
}
162164

165+
/// Payload for Buck file upload trigger
166+
#[derive(Debug, Clone, Serialize, Deserialize)]
167+
pub struct BuckFileUploadPayload {
168+
pub repo: String,
169+
pub from_hash: String,
170+
pub commit_hash: String,
171+
pub cl_link: String,
172+
#[serde(skip_serializing_if = "Option::is_none")]
173+
pub cl_id: Option<i64>,
174+
pub builds: serde_json::Value,
175+
#[serde(skip_serializing_if = "Option::is_none")]
176+
pub triggered_by: Option<String>,
177+
/// Target branch name; always "main" for current single-branch upload flow
178+
#[serde(skip_serializing_if = "Option::is_none")]
179+
pub ref_name: Option<String>,
180+
/// Ref type for display; always "branch" for current flow
181+
#[serde(skip_serializing_if = "Option::is_none")]
182+
pub ref_type: Option<String>,
183+
}
184+
163185
/// Trigger payload - stores context specific to each trigger type
164186
/// This enum is serialized to JSON and stored in database's trigger_payload column
165187
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -171,6 +193,7 @@ pub enum BuildTriggerPayload {
171193
Webhook(WebhookPayload),
172194
Schedule(SchedulePayload),
173195
WebEdit(WebEditPayload),
196+
BuckFileUpload(BuckFileUploadPayload),
174197
}
175198

176199
impl BuildTriggerPayload {
@@ -182,6 +205,7 @@ impl BuildTriggerPayload {
182205
BuildTriggerPayload::Webhook(p) => &p.repo,
183206
BuildTriggerPayload::Schedule(p) => &p.repo,
184207
BuildTriggerPayload::WebEdit(p) => &p.repo,
208+
BuildTriggerPayload::BuckFileUpload(p) => &p.repo,
185209
}
186210
}
187211

@@ -193,6 +217,7 @@ impl BuildTriggerPayload {
193217
BuildTriggerPayload::Webhook(p) => &p.commit_hash,
194218
BuildTriggerPayload::Schedule(p) => &p.commit_hash,
195219
BuildTriggerPayload::WebEdit(p) => &p.commit_hash,
220+
BuildTriggerPayload::BuckFileUpload(p) => &p.commit_hash,
196221
}
197222
}
198223

@@ -204,6 +229,7 @@ impl BuildTriggerPayload {
204229
BuildTriggerPayload::Webhook(p) => &p.cl_link,
205230
BuildTriggerPayload::Schedule(p) => &p.cl_link,
206231
BuildTriggerPayload::WebEdit(p) => &p.cl_link,
232+
BuildTriggerPayload::BuckFileUpload(p) => &p.cl_link,
207233
}
208234
}
209235

@@ -215,6 +241,7 @@ impl BuildTriggerPayload {
215241
BuildTriggerPayload::Webhook(p) => p.cl_id,
216242
BuildTriggerPayload::Schedule(p) => p.cl_id,
217243
BuildTriggerPayload::WebEdit(p) => p.cl_id,
244+
BuildTriggerPayload::BuckFileUpload(p) => p.cl_id,
218245
}
219246
}
220247

@@ -226,6 +253,7 @@ impl BuildTriggerPayload {
226253
BuildTriggerPayload::Webhook(_) => None,
227254
BuildTriggerPayload::Schedule(_) => None,
228255
BuildTriggerPayload::WebEdit(p) => p.triggered_by.as_deref(),
256+
BuildTriggerPayload::BuckFileUpload(p) => p.triggered_by.as_deref(),
229257
}
230258
}
231259

@@ -237,6 +265,7 @@ impl BuildTriggerPayload {
237265
BuildTriggerPayload::Webhook(_) => "",
238266
BuildTriggerPayload::Schedule(_) => "",
239267
BuildTriggerPayload::WebEdit(p) => &p.from_hash,
268+
BuildTriggerPayload::BuckFileUpload(p) => &p.from_hash,
240269
}
241270
}
242271
}
@@ -373,6 +402,36 @@ impl TriggerContext {
373402
ref_type: None,
374403
}
375404
}
405+
406+
/// Build context for Buck file upload trigger.
407+
/// Caller should set context.ref_name and context.ref_type after construction (same as Manual).
408+
pub fn from_buck_upload(
409+
repo_path: String,
410+
from_hash: String,
411+
commit_hash: String,
412+
cl_link: String,
413+
cl_id: Option<i64>,
414+
triggered_by: Option<String>,
415+
) -> Self {
416+
Self {
417+
trigger_type: BuildTriggerType::BuckFileUpload,
418+
trigger_source: if triggered_by.is_some() {
419+
TriggerSource::User
420+
} else {
421+
TriggerSource::System
422+
},
423+
triggered_by,
424+
repo_path,
425+
from_hash,
426+
commit_hash,
427+
cl_link: Some(cl_link),
428+
cl_id,
429+
params: None,
430+
original_trigger_id: None,
431+
ref_name: None,
432+
ref_type: None,
433+
}
434+
}
376435
}
377436

378437
impl From<mega_cl::Model> for TriggerContext {
@@ -458,6 +517,9 @@ impl TriggerResponse {
458517
p.ref_type.clone(),
459518
),
460519
BuildTriggerPayload::Webhook(p) => (p.raw_payload.clone(), None, None, None),
520+
BuildTriggerPayload::BuckFileUpload(p) => {
521+
(None, None, p.ref_name.clone(), p.ref_type.clone())
522+
}
461523
_ => (None, None, None, None),
462524
};
463525

0 commit comments

Comments
 (0)