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 case where port number is lost using resumable #343

Merged
merged 2 commits into from
Aug 14, 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
4 changes: 4 additions & 0 deletions .github/workflows/ci+cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ jobs:

build-and-test:
runs-on: ${{ matrix.os }}
timeout-minutes: 360
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}
cancel-in-progress: true

steps:
- name: Checkout
Expand Down
9 changes: 7 additions & 2 deletions src/LibChorus/VcsDrivers/Mercurial/HgResumeRestApiServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ public HgResumeApiResponse Execute(string method, HgResumeApiParameters request,
[Obsolete] public string UserName => null;
[Obsolete] public string Password => null;

public HgResumeApiResponse Execute(string method, HgResumeApiParameters parameters, byte[] contentToSend, int secondsBeforeTimeout)
public static string FormatUrl(Uri uri, string method, HgResumeApiParameters parameters)
{
string queryString = parameters.BuildQueryString();
Url = string.Format("{0}://{1}/api/v{2}/{3}?{4}", _url.Scheme, _url.Host, ApiVersion, method, queryString);
return $"{uri.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped)}/api/v{ApiVersion}/{method}{queryString}";
}

public HgResumeApiResponse Execute(string method, HgResumeApiParameters parameters, byte[] contentToSend, int secondsBeforeTimeout)
{
Url = FormatUrl(_url, method, parameters);
var req = (HttpWebRequest) WebRequest.Create(Url);
req.UserAgent = $"HgResume v{ApiVersion}";
req.PreAuthenticate = true;
Expand Down
10 changes: 9 additions & 1 deletion src/LibChorus/VcsDrivers/Mercurial/IApiServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ public HgResumeApiParameters()
// used only by getRevisions API
public int Quantity { get; set; }

/// <summary>
/// returns a query string, prefixed with a '?' unless there are no parameters
/// </summary>
/// <returns></returns>
public string BuildQueryString()
{
string query = "";
string query = "?";
if (StartOfWindow >= 0)
{
query += String.Format("offset={0}&", StartOfWindow);
Expand Down Expand Up @@ -77,6 +81,10 @@ public string BuildQueryString()
{
query += String.Format("repoId={0}&", RepoId);
}
if (query == "?")
{
return "";
}
return query.TrimEnd('&');
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Chorus.VcsDrivers.Mercurial;
using NUnit.Framework;

Expand All @@ -21,5 +22,36 @@ public void Constructor_LanguageForgeUrl_IdentityAndProjectIdSetCorrectly()
Assert.That(api.Host, Is.EqualTo("hg.languageforge.org"));
Assert.That(api.ProjectId, Is.EqualTo("kyu-dictionary"));
}

[Test]
public void FormatUrl_FormatsCorrectlyWithEmptyParameters()
{
Assert.That(HgResumeRestApiServer.FormatUrl(
new Uri("https://hg.languageforge.org:1234/projects/kyu-dictionary"),
"foo",
new HgResumeApiParameters()),
Is.EqualTo("https://hg.languageforge.org:1234/api/v03/foo"));
}

[Test]
public void FormatUrl_FormatsCorrectlyWithParameters()
{
//this test is overly specific as the order of the parameters is not important, however this is much simpler to write.
Assert.That(HgResumeRestApiServer.FormatUrl(
new Uri("https://hg.languageforge.org:1234/projects/kyu-dictionary"),
"foo",
new HgResumeApiParameters
{
StartOfWindow = 10,
ChunkSize = 20,
BundleSize = 30,
Quantity = 40,
TransId = "transId",
BaseHashes = new[] { "baseHash1", "baseHash2" },
RepoId = "repoId"
}),
Is.EqualTo(
"https://hg.languageforge.org:1234/api/v03/foo?offset=10&chunkSize=20&bundleSize=30&quantity=40&transId=transId&baseHashes[]=baseHash1&baseHashes[]=baseHash2&repoId=repoId"));
}
}
}
Loading