Skip to content

Commit

Permalink
use config for email, message, name on gitops commits
Browse files Browse the repository at this point in the history
  • Loading branch information
slackspace-io committed Mar 23, 2024
1 parent dad87af commit 0688450
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions backend/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ pub struct GitopsConfig {
pub name: String,
pub repository_url: String,
pub branch: String,
pub commit_name: String,
pub commit_email: String,
pub access_token_env_name: String,
pub commit_message: String,
}

#[derive(Debug, Deserialize, Clone)]
Expand Down
14 changes: 11 additions & 3 deletions backend/src/gitops/gitops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,13 @@ fn stage_changes(repo: &Repository) -> Result<(), git2::Error> {
Ok(())
}

fn commit_changes<'a>(repo: &'a Repository, message: &str) -> Result<Commit<'a>, git2::Error> {
let sig = Signature::now("slackwatch", "[email protected]")?;
fn commit_changes<'a>(
repo: &'a Repository,
message: &str,
commit_name: &str,
commit_email: &str,
) -> Result<Commit<'a>, git2::Error> {
let sig = Signature::now(commit_name, commit_email)?;
let oid = repo.index()?.write_tree()?;
let tree = repo.find_tree(oid)?;
let parent_commit = find_last_commit(repo)?;
Expand Down Expand Up @@ -202,6 +207,9 @@ pub fn run_git_operations(workload: Workload) -> Result<(), Box<dyn Error>> {
);
continue;
}
let commit_name = gitops_config.commit_name;
let commit_email = gitops_config.commit_email;
let commit_message = gitops_config.commit_message;
let repo_url = gitops_config.repository_url;
let branch = gitops_config.branch;
let name = gitops_config.name;
Expand All @@ -215,7 +223,7 @@ pub fn run_git_operations(workload: Workload) -> Result<(), Box<dyn Error>> {
let repo = clone_or_open_repo(&repo_url, &local_path, &access_token)?;
edit_files(&local_path, &workload);
stage_changes(&repo)?;
commit_changes(&repo, "Automated commit by gitops.rs")?;
commit_changes(&repo, &commit_message, &commit_name, &commit_email)?;
push_changes(&repo, &access_token)?;
}

Expand Down

0 comments on commit 0688450

Please sign in to comment.