-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract ResultingChangesetArgs into common module
Summary: ## This stack Migrate all commands from megarepo tool CLI to mononoke admin `megarepo` subcommand, so they use mononoke_app + clap 4, instad of old cmdlib + clap-2. I'll try to do one diff per command. ## This diff Many commands call a `add_resulting_commit_args` function (or variant) to add arguments for a changeset being created. In this diff I extract those into a common module, so they can be easily reused. Reviewed By: liubov-dmitrieva Differential Revision: D68951264 fbshipit-source-id: 361512dcf10bbd6d9f6f81fffc46861bd88605c7
- Loading branch information
1 parent
01471d9
commit 5ef5d21
Showing
3 changed files
with
62 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
* GNU General Public License version 2. | ||
*/ | ||
|
||
pub(crate) mod common; | ||
mod merge; | ||
mod pushredirection; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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::Error; | ||
use anyhow::Result; | ||
use bookmarks::BookmarkKey; | ||
use megarepolib::common::ChangesetArgs as MegarepoNewChangesetArgs; | ||
use mononoke_types::DateTime; | ||
|
||
#[derive(Debug, clap::Args, Clone)] | ||
pub(crate) struct ResultingChangesetArgs { | ||
#[clap(long, short = 'm')] | ||
pub commit_message: String, | ||
#[clap(long, short = 'a')] | ||
pub commit_author: String, | ||
|
||
#[clap(long = "commit-date-rfc3339")] | ||
pub datetime: Option<String>, | ||
|
||
#[clap( | ||
long, | ||
help = "bookmark to point to resulting commits (no sanity checks, will move existing bookmark, be careful)" | ||
)] | ||
pub set_bookmark: Option<String>, | ||
|
||
#[clap(long = "mark-public")] | ||
pub mark_public: bool, | ||
} | ||
|
||
impl TryInto<MegarepoNewChangesetArgs> for ResultingChangesetArgs { | ||
type Error = Error; | ||
|
||
fn try_into(self) -> Result<MegarepoNewChangesetArgs> { | ||
let mb_datetime = self | ||
.datetime | ||
.as_deref() | ||
.map_or_else(|| Ok(DateTime::now()), DateTime::from_rfc3339)?; | ||
|
||
let mb_bookmark = self.set_bookmark.map(BookmarkKey::new).transpose()?; | ||
let res = MegarepoNewChangesetArgs { | ||
message: self.commit_message, | ||
author: self.commit_author, | ||
datetime: mb_datetime, | ||
bookmark: mb_bookmark, | ||
mark_public: self.mark_public, | ||
}; | ||
Ok(res) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters