Skip to content

Commit

Permalink
Replace int IDs by long ones + a few more changes (#811)
Browse files Browse the repository at this point in the history
* Replace int IDs by long ones

Remove redundant stuff

* Remove obsolete code

* Tweak

* Address issue 797

* review + a few more changes related to runners
  • Loading branch information
louis-z authored Dec 16, 2024
1 parent 77e89b5 commit 8bf473e
Show file tree
Hide file tree
Showing 254 changed files with 1,427 additions and 2,039 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Authors>$(Company), NGitLab contributors</Authors>

<!-- Compile Options -->
<LangVersion>11.0</LangVersion>
<LangVersion>12</LangVersion>
<Deterministic>true</Deterministic>
<Features>strict</Features>
<TreatWarningsAsErrors Condition="'$(Configuration)' != 'Debug'">true</TreatWarningsAsErrors>
Expand Down
2 changes: 1 addition & 1 deletion NGitLab.Mock.Tests/MergeRequestsMockTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void Test_merge_requests_approvable_by_me_can_be_listed()
.BuildServer();

var client = server.CreateClient("user1");
var mergeRequests = client.MergeRequests.Get(new MergeRequestQuery { ApproverIds = new[] { 1 } }).ToArray();
var mergeRequests = client.MergeRequests.Get(new MergeRequestQuery { ApproverIds = [1L] }).ToArray();

Assert.That(mergeRequests, Has.Length.EqualTo(1), "Merge requests count is invalid");
Assert.That(mergeRequests[0].Title, Is.EqualTo("Merge request 2"), "Merge request found is invalid");
Expand Down
8 changes: 4 additions & 4 deletions NGitLab.Mock.Tests/MilestonesMockTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public void Test_milestones_can_be_closed_and_activated_from_project()
[Test]
public void Test_projects_merge_request_can_be_found_from_milestone()
{
const int ProjectId = 1;
const int MilestoneId = 1;
const long ProjectId = 1;
const long MilestoneId = 1;
using var server = new GitLabConfig()
.WithUser("user1", isDefault: true)
.WithProject("Test", id: ProjectId, addDefaultUserAsMaintainer: true, configure: project => project
Expand All @@ -122,8 +122,8 @@ public void Test_projects_merge_request_can_be_found_from_milestone()
[Test]
public void Test_groups_merge_request_can_be_found_from_milestone()
{
const int projectId = 1;
const int milestoneId = 1;
const long projectId = 1;
const long milestoneId = 1;
using var server = new GitLabConfig()
.WithUser("user1", isDefault: true)
.WithGroup("parentGroup", id: projectId, configure: group => group
Expand Down
5 changes: 3 additions & 2 deletions NGitLab.Mock.Tests/ProjectsMockTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using FluentAssertions;
Expand Down Expand Up @@ -213,7 +214,7 @@ public async Task CreateAsync_WhenMockCreatedWithSupportedOptions_TheyAreAvailab
{
Name = "MyProject",
Path = "my-project",
NamespaceId = "my-group",
NamespaceId = server.Groups.First(g => string.Equals(g.Name, "MyGroup", StringComparison.Ordinal)).Id,
Description = "Description",
DefaultBranch = "foo",
InitializeWithReadme = true,
Expand All @@ -228,7 +229,7 @@ public async Task CreateAsync_WhenMockCreatedWithSupportedOptions_TheyAreAvailab
actual.Name.Should().Be(expected.Name);
actual.Path.Should().Be(expected.Path);
actual.Description.Should().Be(expected.Description);
actual.Namespace.FullPath.Should().Be(expected.NamespaceId);
actual.Namespace.Id.Should().Be(expected.NamespaceId);
actual.NameWithNamespace.Should().Be($"MyGroup / {expected.Name}");
actual.PathWithNamespace.Should().Be($"my-group/{expected.Path}");
actual.DefaultBranch.Should().Be(expected.DefaultBranch);
Expand Down
2 changes: 1 addition & 1 deletion NGitLab.Mock/Badge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace NGitLab.Mock;

public sealed class Badge : GitLabObject
{
public int Id { get; set; }
public long Id { get; set; }

public string LinkUrl { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion NGitLab.Mock/BadgeCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public BadgeCollection(GitLabObject parent)
{
}

public Badge GetById(int id)
public Badge GetById(long id)
{
return this.FirstOrDefault(badge => badge.Id == id);
}
Expand Down
4 changes: 2 additions & 2 deletions NGitLab.Mock/Clients/BranchClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace NGitLab.Mock.Clients;

internal sealed class BranchClient : ClientBase, IBranchClient
{
private readonly int _projectId;
private readonly long _projectId;

public BranchClient(ClientContext context, int projectId)
public BranchClient(ClientContext context, long projectId)
: base(context)
{
_projectId = projectId;
Expand Down
12 changes: 6 additions & 6 deletions NGitLab.Mock/Clients/ClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected Group GetGroup(object id, GroupPermission permissions)

var group = id switch
{
int idInt => Server.AllGroups.FindById(idInt),
long idLong => Server.AllGroups.FindById(idLong),
string idStr => Server.AllGroups.FindGroup(idStr),
IIdOrPathAddressable gid when gid.Path != null => Server.AllGroups.FindByNamespacedPath(gid.Path),
IIdOrPathAddressable gid => Server.AllGroups.FindById(gid.Id),
Expand Down Expand Up @@ -78,7 +78,7 @@ protected Project GetProject(object id, ProjectPermission permissions)

var project = id switch
{
int idInt => Server.AllProjects.FindById(idInt),
long idLong => Server.AllProjects.FindById(idLong),
string idStr => Server.AllProjects.FindProject(idStr),
IIdOrPathAddressable pid when pid.Path != null => Server.AllProjects.FindByNamespacedPath(pid.Path),
IIdOrPathAddressable pid => Server.AllProjects.FindById(pid.Id),
Expand Down Expand Up @@ -116,7 +116,7 @@ protected Project GetProject(object id, ProjectPermission permissions)
return project;
}

protected User GetUser(int userId)
protected User GetUser(long userId)
{
var user = Server.Users.GetById(userId);
if (user == null)
Expand All @@ -125,7 +125,7 @@ protected User GetUser(int userId)
return user;
}

protected Issue GetIssue(int projectId, int issueId)
protected Issue GetIssue(long projectId, long issueId)
{
var project = GetProject(projectId, ProjectPermission.View);
var issue = project.Issues.GetByIid(issueId);
Expand All @@ -135,7 +135,7 @@ protected Issue GetIssue(int projectId, int issueId)
return issue;
}

protected Milestone GetMilestone(int projectId, int milestoneId)
protected Milestone GetMilestone(long projectId, long milestoneId)
{
var project = GetProject(projectId, ProjectPermission.View);
var milestone = project.Milestones.GetByIid(milestoneId);
Expand All @@ -145,7 +145,7 @@ protected Milestone GetMilestone(int projectId, int milestoneId)
return milestone;
}

protected MergeRequest GetMergeRequest(int projectId, int mergeRequestIid)
protected MergeRequest GetMergeRequest(long projectId, long mergeRequestIid)
{
var project = GetProject(projectId, ProjectPermission.View);
var mergeRequest = project.MergeRequests.GetByIid(mergeRequestIid);
Expand Down
2 changes: 1 addition & 1 deletion NGitLab.Mock/Clients/ClusterClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace NGitLab.Mock.Clients;

internal sealed class ClusterClient : ClientBase, IClusterClient
{
private readonly int _projectId;
private readonly long _projectId;

public ClusterClient(ClientContext context, ProjectId projectId)
: base(context)
Expand Down
2 changes: 1 addition & 1 deletion NGitLab.Mock/Clients/CommitClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace NGitLab.Mock.Clients;

internal sealed class CommitClient : ClientBase, ICommitClient
{
private readonly int _projectId;
private readonly long _projectId;

public CommitClient(ClientContext context, ProjectId projectId)
: base(context)
Expand Down
2 changes: 1 addition & 1 deletion NGitLab.Mock/Clients/CommitStatusClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace NGitLab.Mock.Clients;

internal sealed class CommitStatusClient : ClientBase, ICommitStatusClient
{
private readonly int _projectId;
private readonly long _projectId;

public CommitStatusClient(ClientContext context, ProjectId projectId)
: base(context)
Expand Down
4 changes: 2 additions & 2 deletions NGitLab.Mock/Clients/ContributorClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace NGitLab.Mock.Clients;

internal sealed class ContributorClient : ClientBase, IContributorClient
{
private readonly int _projectId;
private readonly long _projectId;

public ContributorClient(ClientContext context, int projectId)
public ContributorClient(ClientContext context, long projectId)
: base(context)
{
_projectId = projectId;
Expand Down
14 changes: 7 additions & 7 deletions NGitLab.Mock/Clients/EnvironmentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace NGitLab.Mock.Clients;

internal sealed class EnvironmentClient : ClientBase, IEnvironmentClient
{
private readonly int _projectId;
private readonly long _projectId;

public EnvironmentClient(ClientContext context, ProjectId projectId)
: base(context)
Expand All @@ -25,20 +25,20 @@ public EnvironmentInfo Create(string name, string externalUrl)
throw new NotImplementedException();
}

public void Delete(int environmentId)
public void Delete(long environmentId)
{
throw new NotImplementedException();
}

public EnvironmentInfo Edit(int environmentId, string externalUrl) => Edit(environmentId, null, externalUrl);
public EnvironmentInfo Edit(long environmentId, string externalUrl) => Edit(environmentId, null, externalUrl);

[EditorBrowsable(EditorBrowsableState.Never)]
public EnvironmentInfo Edit(int environmentId, string name, string externalUrl)
public EnvironmentInfo Edit(long environmentId, string name, string externalUrl)
{
throw new NotImplementedException();
}

public EnvironmentInfo Stop(int environmentId)
public EnvironmentInfo Stop(long environmentId)
{
throw new NotImplementedException();
}
Expand All @@ -48,12 +48,12 @@ public GitLabCollectionResponse<EnvironmentInfo> GetEnvironmentsAsync(Environmen
return GitLabCollectionResponse.Create(Array.Empty<EnvironmentInfo>());
}

public EnvironmentInfo GetById(int environmentId)
public EnvironmentInfo GetById(long environmentId)
{
throw new NotImplementedException();
}

public Task<EnvironmentInfo> GetByIdAsync(int environmentId, CancellationToken cancellationToken = default)
public Task<EnvironmentInfo> GetByIdAsync(long environmentId, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
Expand Down
6 changes: 3 additions & 3 deletions NGitLab.Mock/Clients/EventClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ namespace NGitLab.Mock.Clients;

internal sealed class EventClient : ClientBase, IEventClient
{
private readonly int? _userId;
private readonly int? _projectId;
private readonly long? _userId;
private readonly long? _projectId;

public EventClient(ClientContext context)
: base(context)
{
}

public EventClient(ClientContext context, int? userId = null, ProjectId? projectId = null)
public EventClient(ClientContext context, long? userId = null, ProjectId? projectId = null)
: base(context)
{
_userId = userId;
Expand Down
4 changes: 2 additions & 2 deletions NGitLab.Mock/Clients/FileClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace NGitLab.Mock.Clients;

internal sealed class FileClient : ClientBase, IFilesClient
{
private readonly int _projectId;
private readonly long _projectId;

public FileClient(ClientContext context, int projectId)
public FileClient(ClientContext context, long projectId)
: base(context)
{
_projectId = projectId;
Expand Down
48 changes: 1 addition & 47 deletions NGitLab.Mock/Clients/GitLabClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public GitLabClient(ClientContext context)

public IMembersClient Members => new MembersClient(Context);

public ICommitClient GetCommits(int projectId) => GetCommits((long)projectId);

public ICommitClient GetCommits(ProjectId projectId) => new CommitClient(Context, projectId);

public IIssueClient Issues => new IssueClient(Context);
Expand Down Expand Up @@ -58,101 +56,57 @@ public IGraphQLClient GraphQL

public IEventClient GetEvents() => new EventClient(Context);

public IEventClient GetUserEvents(int userId) => new EventClient(Context, userId);

public IEventClient GetProjectEvents(int projectId) => GetProjectEvents((long)projectId);
public IEventClient GetUserEvents(long userId) => new EventClient(Context, userId);

public IEventClient GetProjectEvents(ProjectId projectId) => new EventClient(Context, null, projectId);

public ICommitStatusClient GetCommitStatus(int projectId) => GetCommitStatus((long)projectId);

public ICommitStatusClient GetCommitStatus(ProjectId projectId) => new CommitStatusClient(Context, projectId);

public IEnvironmentClient GetEnvironmentClient(int projectId) => GetEnvironmentClient((long)projectId);

public IEnvironmentClient GetEnvironmentClient(ProjectId projectId) => new EnvironmentClient(Context, projectId);

public IClusterClient GetClusterClient(int projectId) => GetClusterClient((long)projectId);

public IClusterClient GetClusterClient(ProjectId projectId) => new ClusterClient(Context, projectId);

public IGroupBadgeClient GetGroupBadgeClient(int groupId) => GetGroupBadgeClient((long)groupId);

public IGroupBadgeClient GetGroupBadgeClient(GroupId groupId) => new GroupBadgeClient(Context, groupId);

public IGroupVariableClient GetGroupVariableClient(int groupId) => GetGroupVariableClient((long)groupId);

public IGroupVariableClient GetGroupVariableClient(GroupId groupId) => new GroupVariableClient(Context, groupId);

public IJobClient GetJobs(int projectId) => GetJobs((long)projectId);

public IJobClient GetJobs(ProjectId projectId) => new JobClient(Context, projectId);

public IMergeRequestClient GetMergeRequest(int projectId) => GetMergeRequest((long)projectId);

public IMergeRequestClient GetMergeRequest(ProjectId projectId) => new MergeRequestClient(Context, projectId);

public IMergeRequestClient GetGroupMergeRequest(GroupId groupId) => new MergeRequestClient(Context, groupId);

public IMilestoneClient GetMilestone(int projectId) => GetMilestone((long)projectId);

public IMilestoneClient GetMilestone(ProjectId projectId) => new MilestoneClient(Context, projectId, MilestoneScope.Projects);

public IMilestoneClient GetGroupMilestone(int groupId) => GetGroupMilestone((long)groupId);

public IMilestoneClient GetGroupMilestone(GroupId groupId) => new MilestoneClient(Context, groupId, MilestoneScope.Groups);

public IReleaseClient GetReleases(int projectId) => GetReleases((long)projectId);

public IReleaseClient GetReleases(ProjectId projectId) => new ReleaseClient(Context, projectId);

public IPipelineClient GetPipelines(int projectId) => GetPipelines((long)projectId);

public IPipelineClient GetPipelines(ProjectId projectId) => new PipelineClient(Context, jobClient: GetJobs(projectId), projectId: projectId);

public IPipelineScheduleClient GetPipelineSchedules(ProjectId projectId)
=> new PipelineScheduleClient(Context, projectId);

public IProjectBadgeClient GetProjectBadgeClient(int projectId) => GetProjectBadgeClient((long)projectId);

public IProjectBadgeClient GetProjectBadgeClient(ProjectId projectId) => new ProjectBadgeClient(Context, projectId);

public IProjectIssueNoteClient GetProjectIssueNoteClient(int projectId) => GetProjectIssueNoteClient((long)projectId);

public IProjectIssueNoteClient GetProjectIssueNoteClient(ProjectId projectId) => new ProjectIssueNoteClient(Context, projectId);

public IProjectVariableClient GetProjectVariableClient(int projectId) => GetProjectVariableClient((long)projectId);

public IProjectVariableClient GetProjectVariableClient(ProjectId projectId) => new ProjectVariableClient(Context, projectId);

public IRepositoryClient GetRepository(int projectId) => GetRepository((long)projectId);

public IRepositoryClient GetRepository(ProjectId projectId) => new RepositoryClient(Context, projectId);

public ITriggerClient GetTriggers(int projectId) => GetTriggers((long)projectId);

public ITriggerClient GetTriggers(ProjectId projectId) => new TriggerClient(Context, projectId);

public IWikiClient GetWikiClient(int projectId) => GetWikiClient((long)projectId);

public IWikiClient GetWikiClient(ProjectId projectId) => new WikiClient(Context, projectId);

public IProjectLevelApprovalRulesClient GetProjectLevelApprovalRulesClient(int projectId) => GetProjectLevelApprovalRulesClient((long)projectId);

public IProjectLevelApprovalRulesClient GetProjectLevelApprovalRulesClient(ProjectId projectId) => new ProjectLevelApprovalRulesClient(Context, projectId);

public IProtectedBranchClient GetProtectedBranchClient(int projectId) => GetProtectedBranchClient((long)projectId);

public IProtectedBranchClient GetProtectedBranchClient(ProjectId projectId) => new ProtectedBranchClient(Context, projectId);

public IProtectedTagClient GetProtectedTagClient(ProjectId projectId) => new ProtectedTagClient(Context, projectId);

public ISearchClient GetGroupSearchClient(int groupId) => GetGroupSearchClient((long)groupId);

public ISearchClient GetGroupSearchClient(GroupId groupId) => new GroupSearchClient(Context, groupId);

public ISearchClient GetProjectSearchClient(int projectId) => GetProjectSearchClient((long)projectId);

public ISearchClient GetProjectSearchClient(ProjectId projectId) => new ProjectSearchClient(Context, projectId);

public IGroupHooksClient GetGroupHooksClient(GroupId groupId) => new GroupHooksClient(Context, groupId);
Expand Down
Loading

0 comments on commit 8bf473e

Please sign in to comment.