Skip to content

Commit

Permalink
newadmin: add command for changing git source of truth config
Browse files Browse the repository at this point in the history
Summary: Adds a newadmin command `git-source-of-truth set` for displaying changing the git source of truth config for a repo.

Reviewed By: RajivTS

Differential Revision: D61920226

fbshipit-source-id: 1a958bea2649f8240fff3d3397a07e857e665058
  • Loading branch information
YousefSalama authored and facebook-github-bot committed Aug 28, 2024
1 parent 74d5b75 commit ed24fc7
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License found in the LICENSE file in the root
# directory of this source tree.

$ . "${TEST_FIXTURES}/library.sh"

setup configuration
$ setup_common_config

$ mononoke_newadmin git-source-of-truth -R repo show
No git source of truth config entry found for repo repo

$ mononoke_newadmin git-source-of-truth -R repo set locked

$ mononoke_newadmin git-source-of-truth -R repo show
GitSourceOfTruthConfigEntry { id: RowId(1), repo_id: RepositoryId(0), repo_name: RepositoryName("repo"), source_of_truth: Locked }

$ mononoke_newadmin git-source-of-truth -R repo set mononoke

$ mononoke_newadmin git-source-of-truth -R repo show
GitSourceOfTruthConfigEntry { id: RowId(2), repo_id: RepositoryId(0), repo_name: RepositoryName("repo"), source_of_truth: Mononoke }

$ mononoke_newadmin git-source-of-truth -R repo set metagit

$ mononoke_newadmin git-source-of-truth -R repo show
GitSourceOfTruthConfigEntry { id: RowId(3), repo_id: RepositoryId(0), repo_name: RepositoryName("repo"), source_of_truth: Metagit }
6 changes: 6 additions & 0 deletions eden/mononoke/tools/admin/src/commands/git_source_of_truth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* GNU General Public License version 2.
*/

mod set;
mod show;

use anyhow::Result;
Expand All @@ -14,6 +15,8 @@ use git_source_of_truth::GitSourceOfTruthConfig;
use mononoke_app::args::RepoArgs;
use mononoke_app::MononokeApp;
use repo_identity::RepoIdentity;
use set::set;
use set::SetArgs;
use show::show;
use show::ShowArgs;

Expand All @@ -31,6 +34,8 @@ pub struct CommandArgs {
pub enum GitSourceOfTruthSubcommand {
/// Show git source of truth config for this repo.
Show(ShowArgs),
/// Set git source of truth config for this repo.
Set(SetArgs),
}

#[facet::container]
Expand All @@ -48,5 +53,6 @@ pub async fn run(app: MononokeApp, args: CommandArgs) -> Result<()> {

match args.subcommand {
GitSourceOfTruthSubcommand::Show(args) => show(&ctx, &repo, args).await,
GitSourceOfTruthSubcommand::Set(args) => set(&ctx, &repo, args).await,
}
}
39 changes: 39 additions & 0 deletions eden/mononoke/tools/admin/src/commands/git_source_of_truth/set.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/

use anyhow::Result;
use clap::builder::PossibleValuesParser;
use clap::Args;
use context::CoreContext;
use git_source_of_truth::GitSourceOfTruth;
use git_source_of_truth::GitSourceOfTruthConfigRef;
use git_source_of_truth::RepositoryName;
use repo_identity::RepoIdentityRef;

use super::Repo;

#[derive(Args)]
pub struct SetArgs {
/// Source of truth to set for this repo. [possible values: metagit, mononoke, locked]
source_of_truth: GitSourceOfTruth,
}

pub async fn set(ctx: &CoreContext, repo: &Repo, args: SetArgs) -> Result<()> {
let repo_id = repo.repo_identity().id();
let repo_name = repo.repo_identity().name();

repo.git_source_of_truth_config()
.set(
ctx,
repo_id,
RepositoryName(repo_name.to_string()),
args.source_of_truth,
)
.await?;

Ok(())
}

0 comments on commit ed24fc7

Please sign in to comment.