Git Product home page Git Product logo

node-bitbucket's Introduction

version:@latest Documentation License

Bitbucket.js

Bitbucket API client for Browser and Node.js

Bitbucket API docs: https://api.bitbucket.org


BITBUCKET CLOUD API LATEST UPDATES: https://developer.atlassian.com/cloud/bitbucket


Installation

via npm:

$ npm install --save bitbucket

via yarn:

$ yarn add bitbucket

Usage

Browser

<script src="https://unpkg.com/bitbucket/lib/index.umd.js"></script>
<script>
  const bitbucket = new Bitbucket()
</script>

Node

const { Bitbucket } = require('bitbucket')

const bitbucket = new Bitbucket()

Client Options

You can set the APIs' baseUrl and modify some behaviors (e.g. request timeout etc.) by passing a clientOptions object to the Bitbucket constructor.

const clientOptions = {
  baseUrl: 'https://api.bitbucket.org/2.0',
  request: {
    timeout: 10,
  },
}

const bitbucket = new Bitbucket(clientOptions)

Authentication

Using username and password:

const clientOptions = {
  auth: {
    username: 'username',
    password: 'password',
  },
}

const bitbucket = new Bitbucket(clientOptions)

Using token:

const clientOptions = {
  auth: {
    token: 'abcdef123456',
  },
}

const bitbucket = new Bitbucket(clientOptions)

API Methods

async/await

try {
  const { data, headers, status, url } = await bitbucket.<namespace>.<api>({ ...params })
} catch (err) {
  const { message, error, headers, request, status } = err
}

Promise

bitbucket.<namespace>
  .<api>({ ...params })
  .then(({ data, headers, status, url }) => {})
  .catch(({ message, error, headers, request, status }) => {})

Notes:

  • <namespace> is one of the Namespace Names
  • <api> is one of the API Names

Namespace Names

branching_model, branchrestrictions, commits, commitstatuses, deploy, deployments, downloads, hook_events, issue_tracker, pipelines, projects, pullrequests, refs, repositories, search, snippet, snippets, source, ssh, teams, user, users, webhooks

API Names

Check API client docs: https://bitbucketjs.netlify.com

Examples
bitbucket.repositories
  .listGlobal({})
  .then(({ data }) => console.log(data.values))
  .catch((err) => console.error(err))

Acknowledgement

This API client is heavily inspired by the octokit/rest.js and a lot of ideas are taken from there. So, thanks goes to the maintainer Gregor Martynus and all the awesome contributors of octokit/rest.js.

License

Licensed under the MIT License. Check the LICENSE file for details.

node-bitbucket's People

Contributors

alexivkin avatar bbathel13 avatar darkmukke avatar dependabot[bot] avatar folofse avatar jdoklovic avatar jeroenonstuimig avatar kirill89 avatar mishkinf avatar muniftanjim avatar prkb avatar rundquist avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

node-bitbucket's Issues

Deploy.createKey route should also take key and label parameter to be sent in body

The bitbucket api to create deploy keys takes two body fields, key and label, which are not included in the node-bitbucket route. It currently only allows for username and repo_slug which are used in the path.

currently:

