Skip to content

Commit

Permalink
fix(remote): avoid setting multiple remotes (#885)
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun authored Sep 25, 2024
1 parent a5786be commit a344c68
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 42 deletions.
23 changes: 23 additions & 0 deletions git-cliff-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,29 @@ pub struct RemoteConfig {
pub bitbucket: Remote,
}

impl RemoteConfig {
/// Returns `true` if any remote is set.
pub fn is_any_set(&self) -> bool {
#[cfg(feature = "github")]
if self.github.is_set() {
return true;
}
#[cfg(feature = "gitlab")]
if self.gitlab.is_set() {
return true;
}
#[cfg(feature = "gitea")]
if self.gitea.is_set() {
return true;
}
#[cfg(feature = "bitbucket")]
if self.bitbucket.is_set() {
return true;
}
false
}
}

/// A single remote.
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct Remote {
Expand Down
65 changes: 23 additions & 42 deletions git-cliff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,52 +123,33 @@ fn process_repository<'a>(
count && !ignore
});

if !config.remote.github.is_set() {
if !config.remote.is_any_set() {
match repository.upstream_remote() {
Ok(remote) => {
debug!("No GitHub remote is set, using remote: {}", remote);
config.remote.github.owner = remote.owner;
config.remote.github.repo = remote.repo;
config.remote.github.is_custom = remote.is_custom;
}
Err(e) => {
debug!("Failed to get remote from GitHub repository: {:?}", e);
}
}
} else if !config.remote.gitlab.is_set() {
match repository.upstream_remote() {
Ok(remote) => {
debug!("No GitLab remote is set, using remote: {}", remote);
config.remote.gitlab.owner = remote.owner;
config.remote.gitlab.repo = remote.repo;
config.remote.gitlab.is_custom = remote.is_custom;
}
Err(e) => {
debug!("Failed to get remote from GitLab repository: {:?}", e);
}
}
} else if !config.remote.gitea.is_set() {
match repository.upstream_remote() {
Ok(remote) => {
debug!("No Gitea remote is set, using remote: {}", remote);
config.remote.gitea.owner = remote.owner;
config.remote.gitea.repo = remote.repo;
config.remote.gitea.is_custom = remote.is_custom;
}
Err(e) => {
debug!("Failed to get remote from Gitea repository: {:?}", e);
}
}
} else if !config.remote.bitbucket.is_set() {
match repository.upstream_remote() {
Ok(remote) => {
debug!("No Bitbucket remote is set, using remote: {}", remote);
config.remote.bitbucket.owner = remote.owner;
config.remote.bitbucket.repo = remote.repo;
config.remote.bitbucket.is_custom = remote.is_custom;
if !config.remote.github.is_set() {
debug!("No GitHub remote is set, using remote: {}", remote);
config.remote.github.owner = remote.owner;
config.remote.github.repo = remote.repo;
config.remote.github.is_custom = remote.is_custom;
} else if !config.remote.gitlab.is_set() {
debug!("No GitLab remote is set, using remote: {}", remote);
config.remote.gitlab.owner = remote.owner;
config.remote.gitlab.repo = remote.repo;
config.remote.gitlab.is_custom = remote.is_custom;
} else if !config.remote.gitea.is_set() {
debug!("No Gitea remote is set, using remote: {}", remote);
config.remote.gitea.owner = remote.owner;
config.remote.gitea.repo = remote.repo;
config.remote.gitea.is_custom = remote.is_custom;
} else if !config.remote.bitbucket.is_set() {
debug!("No Bitbucket remote is set, using remote: {}", remote);
config.remote.bitbucket.owner = remote.owner;
config.remote.bitbucket.repo = remote.repo;
config.remote.bitbucket.is_custom = remote.is_custom;
}
}
Err(e) => {
debug!("Failed to get remote from Bitbucket repository: {:?}", e);
debug!("Failed to get remote from repository: {:?}", e);
}
}
}
Expand Down

0 comments on commit a344c68

Please sign in to comment.