Skip to content

Commit baa9da1

Browse files
authored
support id, path or object of groups and project (#68)
* support id, path or object of groups and project Library should handle path encoding * formatting 😓 * less braces * xml-doc it * xml-doc it, take two * update test project target and dependencies * fix fluent assertion usage * fix xUnit Initialize and Dispose needs to be annotated with Fact * Implement implicit operators, revert BaseUrl pattern * Add solution items * add csharp_space_in_singleline_method as true to match dotnet format * fix formatting * fix copy paste error in commit query builder * fix missing fluent assertion usage, missed due to WIP being too large Commit more often! * remove the last base url method 😓 * fixup pipeline client * skip mono * truly skip mono on travis * use coverlet.collector to generate opencover * chocolatey install no progress
1 parent fde4e25 commit baa9da1

File tree

72 files changed

+829
-855
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+829
-855
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ csharp_style_var_for_built_in_types = false:error
180180
# http://kent-boogaart.com/blog/editorconfig-reference-for-c-developers#csharp_style_var_when_type_is_apparent
181181
csharp_style_var_when_type_is_apparent = true:error
182182

183+
# https://www.jetbrains.com/help/resharper/EditorConfig_CSHARP_SpacesPageSchema.html#resharper_csharp_space_in_singleline_method
184+
csharp_space_in_singleline_method = true
185+
183186
# http://kent-boogaart.com/blog/editorconfig-reference-for-c-developers#dotnet_sort_system_directives_first
184187
dotnet_sort_system_directives_first = true
185188

.travis.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
language: csharp
2-
mono: 5.2.0
3-
dotnet: 2.0.0
4-
dist: trusty
2+
mono: none
3+
dotnet: 3.0.100
4+
dist: bionic
55
sudo: required
6-
install:
7-
- export FrameworkPathOverride=$(dirname $(which mono))/../lib/mono/4.5/
86
services:
97
- docker
108
script:
119
- dotnet build
12-
- (cd ./test/GitLabApiClient.Test && dotnet test)
10+
- dotnet test
1311
cache:
1412
directories:
1513
- $HOME/.nuget

GitLabApiClient.sln

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26730.3
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29324.140
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GitLabApiClient", "src\GitLabApiClient\GitLabApiClient.csproj", "{92D1EE01-7A8D-4EFC-B856-54C0E0645454}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitLabApiClient.Test", "test\GitLabApiClient.Test\GitLabApiClient.Test.csproj", "{11F0436A-3BAC-4C3F-9E59-2F271730A5C8}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GitLabApiClient.Test", "test\GitLabApiClient.Test\GitLabApiClient.Test.csproj", "{11F0436A-3BAC-4C3F-9E59-2F271730A5C8}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6E176091-1CD1-475A-AB85-C1735D9422BD}"
11+
ProjectSection(SolutionItems) = preProject
12+
.editorconfig = .editorconfig
13+
.travis.yml = .travis.yml
14+
appveyor.yml = appveyor.yml
15+
build.ps1 = build.ps1
16+
EndProjectSection
917
EndProject
1018
Global
1119
GlobalSection(SolutionConfigurationPlatforms) = preSolution

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ environment:
88
# Don't report back to the mothership
99
DOTNET_CLI_TELEMETRY_OPTOUT: 1
1010

11-
1211
skip_branch_with_pr: true
1312

1413
before_build:
14+
- ps: cinst -y codecov --no-progress
1515
- ps: dotnet tool install -g dotnet-format
1616
- ps: dotnet format --check --dry-run
1717

coverletArgs.runsettings

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<RunSettings>
3+
<DataCollectionRunSettings>
4+
<DataCollectors>
5+
<DataCollector friendlyName="XPlat code coverage">
6+
<Configuration>
7+
<Format>opencover</Format>
8+
<Exclude>[GitLabApiClient.Test*]*</Exclude>
9+
<Include>[GitLabApiClient*]*</Include>
10+
<SingleHit>false</SingleHit>
11+
</Configuration>
12+
</DataCollector>
13+
</DataCollectors>
14+
</DataCollectionRunSettings>
15+
</RunSettings>

