From b378a6b9b9d07e3d15e6481d45c27a843b0b74ec Mon Sep 17 00:00:00 2001
From: KennyTK <16214078+KennyTK@users.noreply.github.com>
Date: Thu, 26 Jun 2025 14:18:01 -0400
Subject: [PATCH] Update GiteaSource.cs GetApiBaseUrl
Fix #690
---
src/lib-csharp/Sources/GiteaSource.cs | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/lib-csharp/Sources/GiteaSource.cs b/src/lib-csharp/Sources/GiteaSource.cs
index 759597e6..7eed3880 100644
--- a/src/lib-csharp/Sources/GiteaSource.cs
+++ b/src/lib-csharp/Sources/GiteaSource.cs
@@ -128,13 +128,21 @@ namespace Velopack.Sources
/// Given a repository URL (e.g. https://Gitea.com/myuser/myrepo) this function
/// returns the API base for performing requests. (eg. "https://api.Gitea.com/"
/// or http://internal.Gitea.server.local/api/v1)
+ /// or http://localhost:3000/api/v1
///
///
///
protected virtual Uri GetApiBaseUrl(Uri repoUrl)
{
- Uri baseAddress = new Uri(string.Format("{0}{1}{2}/api/v1/", repoUrl.Scheme, Uri.SchemeDelimiter, repoUrl.Host));
- // above ^^ notice the end slashes for the baseAddress, explained here: http://stackoverflow.com/a/23438417/162694
+ Uri baseAddress;
+
+ if (repoUrl.IsDefaultPort) {
+ baseAddress = new Uri(string.Format("{0}{1}{2}/api/v1/", repoUrl.Scheme, Uri.SchemeDelimiter, repoUrl.Host));
+ // above ^^ notice the end slashes for the baseAddress, explained here: http://stackoverflow.com/a/23438417/162694
+ } else {
+ baseAddress = new Uri(string.Format("{0}{1}{2}:{3}/api/v1/", repoUrl.Scheme, Uri.SchemeDelimiter, repoUrl.Host, repoUrl.Port));
+ }
+
return baseAddress;
}
}