Skip to content

Commit 81d7de9

Browse files
authored
fix(repository_hub): URL encode branch and tag names for GitLab API (#481)
## 📝 Description Branch and tag names containing forward slashes (e.g., "feature/branch-name", "release/v1.0.0") were causing 404 errors when making API requests to GitLab. Added URI.encode with char_unreserved predicate to properly encode special characters in names according to RFC 3986. ## ✅ Checklist - [x] I have tested this change - [x] ~This change requires documentation update~
1 parent f69538d commit 81d7de9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

repository_hub/lib/repository_hub/clients/gitlab_client.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,9 @@ defmodule RepositoryHub.GitlabClient do
349349
def get_branch(params, opts \\ []) do
350350
token = fetch_token(opts)
351351
project_id = project_identifier(params)
352+
encoded_branch_name = URI.encode(params.branch_name, &URI.char_unreserved?/1)
352353

353-
"#{@api_url}/projects/#{project_id}/repository/branches/#{params.branch_name}"
354+
"#{@api_url}/projects/#{project_id}/repository/branches/#{encoded_branch_name}"
354355
|> http_get(token, %{})
355356
|> process_response
356357
|> unwrap(fn response ->
@@ -369,8 +370,9 @@ defmodule RepositoryHub.GitlabClient do
369370
def get_tag(params, opts \\ []) do
370371
token = fetch_token(opts)
371372
project_id = project_identifier(params)
373+
encoded_tag_name = URI.encode(params.tag_name, &URI.char_unreserved?/1)
372374

373-
"#{@api_url}/projects/#{project_id}/repository/tags/#{params.tag_name}"
375+
"#{@api_url}/projects/#{project_id}/repository/tags/#{encoded_tag_name}"
374376
|> http_get(token, %{})
375377
|> process_response
376378
|> unwrap(fn response ->

0 commit comments

Comments
 (0)