Skip to content

Commit

Permalink
chore(cli): Separate status message outputting from knowing about our…
Browse files Browse the repository at this point in the history
… env
  • Loading branch information
alerque committed May 18, 2024
1 parent 74b2b11 commit e2d95bb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
12 changes: 11 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use git2::{Oid, Repository, Signature};
use i18n::LocalText;
use regex::Regex;
use std::ffi::OsStr;
use std::{error, fmt, path, result, str};
use std::{env, error, fmt, path, result, str};

pub mod cli;
pub mod config;
Expand Down Expand Up @@ -74,6 +74,16 @@ pub fn get_repo() -> Result<Repository> {
Ok(Repository::discover(path)?)
}

/// Check to see if we're running in GitHub Actions
pub fn is_gha() -> bool {
env::var("GITHUB_ACTIONS").is_ok()
}

/// Check to see if we're running in GitLab CI
pub fn is_glc() -> bool {
env::var("GITLAB_CI").is_ok()
}

pub fn commit(repo: Repository, oid: Oid, msg: &str) -> result::Result<Oid, git2::Error> {
let prefix = "[casile]";
let commiter = repo.signature()?;
Expand Down
4 changes: 2 additions & 2 deletions src/make/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ pub fn run(target: Vec<String>) -> Result<()> {
if targets.is_empty() {
targets.push(String::from("default"));
}
let is_gha = status::is_gha()?;
let is_glc = status::is_glc()?;
let is_gha = status::status_is_gha()?;
let is_glc = status::status_is_glc()?;
if is_gha {
targets.push(String::from("_gha"));
}
Expand Down
10 changes: 5 additions & 5 deletions src/status/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::*;

use git2::{DescribeFormatOptions, DescribeOptions};
use regex::Regex;
use std::{env, path};
use std::path;

// FTL: help-subcommand-status
/// Dump what we know about the repo
Expand Down Expand Up @@ -31,16 +31,16 @@ fn run_as() -> RunAsMode {
}

/// Check to see if we're running in GitHub Actions
pub fn is_gha() -> Result<bool> {
let ret = env::var("GITHUB_ACTIONS").is_ok();
pub fn status_is_gha() -> Result<bool> {
let ret = is_gha();
let status = CASILEUI.new_check("status-is-gha");
status.end(ret);
Ok(ret)
}

/// Check to see if we're running in GitLab CI
pub fn is_glc() -> Result<bool> {
let ret = env::var("GITLAB_CI").is_ok();
pub fn status_is_glc() -> Result<bool> {
let ret = is_glc();
let status = CASILEUI.new_check("status-is-glc");
status.end(ret);
Ok(ret)
Expand Down

0 comments on commit e2d95bb

Please sign in to comment.