Skip to content

Commit

Permalink
refactor(gitlab): clean up url encoding for GitLab
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Jul 28, 2024
1 parent e3e7c07 commit c791418
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions git-cliff-core/src/remote/gitlab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use serde::{
Serialize,
};
use std::env;
use urlencoding::encode;

use super::*;

Expand Down Expand Up @@ -48,7 +47,12 @@ pub struct GitLabProject {

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

fn buffer_size() -> usize {
Expand Down Expand Up @@ -290,17 +294,13 @@ impl GitLabClient {
mod test {
use super::*;
use pretty_assertions::assert_eq;

fn test_remote_entry_url<R: RemoteEntry>(expects: &str) {

#[test]
fn gitlab_remote_encodes_owner() {
let remote = Remote::new("abc/def", "xyz1");
assert_eq!(
expects,
R::url(1, "https://gitlab.test.com/api/v4", &remote, 0)
"https://gitlab.test.com/api/v4/projects/abc%2Fdef%2Fxyz1",
GitLabProject::url(1, "https://gitlab.test.com/api/v4", &remote, 0)
)
}

#[test]
fn it_url_encodes_slashes() {
test_remote_entry_url::<GitLabProject>("https://gitlab.test.com/api/v4/projects/abc%2Fdef%2Fxyz1")
}
}
2 changes: 1 addition & 1 deletion website/docs/integration/gitlab.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ GITLAB_TOKEN="***" git cliff --gitlab-repo "orhun/git-cliff"

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.

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.
When your project on your own GitLab has one or many subgroups (e.g my.gitlab.com/myGroup/mySubgroup/myProject) you don't need to URL encode the owner in the configuration. (i.e. simply use "myGroup/mySubgroup")

:::

Expand Down

0 comments on commit c791418

Please sign in to comment.