Compare commits
No commits in common. "22a0b401c000414ffbb55eda4b2fe48f8555eda0" and "0202be19febfa7ce46c1137a18c37d0e2dfebfe7" have entirely different histories.
22a0b401c0
...
0202be19fe
8 changed files with 88 additions and 181 deletions
|
@ -1,9 +1,6 @@
|
||||||
pub mod branch;
|
pub mod branch;
|
||||||
mod file;
|
mod file;
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests;
|
|
||||||
|
|
||||||
use git_next_config as config;
|
use git_next_config as config;
|
||||||
use git_next_git as git;
|
use git_next_git as git;
|
||||||
|
|
||||||
|
|
|
@ -1,103 +0,0 @@
|
||||||
//
|
|
||||||
use assert2::let_assert;
|
|
||||||
use kxio::network::{MockNetwork, Network, StatusCode};
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
use crate as forgejo;
|
|
||||||
use git::ForgeLike as _;
|
|
||||||
use git_next_config as config;
|
|
||||||
use git_next_git as git;
|
|
||||||
|
|
||||||
mod branch {
|
|
||||||
use super::*;
|
|
||||||
mod get_all {
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn test_branches_get() {
|
|
||||||
let_assert!(Ok(fs) = kxio::fs::temp());
|
|
||||||
let mut net = MockNetwork::new();
|
|
||||||
//given
|
|
||||||
given_forgejo_has_branches(&mut net, 1);
|
|
||||||
let repo_details = given_repo_details(fs.base(), 1);
|
|
||||||
|
|
||||||
let net = Network::from(net);
|
|
||||||
let (repo, _reality) = git::repository::mock();
|
|
||||||
let forge = forgejo::ForgeJo::new(repo_details, net.clone(), repo);
|
|
||||||
|
|
||||||
//when
|
|
||||||
let_assert!(Ok(branches) = forge.branches_get_all().await);
|
|
||||||
|
|
||||||
//then
|
|
||||||
let_assert!(Some(requests) = net.mocked_requests());
|
|
||||||
assert_eq!(requests.len(), 1);
|
|
||||||
assert_eq!(branches, vec![config::BranchName::new("string")]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// mod validate_positions {
|
|
||||||
//
|
|
||||||
// use git::ForgeLike;
|
|
||||||
//
|
|
||||||
// use super::*;
|
|
||||||
//
|
|
||||||
// #[test]
|
|
||||||
// fn should_ok_all_branches_on_same_commit() {
|
|
||||||
// let_assert!(Ok(fs) = kxio::fs::temp());
|
|
||||||
// let mut net = MockNetwork::new();
|
|
||||||
// //given
|
|
||||||
// let repo_details = given_repo_details(fs.base(), 1);
|
|
||||||
// let net = Network::from(net);
|
|
||||||
// let (repo, _reality) = git::repository::mock();
|
|
||||||
// let forge = given_a_forge(repo_details, &net, repo);
|
|
||||||
// let open_repository = given_an_open_repository();
|
|
||||||
// let repo_config = given_a_repo_config();
|
|
||||||
//
|
|
||||||
// let forge = forgejo::ForgeJo::new(repo_details, net.clone(), repo);
|
|
||||||
//
|
|
||||||
// let_assert!(
|
|
||||||
// Ok(positions) = forge
|
|
||||||
// .branches_validate_positions(open_repository, repo_config)
|
|
||||||
// .await
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// fn given_a_forge(
|
|
||||||
// repo_details: git::RepoDetails,
|
|
||||||
// net: &Network,
|
|
||||||
// repo: git::Repository,
|
|
||||||
// ) -> forgejo::ForgeJo {
|
|
||||||
// forgejo::ForgeJo::new(repo_details, net.clone(), repo)
|
|
||||||
// }
|
|
||||||
// fn given_an_open_repository() -> git::OpenRepository {
|
|
||||||
// todo!()
|
|
||||||
// }
|
|
||||||
// fn given_a_repo_config() -> config::RepoConfig {
|
|
||||||
// todo!()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn given_forgejo_has_branches(net: &mut MockNetwork, i: u32) {
|
|
||||||
let hostname = config::common::hostname(i);
|
|
||||||
let path = config::common::repo_path(i);
|
|
||||||
let api_token = config::common::api_token(i);
|
|
||||||
use secrecy::ExposeSecret;
|
|
||||||
let token = api_token.expose_secret();
|
|
||||||
let url = format!("https://{hostname}/api/v1/repos/{path}/branches?token={token}");
|
|
||||||
let body = include_str!("./data-forgejo-branches-get.json");
|
|
||||||
net.add_get_response(&url, StatusCode::OK, body);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn given_repo_details(path: &Path, i: u32) -> git::RepoDetails {
|
|
||||||
git::common::repo_details(
|
|
||||||
i,
|
|
||||||
git::Generation::new(),
|
|
||||||
config::common::forge_details(i, config::ForgeType::ForgeJo),
|
|
||||||
Some(config::common::repo_config(
|
|
||||||
i,
|
|
||||||
config::RepoConfigSource::Repo,
|
|
||||||
)),
|
|
||||||
config::GitDir::new(path),
|
|
||||||
)
|
|
||||||
}
|
|
68
crates/forge/src/tests/forgejo.rs
Normal file
68
crates/forge/src/tests/forgejo.rs
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
//
|
||||||
|
use assert2::let_assert;
|
||||||
|
|
||||||
|
use git_next_config as config;
|
||||||
|
use git_next_git as git;
|
||||||
|
|
||||||
|
use kxio::network::{MockNetwork, StatusCode};
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_name() {
|
||||||
|
let Ok(fs) = kxio::fs::temp() else {
|
||||||
|
panic!("fs")
|
||||||
|
};
|
||||||
|
let net = Network::new_mock();
|
||||||
|
let (repo, _reality) = git::repository::mock();
|
||||||
|
let repo_details = git::common::repo_details(
|
||||||
|
1,
|
||||||
|
git::Generation::new(),
|
||||||
|
config::common::forge_details(1, config::ForgeType::MockForge),
|
||||||
|
Some(config::common::repo_config(
|
||||||
|
1,
|
||||||
|
config::RepoConfigSource::Repo,
|
||||||
|
)),
|
||||||
|
config::GitDir::new(fs.base()),
|
||||||
|
);
|
||||||
|
let forge = Forge::new_forgejo(repo_details, net, repo);
|
||||||
|
assert_eq!(forge.name(), "forgejo");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_branches_get() {
|
||||||
|
let Ok(fs) = kxio::fs::temp() else {
|
||||||
|
panic!("fs")
|
||||||
|
};
|
||||||
|
let mut net = MockNetwork::new();
|
||||||
|
let hostname = config::common::hostname(1);
|
||||||
|
let path = config::common::repo_path(1);
|
||||||
|
let api_token = config::common::api_token(1);
|
||||||
|
use secrecy::ExposeSecret;
|
||||||
|
let token = api_token.expose_secret();
|
||||||
|
let url = format!("https://{hostname}/api/v1/repos/{path}/branches?token={token}");
|
||||||
|
let body = include_str!("./data-forgejo-branches-get.json");
|
||||||
|
net.add_get_response(&url, StatusCode::OK, body);
|
||||||
|
let net = Network::from(net);
|
||||||
|
let (repo, _reality) = git::repository::mock();
|
||||||
|
|
||||||
|
let repo_details = git::common::repo_details(
|
||||||
|
1,
|
||||||
|
git::Generation::new(),
|
||||||
|
config::common::forge_details(1, config::ForgeType::MockForge),
|
||||||
|
Some(config::common::repo_config(
|
||||||
|
1,
|
||||||
|
config::RepoConfigSource::Repo,
|
||||||
|
)),
|
||||||
|
config::GitDir::new(fs.base()),
|
||||||
|
);
|
||||||
|
|
||||||
|
let forge = Forge::new_forgejo(repo_details, net.clone(), repo);
|
||||||
|
|
||||||
|
let_assert!(Ok(branches) = forge.branches_get_all().await);
|
||||||
|
|
||||||
|
let_assert!(Some(requests) = net.mocked_requests());
|
||||||
|
assert_eq!(requests.len(), 1);
|
||||||
|
|
||||||
|
assert_eq!(branches, vec![config::BranchName::new("string")]);
|
||||||
|
}
|
|
@ -1,8 +1,7 @@
|
||||||
//
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use git_next_config as config;
|
#[cfg(feature = "forgejo")]
|
||||||
use git_next_git as git;
|
mod forgejo;
|
||||||
|
|
||||||
#[cfg(feature = "github")]
|
#[cfg(feature = "github")]
|
||||||
mod github;
|
mod github;
|
||||||
|
@ -12,24 +11,3 @@ fn test_mock_name() {
|
||||||
let forge = Forge::new_mock();
|
let forge = Forge::new_mock();
|
||||||
assert_eq!(forge.name(), "mock");
|
assert_eq!(forge.name(), "mock");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_forgejo_name() {
|
|
||||||
let Ok(fs) = kxio::fs::temp() else {
|
|
||||||
panic!("fs")
|
|
||||||
};
|
|
||||||
let net = Network::new_mock();
|
|
||||||
let (repo, _reality) = git::repository::mock();
|
|
||||||
let repo_details = git::common::repo_details(
|
|
||||||
1,
|
|
||||||
git::Generation::new(),
|
|
||||||
config::common::forge_details(1, config::ForgeType::MockForge),
|
|
||||||
Some(config::common::repo_config(
|
|
||||||
1,
|
|
||||||
config::RepoConfigSource::Repo,
|
|
||||||
)),
|
|
||||||
config::GitDir::new(fs.base()),
|
|
||||||
);
|
|
||||||
let forge = Forge::new_forgejo(repo_details, net, repo);
|
|
||||||
assert_eq!(forge.name(), "forgejo");
|
|
||||||
}
|
|
||||||
|
|
|
@ -133,17 +133,6 @@ impl OpenRepositoryLike for MockOpenRepository {
|
||||||
.map(|inner| inner.push(repo_details, branch_name, to_commit, force))
|
.map(|inner| inner.push(repo_details, branch_name, to_commit, force))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn commit_log(
|
|
||||||
&self,
|
|
||||||
branch_name: git_next_config::BranchName,
|
|
||||||
find_commits: Vec<crate::Commit>,
|
|
||||||
) -> Vec<crate::Commit> {
|
|
||||||
self.inner
|
|
||||||
.lock()
|
|
||||||
.map(|inner| inner.commit_log(branch_name, find_commits))
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
impl OpenRepositoryLike for InnerMockOpenRepository {
|
impl OpenRepositoryLike for InnerMockOpenRepository {
|
||||||
fn find_default_remote(&self, direction: Direction) -> Option<GitRemote> {
|
fn find_default_remote(&self, direction: Direction) -> Option<GitRemote> {
|
||||||
|
@ -166,12 +155,4 @@ impl OpenRepositoryLike for InnerMockOpenRepository {
|
||||||
) -> std::prelude::v1::Result<(), crate::push::Error> {
|
) -> std::prelude::v1::Result<(), crate::push::Error> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn commit_log(
|
|
||||||
&self,
|
|
||||||
branch_name: git_next_config::BranchName,
|
|
||||||
find_commits: Vec<crate::Commit>,
|
|
||||||
) -> Vec<crate::Commit> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,44 +6,38 @@ pub mod oreal;
|
||||||
|
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use crate as git;
|
use git_next_config::BranchName;
|
||||||
use git::repository::open::oreal::RealOpenRepository;
|
|
||||||
use git::repository::Direction;
|
use crate::{
|
||||||
use git_next_config as config;
|
fetch, push,
|
||||||
|
repository::{mock::MockOpenRepository, open::oreal::RealOpenRepository, Direction},
|
||||||
|
GitRef, GitRemote, RepoDetails,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum OpenRepository {
|
pub enum OpenRepository {
|
||||||
Real(RealOpenRepository),
|
Real(oreal::RealOpenRepository),
|
||||||
Mock(git::repository::mock::MockOpenRepository), // TODO: (#38) contain a mock model of a repo
|
Mock(MockOpenRepository), // TODO: (#38) contain a mock model of a repo
|
||||||
}
|
}
|
||||||
impl OpenRepository {
|
impl OpenRepository {
|
||||||
pub fn real(gix_repo: gix::Repository) -> Self {
|
pub fn real(gix_repo: gix::Repository) -> Self {
|
||||||
Self::Real(oreal::RealOpenRepository::new(Arc::new(Mutex::new(
|
Self::Real(RealOpenRepository::new(Arc::new(Mutex::new(gix_repo))))
|
||||||
gix_repo,
|
|
||||||
))))
|
|
||||||
}
|
}
|
||||||
#[cfg(not(tarpaulin_include))] // don't test mocks
|
#[cfg(not(tarpaulin_include))] // don't test mocks
|
||||||
pub const fn mock(mock: git::repository::mock::MockOpenRepository) -> Self {
|
pub const fn mock(mock: MockOpenRepository) -> Self {
|
||||||
Self::Mock(mock)
|
Self::Mock(mock)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub trait OpenRepositoryLike {
|
pub trait OpenRepositoryLike {
|
||||||
fn find_default_remote(&self, direction: Direction) -> Option<git::GitRemote>;
|
fn find_default_remote(&self, direction: Direction) -> Option<GitRemote>;
|
||||||
fn fetch(&self) -> Result<(), git::fetch::Error>;
|
fn fetch(&self) -> Result<(), fetch::Error>;
|
||||||
fn push(
|
fn push(
|
||||||
&self,
|
&self,
|
||||||
repo_details: &git::RepoDetails,
|
repo_details: &RepoDetails,
|
||||||
branch_name: config::BranchName,
|
branch_name: BranchName,
|
||||||
to_commit: git::GitRef,
|
to_commit: GitRef,
|
||||||
force: git::push::Force,
|
force: push::Force,
|
||||||
) -> Result<(), git::push::Error>;
|
) -> Result<(), push::Error>;
|
||||||
|
|
||||||
/// List of commits in a branch, optionally up-to any specified commit.
|
|
||||||
fn commit_log(
|
|
||||||
&self,
|
|
||||||
branch_name: config::BranchName,
|
|
||||||
find_commits: Vec<git::Commit>,
|
|
||||||
) -> Vec<git::Commit>;
|
|
||||||
}
|
}
|
||||||
impl std::ops::Deref for OpenRepository {
|
impl std::ops::Deref for OpenRepository {
|
||||||
type Target = dyn OpenRepositoryLike;
|
type Target = dyn OpenRepositoryLike;
|
||||||
|
|
|
@ -100,14 +100,6 @@ impl super::OpenRepositoryLike for RealOpenRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn commit_log(
|
|
||||||
&self,
|
|
||||||
branch_name: git_next_config::BranchName,
|
|
||||||
find_commits: Vec<crate::Commit>,
|
|
||||||
) -> Vec<crate::Commit> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&gix::Url> for GitRemote {
|
impl From<&gix::Url> for GitRemote {
|
||||||
|
|
Loading…
Reference in a new issue