Skip to main content

changeset_operations/traits/
init_interaction.rs

1use changeset_git::DEFAULT_BASE_BRANCH;
2use changeset_manifest::{
3    ChangelogLocation, ComparisonLinks, NoneBumpBehavior, TagFormat, ZeroVersionBehavior,
4};
5
6use crate::Result;
7
8#[derive(Debug, Clone, Copy, Default)]
9pub struct ProjectContext {
10    pub is_single_package: bool,
11}
12
13#[derive(Debug, Clone)]
14pub struct GitSettingsInput {
15    pub commit: bool,
16    pub tags: bool,
17    pub keep_changesets: bool,
18    pub tag_format: TagFormat,
19    pub base_branch: String,
20    pub commit_title_template: Option<String>,
21    pub changes_in_body: Option<bool>,
22}
23
24impl Default for GitSettingsInput {
25    fn default() -> Self {
26        Self {
27            commit: true,
28            tags: true,
29            keep_changesets: false,
30            tag_format: TagFormat::default(),
31            base_branch: String::from(DEFAULT_BASE_BRANCH),
32            commit_title_template: None,
33            changes_in_body: None,
34        }
35    }
36}
37
38#[derive(Debug, Clone, Default)]
39pub struct ChangelogSettingsInput {
40    pub changelog: ChangelogLocation,
41    pub comparison_links: ComparisonLinks,
42    pub comparison_links_template: Option<String>,
43    pub dependency_bump_changelog_template: Option<String>,
44}
45
46#[derive(Debug, Clone, Default)]
47pub struct VersionSettingsInput {
48    pub zero_version_behavior: Option<ZeroVersionBehavior>,
49    pub none_bump_behavior: Option<NoneBumpBehavior>,
50    pub none_bump_promote_message_template: Option<String>,
51}
52
53#[derive(Debug, Clone, Default)]
54pub struct FilteringSettingsInput {
55    pub ignored_files: Vec<String>,
56}
57
58pub trait InitInteractionProvider: Send + Sync {
59    /// # Errors
60    ///
61    /// Returns an error if the interaction cannot be completed.
62    fn configure_git_settings(&self, context: ProjectContext) -> Result<Option<GitSettingsInput>>;
63
64    /// For single-package projects, the changelog location question should be skipped
65    /// (defaulting to root), but `comparison_links` should still be prompted.
66    ///
67    /// # Errors
68    ///
69    /// Returns an error if the interaction cannot be completed.
70    fn configure_changelog_settings(
71        &self,
72        context: ProjectContext,
73    ) -> Result<Option<ChangelogSettingsInput>>;
74
75    /// # Errors
76    ///
77    /// Returns an error if the interaction cannot be completed.
78    fn configure_version_settings(&self) -> Result<Option<VersionSettingsInput>>;
79
80    /// # Errors
81    ///
82    /// Returns an error if the interaction cannot be completed.
83    fn configure_filtering_settings(&self) -> Result<Option<FilteringSettingsInput>>;
84}