MunifTanjim / node-bitbucket

Bitbucket API client for Browser and Node.js
https://bitbucketjs.netlify.app
MIT License
106 stars 28 forks source link

Support for repeatable parameter for list pull request #74

Open chalenge opened 3 years ago

chalenge commented 3 years ago

The state parameter in pullrequests - list can be repeated such as /repositories/{workspace}/{repo_slug}/pullrequests?state=MERGED&state=OPEN

Is there a way this can be supported using in the client. Currently only specifying one parameter is supported

MunifTanjim commented 3 years ago

See the discussion on #44 to know about why this isn't properly supported. (TLDR: Bitbucket's API Specification: https://api.bitbucket.org/swagger.json is incorrect)

With that said, here's a dirty hack that you can do to make this work. (requires: v2.4.2+)

// @ts-ignore
bitbucket.repositories.listPullRequests = bitbucket.repositories.listPullRequests.defaults(
  {
    request: {
      validate: {
        state: {
          enum: undefined,
          type: 'array',
          items: {
            enum: ['OPEN', 'DECLINED', 'MERGED', 'SUPERSEDED'],
            type: 'string',
          },
        },
      },
    },
  }
)

bitbucket.repositories.listPullRequests({
  workspace: '<workspace>',
  repo_slug: '<repo_slug>',
  // @ts-ignore
  state: ['OPEN', 'DECLINED'],
})