Skip to content

Commit

Permalink
support pullrequests
Browse files Browse the repository at this point in the history
  • Loading branch information
lvermeulen committed Feb 21, 2020
1 parent f9fc3cc commit 89c14b1
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ C# Client for Bitbucket Cloud
* [ ] Values
* [ ] Hook Events
* [ ] Subject Type
* [ ] Pull Requests
* [X] Pull Requests
* [X] Selected User
* [X] Repositories
* [X] Workspace
* [X] Repo Slug
Expand Down
5 changes: 1 addition & 4 deletions src/Bitbucket.Cloud.Net/Bitbucket.Cloud.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PackageLicenseUrl>https://github.com/lvermeulen/Bitbucket.Cloud.Net/blob/master/LICENSE</PackageLicenseUrl>
<PackageTags>bitbucket cloud org</PackageTags>
<LangVersion>latest</LangVersion>
<Description>C# client for Bitbucket Cloud</Description>
</PropertyGroup>

<ItemGroup>
Expand All @@ -20,8 +21,4 @@
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="v1\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class PullRequestStatesConverter : JsonEnumConverter<PullRequestStates>
[PullRequestStates.Declined] = "DECLINED"
};

protected override string ConvertToString(PullRequestStates value)
public static string ToString(PullRequestStates value)
{
if (!s_map.TryGetValue(value, out string result))
{
Expand All @@ -25,6 +25,18 @@ protected override string ConvertToString(PullRequestStates value)
return result;
}

public static string ToString(PullRequestStates? value)
{
return value.HasValue
? ToString(value.Value)
: null;
}

protected override string ConvertToString(PullRequestStates value)
{
return ToString(value);
}

protected override PullRequestStates ConvertFromString(string s)
{
var pair = s_map.FirstOrDefault(kvp => kvp.Value.Equals(s, StringComparison.OrdinalIgnoreCase));
Expand Down
34 changes: 34 additions & 0 deletions src/Bitbucket.Cloud.Net/v2/PullRequests/BitbucketCloudClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Bitbucket.Cloud.Net.Common.Converters;
using Bitbucket.Cloud.Net.Common.Models;
using Bitbucket.Cloud.Net.Models;
using Flurl.Http;

// ReSharper disable once CheckNamespace
namespace Bitbucket.Cloud.Net
{
public partial class BitbucketCloudClient
{
private IFlurlRequest GetPullRequestsUrl() => GetBaseUrl("2.0/pullrequests");

private IFlurlRequest GetPullRequestsUrl(string userName) => GetPullRequestsUrl().AppendPathSegment(userName);

public async Task<IEnumerable<PullRequest>> GetPullRequestsAsync(string userName, int? maxPages = null, PullRequestStates? state = null, string q = null, string sort = null)
{
var queryParamValues = new Dictionary<string, object>
{
[nameof(state)] = PullRequestStatesConverter.ToString(state),
[nameof(q)] = q,
[nameof(sort)] = sort
};

return await GetPagedResultsAsync(maxPages, queryParamValues, async qpv =>
await GetPullRequestsUrl(userName)
.SetQueryParams(qpv)
.GetJsonAsync<PagedResults<PullRequest>>()
.ConfigureAwait(false))
.ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Threading.Tasks;
using Xunit;

// ReSharper disable once CheckNamespace
namespace Bitbucket.Cloud.Net.Tests
{
public partial class BitbucketCloudClientShould
{
[Theory]
[InlineData("luve")]
public async Task GetPullRequestsAsync(string userName)
{
var result = await _client.GetPullRequestsAsync(userName).ConfigureAwait(false);
Assert.NotNull(result);
}
}
}

0 comments on commit 89c14b1

Please sign in to comment.