Format TUI commit activity previews
This commit is contained in:
@@ -164,25 +164,23 @@ fn activity_row(activity: &models::Activity) -> ActivityRow {
|
||||
}
|
||||
|
||||
fn activity_detail(activity: &models::Activity) -> String {
|
||||
let text = activity
|
||||
let comment = activity
|
||||
.comment
|
||||
.as_ref()
|
||||
.and_then(|comment| comment.body.as_deref())
|
||||
.or(activity.content.as_deref())
|
||||
.unwrap_or("");
|
||||
if let Ok(payload) = serde_json::from_str::<serde_json::Value>(text) {
|
||||
let commits = payload.get("Len").and_then(|value| value.as_i64());
|
||||
.and_then(|comment| comment.body.as_deref());
|
||||
let text = comment.or(activity.content.as_deref()).unwrap_or("");
|
||||
if comment.is_none()
|
||||
&& let Some(payload) = activity::commit_activity(activity)
|
||||
{
|
||||
let message = payload
|
||||
.get("HeadCommit")
|
||||
.and_then(|commit| commit.get("Message"))
|
||||
.and_then(|message| message.as_str())
|
||||
.map(summary)
|
||||
.commits
|
||||
.last()
|
||||
.map(|commit| summary(&commit.message))
|
||||
.unwrap_or_default();
|
||||
if !message.is_empty() {
|
||||
return match commits {
|
||||
Some(1) => format!("1 commit · {message}"),
|
||||
Some(count) => format!("{count} commits · {message}"),
|
||||
None => message,
|
||||
return match payload.count {
|
||||
1 => format!("1 commit · {message}"),
|
||||
count => format!("{count} commits · {message}"),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user