1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! Types related to maven

use serde::Deserialize;

use crate::client::{self, Result};
use crate::client_internals::path::Path;
use crate::Jenkins;

/// Artifact produced by a build
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Artifact {
    /// Artifact ID
    pub artifact_id: String,
    /// Canonical name
    pub canonical_name: String,
    /// Classifier (sources, javadoc, ...)
    pub classifier: Option<String>,
    /// File name
    pub file_name: String,
    /// Group ID
    pub group_id: String,
    /// MD5 checksum
    pub md5sum: String,
    /// Artifact type (jar, war, javadoc, java-source, ...)
    #[serde(rename = "type")]
    pub artifact_type: String,
    /// Version
    pub version: String,
}

/// Short Maven Artifact Record that is returned when getting a maven build
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ShortMavenArtifactRecord {
    /// URL to the full report
    pub url: String,
}
impl ShortMavenArtifactRecord {
    /// Get the full report of a `MavenArtifactRecord` matching the `ShortMavenArtifactRecord`
    pub fn get_full_artifact_record(
        &self,
        jenkins_client: &Jenkins,
    ) -> Result<MavenArtifactRecord> {
        let path = jenkins_client.url_to_path(&self.url);
        if let Path::MavenArtifactRecord { .. } = path {
            Ok(jenkins_client.get(&path)?.json()?)
        } else {
            Err(client::Error::InvalidUrl {
                url: self.url.clone(),
                expected: client::error::ExpectedType::MavenArtifactRecord,
            }
            .into())
        }
    }
}

/// Describe the artifacts produced by a build
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct MavenArtifactRecord {
    /// URL to this record
    pub url: String,
    /// List of the artifacts
    pub attached_artifacts: Vec<Artifact>,
    /// Main artifact
    pub main_artifact: Artifact,
    /// Parent build
    pub parent: crate::build::ShortBuild,
    /// POM artifact
    pub pom_artifact: Artifact,
}