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
20 changes: 20 additions & 0 deletions apps/staged/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,26 @@ fn update_repo_badge(
return Err("Hue must be between 0 and 360".into());
}
let store = get_store(&store)?;

// Check if another badge already uses this short name.
if let Some(existing) = store
.get_repo_badge_by_short_name(&short_name)
.map_err(|e| e.to_string())?
{
let is_same_badge = existing.github_repo == github_repo && existing.subpath == subpath;
if !is_same_badge {
let owner = if existing.subpath.is_empty() {
existing.github_repo.clone()
} else {
format!("{} ({})", existing.github_repo, existing.subpath)
};
return Err(format!(
"Short name '{}' is already used by {}",
short_name, owner
));
}
}

store
.update_repo_badge(&github_repo, &subpath, &short_name, hue)
.map_err(|e| e.to_string())?;
Expand Down
26 changes: 26 additions & 0 deletions apps/staged/src-tauri/src/store/repo_badges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,32 @@ impl Store {
Ok(())
}

/// Look up a single badge by its short_name.
pub fn get_repo_badge_by_short_name(
&self,
short_name: &str,
) -> Result<Option<RepoBadge>, StoreError> {
use rusqlite::OptionalExtension;
let conn = self.conn.lock().unwrap();
conn.query_row(
"SELECT github_repo, subpath, short_name, hue, created_at
FROM repo_badges
WHERE short_name = ?1",
params![short_name],
|row| {
Ok(RepoBadge {
github_repo: row.get(0)?,
subpath: row.get(1)?,
short_name: row.get(2)?,
hue: row.get(3)?,
created_at: row.get(4)?,
})
},
)
.optional()
.map_err(Into::into)
}

/// Delete a badge by (github_repo, subpath).
pub fn delete_repo_badge(&self, github_repo: &str, subpath: &str) -> Result<(), StoreError> {
let conn = self.conn.lock().unwrap();
Expand Down
Loading