Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
🚧 depth 1 of jenkins api for richer types
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed May 17, 2018
1 parent 739ebda commit 4f2d0db
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/action/maven.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ pub struct Artifact {
/// Version
pub version: String,
}
impl Default for Artifact {
fn default() -> Self {
unimplemented!()
}
}

/// Short Maven Artifact Record that is returned when getting a maven build
#[derive(Deserialize, Debug)]
Expand Down
35 changes: 34 additions & 1 deletion src/action/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,26 @@ tagged_enum_or_default!(
},
/// An action from pipelines
FlowGraphAction (_class = "org.jenkinsci.plugins.workflow.job.views.FlowGraphAction" ) {
/// Nodes of the pipeline
nodes: Vec<PipelineNode>,
},
/// An action with maven artifacts
MavenArtifactRecord (_class = "hudson.maven.reporters.MavenArtifactRecord" ) {
/// URL to the artifacts
url: String,
/// List of the artifacts
attached_artifacts: Vec<maven::Artifact>,
/// Main artifact
main_artifact: maven::Artifact,
/// Parent build
parent: ::build::ShortBuild,
/// POM artifact
pom_artifact: maven::Artifact,
},
/// An action with maven artifacts
MavenAggregatedArtifactRecord (_class = "hudson.maven.reporters.MavenAggregatedArtifactRecord" ) {
/// List of artifact records
module_records: Vec<maven::MavenArtifactRecord>,
},
/// An action with a surefire test report
SurefireReport (_class = "hudson.maven.reporters.SurefireReport" ) {
Expand All @@ -77,6 +89,27 @@ tagged_enum_or_default!(
total_count: u32,
/// URL to the report
url_name: String,
}
},
/// An action marking an approval on a pipeline
PipelineApproverAction (_class = "org.jenkinsci.plugins.workflow.support.steps.input.ApproverAction" ) {
/// User ID
user_id: String,
},
}
);

tagged_enum_or_default!(
/// A node of a pipeline
pub enum PipelineNode {
/// Beginning of a flow
FlowStartNode (_class = "org.jenkinsci.plugins.workflow.graph.FlowStartNode") {},
/// Beginning of a step
StepStartNode (_class = "org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode") {},
/// A step
StepAtomNode (_class = "org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode") {},
/// End of a step
StepEndNode (_class = "org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode") {},
/// End of a flow
FlowEndNode (_class = "org.jenkinsci.plugins.workflow.graph.FlowEndNode") {},
}
);
8 changes: 8 additions & 0 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ impl ShortBuild {
}
}
}
impl Default for ShortBuild {
fn default() -> Self {
ShortBuild {
url: "".to_string(),
number: 0,
}
}
}

/// Status of a build
#[derive(Debug, Deserialize, Clone, Copy, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion src/client/csrf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ mod tests {
fn get_invalid_crumb() {
let jenkins_client = ::JenkinsBuilder::new(JENKINS_URL).build().unwrap();

let _mock = mockito::mock("GET", "/crumbIssuer/api/json")
let _mock = mockito::mock("GET", "/crumbIssuer/api/json?depth=1")
.with_body(
r#"
{
Expand Down
3 changes: 1 addition & 2 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ impl Jenkins {
}

pub(crate) fn get(&self, path: &Path) -> Result<Response, failure::Error> {
let query = self.client.get(&self.url_api_json(&path.to_string()));
Ok(Self::error_for_status(self.send(query)?)?)
self.get_with_params(path, &[("depth", "1")])
}

pub(crate) fn get_with_params(
Expand Down
44 changes: 41 additions & 3 deletions src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,15 +452,25 @@ tagged_enum_or_default!(
/// An SCM
pub enum SCM {
/// No SCM
NullSCM (_class = "hudson.scm.NullSCM") {},
NullSCM (_class = "hudson.scm.NullSCM") {
/// Browser
browser: Option<Browser>,
},
/// Git SCM
GitSCM (_class = "hudson.plugins.git.GitSCM") {},
GitSCM (_class = "hudson.plugins.git.GitSCM") {
/// Browser
browser: Option<Browser>,
/// Merge options
merge_options: MergeOptions,
},
}
);

impl Default for SCM {
fn default() -> Self {
SCM::NullSCM {}
SCM::NullSCM {
browser: None,
}
}
}

Expand All @@ -475,3 +485,31 @@ tagged_enum_or_default!(
BuildDiscarderProperty (_class = "jenkins.model.BuildDiscarderProperty") {},
}
);

tagged_enum_or_default!(
/// A browser
pub enum Browser {
/// Github web browser
GithubWeb (_class = "hudson.plugins.git.browser.GithubWeb") {},
}
);

impl Default for Browser {
fn default() -> Self {
Browser::Unknown { class: None }
}
}

/// SCM merge options
#[derive(Default, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct MergeOptions {
/// Merge strategy
merge_strategy: String,
/// Fast forward mode
fast_forward_mode: String,
/// Merge target
merge_target: Option<String>,
/// Remote branch
remote_branch_name: Option<String>,
}
4 changes: 2 additions & 2 deletions tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn should_be_forbidden() {
assert_eq!(
format!("{:?}", response),
format!(
"Err(Error {{ kind: ClientError(Unauthorized), url: Some(\"{}/api/json\") }})",
"Err(Error {{ kind: ClientError(Unauthorized), url: Some(\"{}/api/json?depth=1\") }})",
JENKINS_URL
)
);
Expand Down Expand Up @@ -79,7 +79,7 @@ fn should_get_view_not_found() {
assert_eq!(
format!("{:?}", response),
format!(
"Err(Error {{ kind: ClientError(NotFound), url: Some(\"{}/view/zut/api/json\") }})",
"Err(Error {{ kind: ClientError(NotFound), url: Some(\"{}/view/zut/api/json?depth=1\") }})",
JENKINS_URL
)
);
Expand Down

0 comments on commit 4f2d0db

Please sign in to comment.