-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move pipeline export to pipeline project
- Loading branch information
Showing
3 changed files
with
67 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,63 @@ | ||
use jenkinsfile::Jenkinsfile; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// common pipeline visualize model | ||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
pub struct Pipeline {} | ||
pub struct Pipeline { | ||
pub name: String, | ||
pub stages: Vec<PipelineStage>, | ||
} | ||
|
||
impl Pipeline { | ||
pub fn from(jenkinsfile: Jenkinsfile) -> Pipeline { | ||
let mut pipeline = Pipeline { | ||
name: jenkinsfile.name, | ||
stages: vec![], | ||
}; | ||
|
||
for main_stage in &jenkinsfile.stages { | ||
let mut stage = PipelineStage::new(main_stage.name.clone()); | ||
for sub_stage in &main_stage.sub_stages { | ||
stage.sub_stages.push(PipelineStage { | ||
name: sub_stage.name.clone(), | ||
steps: sub_stage.steps.clone(), | ||
is_parallel: false, | ||
sub_stages: vec![], | ||
}) | ||
} | ||
|
||
pipeline.stages.push(stage); | ||
} | ||
|
||
pipeline | ||
} | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
pub struct PipelineStage { | ||
pub name: String, | ||
pub steps: Vec<String>, | ||
pub is_parallel: bool, | ||
pub sub_stages: Vec<PipelineStage>, | ||
} | ||
|
||
impl PipelineStage { | ||
pub fn new(name: String) -> PipelineStage { | ||
Self { | ||
name, | ||
steps: vec![], | ||
is_parallel: false, | ||
sub_stages: vec![], | ||
} | ||
} | ||
} | ||
|
||
impl Default for PipelineStage { | ||
fn default() -> Self { | ||
Self { | ||
name: "".to_string(), | ||
steps: vec![], | ||
is_parallel: false, | ||
sub_stages: vec![], | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters