Skip to content

Commit 84a6ec2

Browse files
authored
Add interfaces for GitLabClient and all inner clients (#130)
1 parent 97d3d8d commit 84a6ec2

36 files changed

+1243
-35
lines changed

src/GitLabApiClient/BranchClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace GitLabApiClient
1212
{
13-
public sealed class BranchClient
13+
public sealed class BranchClient : IBranchClient
1414
{
1515
private readonly GitLabHttpFacade _httpFacade;
1616
private readonly BranchQueryBuilder _branchQueryBuilder;

src/GitLabApiClient/CommitsClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace GitLabApiClient
1212
{
13-
public sealed class CommitsClient
13+
public sealed class CommitsClient : ICommitsClient
1414
{
1515
private readonly GitLabHttpFacade _httpFacade;
1616
private readonly CommitQueryBuilder _commitQueryBuilder;

src/GitLabApiClient/FilesClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace GitLabApiClient
99
{
10-
public sealed class FilesClient
10+
public sealed class FilesClient : IFilesClient
1111
{
1212
private readonly GitLabHttpFacade _httpFacade;
1313

src/GitLabApiClient/GitLabClient.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace GitLabApiClient
1515
/// <summary>
1616
/// A client for the GitLab API v4. You can read more about the api here: https://docs.gitlab.com/ce/api/README.html.
1717
/// </summary>
18-
public sealed class GitLabClient
18+
public sealed class GitLabClient : IGitLabClient
1919
{
2020
private readonly GitLabHttpFacade _httpFacade;
2121

@@ -83,87 +83,87 @@ public GitLabClient(string hostUrl, string authenticationToken = "", HttpMessage
8383
/// <summary>
8484
/// Access GitLab's issues API.
8585
/// </summary>
86-
public IssuesClient Issues { get; }
86+
public IIssuesClient Issues { get; }
8787

8888
/// <summary>
8989
/// Access GitLab's uploads API.
9090
/// </summary>
91-
public UploadsClient Uploads { get; }
91+
public IUploadsClient Uploads { get; }
9292

9393
/// <summary>
9494
/// Access GitLab's merge requests API.
9595
/// </summary>
96-
public MergeRequestsClient MergeRequests { get; }
96+
public IMergeRequestsClient MergeRequests { get; }
9797

9898
/// <summary>
9999
/// Access GitLab's projects API.
100100
/// </summary>
101-
public ProjectsClient Projects { get; }
101+
public IProjectsClient Projects { get; }
102102

103103
/// <summary>
104104
/// Access GitLab's users API.
105105
/// </summary>
106-
public UsersClient Users { get; }
106+
public IUsersClient Users { get; }
107107

108108
/// <summary>
109109
/// Access GitLab's groups API.
110110
/// </summary>
111-
public GroupsClient Groups { get; }
111+
public IGroupsClient Groups { get; }
112112

113113
/// <summary>
114114
/// Access GitLab's branches API.
115115
/// </summary>
116-
public BranchClient Branches { get; }
116+
public IBranchClient Branches { get; }
117117

118118
/// <summary>
119119
/// Access GitLab's release API.
120120
/// </summary>
121-
public ReleaseClient Releases { get; }
121+
public IReleaseClient Releases { get; }
122122

123123
/// <summary>
124124
/// Access GitLab's tags API.
125125
/// </summary>
126-
public TagClient Tags { get; }
126+
public ITagClient Tags { get; }
127127

128128
/// <summary>
129129
/// Access GitLab's webhook API.
130130
/// </summary>
131-
public WebhookClient Webhooks { get; }
131+
public IWebhookClient Webhooks { get; }
132132

133133
/// <summary>
134134
/// Access GitLab's commits API.
135135
/// </summary>
136-
public CommitsClient Commits { get; }
136+
public ICommitsClient Commits { get; }
137137

138138
/// <summary>
139139
/// Access GitLab's trees API.
140140
/// </summary>
141-
public TreesClient Trees { get; }
141+
public ITreesClient Trees { get; }
142142

143143
/// <summary>
144144
/// Access GitLab's files API.
145145
/// </summary>
146-
public FilesClient Files { get; }
146+
public IFilesClient Files { get; }
147147

148148
/// <summary>
149149
/// Access GitLab's Markdown API.
150150
/// </summary>
151-
public MarkdownClient Markdown { get; }
151+
public IMarkdownClient Markdown { get; }
152152

153153
/// <summary>
154154
/// Acess GitLab's Pipeline API.
155155
/// </summary>
156-
public PipelineClient Pipelines { get; }
156+
public IPipelineClient Pipelines { get; }
157157

158158
/// <summary>
159159
/// Access GitLab's Runners API.
160160
/// </summary>
161-
public RunnersClient Runners { get; }
161+
public IRunnersClient Runners { get; }
162162

163163
/// <summary>
164164
/// Access GitLab's ToDo-List API.
165165
/// </summary>
166-
public ToDoListClient ToDoList { get; }
166+
public IToDoListClient ToDoList { get; }
167167

168168
/// <summary>
169169
/// Provides a client connection to make rest requests to HTTP endpoints.

src/GitLabApiClient/GroupsClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace GitLabApiClient
2020
/// <exception cref="GitLabException">Thrown if request to GitLab API does not indicate success</exception>
2121
/// <exception cref="HttpRequestException">Thrown if request to GitLab API fails</exception>
2222
/// </summary>
23-
public sealed class GroupsClient
23+
public sealed class GroupsClient : IGroupsClient
2424
{
2525
private readonly GitLabHttpFacade _httpFacade;
2626
private readonly GroupsQueryBuilder _queryBuilder;
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
using GitLabApiClient.Internal.Http;
5+
using GitLabApiClient.Internal.Paths;
6+
using GitLabApiClient.Internal.Queries;
7+
using GitLabApiClient.Models.Branches.Requests;
8+
using GitLabApiClient.Models.Branches.Responses;
9+
using GitLabApiClient.Models.Projects.Responses;
10+
11+
namespace GitLabApiClient
12+
{
13+
public interface IBranchClient
14+
{/// <summary>
15+
/// Retrieves a single branch
16+
/// </summary>
17+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
18+
/// <param name="branchName">The branch name.</param>
19+
/// <returns></returns>
20+
Task<Branch> GetAsync(ProjectId projectId, string branchName);
21+
22+
/// <summary>
23+
///
24+
/// </summary>
25+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
26+
/// <param name="options">Query options <see cref="BranchQueryOptions"/></param>
27+
/// <returns></returns>
28+
Task<IList<Branch>> GetAsync(ProjectId projectId, Action<BranchQueryOptions> options);
29+
30+
/// <summary>
31+
/// Creates a branch
32+
/// </summary>
33+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
34+
/// <param name="request">Create branch request</param>
35+
/// <returns></returns>
36+
Task<Branch> CreateAsync(ProjectId projectId, CreateBranchRequest request);
37+
38+
/// <summary>
39+
/// Deletes a branch
40+
/// </summary>
41+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
42+
/// <param name="branchName">The branch, you want deleted.</param>
43+
Task DeleteBranch(ProjectId projectId, string branchName);
44+
45+
/// <summary>
46+
/// Deletes the merged branches
47+
/// </summary>
48+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
49+
Task DeleteMergedBranches(ProjectId projectId);
50+
51+
/// <summary>
52+
/// Retrieve a single protected branch information.
53+
/// </summary>
54+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
55+
/// <param name="branchName">The protected branch</param>
56+
/// <returns>A protected branch</returns>
57+
Task<ProtectedBranch> GetProtectedBranchesAsync(ProjectId projectId, string branchName);
58+
59+
/// <summary>
60+
/// Retrieves a list of Protected Branches from a project.
61+
/// </summary>
62+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
63+
/// <returns>List of protected branches.</returns>
64+
Task<IList<ProtectedBranch>> GetProtectedBranchesAsync(ProjectId projectId);
65+
66+
/// <summary>
67+
/// Protect a branch
68+
/// </summary>
69+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
70+
/// <param name="request">Protect branch request <see cref="ProtectBranchRequest"/>.</param>
71+
/// <returns>The newly protected branch.</returns>
72+
Task<ProtectedBranch> ProtectBranchAsync(ProjectId projectId, ProtectBranchRequest request);
73+
74+
/// <summary>
75+
/// Unprotect a branch
76+
/// </summary>
77+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
78+
/// <param name="branchName">The Branch, you want to unprotect.</param>
79+
Task UnprotectBranchAsync(ProjectId projectId, string branchName);
80+
}
81+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
using GitLabApiClient.Internal.Http;
5+
using GitLabApiClient.Internal.Paths;
6+
using GitLabApiClient.Internal.Queries;
7+
using GitLabApiClient.Models.Commits.Requests;
8+
using GitLabApiClient.Models.Commits.Responses;
9+
using GitLabApiClient.Models.Projects.Responses;
10+
11+
namespace GitLabApiClient
12+
{
13+
public interface ICommitsClient
14+
{
15+
/// <summary>
16+
/// Get a commit from commit sha
17+
/// </summary>
18+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
19+
/// <param name="sha">The commit hash or name of a repository branch or tag</param>
20+
/// <returns></returns>
21+
Task<Commit> GetAsync(ProjectId projectId, string sha);
22+
23+
/// <summary>
24+
/// Retrieve a list of commits from a project
25+
/// </summary>
26+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
27+
/// <param name="options">Query Options <see cref="CommitQueryOptions"/>.</param>
28+
/// <returns></returns>
29+
Task<IList<Commit>> GetAsync(ProjectId projectId, Action<CommitQueryOptions> options = null);
30+
31+
/// <summary>
32+
/// Retrieve a list of references (from branch or / and tag) that this commit belongs to
33+
/// </summary>
34+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
35+
/// <param name="options">Query Options <see cref="CommitRefsQueryOptions"/>.</param>
36+
/// <param name="sha">The commit hash or name of a repository branch or tag</param>
37+
/// <returns></returns>
38+
Task<IList<CommitRef>> GetRefsAsync(ProjectId projectId, string sha, Action<CommitRefsQueryOptions> options);
39+
40+
/// <summary>
41+
/// Retrieve a list of differences in this commit
42+
/// </summary>
43+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
44+
/// <param name="sha">The commit hash or name of a repository branch or tag</param>
45+
/// <returns></returns>
46+
Task<IList<Diff>> GetDiffsAsync(ProjectId projectId, string sha);
47+
48+
/// <summary>
49+
/// Retrieve a list of statuses in this commit
50+
/// </summary>
51+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
52+
/// <param name="options">Query Options <see cref="CommitStatusesQueryOptions"/>.</param>
53+
/// <param name="sha">The commit hash</param>
54+
/// <returns></returns>
55+
Task<IList<CommitStatuses>> GetStatusesAsync(ProjectId projectId, string sha, Action<CommitStatusesQueryOptions> options = null);
56+
}
57+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Threading.Tasks;
2+
using GitLabApiClient.Internal.Paths;
3+
using GitLabApiClient.Models.Files.Responses;
4+
5+
namespace GitLabApiClient
6+
{
7+
public interface IFilesClient
8+
{
9+
Task<File> GetAsync(ProjectId projectId, string filePath, string reference = "master");
10+
}
11+
}

0 commit comments

Comments
 (0)