Compare commits
2 commits
baf959b7a4
...
3ce69efeba
Author | SHA1 | Date | |
---|---|---|---|
3ce69efeba | |||
012668dd0a |
23 changed files with 174 additions and 251 deletions
|
@ -7,6 +7,7 @@ members = [
|
||||||
"crates/git",
|
"crates/git",
|
||||||
"crates/forge",
|
"crates/forge",
|
||||||
"crates/forge-forgejo",
|
"crates/forge-forgejo",
|
||||||
|
"crates/forge-github",
|
||||||
"crates/repo-actor",
|
"crates/repo-actor",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ git-next-config = { path = "crates/config" }
|
||||||
git-next-git = { path = "crates/git" }
|
git-next-git = { path = "crates/git" }
|
||||||
git-next-forge = { path = "crates/forge" }
|
git-next-forge = { path = "crates/forge" }
|
||||||
git-next-forge-forgejo = { path = "crates/forge-forgejo" }
|
git-next-forge-forgejo = { path = "crates/forge-forgejo" }
|
||||||
|
git-next-forge-github = { path = "crates/forge-github" }
|
||||||
git-next-repo-actor = { path = "crates/repo-actor" }
|
git-next-repo-actor = { path = "crates/repo-actor" }
|
||||||
|
|
||||||
# CLI parsing
|
# CLI parsing
|
||||||
|
|
|
@ -4,7 +4,7 @@ version = { workspace = true }
|
||||||
edition = { workspace = true }
|
edition = { workspace = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["forgejo"]
|
default = ["forgejo", "github"]
|
||||||
forgejo = []
|
forgejo = []
|
||||||
github = []
|
github = []
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
pub mod branch;
|
pub mod branch;
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests;
|
|
||||||
|
|
||||||
use git_next_config as config;
|
|
||||||
use git_next_git as git;
|
use git_next_git as git;
|
||||||
|
|
||||||
use kxio::network::{self, Network};
|
use kxio::network::{self, Network};
|
||||||
|
@ -25,10 +21,6 @@ impl git::ForgeLike for ForgeJo {
|
||||||
"forgejo".to_string()
|
"forgejo".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn branches_get_all(&self) -> Result<Vec<config::BranchName>, git::branch::Error> {
|
|
||||||
branch::get_all(&self.repo_details, &self.net).await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn commit_status(&self, commit: &git::Commit) -> git::commit::Status {
|
async fn commit_status(&self, commit: &git::Commit) -> git::commit::Status {
|
||||||
let repo_details = &self.repo_details;
|
let repo_details = &self.repo_details;
|
||||||
let hostname = &repo_details.forge.hostname();
|
let hostname = &repo_details.forge.hostname();
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
[
|
|
||||||
{
|
|
||||||
"commit": {
|
|
||||||
"added": [
|
|
||||||
"string"
|
|
||||||
],
|
|
||||||
"author": {
|
|
||||||
"email": "user@example.com",
|
|
||||||
"name": "string",
|
|
||||||
"username": "string"
|
|
||||||
},
|
|
||||||
"committer": {
|
|
||||||
"email": "user@example.com",
|
|
||||||
"name": "string",
|
|
||||||
"username": "string"
|
|
||||||
},
|
|
||||||
"id": "string",
|
|
||||||
"message": "string",
|
|
||||||
"modified": [
|
|
||||||
"string"
|
|
||||||
],
|
|
||||||
"removed": [
|
|
||||||
"string"
|
|
||||||
],
|
|
||||||
"timestamp": "2024-04-16T21:35:56.331Z",
|
|
||||||
"url": "string",
|
|
||||||
"verification": {
|
|
||||||
"payload": "string",
|
|
||||||
"reason": "string",
|
|
||||||
"signature": "string",
|
|
||||||
"signer": {
|
|
||||||
"email": "user@example.com",
|
|
||||||
"name": "string",
|
|
||||||
"username": "string"
|
|
||||||
},
|
|
||||||
"verified": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"effective_branch_protection_name": "string",
|
|
||||||
"enable_status_check": true,
|
|
||||||
"name": "string",
|
|
||||||
"protected": true,
|
|
||||||
"required_approvals": 0,
|
|
||||||
"status_check_contexts": [
|
|
||||||
"string"
|
|
||||||
],
|
|
||||||
"user_can_merge": true,
|
|
||||||
"user_can_push": true
|
|
||||||
}
|
|
||||||
]
|
|
|
@ -1,102 +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 forge = forgejo::ForgeJo::new(repo_details, net.clone());
|
|
||||||
|
|
||||||
//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),
|
|
||||||
)
|
|
||||||
}
|
|
59
crates/forge-github/Cargo.toml
Normal file
59
crates/forge-github/Cargo.toml
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
[package]
|
||||||
|
name = "git-next-forge-github"
|
||||||
|
version = { workspace = true }
|
||||||
|
edition = { workspace = true }
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
git-next-config = { workspace = true }
|
||||||
|
git-next-git = { workspace = true }
|
||||||
|
|
||||||
|
# logging
|
||||||
|
console-subscriber = { workspace = true }
|
||||||
|
tracing = { workspace = true }
|
||||||
|
tracing-subscriber = { workspace = true }
|
||||||
|
|
||||||
|
# base64 decoding
|
||||||
|
base64 = { workspace = true }
|
||||||
|
|
||||||
|
# git
|
||||||
|
async-trait = { workspace = true }
|
||||||
|
|
||||||
|
# fs/network
|
||||||
|
kxio = { workspace = true }
|
||||||
|
|
||||||
|
# TOML parsing
|
||||||
|
serde = { workspace = true }
|
||||||
|
serde_json = { workspace = true }
|
||||||
|
toml = { workspace = true }
|
||||||
|
|
||||||
|
# Secrets and Password
|
||||||
|
secrecy = { workspace = true }
|
||||||
|
|
||||||
|
# Conventional Commit check
|
||||||
|
git-conventional = { workspace = true }
|
||||||
|
|
||||||
|
# Webhooks
|
||||||
|
bytes = { workspace = true }
|
||||||
|
ulid = { workspace = true }
|
||||||
|
warp = { workspace = true }
|
||||||
|
|
||||||
|
# boilerplate
|
||||||
|
derive_more = { workspace = true }
|
||||||
|
|
||||||
|
# file watcher
|
||||||
|
inotify = { workspace = true }
|
||||||
|
|
||||||
|
# # Actors
|
||||||
|
# actix = { workspace = true }
|
||||||
|
# actix-rt = { workspace = true }
|
||||||
|
tokio = { workspace = true }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
# Testing
|
||||||
|
assert2 = { workspace = true }
|
||||||
|
|
||||||
|
[lints.clippy]
|
||||||
|
nursery = { level = "warn", priority = -1 }
|
||||||
|
# pedantic = "warn"
|
||||||
|
unwrap_used = "warn"
|
||||||
|
expect_used = "warn"
|
30
crates/forge-github/src/lib.rs
Normal file
30
crates/forge-github/src/lib.rs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
//
|
||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
use derive_more::Constructor;
|
||||||
|
use git_next_config as config;
|
||||||
|
use git_next_git as git;
|
||||||
|
|
||||||
|
use kxio::network::Network;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Constructor)]
|
||||||
|
pub struct Github {
|
||||||
|
net: Network,
|
||||||
|
}
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl git_next_git::ForgeLike for Github {
|
||||||
|
fn name(&self) -> String {
|
||||||
|
"github".to_string()
|
||||||
|
}
|
||||||
|
async fn branches_get_all(&self) -> Result<Vec<config::BranchName>, git::branch::Error> {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Checks the results of any (e.g. CI) status checks for the commit.
|
||||||
|
async fn commit_status(&self, _commit: &git::Commit) -> git::commit::Status {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
}
|
8
crates/forge-github/src/tests/mod.rs
Normal file
8
crates/forge-github/src/tests/mod.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
use git_next_git::ForgeLike as _;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_name() {
|
||||||
|
let net = kxio::network::Network::new_mock();
|
||||||
|
let forge = crate::Github::new(net);
|
||||||
|
assert_eq!(forge.name(), "github");
|
||||||
|
}
|
|
@ -4,14 +4,15 @@ version = { workspace = true }
|
||||||
edition = { workspace = true }
|
edition = { workspace = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["forgejo"]
|
default = ["forgejo", "github"]
|
||||||
forgejo = ["git-next-forge-forgejo"]
|
forgejo = ["git-next-forge-forgejo"]
|
||||||
github = []
|
github = ["git-next-forge-github"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
git-next-config = { workspace = true }
|
git-next-config = { workspace = true }
|
||||||
git-next-git = { workspace = true }
|
git-next-git = { workspace = true }
|
||||||
git-next-forge-forgejo = { workspace = true, optional = true }
|
git-next-forge-forgejo = { workspace = true, optional = true }
|
||||||
|
git-next-forge-github = { workspace = true, optional = true }
|
||||||
|
|
||||||
# logging
|
# logging
|
||||||
console-subscriber = { workspace = true }
|
console-subscriber = { workspace = true }
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
use crate::network::Network;
|
|
||||||
|
|
||||||
struct Github;
|
|
||||||
pub(super) struct GithubEnv {
|
|
||||||
net: Network,
|
|
||||||
}
|
|
||||||
impl GithubEnv {
|
|
||||||
pub(crate) const fn new(net: Network) -> GithubEnv {
|
|
||||||
Self { net }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl super::ForgeLike for GithubEnv {
|
|
||||||
fn name(&self) -> String {
|
|
||||||
"github".to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn branches_get_all(&self) -> Vec<super::Branch> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,34 +1,34 @@
|
||||||
#![allow(dead_code)]
|
//
|
||||||
|
|
||||||
use git_next_forge_forgejo as forgejo;
|
use git_next_forge_forgejo as forgejo;
|
||||||
|
use git_next_forge_github as github;
|
||||||
use git_next_git as git;
|
use git_next_git as git;
|
||||||
use kxio::network::Network;
|
use kxio::network::Network;
|
||||||
|
|
||||||
#[cfg(feature = "github")]
|
|
||||||
mod github;
|
|
||||||
|
|
||||||
mod mock_forge;
|
mod mock_forge;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum Forge {
|
pub enum Forge {
|
||||||
Mock(mock_forge::MockForgeEnv),
|
Mock(mock_forge::MockForge),
|
||||||
#[allow(clippy::enum_variant_names)]
|
|
||||||
#[cfg(feature = "forgejo")]
|
#[cfg(feature = "forgejo")]
|
||||||
ForgeJo(forgejo::ForgeJo),
|
ForgeJo(git_next_forge_forgejo::ForgeJo),
|
||||||
|
|
||||||
#[cfg(feature = "github")]
|
#[cfg(feature = "github")]
|
||||||
Github(github::GithubEnv),
|
Github(git_next_forge_github::Github),
|
||||||
}
|
}
|
||||||
impl Forge {
|
impl Forge {
|
||||||
pub const fn new_mock() -> Self {
|
pub const fn new_mock() -> Self {
|
||||||
Self::Mock(mock_forge::MockForgeEnv::new())
|
Self::Mock(mock_forge::MockForge::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "forgejo")]
|
#[cfg(feature = "forgejo")]
|
||||||
pub const fn new_forgejo(repo_details: git::RepoDetails, net: Network) -> Self {
|
pub const fn new_forgejo(repo_details: git::RepoDetails, net: Network) -> Self {
|
||||||
Self::ForgeJo(forgejo::ForgeJo::new(repo_details, net))
|
Self::ForgeJo(forgejo::ForgeJo::new(repo_details, net))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "github")]
|
#[cfg(feature = "github")]
|
||||||
pub const fn new_github(net: Network) -> Self {
|
pub const fn new_github(net: Network) -> Self {
|
||||||
Self::Github(github::GithubEnv::new(net))
|
Self::Github(github::Github::new(net))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl std::ops::Deref for Forge {
|
impl std::ops::Deref for Forge {
|
||||||
|
@ -39,7 +39,7 @@ impl std::ops::Deref for Forge {
|
||||||
#[cfg(feature = "forgejo")]
|
#[cfg(feature = "forgejo")]
|
||||||
Self::ForgeJo(env) => env,
|
Self::ForgeJo(env) => env,
|
||||||
#[cfg(feature = "github")]
|
#[cfg(feature = "github")]
|
||||||
Forge::Github(env) => env,
|
Self::Github(env) => env,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +1,19 @@
|
||||||
//
|
//
|
||||||
#![cfg(not(tarpaulin_include))]
|
#![cfg(not(tarpaulin_include))]
|
||||||
|
|
||||||
|
use derive_more::Constructor;
|
||||||
use git_next_config as config;
|
use git_next_config as config;
|
||||||
use git_next_git as git;
|
use git_next_git as git;
|
||||||
|
|
||||||
struct MockForge;
|
#[derive(Clone, Debug, Constructor)]
|
||||||
#[derive(Clone, Debug)]
|
pub struct MockForge;
|
||||||
pub struct MockForgeEnv;
|
|
||||||
impl MockForgeEnv {
|
|
||||||
pub(crate) const fn new() -> Self {
|
|
||||||
Self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl git::ForgeLike for MockForgeEnv {
|
impl git::ForgeLike for MockForge {
|
||||||
fn name(&self) -> String {
|
fn name(&self) -> String {
|
||||||
"mock".to_string()
|
"mock".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn branches_get_all(&self) -> Result<Vec<config::BranchName>, git::branch::Error> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn commit_status(&self, _commit: &git::Commit) -> git::commit::Status {
|
async fn commit_status(&self, _commit: &git::Commit) -> git::commit::Status {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_name() {
|
|
||||||
let net = Network::new_mock();
|
|
||||||
let forge = Forge::new_github(net);
|
|
||||||
assert_eq!(forge.name(), "github");
|
|
||||||
}
|
|
|
@ -4,9 +4,6 @@ use super::*;
|
||||||
use git_next_config as config;
|
use git_next_config as config;
|
||||||
use git_next_git as git;
|
use git_next_git as git;
|
||||||
|
|
||||||
#[cfg(feature = "github")]
|
|
||||||
mod github;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_mock_name() {
|
fn test_mock_name() {
|
||||||
let forge = Forge::new_mock();
|
let forge = Forge::new_mock();
|
||||||
|
|
|
@ -11,6 +11,12 @@ pub enum Error {
|
||||||
Fetch(git::fetch::Error),
|
Fetch(git::fetch::Error),
|
||||||
|
|
||||||
Push(git::push::Error),
|
Push(git::push::Error),
|
||||||
|
|
||||||
|
Lock,
|
||||||
|
|
||||||
|
Generic(String),
|
||||||
|
I1(gix::reference::iter::Error),
|
||||||
|
I2(gix::reference::iter::init::Error),
|
||||||
}
|
}
|
||||||
impl std::error::Error for Error {}
|
impl std::error::Error for Error {}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
use crate as git;
|
use crate as git;
|
||||||
use git_next_config as config;
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
pub trait ForgeLike {
|
pub trait ForgeLike {
|
||||||
fn name(&self) -> String;
|
fn name(&self) -> String;
|
||||||
|
|
||||||
/// Returns a list of all branches in the repo.
|
|
||||||
async fn branches_get_all(&self) -> Result<Vec<config::BranchName>, git::branch::Error>;
|
|
||||||
|
|
||||||
/// Checks the results of any (e.g. CI) status checks for the commit.
|
/// Checks the results of any (e.g. CI) status checks for the commit.
|
||||||
async fn commit_status(&self, commit: &git::Commit) -> git::commit::Status;
|
async fn commit_status(&self, commit: &git::Commit) -> git::commit::Status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
GitRemote, RepoDetails,
|
GitRemote, RepoDetails,
|
||||||
};
|
};
|
||||||
use git_next_config::GitDir;
|
use git_next_config as config;
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct MockRepository(Arc<Mutex<Reality>>);
|
pub struct MockRepository(Arc<Mutex<Reality>>);
|
||||||
|
@ -23,7 +23,7 @@ impl MockRepository {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self(Arc::new(Mutex::new(Reality::default())))
|
Self(Arc::new(Mutex::new(Reality::default())))
|
||||||
}
|
}
|
||||||
pub fn can_open_repo(&mut self, gitdir: &GitDir) -> Result<MockOpenRepository> {
|
pub fn can_open_repo(&mut self, gitdir: &config::GitDir) -> Result<MockOpenRepository> {
|
||||||
self.0
|
self.0
|
||||||
.lock()
|
.lock()
|
||||||
.map_err(|_| Error::MockLock)
|
.map_err(|_| Error::MockLock)
|
||||||
|
@ -31,7 +31,7 @@ impl MockRepository {
|
||||||
}
|
}
|
||||||
fn open_repository(
|
fn open_repository(
|
||||||
&self,
|
&self,
|
||||||
gitdir: &GitDir,
|
gitdir: &config::GitDir,
|
||||||
) -> std::result::Result<MockOpenRepository, crate::repository::Error> {
|
) -> std::result::Result<MockOpenRepository, crate::repository::Error> {
|
||||||
self.0.lock().map_err(|_| Error::MockLock).and_then(|r| {
|
self.0.lock().map_err(|_| Error::MockLock).and_then(|r| {
|
||||||
r.open_repository(gitdir)
|
r.open_repository(gitdir)
|
||||||
|
@ -47,7 +47,7 @@ impl MockRepository {
|
||||||
impl RepositoryLike for MockRepository {
|
impl RepositoryLike for MockRepository {
|
||||||
fn open(
|
fn open(
|
||||||
&self,
|
&self,
|
||||||
gitdir: &GitDir,
|
gitdir: &config::GitDir,
|
||||||
) -> std::result::Result<OpenRepository, crate::repository::Error> {
|
) -> std::result::Result<OpenRepository, crate::repository::Error> {
|
||||||
Ok(OpenRepository::Mock(self.open_repository(gitdir)?))
|
Ok(OpenRepository::Mock(self.open_repository(gitdir)?))
|
||||||
}
|
}
|
||||||
|
@ -62,10 +62,10 @@ impl RepositoryLike for MockRepository {
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Reality {
|
pub struct Reality {
|
||||||
openable_repos: HashMap<GitDir, MockOpenRepository>,
|
openable_repos: HashMap<config::GitDir, MockOpenRepository>,
|
||||||
}
|
}
|
||||||
impl Reality {
|
impl Reality {
|
||||||
pub fn can_open_repo(&mut self, gitdir: &GitDir) -> MockOpenRepository {
|
pub fn can_open_repo(&mut self, gitdir: &config::GitDir) -> MockOpenRepository {
|
||||||
let mor = self.openable_repos.get(gitdir);
|
let mor = self.openable_repos.get(gitdir);
|
||||||
match mor {
|
match mor {
|
||||||
Some(mor) => mor.clone(),
|
Some(mor) => mor.clone(),
|
||||||
|
@ -76,7 +76,7 @@ impl Reality {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn open_repository(&self, gitdir: &GitDir) -> Option<MockOpenRepository> {
|
pub fn open_repository(&self, gitdir: &config::GitDir) -> Option<MockOpenRepository> {
|
||||||
self.openable_repos.get(gitdir).cloned()
|
self.openable_repos.get(gitdir).cloned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,6 +109,12 @@ impl InnerMockOpenRepository {
|
||||||
|
|
||||||
#[allow(clippy::unwrap_used)]
|
#[allow(clippy::unwrap_used)]
|
||||||
impl OpenRepositoryLike for MockOpenRepository {
|
impl OpenRepositoryLike for MockOpenRepository {
|
||||||
|
fn remote_branches(&self) -> git::branch::Result<Vec<config::BranchName>> {
|
||||||
|
self.inner
|
||||||
|
.lock()
|
||||||
|
.map(|inner| inner.remote_branches())
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
fn find_default_remote(&self, direction: Direction) -> Option<GitRemote> {
|
fn find_default_remote(&self, direction: Direction) -> Option<GitRemote> {
|
||||||
self.inner
|
self.inner
|
||||||
.lock()
|
.lock()
|
||||||
|
@ -156,6 +162,9 @@ impl OpenRepositoryLike for MockOpenRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl OpenRepositoryLike for InnerMockOpenRepository {
|
impl OpenRepositoryLike for InnerMockOpenRepository {
|
||||||
|
fn remote_branches(&self) -> git::branch::Result<Vec<config::BranchName>> {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
fn find_default_remote(&self, direction: Direction) -> Option<GitRemote> {
|
fn find_default_remote(&self, direction: Direction) -> Option<GitRemote> {
|
||||||
match direction {
|
match direction {
|
||||||
Direction::Push => self.default_push_remote.clone(),
|
Direction::Push => self.default_push_remote.clone(),
|
||||||
|
|
|
@ -28,6 +28,7 @@ impl OpenRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub trait OpenRepositoryLike {
|
pub trait OpenRepositoryLike {
|
||||||
|
fn remote_branches(&self) -> git::branch::Result<Vec<config::BranchName>>;
|
||||||
fn find_default_remote(&self, direction: Direction) -> Option<git::GitRemote>;
|
fn find_default_remote(&self, direction: Direction) -> Option<git::GitRemote>;
|
||||||
fn fetch(&self) -> Result<(), git::fetch::Error>;
|
fn fetch(&self) -> Result<(), git::fetch::Error>;
|
||||||
fn push(
|
fn push(
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
//
|
//
|
||||||
use crate as git;
|
use crate as git;
|
||||||
|
use config::BranchName;
|
||||||
use git_next_config as config;
|
use git_next_config as config;
|
||||||
|
|
||||||
use gix::bstr::BStr;
|
use gix::bstr::BStr;
|
||||||
|
@ -9,6 +10,28 @@ use tracing::{info, warn};
|
||||||
#[derive(Clone, Debug, derive_more::Constructor)]
|
#[derive(Clone, Debug, derive_more::Constructor)]
|
||||||
pub struct RealOpenRepository(Arc<Mutex<gix::Repository>>);
|
pub struct RealOpenRepository(Arc<Mutex<gix::Repository>>);
|
||||||
impl super::OpenRepositoryLike for RealOpenRepository {
|
impl super::OpenRepositoryLike for RealOpenRepository {
|
||||||
|
fn remote_branches(&self) -> git::branch::Result<Vec<config::BranchName>> {
|
||||||
|
let refs = self
|
||||||
|
.0
|
||||||
|
.lock()
|
||||||
|
.map_err(|_| git::branch::Error::Lock)
|
||||||
|
.and_then(|repo| {
|
||||||
|
Ok(repo.references()?).and_then(|refs| {
|
||||||
|
Ok(refs.remote_branches().map(|rb| {
|
||||||
|
rb.filter_map(|rbi| rbi.ok())
|
||||||
|
.map(|r| r.name().to_owned())
|
||||||
|
.map(|n| n.to_string())
|
||||||
|
.filter_map(|p| {
|
||||||
|
p.strip_prefix("refs/remotes/origin/").map(|v| v.to_owned())
|
||||||
|
})
|
||||||
|
.filter(|b| b.as_str() != "HEAD")
|
||||||
|
.map(BranchName::new)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
})?)
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
Ok(refs)
|
||||||
|
}
|
||||||
fn find_default_remote(&self, direction: git::repository::Direction) -> Option<git::GitRemote> {
|
fn find_default_remote(&self, direction: git::repository::Direction) -> Option<git::GitRemote> {
|
||||||
let Ok(repository) = self.0.lock() else {
|
let Ok(repository) = self.0.lock() else {
|
||||||
#[cfg(not(tarpaulin_include))] // don't test mutex lock failure
|
#[cfg(not(tarpaulin_include))] // don't test mutex lock failure
|
||||||
|
|
|
@ -4,7 +4,7 @@ version = { workspace = true }
|
||||||
edition = { workspace = true }
|
edition = { workspace = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["forgejo"]
|
default = ["forgejo", "github"]
|
||||||
forgejo = []
|
forgejo = []
|
||||||
github = []
|
github = []
|
||||||
|
|
||||||
|
|
|
@ -121,12 +121,11 @@ impl Handler<LoadConfigFromRepo> for RepoActor {
|
||||||
fn handle(&mut self, _msg: LoadConfigFromRepo, ctx: &mut Self::Context) -> Self::Result {
|
fn handle(&mut self, _msg: LoadConfigFromRepo, ctx: &mut Self::Context) -> Self::Result {
|
||||||
let details = self.repo_details.clone();
|
let details = self.repo_details.clone();
|
||||||
let addr = ctx.address();
|
let addr = ctx.address();
|
||||||
let forge = self.forge.clone();
|
|
||||||
let Some(open_repository) = self.open_repository.clone() else {
|
let Some(open_repository) = self.open_repository.clone() else {
|
||||||
warn!("missing open repository - can't load configuration");
|
warn!("missing open repository - can't load configuration");
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
repo_actor::load::load_file(details, addr, forge, open_repository)
|
repo_actor::load::load_file(details, addr, open_repository)
|
||||||
.in_current_span()
|
.in_current_span()
|
||||||
.into_actor(self)
|
.into_actor(self)
|
||||||
.wait(ctx);
|
.wait(ctx);
|
||||||
|
|
|
@ -4,7 +4,6 @@ use actix::prelude::*;
|
||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
|
|
||||||
use git_next_config as config;
|
use git_next_config as config;
|
||||||
use git_next_forge as forge;
|
|
||||||
use git_next_git as git;
|
use git_next_git as git;
|
||||||
|
|
||||||
use super::{LoadedConfig, RepoActor};
|
use super::{LoadedConfig, RepoActor};
|
||||||
|
@ -14,11 +13,10 @@ use super::{LoadedConfig, RepoActor};
|
||||||
pub async fn load_file(
|
pub async fn load_file(
|
||||||
repo_details: git::RepoDetails,
|
repo_details: git::RepoDetails,
|
||||||
addr: Addr<RepoActor>,
|
addr: Addr<RepoActor>,
|
||||||
forge: forge::Forge,
|
|
||||||
open_repository: git::OpenRepository,
|
open_repository: git::OpenRepository,
|
||||||
) {
|
) {
|
||||||
info!("Loading .git-next.toml from repo");
|
info!("Loading .git-next.toml from repo");
|
||||||
let repo_config = match load(&repo_details, &forge, open_repository).await {
|
let repo_config = match load(&repo_details, &open_repository).await {
|
||||||
Ok(repo_config) => repo_config,
|
Ok(repo_config) => repo_config,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!(?err, "Failed to load config");
|
error!(?err, "Failed to load config");
|
||||||
|
@ -31,12 +29,11 @@ pub async fn load_file(
|
||||||
|
|
||||||
async fn load(
|
async fn load(
|
||||||
details: &git::RepoDetails,
|
details: &git::RepoDetails,
|
||||||
forge: &forge::Forge,
|
open_repository: &git::OpenRepository,
|
||||||
open_repository: git::OpenRepository,
|
|
||||||
) -> Result<config::RepoConfig, Error> {
|
) -> Result<config::RepoConfig, Error> {
|
||||||
let contents = open_repository.read_file(&details.branch, ".git-next.toml")?;
|
let contents = open_repository.read_file(&details.branch, ".git-next.toml")?;
|
||||||
let config = config::RepoConfig::load(&contents)?;
|
let config = config::RepoConfig::load(&contents)?;
|
||||||
let config = validate(config, forge).await?;
|
let config = validate(config, open_repository).await?;
|
||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,18 +42,15 @@ pub enum Error {
|
||||||
File(git::file::Error),
|
File(git::file::Error),
|
||||||
Config(config::server::Error),
|
Config(config::server::Error),
|
||||||
Toml(toml::de::Error),
|
Toml(toml::de::Error),
|
||||||
Forge(git::branch::Error),
|
Branch(git::branch::Error),
|
||||||
BranchNotFound(config::BranchName),
|
BranchNotFound(config::BranchName),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn validate(
|
pub async fn validate(
|
||||||
config: config::RepoConfig,
|
config: config::RepoConfig,
|
||||||
forge: &forge::Forge,
|
open_repository: &git::OpenRepository,
|
||||||
) -> Result<config::RepoConfig, Error> {
|
) -> Result<config::RepoConfig, Error> {
|
||||||
let branches = forge.branches_get_all().await.map_err(|e| {
|
let branches = open_repository.remote_branches()?;
|
||||||
error!(?e, "Failed to list branches");
|
|
||||||
Error::Forge(e)
|
|
||||||
})?;
|
|
||||||
if !branches
|
if !branches
|
||||||
.iter()
|
.iter()
|
||||||
.any(|branch| branch == &config.branches().main())
|
.any(|branch| branch == &config.branches().main())
|
||||||
|
|
|
@ -3,11 +3,6 @@ name = "git-next-server"
|
||||||
version = { workspace = true }
|
version = { workspace = true }
|
||||||
edition = { workspace = true }
|
edition = { workspace = true }
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["forgejo"]
|
|
||||||
forgejo = []
|
|
||||||
github = []
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
git-next-config = { workspace = true }
|
git-next-config = { workspace = true }
|
||||||
git-next-git = { workspace = true }
|
git-next-git = { workspace = true }
|
||||||
|
|
Loading…
Reference in a new issue