refactor: move cuddle-please to cuddle-please release

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2023-07-31 23:04:49 +02:00
parent 2650edb61e
commit ebbae295fd
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394

View File

@ -165,102 +165,7 @@ impl Command {
}; };
match &self.commands { match &self.commands {
Some(Commands::Config { command }) => match command { Some(Commands::Release {}) => {
ConfigCommand::List { .. } => {
tracing::debug!("running command: config list");
let _config = self.get_config(current_dir.as_path(), stdin)?;
self.ui.write_str_ln("cuddle-config");
}
},
Some(Commands::Gitea { command }) => {
let git_url = url::Url::parse(&self.global.api_url.unwrap())?;
let mut url = String::new();
url.push_str(git_url.scheme());
url.push_str("://");
url.push_str(&git_url.host().unwrap().to_string());
if let Some(port) = git_url.port() {
url.push_str(format!(":{port}").as_str());
}
let client = GiteaClient::new(url, self.global.token);
match command {
GiteaCommand::Connect {} => {
client.connect(self.global.owner.unwrap(), self.global.repo.unwrap())?;
self.ui.write_str_ln("connected succesfully go gitea");
}
GiteaCommand::Tags { command } => match command {
Some(GiteaTagsCommand::MostSignificant {}) => {
let tags = client
.get_tags(self.global.owner.unwrap(), self.global.repo.unwrap())?;
match get_most_significant_version(tags.iter().collect()) {
Some(tag) => {
self.ui.write_str_ln(&format!(
"found most significant tags: {}",
tag.name
));
}
None => {
self.ui.write_str_ln("found no tags with versioning schema");
}
}
}
None => {
let tags = client
.get_tags(self.global.owner.unwrap(), self.global.repo.unwrap())?;
self.ui.write_str_ln("got tags from gitea");
for tag in tags {
self.ui.write_str_ln(&format!("- {}", tag.name))
}
}
},
GiteaCommand::SinceCommit { sha, branch } => {
let commits = client.get_commits_since(
self.global.owner.unwrap(),
self.global.repo.unwrap(),
Some(sha),
branch,
)?;
self.ui.write_str_ln("got commits from gitea");
for commit in commits {
self.ui.write_str_ln(&format!("- {}", commit.get_title()))
}
}
GiteaCommand::CheckPr {} => {
let pr = client.get_pull_request(
self.global.owner.unwrap(),
self.global.repo.unwrap(),
)?;
match pr {
Some(index) => {
self.ui.write_str_ln(&format!(
"found cuddle-please (index={}) pr from gitea",
index
));
}
None => {
self.ui.write_str_ln("found no cuddle-please pr from gitea");
}
}
}
}
}
Some(Commands::Doctor {}) => {
match std::process::Command::new("git").arg("-v").output() {
Ok(o) => {
let stdout = std::str::from_utf8(&o.stdout).unwrap_or("");
self.ui.write_str_ln(&format!("OK: {}", stdout));
}
Err(e) => {
self.ui
.write_str_ln(&format!("WARNING: git is not installed: {}", e));
}
}
}
None => {
tracing::debug!("running bare command"); tracing::debug!("running bare command");
// 2. Parse the cuddle.please.yaml let cuddle.please.yaml take precedence // 2. Parse the cuddle.please.yaml let cuddle.please.yaml take precedence
// 2a. if not existing use default. // 2a. if not existing use default.
@ -387,6 +292,103 @@ impl Command {
} }
}; };
} }
Some(Commands::Config { command }) => match command {
ConfigCommand::List { .. } => {
tracing::debug!("running command: config list");
let _config = self.get_config(current_dir.as_path(), stdin)?;
self.ui.write_str_ln("cuddle-config");
}
},
Some(Commands::Gitea { command }) => {
let git_url = url::Url::parse(&self.global.api_url.unwrap())?;
let mut url = String::new();
url.push_str(git_url.scheme());
url.push_str("://");
url.push_str(&git_url.host().unwrap().to_string());
if let Some(port) = git_url.port() {
url.push_str(format!(":{port}").as_str());
}
let client = GiteaClient::new(url, self.global.token);
match command {
GiteaCommand::Connect {} => {
client.connect(self.global.owner.unwrap(), self.global.repo.unwrap())?;
self.ui.write_str_ln("connected succesfully go gitea");
}
GiteaCommand::Tags { command } => match command {
Some(GiteaTagsCommand::MostSignificant {}) => {
let tags = client
.get_tags(self.global.owner.unwrap(), self.global.repo.unwrap())?;
match get_most_significant_version(tags.iter().collect()) {
Some(tag) => {
self.ui.write_str_ln(&format!(
"found most significant tags: {}",
tag.name
));
}
None => {
self.ui.write_str_ln("found no tags with versioning schema");
}
}
}
None => {
let tags = client
.get_tags(self.global.owner.unwrap(), self.global.repo.unwrap())?;
self.ui.write_str_ln("got tags from gitea");
for tag in tags {
self.ui.write_str_ln(&format!("- {}", tag.name))
}
}
},
GiteaCommand::SinceCommit { sha, branch } => {
let commits = client.get_commits_since(
self.global.owner.unwrap(),
self.global.repo.unwrap(),
Some(sha),
branch,
)?;
self.ui.write_str_ln("got commits from gitea");
for commit in commits {
self.ui.write_str_ln(&format!("- {}", commit.get_title()))
}
}
GiteaCommand::CheckPr {} => {
let pr = client.get_pull_request(
self.global.owner.unwrap(),
self.global.repo.unwrap(),
)?;
match pr {
Some(index) => {
self.ui.write_str_ln(&format!(
"found cuddle-please (index={}) pr from gitea",
index
));
}
None => {
self.ui.write_str_ln("found no cuddle-please pr from gitea");
}
}
}
}
}
Some(Commands::Doctor {}) => {
match std::process::Command::new("git").arg("-v").output() {
Ok(o) => {
let stdout = std::str::from_utf8(&o.stdout).unwrap_or("");
self.ui.write_str_ln(&format!("OK: {}", stdout));
}
Err(e) => {
self.ui
.write_str_ln(&format!("WARNING: git is not installed: {}", e));
}
}
}
None => {}
} }
Ok(()) Ok(())
@ -414,11 +416,15 @@ impl Command {
#[derive(Debug, Clone, Subcommand)] #[derive(Debug, Clone, Subcommand)]
enum Commands { enum Commands {
/// Config is mostly used for debugging the final config output /// Config is mostly used for debugging the final config output
Release {},
#[command(hide = true)]
Config { Config {
#[command(subcommand)] #[command(subcommand)]
command: ConfigCommand, command: ConfigCommand,
}, },
#[command(hide = true)]
Gitea { Gitea {
#[command(subcommand)] #[command(subcommand)]
command: GiteaCommand, command: GiteaCommand,