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

Support for using URL-encoded paths as group or project ids #550

Merged
merged 5 commits into from
Nov 3, 2023
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
2 changes: 1 addition & 1 deletion NGitLab.Mock/Clients/ClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected Group GetGroup(object id, GroupPermission permissions)

var group = id switch
{
int idInt => Server.AllGroups.FindGroupById(idInt),
int idInt => Server.AllGroups.FindById(idInt),
string idStr => Server.AllGroups.FindGroup(idStr),
_ => throw new ArgumentException($"Id of type '{id.GetType()}' is not supported"),
};
Expand Down
4 changes: 2 additions & 2 deletions NGitLab.Mock/Clients/ClusterClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ internal sealed class ClusterClient : ClientBase, IClusterClient
{
private readonly int _projectId;

public ClusterClient(ClientContext context, int projectId)
public ClusterClient(ClientContext context, ProjectId projectId)
: base(context)
{
_projectId = projectId;
_projectId = Server.AllProjects.FindProject(projectId.ValueAsUriParameter()).Id;
}

public IEnumerable<ClusterInfo> All => throw new NotImplementedException();
Expand Down
4 changes: 2 additions & 2 deletions NGitLab.Mock/Clients/CommitClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ internal sealed class CommitClient : ClientBase, ICommitClient
{
private readonly int _projectId;

public CommitClient(ClientContext context, int projectId)
public CommitClient(ClientContext context, ProjectId projectId)
: base(context)
{
_projectId = projectId;
_projectId = Server.AllProjects.FindProject(projectId.ValueAsUriParameter()).Id;
}

public Commit Create(CommitCreate commit)
Expand Down
4 changes: 2 additions & 2 deletions NGitLab.Mock/Clients/CommitStatusClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ internal sealed class CommitStatusClient : ClientBase, ICommitStatusClient
{
private readonly int _projectId;

public CommitStatusClient(ClientContext context, int projectId)
public CommitStatusClient(ClientContext context, ProjectId projectId)
: base(context)
{
_projectId = projectId;
_projectId = Server.AllProjects.FindProject(projectId.ValueAsUriParameter()).Id;
}

public CommitStatusCreate AddOrUpdate(CommitStatusCreate status)
Expand Down
4 changes: 2 additions & 2 deletions NGitLab.Mock/Clients/EnvironmentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ internal sealed class EnvironmentClient : ClientBase, IEnvironmentClient
{
private readonly int _projectId;

public EnvironmentClient(ClientContext context, int projectId)
public EnvironmentClient(ClientContext context, ProjectId projectId)
: base(context)
{
_projectId = projectId;
_projectId = Server.AllProjects.FindProject(projectId.ValueAsUriParameter()).Id;
}

public IEnumerable<EnvironmentInfo> All => throw new NotImplementedException();
Expand Down
4 changes: 2 additions & 2 deletions NGitLab.Mock/Clients/EventClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public EventClient(ClientContext context)
{
}

public EventClient(ClientContext context, int? userId = null, int? projectId = null)
public EventClient(ClientContext context, int? userId = null, ProjectId? projectId = null)
: base(context)
{
_userId = userId;
_projectId = projectId;
_projectId = projectId.HasValue ? Server.AllProjects.FindProject(projectId.ValueAsUriParameter()).Id : null;
}

IEnumerable<Models.Event> IEventClient.Get(EventQuery query)
Expand Down
95 changes: 71 additions & 24 deletions NGitLab.Mock/Clients/GitLabClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NGitLab.Impl;
using NGitLab.Models;

namespace NGitLab.Mock.Clients
{
Expand All @@ -19,7 +20,9 @@ public GitLabClient(ClientContext context)

public IMembersClient Members => new MembersClient(Context);

public ICommitClient GetCommits(int projectId) => new CommitClient(Context, projectId);
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 @@ -55,50 +58,94 @@ public IGraphQLClient GraphQL

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

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

public IEventClient GetProjectEvents(int projectId) => GetProjectEvents((long)projectId);

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 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 IEventClient GetProjectEvents(int projectId) => new EventClient(Context, projectId: projectId);
public IPipelineClient GetPipelines(int projectId) => GetPipelines((long)projectId);

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

public IEnvironmentClient GetEnvironmentClient(int projectId) => new EnvironmentClient(Context, projectId);
public IProjectBadgeClient GetProjectBadgeClient(int projectId) => GetProjectBadgeClient((long)projectId);

public IClusterClient GetClusterClient(int projectId) => new ClusterClient(Context, projectId);
public IProjectBadgeClient GetProjectBadgeClient(ProjectId projectId) => new ProjectBadgeClient(Context, projectId);

public IGroupBadgeClient GetGroupBadgeClient(int groupId) => new GroupBadgeClient(Context, groupId);
public IProjectIssueNoteClient GetProjectIssueNoteClient(int projectId) => GetProjectIssueNoteClient((long)projectId);

public IGroupVariableClient GetGroupVariableClient(int groupId) => new GroupVariableClient(Context, groupId);
public IProjectIssueNoteClient GetProjectIssueNoteClient(ProjectId projectId) => new ProjectIssueNoteClient(Context, projectId);

public IJobClient GetJobs(int projectId) => new JobClient(Context, projectId);
public IProjectVariableClient GetProjectVariableClient(int projectId) => GetProjectVariableClient((long)projectId);

public IMergeRequestClient GetMergeRequest(int projectId) => new MergeRequestClient(Context, projectId);
public IProjectVariableClient GetProjectVariableClient(ProjectId projectId) => new ProjectVariableClient(Context, projectId);

public IMilestoneClient GetMilestone(int projectId) => new MilestoneClient(Context, projectId, MilestoneScope.Projects);
public IRepositoryClient GetRepository(int projectId) => GetRepository((long)projectId);

public IMilestoneClient GetGroupMilestone(int groupId) => new MilestoneClient(Context, groupId, MilestoneScope.Groups);
public IRepositoryClient GetRepository(ProjectId projectId) => new RepositoryClient(Context, projectId);

public IReleaseClient GetReleases(int projectId) => new ReleaseClient(Context, projectId);
public ITriggerClient GetTriggers(int projectId) => GetTriggers((long)projectId);

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

public IProjectBadgeClient GetProjectBadgeClient(int projectId) => new ProjectBadgeClient(Context, projectId);
public IWikiClient GetWikiClient(int projectId) => GetWikiClient((long)projectId);

public IProjectIssueNoteClient GetProjectIssueNoteClient(int projectId) => new ProjectIssueNoteClient(Context, projectId);
public IWikiClient GetWikiClient(ProjectId projectId) => new WikiClient(Context, projectId);

public IProjectVariableClient GetProjectVariableClient(int projectId) => new ProjectVariableClient(Context, projectId);
public IProjectLevelApprovalRulesClient GetProjectLevelApprovalRulesClient(int projectId) => GetProjectLevelApprovalRulesClient((long)projectId);

public IRepositoryClient GetRepository(int projectId) => new RepositoryClient(Context, projectId);
public IProjectLevelApprovalRulesClient GetProjectLevelApprovalRulesClient(ProjectId projectId) => new ProjectLevelApprovalRulesClient(Context, projectId);

public ITriggerClient GetTriggers(int projectId) => new TriggerClient(Context, projectId);
public IProtectedBranchClient GetProtectedBranchClient(int projectId) => GetProtectedBranchClient((long)projectId);

public IWikiClient GetWikiClient(int projectId) => new WikiClient(Context, projectId);
public IProtectedBranchClient GetProtectedBranchClient(ProjectId projectId) => new ProtectedBranchClient(Context, projectId);

public IProjectLevelApprovalRulesClient GetProjectLevelApprovalRulesClient(int projectId) => new ProjectLevelApprovalRulesClient(Context, projectId);
public ISearchClient GetGroupSearchClient(int groupId) => GetGroupSearchClient((long)groupId);

public IProtectedBranchClient GetProtectedBranchClient(int projectId) => new ProtectedBranchClient(Context, projectId);
public ISearchClient GetGroupSearchClient(GroupId groupId) => new GroupSearchClient(Context, groupId);

public ISearchClient GetGroupSearchClient(int groupId) => new GroupSearchClient(Context, groupId);
public ISearchClient GetProjectSearchClient(int projectId) => GetProjectSearchClient((long)projectId);

public ISearchClient GetProjectSearchClient(int projectId) => new ProjectSearchClient(Context, projectId);
public ISearchClient GetProjectSearchClient(ProjectId projectId) => new ProjectSearchClient(Context, projectId);
}
}
4 changes: 2 additions & 2 deletions NGitLab.Mock/Clients/GroupBadgeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ internal sealed class GroupBadgeClient : ClientBase, IGroupBadgeClient
{
private readonly int _groupId;

public GroupBadgeClient(ClientContext context, int groupId)
public GroupBadgeClient(ClientContext context, GroupId groupId)
: base(context)
{
_groupId = groupId;
_groupId = Server.AllGroups.FindGroup(groupId.ValueAsUriParameter()).Id;
}

public Models.Badge this[int id]
Expand Down
2 changes: 1 addition & 1 deletion NGitLab.Mock/Clients/GroupClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public Models.Group Update(int id, GroupUpdate groupUpdate)
{
using (Context.BeginOperationScope())
{
var group = Server.AllGroups.FindGroupById(id);
var group = Server.AllGroups.FindById(id);
if (group == null || !group.CanUserViewGroup(Context.User))
throw new GitLabNotFoundException();

Expand Down
7 changes: 4 additions & 3 deletions NGitLab.Mock/Clients/GroupSearchClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

namespace NGitLab.Mock.Clients
{
internal sealed class GroupSearchClient : ISearchClient
internal sealed class GroupSearchClient : ClientBase, ISearchClient
{
private readonly ClientContext _context;
private readonly int _groupId;

public GroupSearchClient(ClientContext context, int groupId)
public GroupSearchClient(ClientContext context, GroupId groupId)
: base(context)
{
_context = context;
_groupId = groupId;
_groupId = Server.AllGroups.FindGroup(groupId.ValueAsUriParameter()).Id;
}

public GitLabCollectionResponse<SearchBlob> GetBlobsAsync(SearchQuery query)
Expand Down
4 changes: 2 additions & 2 deletions NGitLab.Mock/Clients/GroupVariableClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ internal sealed class GroupVariableClient : ClientBase, IGroupVariableClient
{
private readonly int _groupId;

public GroupVariableClient(ClientContext context, int groupId)
public GroupVariableClient(ClientContext context, GroupId groupId)
: base(context)
{
_groupId = groupId;
_groupId = Server.AllGroups.FindGroup(groupId.ValueAsUriParameter()).Id;
}

public Variable this[string key] => throw new NotImplementedException();
Expand Down
4 changes: 2 additions & 2 deletions NGitLab.Mock/Clients/JobClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ internal sealed class JobClient : ClientBase, IJobClient
{
private readonly int _projectId;

public JobClient(ClientContext context, int projectId)
public JobClient(ClientContext context, ProjectId projectId)
: base(context)
{
_projectId = projectId;
_projectId = Server.AllProjects.FindProject(projectId.ValueAsUriParameter()).Id;
}

public Models.Job Get(int jobId)
Expand Down
4 changes: 2 additions & 2 deletions NGitLab.Mock/Clients/MergeRequestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public MergeRequestClient(ClientContext context)
{
}

public MergeRequestClient(ClientContext context, int projectId)
public MergeRequestClient(ClientContext context, ProjectId projectId)
: base(context)
{
_projectId = projectId;
_projectId = Server.AllProjects.FindProject(projectId.ValueAsUriParameter()).Id;
}

private void AssertProjectId()
Expand Down
9 changes: 7 additions & 2 deletions NGitLab.Mock/Clients/MilestoneClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ internal sealed class MilestoneClient : ClientBase, IMilestoneClient
{
private readonly int _resourceId;

public MilestoneClient(ClientContext context, int id, MilestoneScope scope)
public MilestoneClient(ClientContext context, IIdOrPathAddressable id, MilestoneScope scope)
: base(context)
{
_resourceId = id;
_resourceId = scope switch
{
MilestoneScope.Groups => Server.AllGroups.FindGroup(id.ValueAsUriParameter()).Id,
MilestoneScope.Projects => Server.AllProjects.FindProject(id.ValueAsUriParameter()).Id,
_ => throw new NotSupportedException($"{scope} milestone is not supported yet."),
};
Scope = scope;
}

Expand Down
4 changes: 2 additions & 2 deletions NGitLab.Mock/Clients/PipelineClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ internal sealed class PipelineClient : ClientBase, IPipelineClient
private readonly int _projectId;
private readonly IJobClient _jobClient;

public PipelineClient(ClientContext context, IJobClient jobClient, int projectId)
public PipelineClient(ClientContext context, IJobClient jobClient, ProjectId projectId)
: base(context)
{
_jobClient = jobClient;
_projectId = projectId;
_projectId = Server.AllProjects.FindProject(projectId.ValueAsUriParameter()).Id;
}

public Models.Pipeline this[int id]
Expand Down
4 changes: 2 additions & 2 deletions NGitLab.Mock/Clients/ProjectBadgeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ internal sealed class ProjectBadgeClient : ClientBase, IProjectBadgeClient
{
private readonly int _projectId;

public ProjectBadgeClient(ClientContext context, int projectId)
public ProjectBadgeClient(ClientContext context, ProjectId projectId)
: base(context)
{
_projectId = projectId;
_projectId = Server.AllProjects.FindProject(projectId.ValueAsUriParameter()).Id;
}

public Models.Badge this[int id]
Expand Down
4 changes: 2 additions & 2 deletions NGitLab.Mock/Clients/ProjectIssueNoteClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ internal sealed class ProjectIssueNoteClient : ClientBase, IProjectIssueNoteClie
{
private readonly int _projectId;

public ProjectIssueNoteClient(ClientContext context, int projectId)
public ProjectIssueNoteClient(ClientContext context, ProjectId projectId)
: base(context)
{
_projectId = projectId;
_projectId = Server.AllProjects.FindProject(projectId.ValueAsUriParameter()).Id;
}

public Models.ProjectIssueNote Create(ProjectIssueNoteCreate create)
Expand Down
4 changes: 2 additions & 2 deletions NGitLab.Mock/Clients/ProjectLevelApprovalRulesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ internal sealed class ProjectLevelApprovalRulesClient : ClientBase, IProjectLeve
{
private readonly int _projectId;

public ProjectLevelApprovalRulesClient(ClientContext context, int projectId)
public ProjectLevelApprovalRulesClient(ClientContext context, ProjectId projectId)
: base(context)
{
_projectId = projectId;
_projectId = Server.AllProjects.FindProject(projectId.ValueAsUriParameter()).Id;
}

public List<ApprovalRule> GetProjectLevelApprovalRules()
Expand Down
7 changes: 4 additions & 3 deletions NGitLab.Mock/Clients/ProjectSearchClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

namespace NGitLab.Mock.Clients
{
internal sealed class ProjectSearchClient : ISearchClient
internal sealed class ProjectSearchClient : ClientBase, ISearchClient
{
private readonly ClientContext _context;
private readonly int _projectId;

public ProjectSearchClient(ClientContext context, int projectId)
public ProjectSearchClient(ClientContext context, ProjectId projectId)
: base(context)
{
_context = context;
_projectId = projectId;
_projectId = Server.AllProjects.FindProject(projectId.ValueAsUriParameter()).Id;
}

public GitLabCollectionResponse<SearchBlob> GetBlobsAsync(SearchQuery query)
Expand Down
4 changes: 2 additions & 2 deletions NGitLab.Mock/Clients/ProjectVariableClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ internal sealed class ProjectVariableClient : ClientBase, IProjectVariableClient
{
private readonly int _projectId;

public ProjectVariableClient(ClientContext context, int projectId)
public ProjectVariableClient(ClientContext context, ProjectId projectId)
: base(context)
{
_projectId = projectId;
_projectId = Server.AllProjects.FindProject(projectId.ValueAsUriParameter()).Id;
}

public Variable this[string key] => throw new NotImplementedException();
Expand Down
Loading