mirror of
https://github.com/moghtech/komodo.git
synced 2026-08-26 08:00:26 +00:00
118ae9b92c
* update easy deps * update otel deps * implement template in types + update resource meta * ts types * dev-2 * dev-3 default template query is include * Toggle resource is template in resource header * dev-4 support CopyServer * gen ts * style template selector in New Resource menu * fix new menu show 0 * add template market in omni search bar * fix some dynamic import behavior * template badge on dashboard * dev-5 * standardize interpolation methods with nice api * core use new interpolation methods * refactor git usage * dev-6 refactor interpolation / git methods * fix pull stack passed replacers * new types * remove redundant interpolation for build secret args * clean up periphery docker client * dev-7 include ports in container summary, see if they actually come through * show container ports in container table * refresh processes without tasks (more efficient) * dev-8 keep container stats cache, include with ContainerListItem * gen types * display more container ports * dev-9 fix repo clone when repo doesn't exist initially * Add ports display to more spots * fix function name * add Periphery full container stats api, may be used later * server container stats list * dev-10 * 1.18.4 release * Use reset instead of invalidate to fix GetUser spam on token expiry (#618) --------- Co-authored-by: Jacky Fong <hello@huzky.dev>
110 lines
2.7 KiB
Rust
110 lines
2.7 KiB
Rust
use std::path::Path;
|
|
|
|
use anyhow::{Context, anyhow};
|
|
use formatting::{bold, muted};
|
|
use komodo_client::entities::{
|
|
LatestCommit, komodo_timestamp, update::Log,
|
|
};
|
|
use run_command::async_run_command;
|
|
use tracing::instrument;
|
|
|
|
mod clone;
|
|
mod commit;
|
|
mod init;
|
|
mod pull;
|
|
mod pull_or_clone;
|
|
|
|
pub use crate::{
|
|
clone::clone,
|
|
commit::{commit_all, commit_file, write_commit_file},
|
|
init::init_folder_as_repo,
|
|
pull::pull,
|
|
pull_or_clone::pull_or_clone,
|
|
};
|
|
|
|
#[instrument(level = "debug")]
|
|
pub async fn get_commit_hash_info(
|
|
repo_dir: &Path,
|
|
) -> anyhow::Result<LatestCommit> {
|
|
let command = format!(
|
|
"cd {} && git rev-parse --short HEAD && git rev-parse HEAD && git log -1 --pretty=%B",
|
|
repo_dir.display()
|
|
);
|
|
let output = async_run_command(&command).await;
|
|
let mut split = output.stdout.split('\n');
|
|
let (hash, _, message) = (
|
|
split
|
|
.next()
|
|
.context("Failed to get short commit hash")?
|
|
.to_string(),
|
|
split.next().context("failed to get long commit hash")?,
|
|
split
|
|
.next()
|
|
.context("Failed to get commit message")?
|
|
.to_string(),
|
|
);
|
|
Ok(LatestCommit { hash, message })
|
|
}
|
|
/// returns (Log, commit hash, commit message)
|
|
#[instrument(level = "debug")]
|
|
pub async fn get_commit_hash_log(
|
|
repo_dir: &Path,
|
|
) -> anyhow::Result<(Log, String, String)> {
|
|
let start_ts = komodo_timestamp();
|
|
let command = format!(
|
|
"cd {} && git rev-parse --short HEAD && git rev-parse HEAD && git log -1 --pretty=%B",
|
|
repo_dir.display()
|
|
);
|
|
let output = async_run_command(&command).await;
|
|
let mut split = output.stdout.split('\n');
|
|
let (short_hash, _, msg) = (
|
|
split
|
|
.next()
|
|
.context("Failed to get short commit hash")?
|
|
.to_string(),
|
|
split.next().context("Failed to get long commit hash")?,
|
|
split
|
|
.next()
|
|
.context("Failed to get commit message")?
|
|
.to_string(),
|
|
);
|
|
let log = Log {
|
|
stage: "Latest Commit".into(),
|
|
command,
|
|
stdout: format!(
|
|
"{} {}\n{} {}",
|
|
muted("hash:"),
|
|
bold(&short_hash),
|
|
muted("message:"),
|
|
bold(&msg),
|
|
),
|
|
stderr: String::new(),
|
|
success: true,
|
|
start_ts,
|
|
end_ts: komodo_timestamp(),
|
|
};
|
|
Ok((log, short_hash, msg))
|
|
}
|
|
|
|
/// Gets the remote url, with `.git` stripped from the end.
|
|
pub async fn get_remote_url(path: &Path) -> anyhow::Result<String> {
|
|
let command =
|
|
format!("cd {} && git remote show origin", path.display());
|
|
let output = async_run_command(&command).await;
|
|
if output.success() {
|
|
Ok(
|
|
output
|
|
.stdout
|
|
.strip_suffix(".git")
|
|
.map(str::to_string)
|
|
.unwrap_or(output.stdout),
|
|
)
|
|
} else {
|
|
Err(anyhow!(
|
|
"Failed to get remote url | stdout: {} | stderr: {}",
|
|
output.stdout,
|
|
output.stderr
|
|
))
|
|
}
|
|
}
|