src/GitLabApiClient/BranchClient.cs

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
using System.Collections.Generic;
33
using System.Threading.Tasks;
44
using GitLabApiClient.Internal.Http;
5+
using GitLabApiClient.Internal.Paths;
56
using GitLabApiClient.Internal.Queries;
67
using GitLabApiClient.Models.Branches.Requests;
78
using GitLabApiClient.Models.Branches.Responses;
9+
using GitLabApiClient.Models.Projects.Responses;
810

911
namespace GitLabApiClient
1012
{
@@ -21,10 +23,22 @@ internal BranchClient(
2123
_branchQueryBuilder = branchQueryBuilder;
2224
}
2325

24-
public async Task<Branch> GetAsync(string projectId, string branchName) =>
26+
/// <summary>
27+
/// Retrieves a single branch
28+
/// </summary>
29+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
30+
/// <param name="branchName">The branch name.</param>
31+
/// <returns></returns>
32+
public async Task<Branch> GetAsync(ProjectId projectId, string branchName) =>
2533
await _httpFacade.Get<Branch>($"projects/{projectId}/repository/branches/{branchName}");
2634

27-
public async Task<IList<Branch>> GetAsync(string projectId, Action<BranchQueryOptions> options)
35+
/// <summary>
36+
///
37+
/// </summary>
38+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
39+
/// <param name="options">Query options <see cref="BranchQueryOptions"/></param>
40+
/// <returns></returns>
41+
public async Task<IList<Branch>> GetAsync(ProjectId projectId, Action<BranchQueryOptions> options)
2842
{
2943
var queryOptions = new BranchQueryOptions();
3044
options?.Invoke(queryOptions);
@@ -33,25 +47,62 @@ public async Task<IList<Branch>> GetAsync(string projectId, Action<BranchQueryOp
3347
return await _httpFacade.GetPagedList<Branch>(url);
3448
}
3549

36-
public async Task<Branch> CreateAsync(CreateBranchRequest request) =>
37-
await _httpFacade.Post<Branch>($"projects/{request.ProjectId}/repository/branches", request);
50+
/// <summary>
51+
/// Creates a branch
52+
/// </summary>
53+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
54+
/// <param name="request">Create branch request</param>
55+
/// <returns></returns>
56+
public async Task<Branch> CreateAsync(ProjectId projectId, CreateBranchRequest request) =>
57+
await _httpFacade.Post<Branch>($"projects/{projectId}/repository/branches", request);
3858

39-
public async Task DeleteBranch(DeleteBranchRequest request) =>
40-
await _httpFacade.Delete($"projects/{request.ProjectId}/repository/branches/{request.BranchName}");
59+
/// <summary>
60+
/// Deletes a branch
61+
/// </summary>
62+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
63+
/// <param name="branchName">The branch, you want deleted.</param>
64+
public async Task DeleteBranch(ProjectId projectId, string branchName) =>
65+
await _httpFacade.Delete($"projects/{projectId}/repository/branches/{branchName}");
4166

42-
public async Task DeleteMergedBranches(DeleteMergedBranchesRequest request) =>
43-
await _httpFacade.Delete($"projects/{request.ProjectId}/repository/merged_branches");
67+
/// <summary>
68+
/// Deletes the merged branches
69+
/// </summary>
70+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
71+
public async Task DeleteMergedBranches(ProjectId projectId) =>
72+
await _httpFacade.Delete($"projects/{projectId}/repository/merged_branches");
4473

45-
public async Task<ProtectedBranch> GetProtectedBranchesAsync(string projectId, string branchName) =>
74+
/// <summary>
75+
/// Retrieve a single protected branch information.
76+
/// </summary>
77+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
78+
/// <param name="branchName">The protected branch</param>
79+
/// <returns>A protected branch</returns>
80+
public async Task<ProtectedBranch> GetProtectedBranchesAsync(ProjectId projectId, string branchName) =>
4681
await _httpFacade.Get<ProtectedBranch>($"projects/{projectId}/protected_branches/{branchName}");
4782

48-
public async Task<IList<ProtectedBranch>> GetProtectedBranchesAsync(string projectId) =>
83+
/// <summary>
84+
/// Retrieves a list of Protected Branches from a project.
85+
/// </summary>
86+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
87+
/// <returns>List of protected branches.</returns>
88+
public async Task<IList<ProtectedBranch>> GetProtectedBranchesAsync(ProjectId projectId) =>
4989
await _httpFacade.GetPagedList<ProtectedBranch>($"projects/{projectId}/protected_branches");
5090

51-
public async Task<ProtectedBranch> ProtectBranchAsync(ProtectBranchRequest request) =>
52-
await _httpFacade.Post<ProtectedBranch>($"projects/{request.ProjectId}/protected_branches", request);
91+
/// <summary>
92+
/// Protect a branch
93+
/// </summary>
94+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
95+
/// <param name="request">Protect branch request <see cref="ProtectBranchRequest"/>.</param>
96+
/// <returns>The newly protected branch.</returns>
97+
public async Task<ProtectedBranch> ProtectBranchAsync(ProjectId projectId, ProtectBranchRequest request) =>
98+
await _httpFacade.Post<ProtectedBranch>($"projects/{projectId}/protected_branches", request);
5399

54-
public async Task UnprotectBranchAsync(string projectId, string branchName) =>
100+
/// <summary>
101+
/// Unprotect a branch
102+
/// </summary>
103+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
104+
/// <param name="branchName">The Branch, you want to unprotect.</param>
105+
public async Task UnprotectBranchAsync(ProjectId projectId, string branchName) =>
55106
await _httpFacade.Delete($"projects/{projectId}/protected_branches/{branchName}");
56107
}
57108
}

