|
2 | 2 |
|
3 | 3 | use anyhow::{Context, Result, anyhow, bail}; |
4 | 4 | use cigen::plugin::protocol::{ |
5 | | - self, CigenSchema, CommandDefinition, CommandParameter, CustomStep, Fragment, GenerateRequest, |
| 5 | + CigenSchema, CommandDefinition, CommandParameter, CustomStep, Fragment, GenerateRequest, |
6 | 6 | GenerateResult, Hello, JobDefinition, PlanRequest, PlanResult, PluginInfo, RunStep, Step, |
7 | 7 | UsesStep, WorkflowCondition as ProtoWorkflowCondition, |
8 | 8 | WorkflowConditionKind as ProtoWorkflowConditionKind, |
9 | 9 | }; |
10 | | -use cigen::schema::WorkflowConfig; |
11 | 10 | use serde_yaml::{Mapping, Value}; |
12 | 11 | use std::collections::HashMap; |
13 | 12 | use std::convert::TryFrom; |
@@ -334,7 +333,7 @@ fn generate_setup_config(context: &CircleciContext) -> Result<Value> { |
334 | 333 | grouped_jobs.entry(wf.to_string()).or_default().push(job); |
335 | 334 | } |
336 | 335 |
|
337 | | - for (wf_id, _) in &grouped_jobs { |
| 336 | + for wf_id in grouped_jobs.keys() { |
338 | 337 | let variants = collect_job_variants_for_workflow(context, wf_id)?; |
339 | 338 | all_variants.extend(variants); |
340 | 339 | } |
@@ -399,7 +398,7 @@ fn generate_main_config(context: &CircleciContext) -> Result<Value> { |
399 | 398 | let mut all_variants = Vec::new(); |
400 | 399 | let mut workflow_variants_map: HashMap<String, Vec<JobVariant>> = HashMap::new(); |
401 | 400 |
|
402 | | - for (wf_id, _) in &grouped_jobs { |
| 401 | + for wf_id in grouped_jobs.keys() { |
403 | 402 | let variants = collect_job_variants_for_workflow(context, wf_id)?; |
404 | 403 | workflow_variants_map.insert(wf_id.clone(), variants.clone()); |
405 | 404 | all_variants.extend(variants); |
@@ -465,10 +464,10 @@ fn build_workflow_def( |
465 | 464 | ) -> Result<Value> { |
466 | 465 | let mut workflow_map = Mapping::new(); |
467 | 466 |
|
468 | | - if let Some(conditions) = context.workflow_conditions.get(workflow_id) { |
469 | | - if let Some(when_value) = build_circleci_when(conditions)? { |
470 | | - workflow_map.insert(Value::String("when".into()), when_value); |
471 | | - } |
| 467 | + if let Some(conditions) = context.workflow_conditions.get(workflow_id) |
| 468 | + && let Some(when_value) = build_circleci_when(conditions)? |
| 469 | + { |
| 470 | + workflow_map.insert(Value::String("when".into()), when_value); |
472 | 471 | } |
473 | 472 |
|
474 | 473 | workflow_map.insert( |
@@ -543,12 +542,11 @@ fn convert_job(variant: &JobVariant, context: &CircleciContext) -> Result<Option |
543 | 542 | let job = variant.job; |
544 | 543 |
|
545 | 544 | // Skip approval jobs in definition list (they only appear in workflows) |
546 | | - if let Some(extra_type) = job.extra.get("type") { |
547 | | - if let Ok(val) = parse_yaml_value(extra_type) { |
548 | | - if val.as_str() == Some("approval") { |
549 | | - return Ok(None); |
550 | | - } |
551 | | - } |
| 545 | + if let Some(extra_type) = job.extra.get("type") |
| 546 | + && let Ok(val) = parse_yaml_value(extra_type) |
| 547 | + && val.as_str() == Some("approval") |
| 548 | + { |
| 549 | + return Ok(None); |
552 | 550 | } |
553 | 551 |
|
554 | 552 | let mut map = Mapping::new(); |
@@ -638,12 +636,6 @@ fn convert_job(variant: &JobVariant, context: &CircleciContext) -> Result<Option |
638 | 636 | Ok(Some(Value::Mapping(map))) |
639 | 637 | } |
640 | 638 |
|
641 | | -// ... (rest of the file: helper functions build_checkout_invocation, etc. - copied from original, no substitution logic) |
642 | | - |
643 | | -fn sanitize_job_name(name: &str) -> String { |
644 | | - name.replace(['/', '\\'], "_") |
645 | | -} |
646 | | - |
647 | 639 | fn convert_steps_list(steps: &[Step]) -> Result<Vec<Value>> { |
648 | 640 | let mut converted = Vec::new(); |
649 | 641 | for step in steps { |
@@ -1579,14 +1571,6 @@ fn extract_checkout_config(raw_config: &Value) -> CheckoutConfig { |
1579 | 1571 | config |
1580 | 1572 | } |
1581 | 1573 |
|
1582 | | -fn extract_mapping(raw_config: &Value, key: &str) -> Option<Mapping> { |
1583 | | - raw_config |
1584 | | - .as_mapping() |
1585 | | - .and_then(|map| map.get(&Value::String(key.into()))) |
1586 | | - .and_then(Value::as_mapping) |
1587 | | - .cloned() |
1588 | | -} |
1589 | | - |
1590 | 1574 | fn build_circleci_when(conditions: &[WorkflowRunCondition]) -> Result<Option<Value>> { |
1591 | 1575 | let mut clauses = Vec::new(); |
1592 | 1576 |
|
|
0 commit comments