Skip to content

Commit e3e7c07

Browse files
authored
fix(gitlab): URL-encode the owner in remote requests for GitLab (#742)
Gitlab requires that the project path be fully encoded. See the docs for details. https://docs.gitlab.com/ee/api/rest/#namespaced-path-encoding Pulls in the urlencoding crate here. Might not be needed when you have the choice to just update the documentation. I don't think the end user should be required to url encode their own strings. It might be nicer to just add the subgroup paradigm to the gitlab config in general for the future. This will fix the problem for now.
1 parent 58b729c commit e3e7c07

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git-cliff-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ tokio = { version = "1.38.0", features = [
7474
futures = { version = "0.3.30", optional = true }
7575
url = "2.5.2"
7676
dyn-clone = "1.0.17"
77+
urlencoding = "2.1.3"
7778

7879
[dependencies.git2]
7980
version = "0.19.0"

git-cliff-core/src/remote/gitlab.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use serde::{
66
Serialize,
77
};
88
use std::env;
9+
use urlencoding::encode;
910

1011
use super::*;
1112

@@ -47,7 +48,7 @@ pub struct GitLabProject {
4748

4849
impl RemoteEntry for GitLabProject {
4950
fn url(_id: i64, api_url: &str, remote: &Remote, _page: i32) -> String {
50-
format!("{}/projects/{}%2F{}", api_url, remote.owner, remote.repo)
51+
format!("{}/projects/{}%2F{}", api_url, encode(remote.owner.as_str()), remote.repo)
5152
}
5253

5354
fn buffer_size() -> usize {
@@ -285,3 +286,21 @@ impl GitLabClient {
285286
.collect())
286287
}
287288
}
289+
#[cfg(test)]
290+
mod test {
291+
use super::*;
292+
use pretty_assertions::assert_eq;
293+
294+
fn test_remote_entry_url<R: RemoteEntry>(expects: &str) {
295+
let remote = Remote::new("abc/def", "xyz1");
296+
assert_eq!(
297+
expects,
298+
R::url(1, "https://gitlab.test.com/api/v4", &remote, 0)
299+
)
300+
}
301+
302+
#[test]
303+
fn it_url_encodes_slashes() {
304+
test_remote_entry_url::<GitLabProject>("https://gitlab.test.com/api/v4/projects/abc%2Fdef%2Fxyz1")
305+
}
306+
}

website/docs/integration/gitlab.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ GITLAB_TOKEN="***" git cliff --gitlab-repo "orhun/git-cliff"
6363

6464
You can use the `GITLAB_API_URL` environment variable want to override the API URL. This is useful if you are using your own GitLab instance.
6565

66+
When your project on your own Gitlab has one or many subgroups (e.g my.gitlab.com/myGroup/mySubgroup/myProject) set owner in the toml to "myGroup/mySubgroup" and repo to the repo name.
67+
6668
:::
6769

6870
## Templating

0 commit comments

Comments
 (0)