src/GitLabApiClient/CommitsClient.cs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
using System.Collections.Generic;
33
using System.Threading.Tasks;
44
using GitLabApiClient.Internal.Http;
5+
using GitLabApiClient.Internal.Paths;
56
using GitLabApiClient.Internal.Queries;
67
using GitLabApiClient.Models.Commits.Requests;
78
using GitLabApiClient.Models.Commits.Responses;
9+
using GitLabApiClient.Models.Projects.Responses;
810

911
namespace GitLabApiClient
1012
{
@@ -19,21 +21,28 @@ internal CommitsClient(GitLabHttpFacade httpFacade, CommitQueryBuilder commitQue
1921
_commitQueryBuilder = commitQueryBuilder;
2022
}
2123

22-
public async Task<Commit> GetAsync(string projectId, string sha) =>
23-
await _httpFacade.Get<Commit>(CommitsBaseUrl(projectId) + "/" + sha);
24+
/// <summary>
25+
/// Get a commit from commit sha
26+
/// </summary>
27+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
28+
/// <param name="sha">The commit hash or name of a repository branch or tag</param>
29+
/// <returns></returns>
30+
public async Task<Commit> GetAsync(ProjectId projectId, string sha) =>
31+
await _httpFacade.Get<Commit>($"projects/{projectId}/repository/commits/{sha}");
2432

25-
public async Task<IList<Commit>> GetAsync(string projectId, Action<CommitQueryOptions> options)
33+
/// <summary>
34+
/// Retrieve a list of commits from a project
35+
/// </summary>
36+
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
37+
/// <param name="options">Query Options <see cref="CommitQueryOptions"/>.</param>
38+
/// <returns></returns>
39+
public async Task<IList<Commit>> GetAsync(ProjectId projectId, Action<CommitQueryOptions> options = null)
2640
{
27-
var queryOptions = new CommitQueryOptions(projectId);
41+
var queryOptions = new CommitQueryOptions();
2842
options?.Invoke(queryOptions);
2943

30-
string url = _commitQueryBuilder.Build(CommitsBaseUrl(projectId), queryOptions);
44+
string url = _commitQueryBuilder.Build($"projects/{projectId}/repository/commits", queryOptions);
3145
return await _httpFacade.GetPagedList<Commit>(url);
3246
}
33-
34-
private static string CommitsBaseUrl(string projectId)
35-
{
36-
return $"projects/{projectId}/repository/commits";
37-
}
3847
}
3948
}

src/GitLabApiClient/GitLabApiClient.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
4+
<TargetFrameworks Condition="'$(OS)' != 'Unix'">netstandard2.0;net452</TargetFrameworks>
5+
<TargetFrameworks Condition="'$(OS)' == 'Unix'">netstandard2.0</TargetFrameworks>
56
<Version>1.0.0</Version>
67
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
78
<AssemblyVersion>1.0.0.0</AssemblyVersion>

0 commit comments

Comments
 (0)