From 144bdc3de47d188abc502f19724adf341ca48dd0 Mon Sep 17 00:00:00 2001 From: pauliyobo Date: Mon, 30 Sep 2024 02:58:37 +0200 Subject: [PATCH 1/9] Added api_url configuration to RemoteConfig --- git-cliff-core/src/changelog.rs | 4 ++++ git-cliff-core/src/command.rs | 1 - git-cliff-core/src/config.rs | 3 +++ git-cliff-core/src/remote/bitbucket.rs | 8 ++------ git-cliff-core/src/remote/gitea.rs | 8 ++------ git-cliff-core/src/remote/github.rs | 8 ++------ git-cliff-core/src/remote/gitlab.rs | 10 +++------- git-cliff-core/src/remote/mod.rs | 11 ++++++++++- git-cliff-core/src/repo.rs | 2 ++ 9 files changed, 28 insertions(+), 27 deletions(-) diff --git a/git-cliff-core/src/changelog.rs b/git-cliff-core/src/changelog.rs index a505a127a5..45d7573773 100644 --- a/git-cliff-core/src/changelog.rs +++ b/git-cliff-core/src/changelog.rs @@ -842,24 +842,28 @@ mod test { repo: String::from("awesome"), token: None, is_custom: false, + api_url: None, }, gitlab: Remote { owner: String::from("coolguy"), repo: String::from("awesome"), token: None, is_custom: false, + api_url: None, }, gitea: Remote { owner: String::from("coolguy"), repo: String::from("awesome"), token: None, is_custom: false, + api_url: None, }, bitbucket: Remote { owner: String::from("coolguy"), repo: String::from("awesome"), token: None, is_custom: false, + api_url: None }, }, bump: Bump::default(), diff --git a/git-cliff-core/src/command.rs b/git-cliff-core/src/command.rs index c04a48db0d..22e037f398 100644 --- a/git-cliff-core/src/command.rs +++ b/git-cliff-core/src/command.rs @@ -70,7 +70,6 @@ pub fn run( #[cfg(test)] mod test { - use super::*; #[test] #[cfg(target_family = "unix")] fn run_os_command() -> Result<()> { diff --git a/git-cliff-core/src/config.rs b/git-cliff-core/src/config.rs index 2266bb3444..725cac7ddb 100644 --- a/git-cliff-core/src/config.rs +++ b/git-cliff-core/src/config.rs @@ -182,6 +182,8 @@ pub struct Remote { /// Whether if the remote is set manually. #[serde(skip_deserializing, default = "default_true")] pub is_custom: bool, + /// Remote API URL, if configurable + pub api_url: Option, } /// Returns `true` for serde's `default` attribute. @@ -209,6 +211,7 @@ impl Remote { repo: repo.into(), token: None, is_custom: false, + api_url: None, } } diff --git a/git-cliff-core/src/remote/bitbucket.rs b/git-cliff-core/src/remote/bitbucket.rs index f45a47cfe7..7d672e15c3 100644 --- a/git-cliff-core/src/remote/bitbucket.rs +++ b/git-cliff-core/src/remote/bitbucket.rs @@ -5,7 +5,6 @@ use serde::{ Deserialize, Serialize, }; -use std::env; use super::*; @@ -181,11 +180,8 @@ impl TryFrom for BitbucketClient { } impl RemoteClient for BitbucketClient { - fn api_url() -> String { - env::var(BITBUCKET_API_URL_ENV) - .ok() - .unwrap_or_else(|| BITBUCKET_API_URL.to_string()) - } + const API_URL: &'static str = BITBUCKET_API_URL; + const API_URL_ENV: &'static str = BITBUCKET_API_URL_ENV; fn remote(&self) -> Remote { self.remote.clone() diff --git a/git-cliff-core/src/remote/gitea.rs b/git-cliff-core/src/remote/gitea.rs index f6df6b2e30..d868166206 100644 --- a/git-cliff-core/src/remote/gitea.rs +++ b/git-cliff-core/src/remote/gitea.rs @@ -5,7 +5,6 @@ use serde::{ Deserialize, Serialize, }; -use std::env; use super::*; @@ -145,11 +144,8 @@ impl TryFrom for GiteaClient { } impl RemoteClient for GiteaClient { - fn api_url() -> String { - env::var(GITEA_API_URL_ENV) - .ok() - .unwrap_or_else(|| GITEA_API_URL.to_string()) - } + const API_URL: &'static str = GITEA_API_URL; + const API_URL_ENV: &'static str = GITEA_API_URL_ENV; fn remote(&self) -> Remote { self.remote.clone() diff --git a/git-cliff-core/src/remote/github.rs b/git-cliff-core/src/remote/github.rs index 8a06a706c9..62dae5821b 100644 --- a/git-cliff-core/src/remote/github.rs +++ b/git-cliff-core/src/remote/github.rs @@ -5,7 +5,6 @@ use serde::{ Deserialize, Serialize, }; -use std::env; use super::*; @@ -144,11 +143,8 @@ impl TryFrom for GitHubClient { } impl RemoteClient for GitHubClient { - fn api_url() -> String { - env::var(GITHUB_API_URL_ENV) - .ok() - .unwrap_or_else(|| GITHUB_API_URL.to_string()) - } + const API_URL: &'static str = GITHUB_API_URL; + const API_URL_ENV: &'static str = GITHUB_API_URL_ENV; fn remote(&self) -> Remote { self.remote.clone() diff --git a/git-cliff-core/src/remote/gitlab.rs b/git-cliff-core/src/remote/gitlab.rs index 52b2d590c9..fe2d7f25dc 100644 --- a/git-cliff-core/src/remote/gitlab.rs +++ b/git-cliff-core/src/remote/gitlab.rs @@ -5,7 +5,6 @@ use serde::{ Deserialize, Serialize, }; -use std::env; use super::*; @@ -27,7 +26,7 @@ pub(crate) const TEMPLATE_VARIABLES: &[&str] = /// Representation of a single GitLab Project. /// -/// +/// #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct GitLabProject { /// GitLab id for project @@ -244,11 +243,8 @@ impl TryFrom for GitLabClient { } impl RemoteClient for GitLabClient { - fn api_url() -> String { - env::var(GITLAB_API_URL_ENV) - .ok() - .unwrap_or_else(|| GITLAB_API_URL.to_string()) - } + const API_URL: &'static str = GITLAB_API_URL; + const API_URL_ENV: &'static str = GITLAB_API_URL_ENV; fn remote(&self) -> Remote { self.remote.clone() diff --git a/git-cliff-core/src/remote/mod.rs b/git-cliff-core/src/remote/mod.rs index 77d14e72b5..2c32a3816b 100644 --- a/git-cliff-core/src/remote/mod.rs +++ b/git-cliff-core/src/remote/mod.rs @@ -48,6 +48,7 @@ use serde::{ Deserialize, Serialize, }; +use std::env; use std::fmt::Debug; use std::hash::Hash; use std::time::Duration; @@ -157,8 +158,16 @@ fn create_remote_client( /// Trait for handling the API connection and fetching. pub trait RemoteClient { + /// constant to hardcode the API URL for a particular client + const API_URL: &'static str; + /// Name of the environment variable used to set the API URL to a self-hosted instance, if applicable + const API_URL_ENV: &'static str; /// Returns the API url. - fn api_url() -> String; + fn api_url() -> String { + env::var(Self::API_URL_ENV) + .ok() + .unwrap_or_else(|| Self::API_URL.to_string()) + } /// Returns the remote repository information. fn remote(&self) -> Remote; diff --git a/git-cliff-core/src/repo.rs b/git-cliff-core/src/repo.rs index 8fe1f08731..50bb6201c3 100644 --- a/git-cliff-core/src/repo.rs +++ b/git-cliff-core/src/repo.rs @@ -435,6 +435,7 @@ impl Repository { repo: repo.trim_end_matches(".git").to_string(), token: None, is_custom: false, + api_url: None, }); } } @@ -554,6 +555,7 @@ mod test { repo: String::from("git-cliff"), token: None, is_custom: false, + api_url: remote.api_url.clone(), }, remote ); From c2398dc452b0f8c3aef1a3f7db8c6748a6de7f24 Mon Sep 17 00:00:00 2001 From: pauliyobo Date: Mon, 30 Sep 2024 03:02:21 +0200 Subject: [PATCH 2/9] Added api_url remote config parameter to the documentation --- website/docs/configuration/remote.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/website/docs/configuration/remote.md b/website/docs/configuration/remote.md index 7d5706917c..d070105653 100644 --- a/website/docs/configuration/remote.md +++ b/website/docs/configuration/remote.md @@ -51,3 +51,7 @@ git cliff --github-token ``` Same applies for GitLab/Bitbucket with `--gitlab-token`/`--gitea-token`/`--bitbucket-token` and `GITLAB_TOKEN`/`GITEA_TOKEN`/`BITBUCKET_TOKEN` environment variables. + +### api_url + +Sets the API URL for a particular remote From 8bfff04d559023bd0805946429b3c58291d6ab03 Mon Sep 17 00:00:00 2001 From: pauliyobo Date: Mon, 30 Sep 2024 03:08:28 +0200 Subject: [PATCH 3/9] Fmt --- git-cliff-core/src/changelog.rs | 8 ++++---- git-cliff-core/src/config.rs | 4 ++-- git-cliff-core/src/remote/mod.rs | 9 +++++---- git-cliff-core/src/repo.rs | 4 ++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/git-cliff-core/src/changelog.rs b/git-cliff-core/src/changelog.rs index 45d7573773..4688d587d1 100644 --- a/git-cliff-core/src/changelog.rs +++ b/git-cliff-core/src/changelog.rs @@ -842,28 +842,28 @@ mod test { repo: String::from("awesome"), token: None, is_custom: false, - api_url: None, + api_url: None, }, gitlab: Remote { owner: String::from("coolguy"), repo: String::from("awesome"), token: None, is_custom: false, - api_url: None, + api_url: None, }, gitea: Remote { owner: String::from("coolguy"), repo: String::from("awesome"), token: None, is_custom: false, - api_url: None, + api_url: None, }, bitbucket: Remote { owner: String::from("coolguy"), repo: String::from("awesome"), token: None, is_custom: false, - api_url: None + api_url: None, }, }, bump: Bump::default(), diff --git a/git-cliff-core/src/config.rs b/git-cliff-core/src/config.rs index 725cac7ddb..8d758d5461 100644 --- a/git-cliff-core/src/config.rs +++ b/git-cliff-core/src/config.rs @@ -183,7 +183,7 @@ pub struct Remote { #[serde(skip_deserializing, default = "default_true")] pub is_custom: bool, /// Remote API URL, if configurable - pub api_url: Option, + pub api_url: Option, } /// Returns `true` for serde's `default` attribute. @@ -211,7 +211,7 @@ impl Remote { repo: repo.into(), token: None, is_custom: false, - api_url: None, + api_url: None, } } diff --git a/git-cliff-core/src/remote/mod.rs b/git-cliff-core/src/remote/mod.rs index 2c32a3816b..aa4f6fecd1 100644 --- a/git-cliff-core/src/remote/mod.rs +++ b/git-cliff-core/src/remote/mod.rs @@ -160,13 +160,14 @@ fn create_remote_client( pub trait RemoteClient { /// constant to hardcode the API URL for a particular client const API_URL: &'static str; - /// Name of the environment variable used to set the API URL to a self-hosted instance, if applicable + /// Name of the environment variable used to set the API URL to a + /// self-hosted instance, if applicable const API_URL_ENV: &'static str; /// Returns the API url. fn api_url() -> String { - env::var(Self::API_URL_ENV) - .ok() - .unwrap_or_else(|| Self::API_URL.to_string()) + env::var(Self::API_URL_ENV) + .ok() + .unwrap_or_else(|| Self::API_URL.to_string()) } /// Returns the remote repository information. diff --git a/git-cliff-core/src/repo.rs b/git-cliff-core/src/repo.rs index 50bb6201c3..4f29ef5e95 100644 --- a/git-cliff-core/src/repo.rs +++ b/git-cliff-core/src/repo.rs @@ -435,7 +435,7 @@ impl Repository { repo: repo.trim_end_matches(".git").to_string(), token: None, is_custom: false, - api_url: None, + api_url: None, }); } } @@ -555,7 +555,7 @@ mod test { repo: String::from("git-cliff"), token: None, is_custom: false, - api_url: remote.api_url.clone(), + api_url: remote.api_url.clone(), }, remote ); From 01478d1dcc9dc9d819dd2e45a1d8e1e588652245 Mon Sep 17 00:00:00 2001 From: pauliyobo Date: Mon, 30 Sep 2024 09:33:32 +0200 Subject: [PATCH 4/9] Readded use statement erroneously removed --- git-cliff-core/src/command.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/git-cliff-core/src/command.rs b/git-cliff-core/src/command.rs index 22e037f398..1a14e5a9a3 100644 --- a/git-cliff-core/src/command.rs +++ b/git-cliff-core/src/command.rs @@ -70,6 +70,8 @@ pub fn run( #[cfg(test)] mod test { + use super::*; + #[test] #[cfg(target_family = "unix")] fn run_os_command() -> Result<()> { From d097f5a04d00a53686b82d014dfa904a8ffca691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Sat, 5 Oct 2024 23:19:17 +0300 Subject: [PATCH 5/9] chore: bring back https in gitlab link --- git-cliff-core/src/remote/gitlab.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-cliff-core/src/remote/gitlab.rs b/git-cliff-core/src/remote/gitlab.rs index fe2d7f25dc..b043ca3a0e 100644 --- a/git-cliff-core/src/remote/gitlab.rs +++ b/git-cliff-core/src/remote/gitlab.rs @@ -26,7 +26,7 @@ pub(crate) const TEMPLATE_VARIABLES: &[&str] = /// Representation of a single GitLab Project. /// -/// +/// #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct GitLabProject { /// GitLab id for project From 208fd5e17ead28ccf66d3497ea35a9c7294a1b18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Sat, 5 Oct 2024 23:19:54 +0300 Subject: [PATCH 6/9] docs(website): add missing dot to remote docs --- website/docs/configuration/remote.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/configuration/remote.md b/website/docs/configuration/remote.md index d070105653..e67a212a81 100644 --- a/website/docs/configuration/remote.md +++ b/website/docs/configuration/remote.md @@ -54,4 +54,4 @@ Same applies for GitLab/Bitbucket with `--gitlab-token`/`--gitea-token`/`--bitbu ### api_url -Sets the API URL for a particular remote +Sets the API URL for a particular remote. From a6e12627648d26da5d94a0dba45eaf7601673408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Sat, 5 Oct 2024 23:26:13 +0300 Subject: [PATCH 7/9] refactor(remote): clean up constant handling --- git-cliff-core/src/remote/bitbucket.rs | 10 ++-------- git-cliff-core/src/remote/gitea.rs | 10 ++-------- git-cliff-core/src/remote/github.rs | 10 ++-------- git-cliff-core/src/remote/gitlab.rs | 10 ++-------- git-cliff-core/src/remote/mod.rs | 6 ++++-- 5 files changed, 12 insertions(+), 34 deletions(-) diff --git a/git-cliff-core/src/remote/bitbucket.rs b/git-cliff-core/src/remote/bitbucket.rs index 7d672e15c3..a5ef787b30 100644 --- a/git-cliff-core/src/remote/bitbucket.rs +++ b/git-cliff-core/src/remote/bitbucket.rs @@ -8,12 +8,6 @@ use serde::{ use super::*; -/// Bitbucket REST API url. -const BITBUCKET_API_URL: &str = "https://api.bitbucket.org/2.0/repositories"; - -/// Environment variable for overriding the Bitbucket REST API url. -const BITBUCKET_API_URL_ENV: &str = "BITBUCKET_API_URL"; - /// Log message to show while fetching data from Bitbucket. pub const START_FETCHING_MSG: &str = "Retrieving data from Bitbucket..."; @@ -180,8 +174,8 @@ impl TryFrom for BitbucketClient { } impl RemoteClient for BitbucketClient { - const API_URL: &'static str = BITBUCKET_API_URL; - const API_URL_ENV: &'static str = BITBUCKET_API_URL_ENV; + const API_URL: &str = "https://api.bitbucket.org/2.0/repositories"; + const API_URL_ENV: &str = "BITBUCKET_API_URL"; fn remote(&self) -> Remote { self.remote.clone() diff --git a/git-cliff-core/src/remote/gitea.rs b/git-cliff-core/src/remote/gitea.rs index d868166206..ea10342572 100644 --- a/git-cliff-core/src/remote/gitea.rs +++ b/git-cliff-core/src/remote/gitea.rs @@ -8,12 +8,6 @@ use serde::{ use super::*; -/// Gitea API url. -const GITEA_API_URL: &str = "https://codeberg.org"; - -/// Environment variable for overriding the Gitea REST API url. -const GITEA_API_URL_ENV: &str = "GITEA_API_URL"; - /// Log message to show while fetching data from Gitea. pub const START_FETCHING_MSG: &str = "Retrieving data from Gitea..."; @@ -144,8 +138,8 @@ impl TryFrom for GiteaClient { } impl RemoteClient for GiteaClient { - const API_URL: &'static str = GITEA_API_URL; - const API_URL_ENV: &'static str = GITEA_API_URL_ENV; + const API_URL: &str = "https://codeberg.org"; + const API_URL_ENV: &str = "GITEA_API_URL"; fn remote(&self) -> Remote { self.remote.clone() diff --git a/git-cliff-core/src/remote/github.rs b/git-cliff-core/src/remote/github.rs index 62dae5821b..1c392ac25f 100644 --- a/git-cliff-core/src/remote/github.rs +++ b/git-cliff-core/src/remote/github.rs @@ -8,12 +8,6 @@ use serde::{ use super::*; -/// GitHub REST API url. -const GITHUB_API_URL: &str = "https://api.github.com"; - -/// Environment variable for overriding the GitHub REST API url. -const GITHUB_API_URL_ENV: &str = "GITHUB_API_URL"; - /// Log message to show while fetching data from GitHub. pub const START_FETCHING_MSG: &str = "Retrieving data from GitHub..."; @@ -143,8 +137,8 @@ impl TryFrom for GitHubClient { } impl RemoteClient for GitHubClient { - const API_URL: &'static str = GITHUB_API_URL; - const API_URL_ENV: &'static str = GITHUB_API_URL_ENV; + const API_URL: &str = "https://api.github.com"; + const API_URL_ENV: &str = "GITHUB_API_URL"; fn remote(&self) -> Remote { self.remote.clone() diff --git a/git-cliff-core/src/remote/gitlab.rs b/git-cliff-core/src/remote/gitlab.rs index b043ca3a0e..ff97c70de8 100644 --- a/git-cliff-core/src/remote/gitlab.rs +++ b/git-cliff-core/src/remote/gitlab.rs @@ -8,12 +8,6 @@ use serde::{ use super::*; -/// GitLab REST API url. -const GITLAB_API_URL: &str = "https://gitlab.com/api/v4"; - -/// Environment variable for overriding the GitLab REST API url. -const GITLAB_API_URL_ENV: &str = "GITLAB_API_URL"; - /// Log message to show while fetching data from GitLab. pub const START_FETCHING_MSG: &str = "Retrieving data from GitLab..."; @@ -243,8 +237,8 @@ impl TryFrom for GitLabClient { } impl RemoteClient for GitLabClient { - const API_URL: &'static str = GITLAB_API_URL; - const API_URL_ENV: &'static str = GITLAB_API_URL_ENV; + const API_URL: &str = "https://gitlab.com/api/v4"; + const API_URL_ENV: &str = "GITLAB_API_URL"; fn remote(&self) -> Remote { self.remote.clone() diff --git a/git-cliff-core/src/remote/mod.rs b/git-cliff-core/src/remote/mod.rs index aa4f6fecd1..44abb40e49 100644 --- a/git-cliff-core/src/remote/mod.rs +++ b/git-cliff-core/src/remote/mod.rs @@ -158,11 +158,13 @@ fn create_remote_client( /// Trait for handling the API connection and fetching. pub trait RemoteClient { - /// constant to hardcode the API URL for a particular client + /// API URL for a particular client const API_URL: &'static str; + /// Name of the environment variable used to set the API URL to a - /// self-hosted instance, if applicable + /// self-hosted instance (if applicable). const API_URL_ENV: &'static str; + /// Returns the API url. fn api_url() -> String { env::var(Self::API_URL_ENV) From 13ee7d1bbd4493d645503732d06b2ebf88367dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Tue, 19 Nov 2024 20:02:54 +0300 Subject: [PATCH 8/9] fix: fix the behavior and add fixture test --- .../test-custom-remote-api-url/cliff.toml | 55 +++++++++++++++++++ .../test-custom-remote-api-url/commit.sh | 6 ++ .../test-custom-remote-api-url/expected.md | 9 +++ .github/workflows/test-fixtures.yml | 2 + git-cliff-core/src/config.rs | 2 +- git-cliff-core/src/remote/mod.rs | 7 ++- 6 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 .github/fixtures/test-custom-remote-api-url/cliff.toml create mode 100755 .github/fixtures/test-custom-remote-api-url/commit.sh create mode 100644 .github/fixtures/test-custom-remote-api-url/expected.md diff --git a/.github/fixtures/test-custom-remote-api-url/cliff.toml b/.github/fixtures/test-custom-remote-api-url/cliff.toml new file mode 100644 index 0000000000..4136d1fcb8 --- /dev/null +++ b/.github/fixtures/test-custom-remote-api-url/cliff.toml @@ -0,0 +1,55 @@ +[remote.gitlab] +owner = "archlinux" +repo = "arch-repro-status" +api_url = "https://gitlab.archlinux.org/api/v4" + +[changelog] +# template for the changelog body +# https://keats.github.io/tera/docs/#introduction +body = """ +## What's Changed + +{%- if version %} in {{ version }}{%- endif -%} +{% for commit in commits %} + * {{ commit.message | split(pat="\n") | first | trim }}\ + {% if commit.remote.username %} by @{{ commit.remote.username }}{%- endif -%} + {% if commit.remote.pr_number %} in #{{ commit.remote.pr_number }}{%- endif %} +{%- endfor -%} + +{% if gitlab.contributors | filter(attribute="is_first_time", value=true) | length != 0 %} + {% raw %}\n{% endraw -%} + ### New Contributors +{%- endif %}\ +{% for contributor in gitlab.contributors | filter(attribute="is_first_time", value=true) %} + * @{{ contributor.username }} made their first contribution + {%- if contributor.pr_number %} in \ + [#{{ contributor.pr_number }}]({{ self::remote_url() }}/pull/{{ contributor.pr_number }}) \ + {%- endif %} +{%- endfor -%} + +{% if version %} + {% if previous.version %} + **Full Changelog**: https://gitlab.com/{{ remote.gitlab.owner }}/{{ remote.gitlab.repo }}/compare/{{ previous.version }}...{{ version }} + {% endif %} +{% else -%} + {% raw %}\n{% endraw %} +{% endif %} +""" +# remove the leading and trailing whitespace from the template +trim = true +# changelog footer +footer = """ + +""" + +[git] +# parse the commits based on https://www.conventionalcommits.org +conventional_commits = true +# filter out the commits that are not conventional +filter_unconventional = false +# process each line of a commit as an individual commit +split_commits = false +# regex for preprocessing the commit messages +commit_preprocessors = [{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "" }] +# protect breaking changes from being skipped due to matching a skipping commit_parser +protect_breaking_commits = false diff --git a/.github/fixtures/test-custom-remote-api-url/commit.sh b/.github/fixtures/test-custom-remote-api-url/commit.sh new file mode 100755 index 0000000000..fc3b7b7016 --- /dev/null +++ b/.github/fixtures/test-custom-remote-api-url/commit.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -e + +git remote add origin https://gitlab.archlinux.org/archlinux/arch-repro-status +git fetch +git checkout 5fe2f324db566756ccaf066fe186100a09a87625 diff --git a/.github/fixtures/test-custom-remote-api-url/expected.md b/.github/fixtures/test-custom-remote-api-url/expected.md new file mode 100644 index 0000000000..d20126a97f --- /dev/null +++ b/.github/fixtures/test-custom-remote-api-url/expected.md @@ -0,0 +1,9 @@ +## What's Changed in v1.4.1 +* Update the copyright year in license by @Orhun Parmaksız +* bump dependencies by @Orhun Parmaksız +* update cargo-deny config by @Orhun Parmaksız +* prepare for 1.4.1 by @Orhun Parmaksız + +**Full Changelog**: https://gitlab.com/archlinux/arch-repro-status/compare/v1.4.0...v1.4.1 + + diff --git a/.github/workflows/test-fixtures.yml b/.github/workflows/test-fixtures.yml index 09e7d138d8..00b09a68f9 100644 --- a/.github/workflows/test-fixtures.yml +++ b/.github/workflows/test-fixtures.yml @@ -102,6 +102,8 @@ jobs: command: --unreleased --tag v0.2.0 - fixtures-name: test-unchanged-tag-date command: --tag v0.2.0 + - fixtures-name: test-custom-remote-api-url + command: --latest steps: - name: Checkout diff --git a/git-cliff-core/src/config.rs b/git-cliff-core/src/config.rs index 8d758d5461..54fc56a94c 100644 --- a/git-cliff-core/src/config.rs +++ b/git-cliff-core/src/config.rs @@ -182,7 +182,7 @@ pub struct Remote { /// Whether if the remote is set manually. #[serde(skip_deserializing, default = "default_true")] pub is_custom: bool, - /// Remote API URL, if configurable + /// Remote API URL. pub api_url: Option, } diff --git a/git-cliff-core/src/remote/mod.rs b/git-cliff-core/src/remote/mod.rs index 2ef35b0fd1..5527d645cf 100644 --- a/git-cliff-core/src/remote/mod.rs +++ b/git-cliff-core/src/remote/mod.rs @@ -177,9 +177,10 @@ pub trait RemoteClient { const API_URL_ENV: &'static str; /// Returns the API url. - fn api_url() -> String { + fn api_url(&self) -> String { env::var(Self::API_URL_ENV) .ok() + .or(self.remote().api_url) .unwrap_or_else(|| Self::API_URL.to_string()) } @@ -200,7 +201,7 @@ pub trait RemoteClient { project_id: i64, page: i32, ) -> Result { - let url = T::url(project_id, &Self::api_url(), &self.remote(), page); + let url = T::url(project_id, &self.api_url(), &self.remote(), page); debug!("Sending request to: {url}"); let response = self.client().get(&url).send().await?; let response_text = if response.status().is_success() { @@ -221,7 +222,7 @@ pub trait RemoteClient { project_id: i64, page: i32, ) -> Result> { - let url = T::url(project_id, &Self::api_url(), &self.remote(), page); + let url = T::url(project_id, &self.api_url(), &self.remote(), page); debug!("Sending request to: {url}"); let response = self.client().get(&url).send().await?; let response_text = if response.status().is_success() { From e80ca3e8306abe03299070ad3e350ae51e1ed066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Tue, 19 Nov 2024 20:06:02 +0300 Subject: [PATCH 9/9] docs: add example of api_url --- website/docs/configuration/remote.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/website/docs/configuration/remote.md b/website/docs/configuration/remote.md index e67a212a81..e0a0e1ff03 100644 --- a/website/docs/configuration/remote.md +++ b/website/docs/configuration/remote.md @@ -55,3 +55,15 @@ Same applies for GitLab/Bitbucket with `--gitlab-token`/`--gitea-token`/`--bitbu ### api_url Sets the API URL for a particular remote. + +--- + +Here is a complete example for a project hosted on GitLab: + +```toml +[remote.gitlab] +owner = "archlinux" +repo = "arch-repro-status" +api_url = "https://gitlab.archlinux.org/api/v4" +token = "deadbeef" +```