Compare commits
1 commit
e51f09ccb3
...
7aea70f5ee
Author | SHA1 | Date | |
---|---|---|---|
7aea70f5ee |
9 changed files with 68 additions and 37 deletions
|
@ -4,20 +4,26 @@ mod file;
|
|||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use git::validation::repo::validate_repo;
|
||||
use git_next_config as config;
|
||||
use git_next_git as git;
|
||||
|
||||
use kxio::network::{self, Network};
|
||||
use tracing::{error, warn};
|
||||
use tracing::{error, info, warn};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ForgeJo {
|
||||
repo_details: git::RepoDetails,
|
||||
net: Network,
|
||||
repo: git::Repository,
|
||||
}
|
||||
impl ForgeJo {
|
||||
pub const fn new(repo_details: git::RepoDetails, net: Network) -> Self {
|
||||
Self { repo_details, net }
|
||||
pub const fn new(repo_details: git::RepoDetails, net: Network, repo: git::Repository) -> Self {
|
||||
Self {
|
||||
repo_details,
|
||||
net,
|
||||
repo,
|
||||
}
|
||||
}
|
||||
}
|
||||
#[async_trait::async_trait]
|
||||
|
@ -35,7 +41,6 @@ impl git::ForgeLike for ForgeJo {
|
|||
branch: &config::BranchName,
|
||||
file_path: &str,
|
||||
) -> Result<String, git::file::Error> {
|
||||
// TODO: get from local cloned repo
|
||||
file::contents_get(&self.repo_details, &self.net, branch, file_path).await
|
||||
}
|
||||
|
||||
|
@ -82,6 +87,22 @@ impl git::ForgeLike for ForgeJo {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn repo_clone(
|
||||
&self,
|
||||
gitdir: config::GitDir,
|
||||
) -> Result<git::OpenRepository, git::repository::Error> {
|
||||
let repository = if !gitdir.exists() {
|
||||
info!("Local copy not found - cloning...");
|
||||
self.repo.git_clone(&self.repo_details)?
|
||||
} else {
|
||||
self.repo.open(&gitdir)?
|
||||
};
|
||||
info!("Validating...");
|
||||
validate_repo(&repository, &self.repo_details)
|
||||
.map_err(|e| git::repository::Error::Validation(e.to_string()))?;
|
||||
Ok(repository)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
|
|
|
@ -23,7 +23,8 @@ mod branch {
|
|||
let repo_details = given_repo_details(fs.base(), 1);
|
||||
|
||||
let net = Network::from(net);
|
||||
let forge = forgejo::ForgeJo::new(repo_details, net.clone());
|
||||
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);
|
||||
|
|
|
@ -36,4 +36,12 @@ impl git_next_git::ForgeLike for Github {
|
|||
async fn commit_status(&self, _commit: &git::Commit) -> git::commit::Status {
|
||||
todo!();
|
||||
}
|
||||
|
||||
/// Clones a repo to disk.
|
||||
fn repo_clone(
|
||||
&self,
|
||||
_gitdir: config::GitDir,
|
||||
) -> Result<git::OpenRepository, git::repository::Error> {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,8 +22,12 @@ impl Forge {
|
|||
}
|
||||
|
||||
#[cfg(feature = "forgejo")]
|
||||
pub const fn new_forgejo(repo_details: git::RepoDetails, net: Network) -> Self {
|
||||
Self::ForgeJo(forgejo::ForgeJo::new(repo_details, net))
|
||||
pub const fn new_forgejo(
|
||||
repo_details: git::RepoDetails,
|
||||
net: Network,
|
||||
repo: git::Repository,
|
||||
) -> Self {
|
||||
Self::ForgeJo(forgejo::ForgeJo::new(repo_details, net, repo))
|
||||
}
|
||||
|
||||
#[cfg(feature = "github")]
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#![cfg(not(tarpaulin_include))]
|
||||
|
||||
use derive_more::Constructor;
|
||||
use git::OpenRepository;
|
||||
use git_next_config as config;
|
||||
use git_next_git as git;
|
||||
|
||||
|
@ -29,4 +30,11 @@ impl git::ForgeLike for MockForge {
|
|||
async fn commit_status(&self, _commit: &git::Commit) -> git::commit::Status {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn repo_clone(
|
||||
&self,
|
||||
_gitdir: config::GitDir,
|
||||
) -> Result<OpenRepository, git::repository::Error> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ fn test_forgejo_name() {
|
|||
panic!("fs")
|
||||
};
|
||||
let net = Network::new_mock();
|
||||
let (repo, _reality) = git::repository::mock();
|
||||
let repo_details = git::common::repo_details(
|
||||
1,
|
||||
git::Generation::new(),
|
||||
|
@ -26,6 +27,6 @@ fn test_forgejo_name() {
|
|||
)),
|
||||
config::GitDir::new(fs.base()),
|
||||
);
|
||||
let forge = Forge::new_forgejo(repo_details, net);
|
||||
let forge = Forge::new_forgejo(repo_details, net, repo);
|
||||
assert_eq!(forge.name(), "forgejo");
|
||||
}
|
||||
|
|
|
@ -17,4 +17,10 @@ pub trait ForgeLike {
|
|||
|
||||
/// Checks the results of any (e.g. CI) status checks for the commit.
|
||||
async fn commit_status(&self, commit: &git::Commit) -> git::commit::Status;
|
||||
|
||||
/// Clones a repo to disk.
|
||||
fn repo_clone(
|
||||
&self,
|
||||
gitdir: config::GitDir,
|
||||
) -> Result<git::OpenRepository, git::repository::Error>;
|
||||
}
|
||||
|
|
|
@ -6,12 +6,11 @@ mod real;
|
|||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use git_next_config as config;
|
||||
use git_next_config::GitDir;
|
||||
|
||||
pub use open::OpenRepository;
|
||||
|
||||
use crate::{repository::mock::MockRepository, validation::repo::validate_repo};
|
||||
use crate::repository::mock::MockRepository;
|
||||
|
||||
use super::RepoDetails;
|
||||
|
||||
|
@ -28,23 +27,6 @@ pub fn mock() -> (Repository, MockRepository) {
|
|||
(Repository::Mock(mock_repository.clone()), mock_repository)
|
||||
}
|
||||
|
||||
/// Opens a repository, cloning if necessary
|
||||
pub fn open(
|
||||
repository: &Repository,
|
||||
repo_details: &RepoDetails,
|
||||
gitdir: config::GitDir,
|
||||
) -> Result<OpenRepository> {
|
||||
let repository = if !gitdir.exists() {
|
||||
// info!("Local copy not found - cloning...");
|
||||
repository.git_clone(repo_details)?
|
||||
} else {
|
||||
repository.open(&gitdir)?
|
||||
};
|
||||
// info!("Validating...");
|
||||
validate_repo(&repository, repo_details).map_err(|e| Error::Validation(e.to_string()))?;
|
||||
Ok(repository)
|
||||
}
|
||||
|
||||
pub trait RepositoryLike {
|
||||
fn open(&self, gitdir: &GitDir) -> Result<OpenRepository>;
|
||||
fn git_clone(&self, repo_details: &RepoDetails) -> Result<OpenRepository>;
|
||||
|
|
|
@ -31,8 +31,7 @@ pub struct RepoActor {
|
|||
last_main_commit: Option<git::Commit>,
|
||||
last_next_commit: Option<git::Commit>,
|
||||
last_dev_commit: Option<git::Commit>,
|
||||
repository: git::Repository,
|
||||
open_repository: Option<git::OpenRepository>,
|
||||
repository: Option<git::OpenRepository>,
|
||||
net: Network,
|
||||
forge: forge::Forge,
|
||||
}
|
||||
|
@ -46,7 +45,9 @@ impl RepoActor {
|
|||
) -> Self {
|
||||
let forge = match details.forge.forge_type() {
|
||||
#[cfg(feature = "forgejo")]
|
||||
config::ForgeType::ForgeJo => forge::Forge::new_forgejo(details.clone(), net.clone()),
|
||||
config::ForgeType::ForgeJo => {
|
||||
forge::Forge::new_forgejo(details.clone(), net.clone(), repo)
|
||||
}
|
||||
config::ForgeType::MockForge => forge::Forge::new_mock(),
|
||||
};
|
||||
debug!(?forge, "new");
|
||||
|
@ -60,8 +61,7 @@ impl RepoActor {
|
|||
last_main_commit: None,
|
||||
last_next_commit: None,
|
||||
last_dev_commit: None,
|
||||
repository: repo,
|
||||
open_repository: None,
|
||||
repository: None,
|
||||
net,
|
||||
forge,
|
||||
}
|
||||
|
@ -96,9 +96,9 @@ impl Handler<CloneRepo> for RepoActor {
|
|||
#[tracing::instrument(name = "RepoActor::CloneRepo", skip_all, fields(repo = %self.repo_details, gitdir = %self.repo_details.gitdir))]
|
||||
fn handle(&mut self, _msg: CloneRepo, ctx: &mut Self::Context) -> Self::Result {
|
||||
let gitdir = self.repo_details.gitdir.clone();
|
||||
match git::repository::open(&self.repository, &self.repo_details, gitdir) {
|
||||
match self.forge.repo_clone(gitdir) {
|
||||
Ok(repository) => {
|
||||
self.open_repository.replace(repository);
|
||||
self.repository.replace(repository);
|
||||
if self.repo_details.repo_config.is_none() {
|
||||
ctx.address().do_send(LoadConfigFromRepo);
|
||||
} else {
|
||||
|
@ -179,7 +179,7 @@ impl Handler<ValidateRepo> for RepoActor {
|
|||
.wait(ctx);
|
||||
}
|
||||
if let (Some(repository), Some(repo_config)) = (
|
||||
self.open_repository.clone(),
|
||||
self.repository.clone(),
|
||||
self.repo_details.repo_config.clone(),
|
||||
) {
|
||||
let repo_details = self.repo_details.clone();
|
||||
|
@ -241,7 +241,7 @@ impl Handler<StartMonitoring> for RepoActor {
|
|||
.into_actor(self)
|
||||
.wait(ctx);
|
||||
} else if dev_ahead_of_next {
|
||||
if let Some(repository) = self.open_repository.clone() {
|
||||
if let Some(repository) = self.repository.clone() {
|
||||
branch::advance_next(
|
||||
msg.next,
|
||||
msg.dev_commit_history,
|
||||
|
@ -282,7 +282,7 @@ impl Handler<AdvanceMainTo> for RepoActor {
|
|||
warn!("No config loaded");
|
||||
return;
|
||||
};
|
||||
let Some(repository) = self.open_repository.clone() else {
|
||||
let Some(repository) = self.repository.clone() else {
|
||||
warn!("No repository opened");
|
||||
return;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue