lvermeulen / bitbucket.cloud.net Goto Github PK
View Code? Open in Web Editor NEWC# client for Atlassian Bitbucket Cloud
License: MIT License
C# client for Atlassian Bitbucket Cloud
License: MIT License
I've checked why it occurs and come across that authorization header never goes to bitbucket api. I used basic/app/oauth authentication options. I also checked that oauth token is valid and works well with straightforward requests through Postman but in exception details returning with 403 response no auth header is included.
Btw, the GetRepositoryPullRequestAsync works perfectly as expected.
Newtonsoft.Json.JsonSerializationException: 'No JSON content found and type 'System.Boolean' is not nullable. Path '', line 0, position 0.'
This exception was originally thrown at this call stack:
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(Newtonsoft.Json.JsonReader, System.Type, bool)
Newtonsoft.Json.JsonSerializer.DeserializeInternal(Newtonsoft.Json.JsonReader, System.Type)
Newtonsoft.Json.JsonSerializer.Deserialize(Newtonsoft.Json.JsonReader, System.Type)
Newtonsoft.Json.JsonConvert.DeserializeObject(string, System.Type, Newtonsoft.Json.JsonSerializerSettings)
Newtonsoft.Json.JsonConvert.DeserializeObject<T>(string, Newtonsoft.Json.JsonSerializerSettings)
Newtonsoft.Json.JsonConvert.DeserializeObject<T>(string)
Bitbucket.Cloud.Net.BitbucketCloudClient.ReadResponseContentAsync<TResult>(System.Net.Http.HttpResponseMessage, System.Func<string, TResult>)
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
...
[Call Stack Truncated]
Current implementation of GetRepositorySourceAsync
only implements /2.0/repositories/{workspace}/{repo_slug}/src, which can only give the sources listing in the main branch. /2.0/repositories/{workspace}/{repo_slug}/src/{commit}/{path} would provide the ability to get the sources (and their raw contents as well) at any given commit.
I needed to get PRs in all states, and the state
parameter wasn't available so I locally modified GetRepositoryPullRequestsAsync
:
public async Task<IEnumerable<PullRequest>> GetRepositoryPullRequestsAsync(string workspaceId, string repositorySlug, int? maxPages = null, string q = null, PullRequestStates[] states = null)
{
var queryParamValues = new Dictionary<string, object>
{
[nameof(q)] = q,
["state"] = states
};
It would be nice to add Dictionary<string, object> otherQueryParameters
to all APIs which would be less work than working out which parameters could be added per call, and it futureproofs the library if there are new parameters added to the Bitbucket API.
An alternate/complimentary idea would be to have some sort of callback after SetQueryParams(qpv)
to let the query string to be modified. Leads to the potential for other callbacks, although you probably would want to abstract furl away from the callbacks.
Example, although, being lazy, I'd be inclined to create new furl extensions that would combine the existing furl call with the callback.
return await GetPagedResultsAsync(maxPages, queryParamValues, async qpv =>
await GetPullRequestsUrl(workspaceId, repositorySlug)
// Modify the URL
.GetPullRequestsUrlEvent()
.SetQueryParams(qpv)
// modify parameters
.SetQueryParamsEvent()
.GetJsonAsync<PagedResults<PullRequest>>()
// hack/log json?
.GetJsonAsyncEvent()
.ConfigureAwait(false))
.ConfigureAwait(false);
Finally, thanks for writing this library!
I think that this would benefit greatly from adding some examples for how to authenticate / make calls for bitbucket
Hi,
When a repository is quite large, querying a workspace for repositories (client.GetWorkspaceRepositoriesAsync
) fails.
{"JSON integer 11289926597 is too large or small for an Int32. Path 'values[0].size', line 1, position 2913."}
It seems to point to this line. I think if you make it a long instead of int, it should be good already. But I'll let you be the judge on that :-) :
Using the client, I can grab the latest commit from a repo, but I can't see any way to tell which branch that commit was made in? I have the BitBucket.Cloud.Net.Models.v2.Commit
object, I just need to record which branch it happened in.
Thanks
Thank you for the great job done.
If it is not difficult for you, add some simple example of use on the main md page before.
Just a couple of lines
Thanks
Using the following request..
var commits = await _client.GetRepositoryPullRequestCommitsAsync(workspaceId, repositorySlug, pullRequest.Id.ToString(), maxPages: 30);
I only ever get 10 results back, it looks like paging is not working.
Hi
I authenticate with AppPasswordAuthentication.
GetRepositoryPullRequestsAsync works fine.
But both GetRepositoryPullRequestDiffStatAsync and GetRepositoryPullRequestDiffAsync gives me:
"Flurl.Http.FlurlHttpException: Call failed with status code 403 (Forbidden): GET https://bitbucket.org/!api/2.0/repositories/loansys_v2/reloansys.identityservice/pullrequests/963/diffstat ..."
Visiting that URL with a browser works fine. (logged in with the same username and password).
There is a redirect, though. Could that be the problem?
For the biggest part of the project I'm using this library to fetch data. But for fetching pipeline data I have had to implement the request myself. I had to do this because the current implementation returns the 10 oldest pipelines but I want to get the newest pipelines. This can be achieved by adding &sort=-created_on
to the request url.
These options are not documented but they were found by checking the http request done by Atlassians own API. There are a few more filter options available such as branch name but I have no interest in them.
Example request URL:
?fields=%2Bvalues.target.commit.message%2C%2Bvalues.target.commit.summary.html%2C%2Bvalues.target.%2A%2C%2Bvalues.%2A%2C%2Bpage%2C%2Bsize
&page=1
&pagelen=20
&sort=-created_on
&status=FAILED
&target.branch=master
&trigger_type=PUSH
Official API: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pipelines/#get
If you are ok with adding (some of) these options I can create a pull request to implement it.
Code:
var pr = await client.CreateRepositoryPullRequestAsync(workspaceId, repositorySlug,
new PullRequestCreationParameters
{
Title = $"Auto-merge for release {version} completion.",
Source = new HasName { Name = releaseBranch },
Destination = new HasName { Name = "develop" }
}).ConfigureAwait(false);
Error:
Unhandled exception. Flurl.Http.FlurlHttpException: Call failed with status code 400 (Bad Request): POST https://api.bitbucket.org/2.0/repositories/english1/auth2/pullrequests
According to the API document (link), the expected request body is
{
"title": "My Title",
"source": {
"branch": {
"name": "my-feature-branch"
}
},
"destination": {
"branch": {
"name": "staging"
}
}
}
The actual request body is
{
"title": "My Title",
"source": {
"name": "my-feature-branch"
},
"destination": {
"name": "staging"
}
}
Furthermore, PullRequestCreationParameters requests Reviewer but it is not used when sending the REST request.
The call await client.GetRepositoryCommitsAsync(workspace, repoSlug, 20) gives the same page 20 times. (I am using the version 1.0.0 Nuget package)
Error at GetRepositoryCommitsAsync()
Source "Flurl.Http"
Message "Response could not be deserialized to JSON: GET https://bitbucket.org/2.0/repositories/bxbts/smscore/commits"
InnerException
Source "Newtonsoft.Json"
StackTrace
at Newtonsoft.Json.JsonTextReader.ParseValue()
at Newtonsoft.Json.JsonTextReader.Read()
at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader reader)
at Flurl.Http.Configuration.NewtonsoftJsonSerializer.Deserialize[T](Stream stream)
at Flurl.Http.HttpResponseMessageExtensions.d__0`1.MoveNext()
Message "Unexpected character encountered while parsing value: <. Path '', line 0, position 0."
Sometimes, getting error related to pagination
{
"type": "error",
"error": {
"message": "Page is no longer valid"
}
}
and stacktrace
Flurl.Http.FlurlHttpException: Call failed with status code 400 (Bad Request): GET https://api.bitbucket.org/2.0/repositories/cloudpayments/cloudpayments.dashboard/pullrequests/32/activity?page=2 at at Flurl.Http.FlurlRequest.HandleExceptionAsync(HttpCall call, Exception ex, CancellationToken token) at at Flurl.Http.FlurlRequest.SendAsync(HttpMethod verb, HttpContent content, CancellationToken cancellationToken, HttpCompletionOption completionOption) at at Flurl.Http.FlurlRequest.SendAsync(HttpMethod verb, HttpContent content, CancellationToken cancellationToken, HttpCompletionOption completionOption) at at Flurl.Http.HttpResponseMessageExtensions.ReceiveJson[T](Task
1 response)
at Bitbucket.Cloud.Net.BitbucketCloudClient.<>c__DisplayClass228_0.<b__0>d.MoveNext() in C:\projects\Bitbucket.Cloud.Net\Bitbucket.Cloud.Net\src\Bitbucket.Cloud.Net\v2\Repositories\PullRequests\BitbucketCloudClient.cs:54
at Bitbucket.Cloud.Net.BitbucketCloudClient.GetPagedResultsAsync[T](Nullable1 maxPages, IDictionary
2 queryParamValues, Func2 selector) in C:\projects\Bitbucket.Cloud.Net\Bitbucket.Cloud.Net\src\Bitbucket.Cloud.Net\BitbucketCloudClient.cs:98
The problem is with response and logic to check if next page exists
isLastPage = selectorResults.Next == null
For url https://api.bitbucket.org/2.0/repositories/cloudpayments/cloudpayments.dashboard/pullrequests/32/activity?page=1
The response would be
{ "pagelen": 10, "values": [ ... ], "next": "https://api.bitbucket.org/2.0/repositories/cloudpayments/cloudpayments.dashboard/pullrequests/32/activity?ctx=M6CXugHbHz&page=1" }
while having only 10 results, the next field points to the same page 1, so we getting bad request
First of all: Many thanks for this project! It was very helpful for me ❤️
I came across a small issue in line 37 of BitbucketCloudClient.cs: The query parameter should be named state
instead of q
to match the description of the API method:
public async Task<IEnumerable<PullRequest>> GetRepositoryPullRequestsAsync(string workspaceId, string repositorySlug, int? maxPages = null, string state = null)
{
var queryParamValues = new Dictionary<string, object>
{
[nameof(state)] = state
};
...
Is there a way to get the two git hash that are used to generate the DiffStat?
I am trying to get the details of a merged pull request based on a commit hash. I think the method GetRepositoryCommitPullRequestsAsync is what I'm after, but I get an exception saying the URL doesn't exist.
I've updated the unit test GetRepositoryCommitPullRequestsAsync to be a repository I have permissions to (luve / test doesn't work) and I see the same exception. Are you able to provide an example which works?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.