Skip to content

Commit

Permalink
Some improvements in GitHub reconciliation (#133)
Browse files Browse the repository at this point in the history
Signed-off-by: Sergio Castaño Arteaga <[email protected]>
  • Loading branch information
tegioz authored Nov 15, 2023
1 parent e9e4c6b commit 8ce70fa
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ rust-version = "1.70"

[workspace.dependencies]
anyhow = "1.0.75"
as-any = "0.3.1"
askama = "0.12.0"
async-trait = "0.1.73"
axum = { version = "0.6.20", features = ["macros"] }
Expand Down
1 change: 1 addition & 0 deletions clowarden-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ rust-version.workspace = true

[dependencies]
anyhow = { workspace = true }
as-any = { workspace = true }
async-trait = { workspace = true }
base64 = { workspace = true }
cached = { workspace = true }
Expand Down
16 changes: 15 additions & 1 deletion clowarden-core/src/services/github/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
services::ChangeApplied,
};
use anyhow::{Context, Result};
use as_any::Downcast;
use async_trait::async_trait;
use tracing::debug;

Expand Down Expand Up @@ -132,13 +133,26 @@ impl ServiceHandler for Handler {
}

// Apply repositories changes
for change in changes.repositories {
'changes_repositories: for change in changes.repositories {
let err = match &change {
RepositoryChange::RepositoryAdded(repo) => self.svc.add_repository(&ctx, repo).await.err(),
RepositoryChange::TeamAdded(repo_name, team_name, role) => {
self.svc.add_repository_team(&ctx, repo_name, team_name, role).await.err()
}
RepositoryChange::TeamRemoved(repo_name, team_name) => {
// If the team has just been deleted from the directory in
// this reconciliation, there is no need to remove it from
// the repository as this will be done automatically when
// the team is deleted from GitHub
for entry in &changes_applied {
let change = (*entry.change).downcast_ref::<DirectoryChange>();
if let Some(DirectoryChange::TeamRemoved(team_removed_name)) = change {
if team_name == team_removed_name {
continue 'changes_repositories;
}
}
}

self.svc.remove_repository_team(&ctx, repo_name, team_name).await.err()
}
RepositoryChange::TeamRoleUpdated(repo_name, team_name, role) => {
Expand Down
3 changes: 2 additions & 1 deletion clowarden-core/src/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use crate::{cfg::Organization, github::Source};
use anyhow::Result;
use as_any::AsAny;
use async_trait::async_trait;
use std::fmt::Debug;

Expand Down Expand Up @@ -46,7 +47,7 @@ pub struct ChangeApplied {
}

/// Trait that defines some operations a Change implementation must support.
pub trait Change: Debug {
pub trait Change: AsAny + Debug {
/// Return some details about the change.
fn details(&self) -> ChangeDetails;

Expand Down

0 comments on commit 8ce70fa

Please sign in to comment.