MitjaBezensek / SharpBucket

SharpBucket is a .Net wrapper for the Bitbucket's REST API.
MIT License
67 stars 59 forks source link

How do I get the last pull request from the master? to avoid the problem I'm having slow. method used: .GetPullRequestLog () #120

Closed tiago-mateus closed 5 years ago

tiago-mateus commented 5 years ago

How do I get the last pull request from the master? to avoid the problem I'm having slow. method used: .GetPullRequestLog ()

mnivet commented 5 years ago

You should do that using a query filter and a sort instruction on the ListPullRequests(ListParameters parameters) method

you can refer to the Bitbucket documentation about filtering and sorting to build your filter and sort strings: https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering

It should looks like that:

var branchName = "master";
var parameters = new ListParameters
{
Filter = $"destination.branch.name = \"{branchName}\"",
Sort = "-updated_on", /* or "-created_on"  in function of what you mean by last */
Max = 1 /* since you are not interested to get all */
};
var lastPullRequest = pullRequestsResource.ListPullRequests(parameters).FirstOrDefault();
tiago-mateus commented 5 years ago

Obrigadoo!