Skip to content

Commit

Permalink
Restore ability to deserialize post without raw.
Browse files Browse the repository at this point in the history
  • Loading branch information
awaitlink committed Apr 10, 2024
1 parent 3642c52 commit 7c2c481
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
25 changes: 23 additions & 2 deletions src/discourse/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct Post {

pub user_id: u64,

pub raw: String,
pub raw: Option<String>,
}

#[derive(Deserialize, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -123,7 +123,28 @@ mod tests {
topic_id: 0,
post_number: 0,
user_id: 0,
raw: String::from("content"),
raw: Some(String::from("content")),
}))
);
}

#[test]
fn api_response_ok_post_deserialization_without_raw() {
let input = json! {{
"id": 0,
"topic_id": 0,
"post_number": 0,
"user_id": 0,
}};

assert_eq!(
serde_json::from_str::<ApiResponse<CreatePostResponse>>(&input.to_string()).unwrap(),
ApiResponse::Ok(CreatePostResponse::Posted(Post {
id: 0,
topic_id: 0,
post_number: 0,
user_id: 0,
raw: None,
}))
);
}
Expand Down
19 changes: 12 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod platform;
mod state;
mod utils;

use anyhow::Context;
use anyhow::{bail, Context};
use chrono::prelude::*;
use github::Tag;
use semver::Version;
Expand Down Expand Up @@ -164,13 +164,18 @@ async fn edit_existing_android_post_if_needed(

tracing::trace!("getting existing post...");
let existing_post = discourse::get_post(id, &discourse_api_key).await?;
let new_raw = existing_post.raw.replace(
Android.availability_notice(false),
Android.availability_notice(true),
);

discourse::edit_post(id, &discourse_api_key, &new_raw).await?;
tracing::trace!("probably edited post!");
if let Some(raw) = existing_post.raw {
let new_raw = raw.replace(
Android.availability_notice(false),
Android.availability_notice(true),
);

discourse::edit_post(id, &discourse_api_key, &new_raw).await?;
tracing::trace!("probably edited post!");
} else {
bail!("no raw in post?");
}
} else {
tracing::warn!("there's no post information but there is a last posted version!");
}
Expand Down

0 comments on commit 7c2c481

Please sign in to comment.