GithubHelp home page GithubHelp logo

bitbucket.cloud.net's Introduction

Icon

Bitbucket.Cloud.Net

Build status license NuGet

C# Client for Bitbucket Cloud

Documentation is at https://developer.atlassian.com/bitbucket/api/2/reference/.

If you're looking for Bitbucket Server API, try this repository.

Features

  • Authentication
    • OAuth2
    • App Passwords
    • Basic
  • 1.0
    • Group Privileges
    • Groups
    • Invitations
    • Users
      • Invitations
  • 2.0
    • Hook Events
      • Subject Type
    • Pull Requests
      • Selected User
    • Repositories
      • Workspace
        • Repo Slug
          • Branch Restrictions
            • Id
          • Branching Model
            • Settings
          • Commit
            • Commit
              • Properties
                • App Key
                  • Property Name
            • Node
              • Approve
              • Comments
                • Comment Id
              • Statuses
                • Build
                  • Key
          • Commits
            • Revision
          • Components
            • Component Id
          • Default Reviewers
            • Target User Name
          • Deploy Keys
            • Key Id
          • Deployments
            • Deployment Uuid
          • Deployments Config
            • Environments
              • Environment Uuid
                • Variables
                  • Variable Uuid
          • Diff
            • Spec
          • Diffstat
            • Spec
          • Downloads
            • Filename
          • Environments
            • Environment Uuid
              • Changes
          • File History
            • Node
              • Path
          • Forks
          • Hooks
            • Uid
          • Issues
            • Export
            • Import
            • Issue Id
              • Attachments
                • Path
              • Changes
                • Change Id
              • Comments
                • Comment Id
              • Vote
              • Watch
          • Milestones
            • Milestone Id
          • Patch
            • Spec
          • Pipelines
            • Pipeline Uuid
              • Steps
                • Step Uuid
                  • Log
                    • Log Uuid
                  • Test Reports
                    • Test Cases
                    • Test Case Uuid
                    • Test Case Reasons
              • Stop Pipeline
          • Pipelines Config
            • Build Number
            • Schedules
              • Schedule Uuid
                • Executions
            • Ssh
              • Key Pair
              • Known Hosts
                • Known Host Uuid
            • Variables
              • Variable Uuid
          • Properties
            • App Key
              • Property Name
          • Pull Requests
            • Activity
            • Pull Request Id
              • Activity
              • Approve
              • Comments
              • Commits
              • Decline
              • Diff
              • Diffstat
              • Merge
              • Patch
              • Statuses
              • Properties
                • App Key
                  • Property Name
          • Refs
            • Branches
              • Name
            • Tags
              • Name
          • Src
            • Node
              • Path
          • Versions
            • Version Id
          • Watchers
    • Snippets
      • Workspace
        • Encoded Id
          • Comments
            • Comment Id
          • Commits
            • Revision
          • Files
            • Path
          • Watch
          • Watchers
          • Node Id
            • Files
              • Path
          • Revision
            • Diff
            • Patch
    • Teams
      • User Name
        • Followers
        • Following
        • Hooks
          • Uid
        • [X] Members (deprecated)
        • Permissions
          • Repositories
            • Repo Slug
        • Pipelines Config
          • Variables
            • Variable Uuid
        • Projects
          • Project Key
        • Repositories
        • Search
          • Code
    • User
      • Emails
        • Email
      • Permissions
        • Repositories
        • Teams
    • Users
      • User Name
        • [X] Followers (deprecated)
        • [X] Following (deprecated)
        • Hooks
          • Uid
        • [X] Members (deprecated)
        • Pipelines Config
          • Variables
            • Variable Uuid
        • Repositories
        • Search
          • Code
        • Ssh Keys

bitbucket.cloud.net's People

Contributors

alexeyvs avatar bob343 avatar feodorfitsner avatar lvermeulen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

bitbucket.cloud.net's Issues

DeleteRepositoryWebhookAsync deserialization error

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]

View pull request by commit hash

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?

CreateRepositoryPullRequestAsync failed because of status code 400

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.

DiffStat 403 (Forbidden)

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?

Add pagelen and sort as parameters to GetRepositoryPipelinesAsync

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.

Get Git Hash

Is there a way to get the two git hash that are used to generate the DiffStat?

Failed to parse Json

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 :-) :

Wrong pagination

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](Task1 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, IDictionary2 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

Add generic parameter array to endpoints

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!

Better documentation

I think that this would benefit greatly from adding some examples for how to authenticate / make calls for bitbucket

Error at GetRepositoryCommitsAsync()

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."

PullRequests' Diff And DiffStat calls always return 403

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.

Query parameter in GetRepositoryPullRequestsAsync misnamed

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
    };
    ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.