Skip to content
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
14 changes: 3 additions & 11 deletions rfd-api/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use octorust::{
};
use partial_struct::partial;
use rfd_data::{
content::{RfdContent, RfdContentError, RfdDocument, RfdTemplate, TemplateError},
content::{RfdContent, RfdDocument, RfdTemplate, TemplateError},
RfdNumber,
};
use rfd_github::{GitHubError, GitHubNewRfdNumber, GitHubRfdRepo};
Expand Down Expand Up @@ -87,8 +87,6 @@ pub enum UpdateRfdContentError {
GitHub(#[from] GitHubError),
#[error("Internal GitHub state does not currently allow for update. This commit appears as the head commit on multiple branches.")]
InternalState,
#[error("Unable to parse RFD contents")]
InvalidContent(#[from] RfdContentError),
#[error("Failed to construct new RFD template")]
InvalidTemplate(#[from] TemplateError),
#[error("Unable to perform action. Unable to find the default branch on GitHub.")]
Expand Down Expand Up @@ -676,14 +674,8 @@ impl RfdContext {
.inner_err_into()?;

let sha = latest_revision.commit.clone();
let mut updated_content: RfdContent = latest_revision
.try_into()
.map_err(UpdateRfdContentError::InvalidContent)
.map_err(ResourceError::InternalError)?;
updated_content
.update_body(content)
.map_err(UpdateRfdContentError::InvalidContent)
.map_err(ResourceError::InternalError)?;
let mut updated_content: RfdContent = latest_revision.into();
updated_content.update_body(content);

self.commit_rfd_document(
caller,
Expand Down
27 changes: 3 additions & 24 deletions rfd-api/src/endpoints/rfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,7 @@ async fn view_rfd_attr_op(
let rfd = ctx.view_rfd(caller, rfd_number, None).await?;
let content = match (rfd.content, rfd.format) {
(Some(content), Some(ContentFormat::Asciidoc)) => {
RfdContent::Asciidoc(RfdAsciidoc::new(content).map_err(|err| {
tracing::warn!(?err, "Failed to parse RFD content");
HttpError::for_internal_error(format!(
"Failed to parse RFD content for RFD {}",
number
))
})?)
RfdContent::Asciidoc(RfdAsciidoc::new(content))
}
(Some(content), Some(ContentFormat::Markdown)) => {
RfdContent::Markdown(RfdMarkdown::new(content))
Expand Down Expand Up @@ -760,15 +754,7 @@ async fn set_rfd_attr_op(

// TODO: Get rid of these clones
let mut content = match revision.content_format {
ContentFormat::Asciidoc => {
RfdContent::Asciidoc(RfdAsciidoc::new(revision.content).map_err(|err| {
tracing::warn!(?err, "Failed to parse RFD content");
HttpError::for_internal_error(format!(
"Failed to parse RFD content for RFD {}",
number
))
})?)
}
ContentFormat::Asciidoc => RfdContent::Asciidoc(RfdAsciidoc::new(revision.content)),
ContentFormat::Markdown => RfdContent::Markdown(RfdMarkdown::new(revision.content)),
};

Expand All @@ -783,14 +769,7 @@ async fn set_rfd_attr_op(
})?;
content.update_state(&state.to_string())
}
}
.map_err(|err| {
tracing::info!(?err, "Update resulted in malfored RFD");
HttpError::for_bad_request(
None,
"Update would result in a malformed RFD. Update has not been applied".to_string(),
)
})?;
};

tracing::info!("Updated attribute in RFD document");

Expand Down
Loading
Loading