Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gitlab): URL-encode the owner in remote requests for GitLab #742

Merged
merged 1 commit into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions git-cliff-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ tokio = { version = "1.38.0", features = [
futures = { version = "0.3.30", optional = true }
url = "2.5.2"
dyn-clone = "1.0.17"
urlencoding = "2.1.3"

[dependencies.git2]
version = "0.19.0"
Expand Down
21 changes: 20 additions & 1 deletion git-cliff-core/src/remote/gitlab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use serde::{
Serialize,
};
use std::env;
use urlencoding::encode;

use super::*;

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

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

fn buffer_size() -> usize {
Expand Down Expand Up @@ -285,3 +286,21 @@ impl GitLabClient {
.collect())
}
}
#[cfg(test)]
mod test {
use super::*;
use pretty_assertions::assert_eq;

fn test_remote_entry_url<R: RemoteEntry>(expects: &str) {
let remote = Remote::new("abc/def", "xyz1");
assert_eq!(
expects,
R::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: 2 additions & 0 deletions website/docs/integration/gitlab.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ 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.

:::

## Templating
Expand Down
Loading