Add first-class Actions management (#63)
This commit is contained in:
@@ -5,7 +5,7 @@ use std::{
|
||||
|
||||
pub use gotcha_gitea::{
|
||||
HistoryCommit, HomeData, IssueDetails, IssueEditorData, MilestoneDetails, Page, PullDetails,
|
||||
civil_from_days, days_from_civil, parse_api_date,
|
||||
civil_from_days, days_from_civil, parse_api_date, parse_api_timestamp,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -74,6 +74,8 @@ pub struct Preferences {
|
||||
pub notifications_enabled: bool,
|
||||
#[serde(default)]
|
||||
pub notification_cursors: BTreeMap<String, String>,
|
||||
#[serde(default = "default_primary_destinations")]
|
||||
pub primary_destinations: Vec<crate::PrimaryDestination>,
|
||||
}
|
||||
|
||||
impl Default for Preferences {
|
||||
@@ -90,10 +92,32 @@ impl Default for Preferences {
|
||||
appearance: AppearanceMode::default(),
|
||||
notifications_enabled: false,
|
||||
notification_cursors: BTreeMap::new(),
|
||||
primary_destinations: default_primary_destinations(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn default_primary_destinations() -> Vec<crate::PrimaryDestination> {
|
||||
vec![
|
||||
crate::PrimaryDestination::Issues,
|
||||
crate::PrimaryDestination::Repositories,
|
||||
crate::PrimaryDestination::PullRequests,
|
||||
crate::PrimaryDestination::Milestones,
|
||||
]
|
||||
}
|
||||
|
||||
pub fn normalize_primary_destinations(destinations: &mut Vec<crate::PrimaryDestination>) -> bool {
|
||||
let original = destinations.clone();
|
||||
let mut unique = Vec::with_capacity(destinations.len().min(4));
|
||||
for destination in destinations.drain(..) {
|
||||
if !unique.contains(&destination) && unique.len() < 4 {
|
||||
unique.push(destination);
|
||||
}
|
||||
}
|
||||
*destinations = unique;
|
||||
*destinations != original
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Deserialize, Eq, PartialEq, Serialize)]
|
||||
pub struct IssueFilter {
|
||||
#[serde(default)]
|
||||
@@ -222,4 +246,32 @@ mod tests {
|
||||
""
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn primary_destinations_are_ordered_unique_and_limited() {
|
||||
let migrated: Preferences = serde_json::from_str("{}").unwrap();
|
||||
assert_eq!(
|
||||
migrated.primary_destinations,
|
||||
default_primary_destinations()
|
||||
);
|
||||
|
||||
let mut destinations = vec![
|
||||
crate::PrimaryDestination::Actions,
|
||||
crate::PrimaryDestination::Actions,
|
||||
crate::PrimaryDestination::Issues,
|
||||
crate::PrimaryDestination::Repositories,
|
||||
crate::PrimaryDestination::PullRequests,
|
||||
crate::PrimaryDestination::Milestones,
|
||||
];
|
||||
assert!(normalize_primary_destinations(&mut destinations));
|
||||
assert_eq!(
|
||||
destinations,
|
||||
[
|
||||
crate::PrimaryDestination::Actions,
|
||||
crate::PrimaryDestination::Issues,
|
||||
crate::PrimaryDestination::Repositories,
|
||||
crate::PrimaryDestination::PullRequests,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user