"createDeployKey": {
      "method": "POST",
      "params": {
        "repo_slug": {
          "in": "path",
          "required": true,
          "type": "string"
        },
        "username": {
          "in": "path",
          "required": true,
          "type": "string"
        },
      },
      "returns": "DeployKey",
      "url": "/repositories/{username}/{repo_slug}/deploy-keys"
    },`

I think it should look more like this:

"createDeployKey": {
      "method": "POST",
      "params": {
        "repo_slug": {
          "in": "path",
          "required": true,
          "type": "string"
        },
        "username": {
          "in": "path",
          "required": true,
          "type": "string"
        },
        "label":{
          "in":"body",
          "required":true,
          "type":"string"
        },
        "key":{
          "in":"body",
          "required":true,
          "type":"string"
        }
      },
      "returns": "DeployKey",
      "url": "/repositories/{username}/{repo_slug}/deploy-keys"
    },

Downloads GET not working

I tried this API but it didn't work due to some redirect issue (I guessed)...

const { data, headers } = await bitbucket.downloads.get({ filename, repo_slug, workspace, fields })

listRepositories returns only public results

Hi,
trying to use the following method, but failed to retrieve any private repos, only public ones.

Trying to use the official API works well, so it looks like something might be wrong on the library side.

Is it a known issue? using v1.15.1
Oh, and what is "q" parameter means? what's the usage? no description in the documentation.

Thanks!

Add update guide to v2

@MunifTanjim Could you add a changelog with a list of breaking changes or some upgrade guide from v1 to v2?

I have got some errors and don't know what to change...

See "yarn build" log in terminal node_modules/bitbucket/src/request/types.ts:2:3 - error TS2440: Import declaration conflicts with local declaration of 'Endpoint'.

2 Endpoint,
~~~~~~~~

node_modules/bitbucket/src/request/types.ts:3:3 - error TS2440: Import declaration conflicts with local declaration of 'EndpointDefaults'.

3 EndpointDefaults,
~~~~~~~~~~~~~~~~

node_modules/bitbucket/src/request/types.ts:4:3 - error TS2440: Import declaration conflicts with local declaration of 'EndpointOptions'.

4 EndpointOptions,
~~~~~~~~~~~~~~~

node_modules/bitbucket/src/request/types.ts:5:3 - error TS2440: Import declaration conflicts with local declaration of 'EndpointParams'.

5 EndpointParams,
~~~~~~~~~~~~~~

node_modules/bitbucket/src/request/types.ts:6:3 - error TS2440: Import declaration conflicts with local declaration of 'Headers'.

6 Headers
~~~~~~~

node_modules/bitbucket/src/client/types.ts:3:27 - error TS2307: Cannot find module '../error'.

3 import { HTTPError } from '../error'
~~~~~~~~~~

src/services/bitbucket/BitbucketService.ts:42:28 - error TS2709: Cannot use namespace 'Bitbucket' as a type.

42 private readonly client: Bitbucket;
~~~~~~~~~

src/services/bitbucket/BitbucketService.ts:51:23 - error TS2351: This expression is not constructable.
Type 'typeof import("/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index")' has no construct signatures.

51 this.client = new Bitbucket({
~~~~~~~~~

src/services/bitbucket/BitbucketService.ts:73:25 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Auth'.

73 let auth: Bitbucket.Auth;
~~~~

src/services/bitbucket/BitbucketService.ts:83:29 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Params'.

83 const params: Bitbucket.Params.RepositoriesGet = {
~~~~~~

src/services/bitbucket/BitbucketService.ts:107:44 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Response'.

107 const response: DeepRequired<Bitbucket.Response<Bitbucket.Schema.PaginatedPullrequests>> = await axios.get(apiUrl, {
~~~~~~~~

src/services/bitbucket/BitbucketService.ts:107:63 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Schema'.

107 const response: DeepRequired<Bitbucket.Response<Bitbucket.Schema.PaginatedPullrequests>> = await axios.get(apiUrl, {
~~~~~~

src/services/bitbucket/BitbucketService.ts:113:39 - error TS7006: Parameter 'val' implicitly has an 'any' type.

113 response.data.values.map(async (val) => {
~~~

src/services/bitbucket/BitbucketService.ts:155:14 - error TS2322: Type '[unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown]' is not assignable to type 'PullRequest[]'.
Type 'unknown' is not assignable to type 'PullRequest'.

155 return { items, ...pagination };
~~~~~

src/inspectors/common/Paginated.ts:7:3
7 items: T[];
~~~~~
The expected type comes from property 'items' which is declared here on type 'Paginated'

src/services/bitbucket/BitbucketService.ts:170:46 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Response'.

170 const response = <DeepRequired<Bitbucket.Response<Bitbucket.Schema.Pullrequest>>>await this.client.pullrequests.get(params);
~~~~~~~~

src/services/bitbucket/BitbucketService.ts:170:65 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Schema'.

170 const response = <DeepRequired<Bitbucket.Response<Bitbucket.Schema.Pullrequest>>>await this.client.pullrequests.get(params);
~~~~~~

src/services/bitbucket/BitbucketService.ts:222:29 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Params'.

222 const params: Bitbucket.Params.PullrequestsListCommits = {
~~~~~~

src/services/bitbucket/BitbucketService.ts:228:46 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Response'.

228 const response = <DeepRequired<Bitbucket.Response>>await this.client.pullrequests.listCommits(params);
~~~~~~~~

src/services/bitbucket/BitbucketService.ts:230:45 - error TS7006: Parameter 'val' implicitly has an 'any' type.

230 const items = response.data.values.map((val) => {
~~~

src/services/bitbucket/BitbucketService.ts:274:44 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Response'.

274 const response: DeepRequired<Bitbucket.Response<Bitbucket.Schema.PaginatedIssues>> = await axios.get(apiUrl, {
~~~~~~~~

src/services/bitbucket/BitbucketService.ts:274:63 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Schema'.

274 const response: DeepRequired<Bitbucket.Response<Bitbucket.Schema.PaginatedIssues>> = await axios.get(apiUrl, {
~~~~~~

src/services/bitbucket/BitbucketService.ts:279:45 - error TS7006: Parameter 'val' implicitly has an 'any' type.

279 const items = response.data.values.map((val) => ({
~~~

src/services/bitbucket/BitbucketService.ts:301:29 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Params'.

301 const params: Bitbucket.Params.IssueTrackerGet = {
~~~~~~

src/services/bitbucket/BitbucketService.ts:306:46 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Response'.

306 const response = <DeepRequired<Bitbucket.Response<Bitbucket.Schema.Issue>>>await this.client.issue_tracker.get(params);
~~~~~~~~

src/services/bitbucket/BitbucketService.ts:306:65 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Schema'.

306 const response = <DeepRequired<Bitbucket.Response<Bitbucket.Schema.Issue>>>await this.client.issue_tracker.get(params);
~~~~~~

src/services/bitbucket/BitbucketService.ts:329:29 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Params'.

329 const params: Bitbucket.Params.IssueTrackerListComments = {
~~~~~~

src/services/bitbucket/BitbucketService.ts:334:46 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Response'.

334 const response = <DeepRequired<Bitbucket.Response<Bitbucket.Schema.PaginatedIssueComments>>>(
~~~~~~~~

src/services/bitbucket/BitbucketService.ts:334:65 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Schema'.

334 const response = <DeepRequired<Bitbucket.Response<Bitbucket.Schema.PaginatedIssueComments>>>(
~~~~~~

src/services/bitbucket/BitbucketService.ts:338:45 - error TS7006: Parameter 'val' implicitly has an 'any' type.

338 const items = response.data.values.map((val) => ({
~~~

src/services/bitbucket/BitbucketService.ts:363:29 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Params'.

363 const params: Bitbucket.Params.RepositoriesListCommits = {
~~~~~~

src/services/bitbucket/BitbucketService.ts:369:46 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Response'.

369 const response = <DeepRequired<Bitbucket.Response>>await this.client.repositories.listCommits(params);
~~~~~~~~

src/services/bitbucket/BitbucketService.ts:370:45 - error TS7006: Parameter 'val' implicitly has an 'any' type.

370 const items = response.data.values.map((val) => {
~~~

src/services/bitbucket/BitbucketService.ts:396:29 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Params'.

396 const params: Bitbucket.Params.CommitsGet = {
~~~~~~

src/services/bitbucket/BitbucketService.ts:401:46 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Response'.

401 const response = <DeepRequired<Bitbucket.Response<Bitbucket.Schema.Commit>>>await this.client.commits.get(params);
~~~~~~~~

src/services/bitbucket/BitbucketService.ts:401:65 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Schema'.

401 const response = <DeepRequired<Bitbucket.Response<Bitbucket.Schema.Commit>>>await this.client.commits.get(params);
~~~~~~

src/services/bitbucket/BitbucketService.ts:432:46 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Response'.

432 const response = <DeepRequired<Bitbucket.Response<Bitbucket.Schema.PaginatedPullrequestComments>>>(
~~~~~~~~

src/services/bitbucket/BitbucketService.ts:432:65 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Schema'.

432 const response = <DeepRequired<Bitbucket.Response<Bitbucket.Schema.PaginatedPullrequestComments>>>(
~~~~~~

src/services/bitbucket/BitbucketService.ts:442:45 - error TS7006: Parameter 'comment' implicitly has an 'any' type.

442 const items = response.data.values.map((comment) => ({
~~~~~~~

src/services/bitbucket/BitbucketService.ts:461:46 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Response'.

461 const response = <DeepRequired<Bitbucket.Response<Bitbucket.Schema.Comment>>>await this.client.pullrequests.createComment({
~~~~~~~~

src/services/bitbucket/BitbucketService.ts:461:65 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Schema'.

461 const response = <DeepRequired<Bitbucket.Response<Bitbucket.Schema.Comment>>>await this.client.pullrequests.createComment({
~~~~~~

src/services/bitbucket/BitbucketService.ts:490:46 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Response'.

490 const response = <DeepRequired<Bitbucket.Response<Bitbucket.Schema.Comment>>>await this.client.pullrequests.updateComment({
~~~~~~~~

src/services/bitbucket/BitbucketService.ts:490:65 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Schema'.

490 const response = <DeepRequired<Bitbucket.Response<Bitbucket.Schema.Comment>>>await this.client.pullrequests.updateComment({
~~~~~~

src/services/bitbucket/BitbucketService.ts:547:54 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Response'.

547 private unwrap(clientPromise: Promise<Bitbucket.Response>) {
~~~~~~~~

src/services/bitbucket/BitbucketService.ts:563:60 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Response'.

563 private debugBitbucketResponse = (response: Bitbucket.Response) => {
~~~~~~~~

src/services/bitbucket/BitbucketService.ts:594:21 - error TS2694: Namespace '"/Users/prokop/Sites/_dxheroes/scanner/node_modules/bitbucket/lib/index"' has no exported member 'Schema'.

594 values: Bitbucket.Schema.Commit[];
~~~~~~

src/test/factories/responses/bitbucket/listIssueCommentsResponseFactory.ts:2:10 - error TS2503: Cannot find namespace 'Bitbucket'.

2 items: Bitbucket.Schema.IssueComment[] = [],
~~~~~~~~~

src/test/factories/responses/bitbucket/listIssueCommentsResponseFactory.ts:3:4 - error TS2503: Cannot find namespace 'Bitbucket'.

3 ): Bitbucket.Schema.PaginatedIssueComments => {
~~~~~~~~~

src/test/factories/responses/bitbucket/listIssuesResponseFactory.ts:1:59 - error TS2503: Cannot find namespace 'Bitbucket'.

1 export const bitbucketListIssuesResponseFactory = (items: Bitbucket.Schema.Issue[] = []): Bitbucket.Schema.PaginatedIssues => {
~~~~~~~~~

src/test/factories/responses/bitbucket/listIssuesResponseFactory.ts:1:91 - error TS2503: Cannot find namespace 'Bitbucket'.

1 export const bitbucketListIssuesResponseFactory = (items: Bitbucket.Schema.Issue[] = []): Bitbucket.Schema.PaginatedIssues => {
~~~~~~~~~

src/test/factories/responses/bitbucket/listPrsResponseFactory.ts:1:56 - error TS2503: Cannot find namespace 'Bitbucket'.

1 export const bitbucketListPRsResponseFactory = (items: Bitbucket.Schema.Pullrequest[] = []): Bitbucket.Schema.PaginatedPullrequests => {
~~~~~~~~~

src/test/factories/responses/bitbucket/listPrsResponseFactory.ts:1:94 - error TS2503: Cannot find namespace 'Bitbucket'.

1 export const bitbucketListPRsResponseFactory = (items: Bitbucket.Schema.Pullrequest[] = []): Bitbucket.Schema.PaginatedPullrequests => {
~~~~~~~~~

src/test/factories/responses/bitbucket/listPullCommitsResponseFactory.ts:3:64 - error TS2503: Cannot find namespace 'Bitbucket'.

3 export const bitbucketListPullCommitsResponseFactory = (items: Bitbucket.Schema.Commit[] = []): BitbucketCommit => {
~~~~~~~~~

src/test/factories/responses/bitbucket/listRepoCommitsResponseFactory.ts:3:59 - error TS2503: Cannot find namespace 'Bitbucket'.

3 export const bitbucketListCommitResponseFactory = (items: Bitbucket.Schema.Commit[]): BitbucketCommit => {
~~~~~~~~~

src/test/helpers/bitbucketNock.ts:49:19 - error TS2503: Cannot find namespace 'Bitbucket'.

49 pullRequests: Bitbucket.Schema.Pullrequest[],
~~~~~~~~~

src/test/helpers/bitbucketNock.ts:64:39 - error TS2503: Cannot find namespace 'Bitbucket'.

64 getPullRequestResponse(pullRequest: Bitbucket.Schema.Pullrequest) {
~~~~~~~~~

src/test/helpers/bitbucketNock.ts:78:13 - error TS2503: Cannot find namespace 'Bitbucket'.

78 issues: Bitbucket.Schema.Issue[],
~~~~~~~~~

src/test/helpers/bitbucketNock.ts:96:27 - error TS2503: Cannot find namespace 'Bitbucket'.

96 getIssueResponse(issue: Bitbucket.Schema.Issue) {
~~~~~~~~~

src/test/helpers/bitbucketNock.ts:102:44 - error TS2503: Cannot find namespace 'Bitbucket'.

102 listIssueCommentsResponse(issueComments: Bitbucket.Schema.IssueComment[], issueId: number) {
~~~~~~~~~

src/test/helpers/bitbucketNock.ts:109:32 - error TS2503: Cannot find namespace 'Bitbucket'.

109 listPullCommits(pullCommits: Bitbucket.Schema.Commit[], prNumber: number) {
~~~~~~~~~

src/test/helpers/bitbucketNock.ts:116:32 - error TS2503: Cannot find namespace 'Bitbucket'.

116 listCommitsResponse(commits: Bitbucket.Schema.Commit[]) {
~~~~~~~~~

src/test/helpers/bitbucketNock.ts:123:29 - error TS2503: Cannot find namespace 'Bitbucket'.

123 getCommitResponse(commit: Bitbucket.Schema.Commit, commitSha: string) {
~~~~~~~~~

src/test/factories/responses/bitbucket/prResponseFactory.ts:5:70 - error TS2503: Cannot find namespace 'Bitbucket'.

5 export const bitbucketPullRequestResponseFactory = (params?: Partial<Bitbucket.Schema.Pullrequest>): Bitbucket.Schema.Pullrequest => {
~~~~~~~~~

src/test/factories/responses/bitbucket/prResponseFactory.ts:5:102 - error TS2503: Cannot find namespace 'Bitbucket'.

5 export const bitbucketPullRequestResponseFactory = (params?: Partial<Bitbucket.Schema.Pullrequest>): Bitbucket.Schema.Pullrequest => {
~~~~~~~~~

src/test/factories/responses/bitbucket/issueCommentResponseFactory.ts:4:71 - error TS2503: Cannot find namespace 'Bitbucket'.

4 export const bitbucketIssueCommentResponseFactory = (params?: Partial<Bitbucket.Schema.IssueComment>): Bitbucket.Schema.IssueComment => {
~~~~~~~~~

src/test/factories/responses/bitbucket/issueCommentResponseFactory.ts:4:104 - error TS2503: Cannot find namespace 'Bitbucket'.

4 export const bitbucketIssueCommentResponseFactory = (params?: Partial<Bitbucket.Schema.IssueComment>): Bitbucket.Schema.IssueComment => {
~~~~~~~~~

src/test/factories/responses/bitbucket/issueResponseFactory.ts:4:63 - error TS2503: Cannot find namespace 'Bitbucket'.

4 export const bitbucketIssueResponseFactory = (params: Partial<Bitbucket.Schema.Issue>): Bitbucket.Schema.Issue => {
~~~~~~~~~

src/test/factories/responses/bitbucket/issueResponseFactory.ts:4:89 - error TS2503: Cannot find namespace 'Bitbucket'.

4 export const bitbucketIssueResponseFactory = (params: Partial<Bitbucket.Schema.Issue>): Bitbucket.Schema.Issue => {
~~~~~~~~~

src/test/factories/responses/bitbucket/pullCommitsFactory.ts:4:70 - error TS2503: Cannot find namespace 'Bitbucket'.

4 export const bitbucketPullCommitsResponseFactory = (params?: Partial<Bitbucket.Schema.Commit>): Bitbucket.Schema.Commit => {
~~~~~~~~~

src/test/factories/responses/bitbucket/pullCommitsFactory.ts:4:97 - error TS2503: Cannot find namespace 'Bitbucket'.

4 export const bitbucketPullCommitsResponseFactory = (params?: Partial<Bitbucket.Schema.Commit>): Bitbucket.Schema.Commit => {
~~~~~~~~~

src/test/factories/responses/bitbucket/repoCommitsResponseFactory.ts:4:70 - error TS2503: Cannot find namespace 'Bitbucket'.

4 export const bitbucketRepoCommitsResponseFactory = (params?: Partial<Bitbucket.Schema.Commit>): Bitbucket.Schema.Commit => {
~~~~~~~~~

src/test/factories/responses/bitbucket/repoCommitsResponseFactory.ts:4:97 - error TS2503: Cannot find namespace 'Bitbucket'.

4 export const bitbucketRepoCommitsResponseFactory = (params?: Partial<Bitbucket.Schema.Commit>): Bitbucket.Schema.Commit => {
~~~~~~~~~

Found 71 errors.

error Command failed with exit code 1.

Fetching files with `source.read` fails to fetch nested files

When fetching files nested in subdirectories, it looks like the source.read API might be URL escaping the paths separators in the path argument. Pre-v2 I had code that was fetching nested files, but now it fails with errors like this:

 error: {
    type: 'error',
    error: { message: 'No such file or directory: deploy/dependencies.yaml' }
  },
  request: {
    method: 'GET',
    url: 'https://api.bitbucket.org/2.0/repositories/<workspace>/<repo>/src/master/deploy%2Fdependencies.yaml',
  },
  status: 404

unhandled exception occurs on fetch call

Attempting to create variables in repositories can throw an unhandled exception error which cannot be properly caught if the user does not have proper permissions.

(node:91125) UnhandledPromiseRejectionWarning: HTTPError: Your credentials lack one or more required privilege scopes.
    at getData.then.error (~/cli/node_modules/bitbucket/src/request/fetch.js:53:17)

Unfortunately due to this my try / catch around this part of my code never gets called.

/bitbucket/src/request/fetch.js:53:17

Error message when using plugin

You are setting an error and info message in console when we use your plugin:

error: BITBUCKET CLOUD API CHANGING NOTICE: https://developer.atlassian.com/cloud/bitbucket/bitbucket-api-changes-gdpr
info: BITBUCKET CLOUD API MIGRATION GUIDE: https://developer.atlassian.com/cloud/bitbucket/bbc-gdpr-api-migration-guide

Please make them both info, since error messages will fail when you try to build the code in google firebase cloud functions

This are the lines in your index.js. Please make them both console.info or remove it entirely and just quote this lines in the readme.

console.warn(
\x1b[43m\x1b[30m %s \x1b[0m\x1b[33m %s \x1b[0m,
BITBUCKET CLOUD API CHANGING NOTICE:,
https://developer.atlassian.com/cloud/bitbucket/bitbucket-api-changes-gdpr
)

console.info(
'\x1b[46m\x1b[30m %s \x1b[0m\x1b[36m %s \x1b[0m',
BITBUCKET CLOUD API MIGRATION GUIDE:,
https://developer.atlassian.com/cloud/bitbucket/bbc-gdpr-api-migration-guide
)

Random timeouts

Hi I'm getting HTTPError: request to https://api.bitbucket.org/2.0/repositories/XXX/YYY/pullrequests/NNNN failed, reason: connect ETIMEDOUT x.x.x.x:443 but it's quite random. Bitbucket status says ok. I'm basically wondering how I could increase the timeout. Many thanks in advance

/list only works for the owner

api.repositories.list() takes username as a MUST parameter and thus only returns repositories that are owned by this username regardless of the role specified, thus making impossible to get repos for the {role: 'contributor'}
For the official bitbucket API {username} is not a mandatory parameter, and thus when not provided results are filtered for the authenticated user and the {role} provided.

Could you fix this please?

listPullRequestsActivityLog does not accept stated parameters

I wanted to get more than 10 entries in the activity log, but the available functions have issues:

bitbucket.pullrequests.getActivityLog does not accept pagelen parameter. The documentation does not state pagelen is a possible parameter but it works when passed manually.

bitbucket.repositories.listPullRequestsActivityLog is described to accept pull_request_id as a required (!) parameter, but it is ignored and not sent to BitBucket API. The documentation states pull_request_id as path parameter, but it's a mistake there since it does not exist on this path. pagelen is accepted and sent to API.

Could you extend getActivityLog so it accepts pagelen parameter?

Add User to Repo / Privileges API

Hey,
Do you know if its possible to add a user/collaborator to a repo using the bitbucket API? Its definitely possible via the web-ui, but I can't seem to find it in the v2 documentation.

Using with teams

I tested this with a username and password on an account/repo combination that is not in a team and it works fine. When I use it with an account/repo that is team based, I get a 404 because username/repoName is not found, even though that repo is shown on the users repo list page. I'm using this for pullrequests.create, refs.listBranches, repositories.getPullRequestDiff, repositories.mergePullRequest.

I have verified the user has write access to the repo.

Is it possible to use this with a team-based repo? If so, how?

implementing the hideNotice in the clientOptions doesn't appear to work

I am trying to have it stop the annoying Bitbucket API logs, and i see that you have a logNotice() function the will get removed if you have a this.options.hideNotice set. I have tried the following to no joy:

const clientOptions: Bitbucket.Options = {
  options: {
    hideNotice: true
  }
}

const bitbucket = new Bitbucket(clientOptions)

If also tried:

const clientOptions: Bitbucket.Options = {
    hideNotice: true
}

but hideNotice isn't a supported Type on Bitbucket.Options.

Any insight would be super helpful. Thanks in advance

Bitbucket.pipelines.getStepLog response Body is Bitbucket.Schema.Error

I was looking to implement the use of step logs in our cli tool, it appears that the getStepLog only returns the Bitbucket.Schema.Error interface.

getStepLog(params: Bitbucket.Params.PipelinesGetStepLog, callback?: Bitbucket.Callback<Bitbucket.Response<Bitbucket.Schema.Error>>): Promise<Bitbucket.Response<Bitbucket.Schema.Error>>;

Is this an oversight or a placeholder for future implementation?

bitbucket.users.get() throwing error now...

This code has been working for ages, but lately we've been getting the following error now when trying to get users from bitbucket..

HTTPError: richard_lyle at getData.then.error (/var/task/node_modules/bitbucket/src/request/fetch.js:53:17) at process._tickCallback (internal/process/next_tick.js:68:7) Message: richard_lyle

This is the code we are using to grab a user by their username:

    getUser(username) {
        return new Promise((resolve, reject) => {
            bitbucket.users.get({username}).then(({data}) => {
                log.debug("getUser result:", data );
                resolve(data);
            }).catch((err) => {
                log.error("getUser error:", err );
                reject(err);
            })
        })
    }


fields support

Bitbucket allows to specify fields as a query parameter and that limits the response fields. However, this option is not available here.
See the docs: https://developer.atlassian.com/bitbucket/api/2/reference/meta/partial-response
eg. if I add

        "fields": {
          "in": "query",
          "type": "string"
        },

to routes.json -> listTags then it properly works by adding the fields parameter using a call like:

        let {
            data,
            headers
        } = await bitbucket.refs.listTags({
            repo_slug: 'myrepo',
            username: 'myteam',
            pagelen: 20,
            sort: "-name",
            fields: "values.name,values.target.hash"
        });

Could you add "fields" parameter to queries?

Issue with Client Credentials authentication

Is the authentication method Client Authentication Grant supported?

I found several references to it in the code, but I did not figure out how to use it successfully.
I tried using:

bitbucket.authenticate({
        type: 'oauth',
        key: key,
        secret: secret
})

But this sets key and secret as query param, which is not correct (I don't see it mentioned anywhere in on the Authentication page): https://api.bitbucket.org/2.0/repositories/my-user/my-repo/commit/c0f212a586f0cf6be721f39acd334e9f4cdc9c48/statuses/build?client_id=****&client_secret=****

I also found the clientCredentialsGrant mentioned in src/plugins/oauth/routes.js, but this plugin is not hooked up in src/index.js and I'm not sure if / how it is supposed to be used.

source.get no longer a function..

Whatever was in this last update broke us, we are now getting a bitbucket.source.get is not a function error when we try to run.. we had to force our package.json to 1.8.1 to fix our end..

TypeScript: Many return values are optional

Hello!

Had a general query about the library; it seems like almost every single return value is optional, which doesn't reflect Bitbuckets upstream APIs. What was the reasoning behind that? Are you open to PRs to update this?

Thanks for your help!

{workspace} in routes.json needs to be {username}

Hi @MunifTanjim

Thank you for all your great work!!

I found that {workspace} in routes.json needs to be replaced with {username} in the urls, in order to work properly.

The methods effected are:

  • createDeploymentVariable
  • deleteDeploymentVariable
  • listDeploymentVariables
  • updateDeploymentVariable

teams.listRepositories and teams.listRepositoriesForUser retrieve same info as repositories.list

When I use those methods mentioned, I get the same results, I would expect those methods to retrieve the repositories of the team(s) the user is member of, not just the repositories of the user, I tried passing the role parameter with different values to repositories.list but in all cases I get the same result, am I misunderstanding something?

Also, pagination doesn't work for listRepositories and listRepositoriesForUser.

I'm using the CDN version, but I did a quick test with the npm version and got the same results.

Thanks in advance!

bitbucket.repositories.get is not a function (using with Electron webContents.send)

Hey, I'm currently trying to build a little BitBucket electron app for myself and colleagues and your project seems to be the most recent so I thought I'd give it a try.
I have a login screen which submits to the main process which then loads the main screen, authenticates the client and sends the bitbucket object to that screen.

ipcRenderer.on("ret:client", (e, client)=>{
    console.log(client)
    client.repositories
    .get({ repo_slug: "myrepo", username: 'myusername' })
    .then(({ data, headers }) => console.log(data.values))
    .catch(err => console.error(err))
})

When I now try to use any method like repositories.get or repositories.list, I get an error that the function does not exist. Upon displaying the bitbucket object in my console, it is empty.

Am I not getting something here?
I hope you can help me there! 👍

Queries is not working on listRepositories

Hi!

I'm trying to get repositories using query, but isn't working. The API is returning all repositories of this team/user instead just my filtered repo.

See my code:

const repositories = await bitbucket.teams.listRepositories({ pagelen: 2, page: 1, q: 'full_name="repo1"', username });

Is my syntax correct? I'm following patterns described on Bickbucket Filtering and Sorting documentation.

Thanks!

How to paginate in Node

Hey,
I'm trying to determine how to pass a page querystring parameter when requesting a list of repositories.

Using state = 'DECLINED' param with q param ignores state

Hello! I noticed that there's a bug when using the state param with q param, for example:

bitbucket.repositories.list({ page: 1, repo_slug: 'repository', state: 'DECLINED', q: 'created_on >=' + initialDate + ' AND created_on <=' + finalDate});

This will bring all pull requests between the dates requested regardless their state, however if the state is included in the query like this:

bitbucket.repositories.list({ page: 1, repo_slug: 'repository', q: 'created_on >=' + initialDate + ' AND created_on <=' + finalDate + ' AND state = "DECLINED"'});

then it works as expected.

Webhook Event Type Definitions

Great to see this library.

I was looking for some typescript type definitions for the webhook events and was hoping this might be where I'd find it.

I'm not sure if it's on your list, as it's not part of the web api, but I thought it might add value to support it.

Webhook Event Payload Documentation

I'm not sure I'll have time to contribute this - but I'll leave this suggestion here for you - at least for now.

repositories.listBranches is throwing an error

Looks like a side-effect of the bitbucket API upgrade:
I am getting the following error when using the repositories.listBranches method:

code:500 error:"network timeout at: https://api.bitbucket.org/2.0/repositories/roofstockinc/roofstock.Databases/refs/branches?page=1&pagelen=100" headers:Object {} message:"network timeout at: https://api.bitbucket.org/2.0/repositories/roofstockinc/roofstock.Databases/refs/branches?page=1&pagelen=100" name:"HTTPError" stack:"HTTPError: network timeout at: https://api.bitbucket.org/2.0/repositories/roofstockinc/roofstock.Databases/refs/branches?page=1&pagelen=100\n at fetch.then.then.catch.error ("

I tried the following:

  1. Use clientOptions and pass it to the bitbucket.authenticate method
  2. I am attaching a sample code. Would appreciate if you could provide a working sample of using Token and ClientKey and Secret.
    I was able to get it to work without the bitbucket package by making direct REST API calls in Node.js.
    I first called the https://bitbucket.org/site/oauth2/access_token endpoint passing in the Base64 encoding od Key:Secret. This returns the Token
    Using the Token I was then able to call the https://api.bitbucket.org/2.0/repositories/{token}/{repositoryname}/refs/branches?page=1&pagelen=100 endpoint

I think the issue with the bitbucket module is that I am not able to pass in grant_type: 'client_credentials'

index.txt

Error: Cannot find module '../../specification/others'

Thanks a lot for starting this project off!

It seems right now you are not publishing the specifications/ dir (in your package.json you have "files": ["src", "dist/*.js"]), and this cause the library to immediately crash as it is being required by things within src.

Code to reproduce is literally just:

const BitBucket = require('bitbucket');

I'm happy to submit a PR if the change is just a matter of also publishing that dir.

Webpack error: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'

I get many of these errors (I'm on Typescript 3.9.3 and nextjs latest)

Creating an optimized production build

Failed to compile.

C:/p/myapp/node_modules/bitbucket/src/plugins/auth/types.ts
ERROR in C:/p/myapp/node_modules/bitbucket/src/plugins/auth/types.ts(1,10):
1:10 Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
  > 1 | export { Options } from '../../client/types'
      |          ^
    2 | export { RequestOptions } from '../../endpoint/types'
    3 | 
    4 | export type APIClient = import('../../client/types').APIClient


> Build error occurred
Error: > Build failed because of webpack errors

It seems the solution is to change those "export" to "export type" throughout your codebase.

updateEnvironment requires a _body parameter

Hi

I write here instead of creating a PR, basically we need to add a _body to the updateEnvironment

"_body": {
  "in": "body",
  "required": true,
  "schema": "DeploymentEnvironment",
  "type": "any"
},

It's not documented in the API´s

https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/environments/%7Benvironment_uuid%7D/changes/ )

But this endpoints takes a body with changes like this

{
  "change":{
    "name":"My Environment name",
  }
}

I don't think we can change its type like Test|Staging|Production since this don't seems to be able to change it in Bitbucket dashboard either.

PUT requests without body content throw a 400

It appears the PUT requests (possibly POSTS as well?) that have no body content are failing with a 400 status code error.
In my example usingbitbucket.repositories.addDefaultReviewer( { workspace, repo_slug, target_username}) which uses a url like
/repositories/{workspace}/{repo_slug}/default-reviewers/{target_username} to attach a default reviewer to a repo, and has no body content, does not work.

I have successfully called the same endpoint in PostMan without a 400.

In my testing the difference is the passing of the content-type: application/json header. Adding this to the POSTman request causes a similar 400 error. Removing it allows the request to go through successfully.

I attempt to use hooks to intercept the request and remove the header, but the header must be added further on in the flow as it wasn't present in the options at before-hook time, yet the error response shows it is present.

Readme has an invalid example

See here

bitbucket.repositories
  .list({ username: 'MunifTanjim' })
  .then(({ data }) => console.log(data.values))
  .catch((err) => console.error(err))

I think that you meant listGlobal

GDPR Support

Hi,

Does your readSrc endpoint support getting account_id or uuid as username? Based on the Bitbucket API, it should work. I can call smth like https://api.bitbucket.org/2.0/repositories/%7B<UUID>%7D/<repoSlug>/src/<branch>/<file> and get file content back. However it seems that
this.api.repositories.readSrc({ repo_slug, username: uuid, node, path, });

Fails with
HTTPError: Repository <uuid>/<repoSlug> not found at getData.then.error (node_modules/bitbucket/src/request/fetch.js:53:17)

Can't use the client with BitBucket Server

Can't use the client with BitBucket Server. Not sure if I'm supposed to specify anything other than the baseUrl differently for it to work? It seems like the API's are different.

Support for signing requests with JWT token

According to these docs, if you want to call the API as an connect app you need to pass JWT in the query string or header param:

https://developer.atlassian.com/cloud/bitbucket/authentication-for-apps/

Also to create the JWT token in the first place according to these cdocs you need to include a query string hash: "A query string hash is a signed canonical request for the URI of the API you want to call.":

https://developer.atlassian.com/cloud/bitbucket/understanding-jwt-for-apps/

Does node-bitbucket support this?

Sending incorrect `accepts` value to pipelines logs endpoint

Bitbucket.pipelines.getStepLog throws HTTPError: Cannot read property 'message' of undefined. This is happening because the server is returning a 406 because the request specifies an accepts value of application/json while the endpoint only returns application/octet-stream.

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.