Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graph-builder: add plugin to fetch openshift/cincinnati-graph-data from github #226

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 44 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions cincinnati/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ impl Release {
Release::Concrete(release) => &release.version,
}
}

/// Get a mutable borrow of the release metadata if any
pub fn get_metadata_mut(&mut self) -> Option<&mut HashMap<String, String>> {
match self {
Release::Abstract(_) => None,
Release::Concrete(release) => Some(&mut release.metadata),
}
}
}

/// Type to represent a Release with all its information.
Expand Down
4 changes: 3 additions & 1 deletion graph-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ semver = { version = "^0.9.0", features = [ "serde" ] }
serde = "^1.0.70"
serde_derive = "^1.0.70"
serde_json = "^1.0.22"
serde_yaml = "^0.8.11"
smart-default = "^0.5.1"
structopt = "^0.2.10"
tar = "^0.4.16"
tokio = "0.2"
tokio = { version = "0.2.11", features = [ "fs", "stream" ] }
toml = "^0.4.10"
url = "^1.7.2"
parking_lot = "^0.8.0"
Expand All @@ -42,6 +43,7 @@ custom_debug_derive = "^0.1.7"
built = "^0.3.2"

[dev-dependencies]
walkdir = "2.3.1"
twoway = "^0.2"
assert-json-diff = "1.0.0"
test-case = "1.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//! This is a helper module for accessing the [GitHub API v3][].
//!
//! [GitHub API v3]: https://developer.github.com/v3/

/// Commit structure.
#[derive(Default, Clone, Debug, Deserialize, PartialEq, Eq)]
pub(crate) struct Commit {
pub(crate) sha: String,
pub(crate) url: String,
}

/// Branch structure.
#[derive(Debug, Deserialize, PartialEq, Eq)]
pub(crate) struct Branch {
pub(crate) name: String,
pub(crate) commit: Commit,
pub(crate) protected: bool,
}

/// Format the URL to request branch information.
pub(crate) fn branches_url(org: &str, repo: &str) -> String {
format!(
"https://api.github.com/repos/{org}/{repo}/branches",
org = &org,
repo = &repo,
)
}

/// Format the URL to request a tarball URL.
pub(crate) fn tarball_url(org: &str, repo: &str, commit: &Commit) -> String {
format!(
"https://api.github.com/repos/{org}/{repo}/tarball/{sha}",
org = org,
repo = repo,
sha = commit.sha,
)
}

/// Format a subdirectory name for a specific revision's tarball.
pub(crate) fn archive_entry_directory_name(org: &str, repo: &str, commit: &Commit) -> String {
format!("{}-{}-{}", &org, &repo, &commit.sha[0..7],)
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn de_serialize_branch() {
let json = r#"
[
{
"name": "master",
"commit": {
"sha": "fef06adb57b9d965bfc9ae0959bd038f3044207e",
"url": "https://api.github.com/repos/openshift/cincinnati-graph-data/commits/fef06adb57b9d965bfc9ae0959bd038f3044207e"
},
"protected": true
}
]
"#;

let branches = serde_json::from_str::<Vec<Branch>>(&json).unwrap();

let branches_expected = vec![Branch {
name: "master".to_string(),
commit: Commit {
sha: "fef06adb57b9d965bfc9ae0959bd038f3044207e".to_string(),
url: "https://api.github.com/repos/openshift/cincinnati-graph-data/commits/fef06adb57b9d965bfc9ae0959bd038f3044207e".to_string()
},
protected: true
}];

assert_eq!(branches_expected, branches);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! This plugin downloads repository content and extracts it to a given output directory.
//!
//! It is meant to be included in the plugin chain, preceding other plugins who
//! rely on the data being in the output directory.
//! The plugin will only download a tarball if detects a change of revision or on first run.

mod github_v3;
pub mod plugin;

pub use plugin::{
GithubOpenshiftSecondaryMetadataScraperPlugin, GithubOpenshiftSecondaryMetadataScraperSettings,
};
Loading