feat(server): reload .git-next.toml from repo when main branch updated
Some checks failed
ci/woodpecker/cron/cron-docker-builder Pipeline was successful
ci/woodpecker/cron/push-next Pipeline was successful
ci/woodpecker/cron/tag-created Pipeline was successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
ci/woodpecker/push/push-next Pipeline failed

Only does this if the repo config (i.e. the main, next and dev branches) are detailed in the
.git-next.toml file within the repo, rather than in the git-next-server.toml file.

Closes kemitix/git-next#74
This commit is contained in:
Paul Campbell 2024-05-08 07:34:35 +01:00
parent ec2ebe70cf
commit e5a8051a31
5 changed files with 35 additions and 19 deletions

View file

@ -5,8 +5,9 @@ use actix::prelude::*;
use tracing::{info, warn};
use crate::server::{
actors::repo::{RepoActor, ValidateRepo},
config, gitforge,
actors::repo::{LoadConfigFromRepo, RepoActor, ValidateRepo},
config::{self, RepoConfigSource},
gitforge,
};
// advance next to the next commit towards the head of the dev branch
@ -89,7 +90,10 @@ pub async fn advance_main(
) {
warn!(?err, "Failed")
};
addr.do_send(ValidateRepo { message_token })
match repo_config.source() {
RepoConfigSource::Repo => addr.do_send(LoadConfigFromRepo),
RepoConfigSource::Server => addr.do_send(ValidateRepo { message_token }),
}
}
#[cfg(test)]

View file

@ -95,20 +95,25 @@ impl ServerStorage {
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)]
pub struct RepoConfig {
branches: RepoBranches,
source: RepoConfigSource,
}
impl RepoConfig {
#[cfg(test)]
pub const fn new(branches: RepoBranches) -> Self {
Self { branches }
pub const fn new(branches: RepoBranches, source: RepoConfigSource) -> Self {
Self { branches, source }
}
// #[cfg(test)]
pub fn load(toml: &str) -> Result<Self> {
toml::from_str(toml).map_err(Into::into)
toml::from_str(format!("source = \"Repo\"\n{}", toml).as_str()).map_err(Into::into)
}
pub const fn branches(&self) -> &RepoBranches {
&self.branches
}
pub const fn source(&self) -> RepoConfigSource {
self.source
}
}
impl Display for RepoConfig {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
@ -116,6 +121,12 @@ impl Display for RepoConfig {
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize)]
pub enum RepoConfigSource {
Repo,
Server,
}
/// Mapped from `.git-next.toml` file at `branches`
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)]
pub struct RepoBranches {
@ -232,6 +243,7 @@ impl ServerRepoConfig {
next: next.to_string(),
dev: dev.to_string(),
},
source: RepoConfigSource::Server,
}),
_ => None,
}

View file

@ -105,6 +105,7 @@ fn load_should_parse_server_config() -> Result<()> {
next: "upcoming".to_string(),
dev: "sam-dev".to_string(),
},
source: RepoConfigSource::Server,
});
assert_eq!(repo_config, expected, "RepoConfig");
}
@ -115,8 +116,7 @@ fn load_should_parse_server_config() -> Result<()> {
#[test]
fn test_repo_config_load() -> Result<()> {
let toml = r#"
[branches]
let toml = r#"[branches]
main = "main"
next = "next"
dev = "dev"
@ -133,6 +133,7 @@ fn test_repo_config_load() -> Result<()> {
next: "next".to_string(),
dev: "dev".to_string(),
},
source: RepoConfigSource::Repo
}
);

View file

@ -1,7 +1,7 @@
use crate::server::{
config::{
ApiToken, BranchName, ForgeDetails, ForgeName, ForgeType, GitDir, Hostname, RepoAlias,
RepoBranches, RepoConfig, RepoDetails, RepoPath, User,
RepoBranches, RepoConfig, RepoConfigSource, RepoDetails, RepoPath, User,
},
types::ServerGeneration,
};
@ -61,10 +61,9 @@ pub fn repo_alias(n: u32) -> RepoAlias {
RepoAlias(format!("repo-alias-{}", n))
}
pub fn repo_config(n: u32) -> RepoConfig {
RepoConfig::new(RepoBranches::new(
format!("main-{n}"),
format!("next-{n}"),
format!("dev-{n}"),
))
pub fn repo_config(n: u32, source: RepoConfigSource) -> RepoConfig {
RepoConfig::new(
RepoBranches::new(format!("main-{n}"), format!("next-{n}"), format!("dev-{n}")),
source,
)
}

View file

@ -3,7 +3,7 @@ use assert2::let_assert;
use kxio::network::{MockNetwork, StatusCode};
use crate::server::{
config::{BranchName, ForgeType},
config::{BranchName, ForgeType, RepoConfigSource},
types::ServerGeneration,
};
@ -19,7 +19,7 @@ fn test_name() {
1,
ServerGeneration::new(),
common::forge_details(1, ForgeType::MockForge),
Some(common::repo_config(1)),
Some(common::repo_config(1, RepoConfigSource::Repo)),
GitDir::new(fs.base()),
);
let forge = Forge::new_forgejo(repo_details, net);
@ -46,7 +46,7 @@ async fn test_branches_get() {
1,
ServerGeneration::new(),
common::forge_details(1, ForgeType::MockForge),
Some(common::repo_config(1)),
Some(common::repo_config(1, RepoConfigSource::Repo)),
GitDir::new(fs.base()),
);