add repo star and repo unstar

This commit is contained in:
Cyborus 2024-05-14 16:45:58 -04:00
parent a259a44eca
commit 6687c9e2c1
No known key found for this signature in database

View file

@ -275,6 +275,12 @@ pub enum RepoCommand {
#[clap(long, short = 'R')] #[clap(long, short = 'R')]
remote: Option<String>, remote: Option<String>,
}, },
Star {
repo: String,
},
Unstar {
repo: String,
},
Browse { Browse {
name: Option<String>, name: Option<String>,
#[clap(long, short = 'R')] #[clap(long, short = 'R')]
@ -456,6 +462,21 @@ impl RepoCommand {
println!("View online at {html_url}"); println!("View online at {html_url}");
} }
} }
RepoCommand::Star { repo } => {
let repo = RepoInfo::get_current(host_name, Some(&repo), None)?;
let api = keys.get_api(&repo.host_url())?;
let name = repo.name().unwrap();
api.user_current_put_star(name.owner(), name.name()).await?;
println!("Starred {}/{}!", name.owner(), name.name());
}
RepoCommand::Unstar { repo } => {
let repo = RepoInfo::get_current(host_name, Some(&repo), None)?;
let api = keys.get_api(&repo.host_url())?;
let name = repo.name().unwrap();
api.user_current_delete_star(name.owner(), name.name())
.await?;
println!("Removed star from {}/{}", name.owner(), name.name());
}
RepoCommand::Browse { name, remote } => { RepoCommand::Browse { name, remote } => {
let repo = RepoInfo::get_current(host_name, name.as_deref(), remote.as_deref())?; let repo = RepoInfo::get_current(host_name, name.as_deref(), remote.as_deref())?;
let mut url = repo.host_url().clone(); let mut url = repo.host_url().clone();