diff --git a/cio/src/certs.rs b/cio/src/certs.rs index 556ae6c79..47b2dc350 100644 --- a/cio/src/certs.rs +++ b/cio/src/certs.rs @@ -34,7 +34,7 @@ use crate::{ db::Database, dns_providers::{DNSProviderOps, DnsRecord, DnsRecordType, DnsUpdateMode}, schema::certificates, - utils::{create_or_update_file_in_github_repo, get_file_content_from_repo}, + utils::{create_or_update_file_in_github_repo, get_file_content_from_repo, SliceExt}, }; /// A data type to hold the values of a let's encrypt certificate for a domain. @@ -391,7 +391,7 @@ impl CertificateStorage for GitHubBackend { &self.repo, &repo.default_branch, &self.path(domain, "fullchain.pem"), - data.to_vec(), + data.to_vec().trim(), ) .await?; @@ -410,7 +410,7 @@ impl KeyStorage for GitHubBackend { &self.repo, &repo.default_branch, &self.path(domain, "privkey.pem"), - data.to_vec(), + data.to_vec().trim(), ) .await?; diff --git a/cio/src/huddles.rs b/cio/src/huddles.rs index 4f7ca4464..f413b3c0f 100644 --- a/cio/src/huddles.rs +++ b/cio/src/huddles.rs @@ -14,7 +14,7 @@ use crate::{ configs::{get_configs_from_repo, User}, core::{DiscussionTopic, Meeting, MeetingReminderEmailData}, db::Database, - utils::create_or_update_file_in_github_repo, + utils::{create_or_update_file_in_github_repo, SliceExt}, }; /// Make sure if an event is moved in Google Calendar that Airtable is updated. @@ -476,7 +476,7 @@ pub async fn sync_huddle_meeting_notes(company: &Company) -> Result<()> { "reports", "", ¬es_path, - notes.as_bytes().to_vec(), + notes.as_bytes().to_vec().trim(), ) .await?; } diff --git a/cio/src/rfd/github.rs b/cio/src/rfd/github.rs index acc81b443..01d3c9862 100644 --- a/cio/src/rfd/github.rs +++ b/cio/src/rfd/github.rs @@ -11,7 +11,7 @@ use crate::{ companies::Company, core::GitHubPullRequest, utils::is_image, - utils::{create_or_update_file_in_github_repo, decode_base64_to_string, get_file_content_from_repo}, + utils::{create_or_update_file_in_github_repo, decode_base64_to_string, get_file_content_from_repo, SliceExt}, }; use super::{PDFStorage, RFDContent, RFDNumber, RFDPdf}; @@ -346,7 +346,7 @@ impl PDFStorage for GitHubRFDBranch { &self.repo, &self.branch, &rfd_path, - pdf.contents.to_vec(), + pdf.contents.to_vec().trim(), ) .await .map(|_| "".to_string()) diff --git a/cio/src/templates.rs b/cio/src/templates.rs index c78ed5d4f..ca6112fa1 100644 --- a/cio/src/templates.rs +++ b/cio/src/templates.rs @@ -2,7 +2,7 @@ use anyhow::Result; use handlebars::{Context, Handlebars, Helper, HelperResult, Output, RenderContext}; use serde::{Deserialize, Serialize}; -use crate::{configs::User, shorturls::ShortUrl, utils::create_or_update_file_in_github_repo}; +use crate::{configs::User, shorturls::ShortUrl, utils::{create_or_update_file_in_github_repo, SliceExt}}; /// Helper function so the terraform names do not start with a number. /// Otherwise terraform will fail. @@ -72,7 +72,7 @@ pub async fn generate_nginx_files_for_shorturls( repo, "", // leaving the branch blank gives us the default branch &nginx_file, - nginx_rendered.as_bytes().to_vec(), + nginx_rendered.as_bytes().to_vec().trim(), ) .await?; } @@ -93,7 +93,7 @@ pub async fn generate_nginx_files_for_shorturls( repo, "", // leaving the branch blank gives us the default branch &nginx_paths_file, - nginx_paths_rendered.as_bytes().to_vec(), + nginx_paths_rendered.as_bytes().to_vec().trim(), ) .await?; } diff --git a/cio/src/utils.rs b/cio/src/utils.rs index cf06d242d..fdc7fc9ac 100644 --- a/cio/src/utils.rs +++ b/cio/src/utils.rs @@ -140,7 +140,6 @@ pub async fn create_or_update_file_in_github_repo( path: &str, new_content: Vec, ) -> Result<()> { - let content = new_content.trim(); // Add the starting "/" so this works. // TODO: figure out why it doesn't work without it. let mut file_path = path.to_string(); @@ -157,7 +156,7 @@ pub async fn create_or_update_file_in_github_repo( }; if !existing_content.is_empty() || !sha.is_empty() { - if content == existing_content { + if new_content == existing_content { // They are the same so we can return early, we do not need to update the // file. info!("github file contents at {} are the same, no update needed", file_path); @@ -167,7 +166,7 @@ pub async fn create_or_update_file_in_github_repo( // When the pdfs are generated they change the modified time that is // encoded in the file. We want to get that diff and see if it is // the only change so that we are not always updating those files. - let diff = diffy::create_patch_bytes(&existing_content, &content); + let diff = diffy::create_patch_bytes(&existing_content, &new_content); let bdiff = diff.to_bytes(); let str_diff = from_utf8(&bdiff).unwrap_or(""); if str_diff.contains("-/ModDate") @@ -187,7 +186,7 @@ pub async fn create_or_update_file_in_github_repo( "[github content] Writing file to GitHub repo: {} / path: {} / content_length: {} / existing_content_length: {}", repo, file_path, - content.len(), + new_content.len(), existing_content.len() ); @@ -206,7 +205,7 @@ pub async fn create_or_update_file_in_github_repo( ), sha, branch: branch.to_string(), - content: base64::encode(content), + content: base64::encode(new_content), committer: Default::default(), author: Default::default(), }, @@ -225,7 +224,7 @@ pub async fn create_or_update_file_in_github_repo( } } -trait SliceExt { +pub trait SliceExt { fn trim(&self) -> Self; }