Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

Commit

Permalink
feat: show librad project repository (#86)
Browse files Browse the repository at this point in the history
To show the actual source tree we obtain the surf browser from the
respective librad project. It imposes in our ways we test and they show
their age now, the testing of the GraphQL API surface should be
reevaluated in due time.

* Attempt to use browser from librad project
* Bump librad
* Nuke test test case
* Bump librad
* Clone platinum per test case
* Fix tags test case
* Fix tests
  • Loading branch information
xla authored and rudolfs committed Mar 4, 2020
1 parent d1bda34 commit 17ab237
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 125 deletions.
6 changes: 3 additions & 3 deletions proxy/Cargo.lock

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

2 changes: 1 addition & 1 deletion proxy/Cargo.toml
Expand Up @@ -31,7 +31,7 @@ warp = "0.1"

[dependencies.librad]
git = "https://github.com/radicle-dev/radicle-link.git"
rev = "0aa3fe0895c3e1b0cceef98ab27bcf1b2a669744"
rev = "0034bd0fca27596b6fd2982ec875daa426ded120"

[dependencies.radicle-registry-client]
git = "https://github.com/radicle-dev/radicle-registry.git"
Expand Down
9 changes: 9 additions & 0 deletions proxy/src/schema/error.rs
Expand Up @@ -252,6 +252,15 @@ fn convert_librad_git(error: &librad::git::Error) -> FieldError {
}),
),
librad::git::Error::Surf(surf_error) => convert_git(surf_error),
librad::git::Error::MissingDefaultBranch(branch, _) => FieldError::new(
format!(
"Branch {} specified as default_branch does not exist in the source repo",
branch
),
graphql_value!({
"type": "LIBRAD_MISING_DEFAULT_BRANCH"
}),
),
}
}

Expand Down
27 changes: 24 additions & 3 deletions proxy/src/schema/git.rs
Expand Up @@ -2,6 +2,7 @@

use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use std::str::FromStr;

use librad::meta::common::Url;
use librad::paths::Paths;
Expand Down Expand Up @@ -126,8 +127,28 @@ pub struct TreeEntry {
pub path: String,
}

/// Given a project id to a repo returns the list of branches.
pub fn branches(librad_paths: &Paths, id: &str) -> Result<Vec<Branch>, Error> {
let project_id = librad::project::ProjectId::from_str(id)?;
let project = librad::project::Project::open(librad_paths, &project_id)?;
let browser = match project {
librad::project::Project::Git(git_project) => git_project.browser()?,
};

let mut branches = browser
.list_branches(None)
.expect("Getting branches failed")
.into_iter()
.map(|b| Branch(b.name.name()))
.collect::<Vec<Branch>>();

branches.sort();

Ok(branches)
}

/// Given a path to a repo returns the list of branches.
pub fn branches(repo_path: &str) -> Result<Vec<Branch>, Error> {
pub fn local_branches(repo_path: &str) -> Result<Vec<Branch>, Error> {
let repo = surf::git::Repository::new(repo_path)?;
let browser = surf::git::Browser::new(repo)?;
let mut branches = browser
Expand Down Expand Up @@ -200,7 +221,7 @@ pub fn setup_fixtures(librad_paths: &Paths, root: &str) -> Result<(), Error> {
(
"Monadic",
"Open source organization of amazing things.",
"stable",
"master",
"https://res.cloudinary.com/juliendonck/image/upload/v1549554598/monadic-icon_myhdjk.svg",
),
(
Expand All @@ -212,7 +233,7 @@ pub fn setup_fixtures(librad_paths: &Paths, root: &str) -> Result<(), Error> {
(
"radicle",
"Decentralized open source collaboration",
"dev",
"master",
"https://avatars0.githubusercontent.com/u/48290027",
),
];
Expand Down

0 comments on commit 17ab237

Please sign in to comment.