-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move submitter code to separate module.
- Loading branch information
1 parent
1fd0025
commit 503b7fb
Showing
25 changed files
with
107 additions
and
97 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 |
---|---|---|
|
@@ -13,5 +13,6 @@ mod proposal_executors; | |
mod qualification; | ||
mod runner; | ||
mod store; | ||
mod submitter; | ||
mod subnet_manager; | ||
mod util; |
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
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,73 @@ | ||
use clap::Args as ClapArgs; | ||
use log::warn; | ||
|
||
use crate::{ | ||
confirm::{ConfirmationModeOptions, HowToProceed}, | ||
forum::{ForumContext, ForumParameters, ForumPostKind}, | ||
proposal_executors::ProposalExecution, | ||
util::yesno, | ||
}; | ||
|
||
#[derive(ClapArgs, Debug, Clone)] | ||
pub struct SubmissionParameters { | ||
#[clap(flatten)] | ||
pub forum_parameters: ForumParameters, | ||
|
||
#[clap(flatten)] | ||
pub confirmation_mode: ConfirmationModeOptions, | ||
} | ||
|
||
/// Helps the caller preview and then submit a proposal automatically, | ||
/// handling the forum post part of the work as smoothly as possible. | ||
pub struct Submitter { | ||
mode: HowToProceed, | ||
forum_parameters: ForumParameters, | ||
} | ||
|
||
impl From<&SubmissionParameters> for Submitter { | ||
fn from(other: &SubmissionParameters) -> Self { | ||
Self { | ||
mode: (&other.confirmation_mode).into(), | ||
forum_parameters: other.forum_parameters.clone(), | ||
} | ||
} | ||
} | ||
|
||
impl Submitter { | ||
/// Submits a proposal (maybe in dry-run mode) with confirmation from the user, unless the user | ||
/// specifies in the command line that he wants no confirmation (--yes). | ||
pub async fn propose(&self, execution: Box<dyn ProposalExecution>, kind: ForumPostKind) -> anyhow::Result<()> { | ||
if let HowToProceed::Unconditional = self.mode { | ||
} else { | ||
execution.simulate().await?; | ||
}; | ||
|
||
if let HowToProceed::Confirm = self.mode { | ||
// Ask for confirmation | ||
if !yesno("Do you want to continue?", false).await?? { | ||
return Ok(()); | ||
} | ||
} | ||
|
||
if let HowToProceed::DryRun = self.mode { | ||
Ok(()) | ||
} else { | ||
let forum_post = ForumContext::from(&self.forum_parameters).client()?.forum_post(kind).await?; | ||
let res = execution.submit(forum_post.url()).await; | ||
match res { | ||
Ok(res) => forum_post.add_proposal_url(res.into()).await, | ||
Err(e) => { | ||
if let Some(forum_post_url) = forum_post.url() { | ||
// Here we would ask the forum post code to delete the post since | ||
// the submission has failed... that is, if we had that feature. | ||
warn!( | ||
"Forum post {} may have been created for this proposal, but proposal submission failed. Please delete the forum post if necessary, as it now serves no purpose.", | ||
forum_post_url | ||
); | ||
}; | ||
Err(e) | ||
} | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.