Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some improvements in GitHub reconciliation #133

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading