Skip to content

Commit

Permalink
[bug] Fix API URLs for GitHub Enterprise Server (#2626)
Browse files Browse the repository at this point in the history
* Fix API URLs for GHES

Fix leading slashes causing API calls to fail when used with GitHub Enterprise.

* Fix tests

Fix tests that should have been updated in the previous commit.

Co-authored-by: Keegan Campbell <[email protected]>
  • Loading branch information
martincostello and kfcampbell authored Dec 1, 2022
1 parent 46b5077 commit 9780938
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 129 deletions.
16 changes: 8 additions & 8 deletions Octokit.Tests/Clients/ActionsWorkflowJobsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task RequestsCorrectUrl()
await client.Rerun("fake", "repo", 123);

connection.Received().Post(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/jobs/123/rerun"));
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/jobs/123/rerun"));
}

[Fact]
Expand Down Expand Up @@ -63,7 +63,7 @@ public async Task RequestsCorrectUrl()
await client.Get("fake", "repo", 123);

connection.Received().Get<WorkflowJob>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/jobs/123"));
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/jobs/123"));
}

[Fact]
Expand Down Expand Up @@ -98,7 +98,7 @@ public async Task RequestsCorrectUrl()
await client.GetLogs("fake", "repo", 123);

connection.Connection.Received().Get<string>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/jobs/123/logs"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/jobs/123/logs"),
null);
}

Expand Down Expand Up @@ -134,14 +134,14 @@ public async Task RequestsCorrectUrl()
await client.List("fake", "repo", 123);

connection.Received().GetAll<WorkflowJobsResponse>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/runs/123/jobs"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/runs/123/jobs"),
Args.EmptyDictionary,
Args.ApiOptions);

await client.List("fake", "repo", 123, 456);

connection.Received().GetAll<WorkflowJobsResponse>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/runs/123/attempts/456/jobs"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/runs/123/attempts/456/jobs"),
null,
Args.ApiOptions);
}
Expand All @@ -160,7 +160,7 @@ public async Task RequestsCorrectUrlWithRequest()
await client.List("fake", "repo", 123, request);

connection.Received().GetAll<WorkflowJobsResponse>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/runs/123/jobs"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/runs/123/jobs"),
Arg.Is<Dictionary<string, string>>(x =>
x.Count == 1
&& x["filter"] == "all"),
Expand All @@ -179,7 +179,7 @@ public async Task RequestsCorrectUrlWithRequestWithApiOptions()
await client.List("fake", "repo", 123, request, options);

connection.Received().GetAll<WorkflowJobsResponse>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/runs/123/jobs"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/runs/123/jobs"),
Arg.Is<Dictionary<string, string>>(x =>
x.Count == 1
&& x["filter"] == "latest"),
Expand All @@ -188,7 +188,7 @@ public async Task RequestsCorrectUrlWithRequestWithApiOptions()
await client.List("fake", "repo", 123, 456, options);

connection.Received().GetAll<WorkflowJobsResponse>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/runs/123/attempts/456/jobs"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/runs/123/attempts/456/jobs"),
null,
options);
}
Expand Down
44 changes: 22 additions & 22 deletions Octokit.Tests/Clients/ActionsWorkflowRunsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task RequestsCorrectUrl()
await client.Approve("fake", "repo", 123);

connection.Received().Post(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/runs/123/approve"));
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/runs/123/approve"));
}

[Fact]
Expand Down Expand Up @@ -65,7 +65,7 @@ public async Task RequestsCorrectUrl()
await client.Cancel("fake", "repo", 123);

connection.Received().Post(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/runs/123/cancel"));
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/runs/123/cancel"));
}

[Fact]
Expand Down Expand Up @@ -100,7 +100,7 @@ public async Task RequestsCorrectUrl()
await client.Delete("fake", "repo", 123);

connection.Received().Delete(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/runs/123"));
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/runs/123"));
}

[Fact]
Expand Down Expand Up @@ -135,7 +135,7 @@ public async Task RequestsCorrectUrl()
await client.DeleteLogs("fake", "repo", 123);

connection.Received().Delete(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/runs/123/logs"));
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/runs/123/logs"));
}

[Fact]
Expand Down Expand Up @@ -170,7 +170,7 @@ public async Task RequestsCorrectUrl()
await client.Get("fake", "repo", 123);

connection.Received().Get<WorkflowRun>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/runs/123"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/runs/123"),
null);
}

Expand Down Expand Up @@ -205,7 +205,7 @@ public async Task RequestsCorrectUrl()
var responseTask = Task.FromResult<IApiResponse<byte[]>>(new ApiResponse<byte[]>(response));

var connection = Substitute.For<IConnection>();
connection.GetRaw(Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/runs/123/logs"), null)
connection.GetRaw(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/runs/123/logs"), null)
.Returns(responseTask);

var apiConnection = Substitute.For<IApiConnection>();
Expand Down Expand Up @@ -250,7 +250,7 @@ public async Task RequestsCorrectUrl()
await client.GetAttempt("fake", "repo", 123, 456);

connection.Received().Get<WorkflowRun>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/runs/123/attempts/456"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/runs/123/attempts/456"),
null);
}

Expand Down Expand Up @@ -285,7 +285,7 @@ public async Task RequestsCorrectUrl()
var responseTask = Task.FromResult<IApiResponse<byte[]>>(new ApiResponse<byte[]>(response));

var connection = Substitute.For<IConnection>();
connection.GetRaw(Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/runs/123/attempts/456/logs"), null)
connection.GetRaw(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/runs/123/attempts/456/logs"), null)
.Returns(responseTask);

var apiConnection = Substitute.For<IApiConnection>();
Expand Down Expand Up @@ -330,7 +330,7 @@ public async Task RequestsCorrectUrl()
await client.GetReviewHistory("fake", "repo", 123);

connection.Received().GetAll<EnvironmentApprovals>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/runs/123/approvals"));
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/runs/123/approvals"));
}

[Fact]
Expand Down Expand Up @@ -371,7 +371,7 @@ public async Task RequestsCorrectUrl()
await client.GetUsage("fake", "repo", 123);

connection.Received().Get<WorkflowRunUsage>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/runs/123/timing"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/runs/123/timing"),
null);
}

Expand Down Expand Up @@ -407,7 +407,7 @@ public async Task RequestsCorrectUrl()
await client.List("fake", "repo");

connection.Received().GetAll<WorkflowRunsResponse>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/runs"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/runs"),
Args.EmptyDictionary,
Args.ApiOptions);
}
Expand All @@ -432,7 +432,7 @@ public async Task RequestsCorrectUrlWithRequest()
await client.List("fake", "repo", request);

connection.Received().GetAll<WorkflowRunsResponse>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/runs"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/runs"),
Arg.Is<Dictionary<string, string>>(x =>
x.Count == 7
&& x["actor"] == "octocat"
Expand All @@ -458,7 +458,7 @@ public async Task RequestsCorrectUrlWithRequestWithApiOptions()
await client.List("fake", "repo", request, options);

connection.Received().GetAll<WorkflowRunsResponse>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/runs"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/runs"),
Arg.Is<Dictionary<string, string>>(x =>
x.Count == 3
&& x["branch"] == "main"
Expand Down Expand Up @@ -520,7 +520,7 @@ public async Task RequestsCorrectUrlWithId()
await client.ListByWorkflow("fake", "repo", 123);

connection.Received().GetAll<WorkflowRunsResponse>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/workflows/123/runs"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/workflows/123/runs"),
Args.EmptyDictionary,
Args.ApiOptions);
}
Expand All @@ -534,7 +534,7 @@ public async Task RequestsCorrectUrlWithName()
await client.ListByWorkflow("fake", "repo", "main.yml");

connection.Received().GetAll<WorkflowRunsResponse>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/workflows/main.yml/runs"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/workflows/main.yml/runs"),
Args.EmptyDictionary,
Args.ApiOptions);
}
Expand All @@ -559,7 +559,7 @@ public async Task RequestsCorrectUrlWithIdWithRequest()
await client.ListByWorkflow("fake", "repo", 123, request);

connection.Received().GetAll<WorkflowRunsResponse>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/workflows/123/runs"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/workflows/123/runs"),
Arg.Is<Dictionary<string, string>>(x =>
x.Count == 7
&& x["actor"] == "octocat"
Expand Down Expand Up @@ -593,7 +593,7 @@ public async Task RequestsCorrectUrlWithNameWithRequest()
await client.ListByWorkflow("fake", "repo", "main.yml", request);

connection.Received().GetAll<WorkflowRunsResponse>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/workflows/main.yml/runs"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/workflows/main.yml/runs"),
Arg.Is<Dictionary<string, string>>(x =>
x.Count == 7
&& x["actor"] == "octocat"
Expand All @@ -619,7 +619,7 @@ public async Task RequestsCorrectUrlWithIdWithRequestWithApiOptions()
await client.ListByWorkflow("fake", "repo", 123, request, options);

connection.Received().GetAll<WorkflowRunsResponse>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/workflows/123/runs"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/workflows/123/runs"),
Arg.Is<Dictionary<string, string>>(x =>
x.Count == 3
&& x["branch"] == "main"
Expand All @@ -640,7 +640,7 @@ public async Task RequestsCorrectUrlWithNameWithRequestWithApiOptions()
await client.ListByWorkflow("fake", "repo", "main.yml", request, options);

connection.Received().GetAll<WorkflowRunsResponse>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/workflows/main.yml/runs"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/workflows/main.yml/runs"),
Arg.Is<Dictionary<string, string>>(x =>
x.Count == 3
&& x["branch"] == "main"
Expand Down Expand Up @@ -732,7 +732,7 @@ public async Task RequestsCorrectUrl()
await client.Rerun("fake", "repo", 123);

connection.Received().Post(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/runs/123/rerun"));
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/runs/123/rerun"));
}

[Fact]
Expand Down Expand Up @@ -769,7 +769,7 @@ public async Task RequestsCorrectUrl()
await client.RerunFailedJobs("fake", "repo", 123);

connection.Received().Post(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/runs/123/rerun-failed-jobs"));
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/runs/123/rerun-failed-jobs"));
}

[Fact]
Expand Down Expand Up @@ -806,7 +806,7 @@ public async Task RequestsCorrectUrl()
await client.ReviewPendingDeployments("fake", "repo", 123, review);

connection.Received().Post<Deployment>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/runs/123/pending_deployments"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/runs/123/pending_deployments"),
review);
}

Expand Down
24 changes: 12 additions & 12 deletions Octokit.Tests/Clients/ActionsWorkflowsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public async Task RequestsCorrectUrlByWorkflowId()
await client.CreateDispatch("fake", "repo", 123, createDispatch);

connection.Received().Post<object>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/workflows/123/dispatches"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/workflows/123/dispatches"),
createDispatch);
}

Expand All @@ -57,7 +57,7 @@ public async Task RequestsCorrectUrlByWorkflowFileName()
await client.CreateDispatch("fake", "repo", "main.yaml", createDispatch);

connection.Received().Post<object>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/workflows/main.yaml/dispatches"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/workflows/main.yaml/dispatches"),
createDispatch);
}

Expand Down Expand Up @@ -107,7 +107,7 @@ public async Task RequestsCorrectUrlByWorkflowId()
await client.Disable("fake", "repo", 123);

connection.Received().Put(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/workflows/123/disable"));
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/workflows/123/disable"));
}

[Fact]
Expand All @@ -119,7 +119,7 @@ public async Task RequestsCorrectUrlByWorkflowFileName()
await client.Disable("fake", "repo", "main.yaml");

connection.Received().Put(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/workflows/main.yaml/disable"));
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/workflows/main.yaml/disable"));
}

[Fact]
Expand Down Expand Up @@ -162,7 +162,7 @@ public async Task RequestsCorrectUrlByWorkflowId()
await client.Enable("fake", "repo", 123);

connection.Received().Put(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/workflows/123/enable"));
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/workflows/123/enable"));
}

[Fact]
Expand All @@ -174,7 +174,7 @@ public async Task RequestsCorrectUrlByWorkflowFileName()
await client.Enable("fake", "repo", "main.yaml");

connection.Received().Put(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/workflows/main.yaml/enable"));
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/workflows/main.yaml/enable"));
}

[Fact]
Expand Down Expand Up @@ -217,7 +217,7 @@ public async Task RequestsCorrectUrlByWorkflowId()
await client.Get("fake", "repo", 123);

connection.Received().Get<Workflow>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/workflows/123"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/workflows/123"),
null);
}

Expand All @@ -230,7 +230,7 @@ public async Task RequestsCorrectUrlByWorkflowFileName()
await client.Get("fake", "repo", "main.yaml");

connection.Received().Get<Workflow>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/workflows/main.yaml"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/workflows/main.yaml"),
null);
}

Expand Down Expand Up @@ -274,7 +274,7 @@ public async Task RequestsCorrectUrlByWorkflowId()
await client.GetUsage("fake", "repo", 123);

connection.Received().Get<WorkflowUsage>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/workflows/123/timing"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/workflows/123/timing"),
null);
}

Expand All @@ -287,7 +287,7 @@ public async Task RequestsCorrectUrlByWorkflowFileName()
await client.GetUsage("fake", "repo", "main.yaml");

connection.Received().Get<WorkflowUsage>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/workflows/main.yaml/timing"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/workflows/main.yaml/timing"),
null);
}

Expand Down Expand Up @@ -331,7 +331,7 @@ public async Task RequestsCorrectUrl()
await client.List("fake", "repo");

connection.Received().GetAll<WorkflowsResponse>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/workflows"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/workflows"),
null,
Args.ApiOptions);
}
Expand All @@ -347,7 +347,7 @@ public async Task RequestsCorrectUrlWithRequestWithApiOptions()
await client.List("fake", "repo", options);

connection.Received().GetAll<WorkflowsResponse>(
Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/actions/workflows"),
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/actions/workflows"),
null,
options);
}
Expand Down
Loading

0 comments on commit 9780938

Please sign in to comment.