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

[FIL-402] Fix missing application after grant DataCap #245

Merged
merged 1 commit into from
Nov 27, 2024
Merged
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
59 changes: 12 additions & 47 deletions fplus-database/src/database/applications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,66 +261,31 @@ pub async fn merge_application_by_pr_number(
owner: String,
repo: String,
pr_number: u64,
) -> Result<ApplicationModel, sea_orm::DbErr> {
) -> Result<(), sea_orm::DbErr> {
let conn = get_database_connection().await?;
let pr_application =
get_application_by_pr_number(owner.clone(), repo.clone(), pr_number).await?;
let mut exists_merged = true;

let mut merged_application = match get_application(
let mut application_active_model: ActiveModel;
if let Ok(application) = get_application(
pr_application.id.clone(),
owner.clone(),
repo.clone(),
Some(0),
)
.await
{
Ok(application) => application.into_active_model(),
Err(_) => {
exists_merged = false;
ActiveModel {
id: Set(pr_application.id.clone()),
owner: Set(owner),
repo: Set(repo),
pr_number: Set(0),
application: Set(pr_application.application.clone()),
path: Set(pr_application.path.clone()),
..Default::default()
}
}
};

let mut hasher = Sha1::new();
let application = match pr_application.application.clone() {
Some(app) => format!("blob {}\x00{}", app.len(), app),
None => "".to_string(),
};
hasher.update(application.as_bytes());
let file_sha = format!("{:x}", hasher.finalize());
merged_application.sha = Set(Some(file_sha));
merged_application.application = Set(pr_application.application.clone());

pr_application.delete(&conn).await?;

if exists_merged {
let result = merged_application.update(&conn).await;
match result {
Ok(application) => Ok(application),
Err(e) => Err(sea_orm::DbErr::Custom(format!(
"Failed to merge application: {}",
e
))),
}
application_active_model = application.into_active_model();
application_active_model.application = Set(pr_application.application.clone());
kacperzuk-neti marked this conversation as resolved.
Show resolved Hide resolved
application_active_model.sha = Set(pr_application.sha.clone());
application_active_model.update(&conn).await?;
} else {
let result = merged_application.insert(&conn).await;
match result {
Ok(application) => Ok(application),
Err(e) => Err(sea_orm::DbErr::Custom(format!(
"Failed to merge application: {}",
e
))),
}
application_active_model = pr_application.clone().into_active_model();
application_active_model.pr_number = Set(0);
application_active_model.insert(&conn).await?;
}
pr_application.delete(&conn).await?;
Ok(())
}

/**
Expand Down