diff --git a/Cargo.toml b/Cargo.toml index 6d09ea9..11b95fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "amp-common" description = "Rust libraries shared across Amphitheatre components and libraries" -version = "0.7.4" +version = "0.7.5" edition = "2021" license = "Apache-2.0" homepage = "https://amphitheatre.app" diff --git a/src/scm/driver/github/git.rs b/src/scm/driver/github/git.rs index 97dba69..e8a2e73 100644 --- a/src/scm/driver/github/git.rs +++ b/src/scm/driver/github/git.rs @@ -20,7 +20,7 @@ use super::utils::convert_list_options; use super::GithubFile; use crate::http::{Client, Endpoint}; use crate::scm::client::ListOptions; -use crate::scm::git::{Commit, GitService, Reference, Signature, Tree}; +use crate::scm::git::{Commit, GitService, Reference, Signature, Tree, TreeEntry}; use crate::scm::utils; pub struct GithubGitService { @@ -35,7 +35,7 @@ impl GitService for GithubGitService { fn list_branches(&self, repo: &str, opts: ListOptions) -> anyhow::Result> { let path = GITHUB_PATH_BRANCHES.replace("{repo}", repo); let options = Some(convert_list_options(opts)); - let res = self.client.get::(&path, options)?; + let res = self.client.get::(&path, options)?; if let Some(branches) = res.data { return Ok(branches.iter().map(|v| v.into()).collect()); @@ -51,7 +51,7 @@ impl GitService for GithubGitService { fn list_tags(&self, repo: &str, opts: ListOptions) -> anyhow::Result> { let path = GITHUB_PATH_TAGS.replace("{repo}", repo); let options = Some(convert_list_options(opts)); - let res = self.client.get::(&path, options)?; + let res = self.client.get::(&path, options)?; if let Some(tags) = res.data { return Ok(tags.iter().map(|v| v.into()).collect()); @@ -84,8 +84,9 @@ impl GitService for GithubGitService { let options = recursive .map(|r| Some(HashMap::from([("recursive".to_string(), r.to_string())]))) .unwrap_or_default(); - let res = self.client.get::(&path, options)?; - Ok(res.data) + let res = self.client.get::(&path, options)?; + + Ok(res.data.map(|v| v.into())) } } @@ -166,9 +167,9 @@ pub struct GithubAuthor { pub login: String, } -struct GithubBranchsEndpoint; +struct GithubBranchesEndpoint; -impl Endpoint for GithubBranchsEndpoint { +impl Endpoint for GithubBranchesEndpoint { type Output = Vec; } @@ -178,8 +179,47 @@ impl Endpoint for GithubCommitEndpoint { type Output = GithubCommit; } -struct TreeResponseEndpoint; +#[derive(Debug, Deserialize, Serialize)] +pub struct GithubTree { + pub sha: String, + pub tree: Vec, + pub truncated: bool, +} + +impl From for Tree { + fn from(val: GithubTree) -> Self { + Self { + sha: val.sha, + tree: val.tree.iter().map(|v| v.into()).collect(), + truncated: val.truncated, + } + } +} + +#[derive(Debug, Deserialize, Serialize)] +pub struct GithubTreeEntry { + pub mode: String, + pub path: String, + pub sha: String, + #[serde(rename = "type")] + pub kind: String, + pub size: Option, +} + +impl From<&GithubTreeEntry> for TreeEntry { + fn from(val: &GithubTreeEntry) -> Self { + Self { + mode: val.mode.clone(), + path: val.path.clone(), + sha: val.sha.clone(), + kind: val.kind.clone(), + size: val.size, + } + } +} + +struct GithubTreeEndpoint; -impl Endpoint for TreeResponseEndpoint { - type Output = Tree; +impl Endpoint for GithubTreeEndpoint { + type Output = GithubTree; } diff --git a/src/scm/driver/gitlab/git.rs b/src/scm/driver/gitlab/git.rs index 106dd8c..79dc164 100644 --- a/src/scm/driver/gitlab/git.rs +++ b/src/scm/driver/gitlab/git.rs @@ -33,7 +33,7 @@ impl GitService for GitlabGitService { fn list_branches(&self, repo: &str, opts: ListOptions) -> anyhow::Result> { let path = GITLAB_PATH_BRANCHES.replace("{repo}", &encode(repo)); let options = Some(convert_list_options(opts)); - let res = self.client.get::(&path, options)?; + let res = self.client.get::(&path, options)?; if let Some(branches) = res.data { return Ok(branches.iter().map(|v| v.into()).collect()); @@ -49,7 +49,7 @@ impl GitService for GitlabGitService { fn list_tags(&self, repo: &str, opts: ListOptions) -> anyhow::Result> { let path = GITLAB_PATH_TAGS.replace("{repo}", &encode(repo)); let options = Some(convert_list_options(opts)); - let res = self.client.get::(&path, options)?; + let res = self.client.get::(&path, options)?; if let Some(tags) = res.data { return Ok(tags.iter().map(|v| v.into()).collect()); @@ -71,6 +71,7 @@ impl GitService for GitlabGitService { Ok(res.data.map(|v| v.into())) } + /// @TODO: Get a tree of a project. fn get_tree( &self, _repo: &str, @@ -97,9 +98,9 @@ impl From<&GitlabBranch> for Reference { } } -struct GitlabBranchsEndpoint; +struct GitlabBranchesEndpoint; -impl Endpoint for GitlabBranchsEndpoint { +impl Endpoint for GitlabBranchesEndpoint { type Output = Vec; } diff --git a/src/scm/git.rs b/src/scm/git.rs index 4b31880..31fe4d5 100644 --- a/src/scm/git.rs +++ b/src/scm/git.rs @@ -48,21 +48,18 @@ pub struct Signature { #[derive(Debug, Default, PartialEq, Serialize, Deserialize, ToSchema)] pub struct Tree { pub sha: String, - pub url: String, pub tree: Vec, pub truncated: bool, } #[derive(Debug, Default, PartialEq, Serialize, Deserialize, ToSchema)] pub struct TreeEntry { - pub path: String, pub mode: String, + pub path: String, + pub sha: String, #[serde(rename = "type")] - pub entry_type: String, + pub kind: String, pub size: Option, - // Some entries have a "size" field, but it might be absent - pub sha: String, - pub url: String, } /// Provides access to git resources. pub trait GitService {