Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
Do not trim by default on commits
Browse files Browse the repository at this point in the history
  • Loading branch information
augustuswm committed Dec 11, 2023
1 parent 697a105 commit 46e7168
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
6 changes: 3 additions & 3 deletions cio/src/certs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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?;

Expand All @@ -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?;

Expand Down
4 changes: 2 additions & 2 deletions cio/src/huddles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -476,7 +476,7 @@ pub async fn sync_huddle_meeting_notes(company: &Company) -> Result<()> {
"reports",
"",
&notes_path,
notes.as_bytes().to_vec(),
notes.as_bytes().to_vec().trim(),
)
.await?;
}
Expand Down
4 changes: 2 additions & 2 deletions cio/src/rfd/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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())
Expand Down
6 changes: 3 additions & 3 deletions cio/src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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?;
}
Expand All @@ -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?;
}
Expand Down
11 changes: 5 additions & 6 deletions cio/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ pub async fn create_or_update_file_in_github_repo(
path: &str,
new_content: Vec<u8>,
) -> 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();
Expand All @@ -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);
Expand All @@ -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")
Expand All @@ -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()
);

Expand All @@ -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(),
},
Expand All @@ -225,7 +224,7 @@ pub async fn create_or_update_file_in_github_repo(
}
}

trait SliceExt {
pub trait SliceExt {
fn trim(&self) -> Self;
}

Expand Down

0 comments on commit 46e7168

Please sign in to comment.