mirror of
https://github.com/orhun/git-cliff.git
synced 2024-12-01 23:26:22 +03:00
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.
This commit is contained in:
parent
58b729c71f
commit
e3e7c07940
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -812,6 +812,7 @@ dependencies = [
|
||||
"tokio",
|
||||
"toml",
|
||||
"url",
|
||||
"urlencoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2881,6 +2882,12 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "urlencoding"
|
||||
version = "2.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.1"
|
||||
|
@ -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"
|
||||
|
@ -6,6 +6,7 @@ use serde::{
|
||||
Serialize,
|
||||
};
|
||||
use std::env;
|
||||
use urlencoding::encode;
|
||||
|
||||
use super::*;
|
||||
|
||||
@ -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 {
|
||||
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user