MunifTanjim / node-bitbucket

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

Add update guide to v2 #50

Closed prokopsimek closed 4 years ago

prokopsimek commented 4 years ago

@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> = 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> = 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 = >>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 = >>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 = >>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> = 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> = 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 = >>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 = >>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 = >>( ~~~~~~~~ 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 = >>( ~~~~~~ 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 = >>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 = >>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 = >>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 = >>( ~~~~~~~~ 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 = >>( ~~~~~~ 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 = >>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 = >>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 = >>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 = >>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>) { ~~~~~~~~ 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 => { ~~~~~~~~~ src/test/factories/responses/bitbucket/prResponseFactory.ts:5:102 - error TS2503: Cannot find namespace 'Bitbucket'. 5 export const bitbucketPullRequestResponseFactory = (params?: Partial): 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 => { ~~~~~~~~~ src/test/factories/responses/bitbucket/issueCommentResponseFactory.ts:4:104 - error TS2503: Cannot find namespace 'Bitbucket'. 4 export const bitbucketIssueCommentResponseFactory = (params?: Partial): 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 => { ~~~~~~~~~ src/test/factories/responses/bitbucket/issueResponseFactory.ts:4:89 - error TS2503: Cannot find namespace 'Bitbucket'. 4 export const bitbucketIssueResponseFactory = (params: Partial): 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 => { ~~~~~~~~~ src/test/factories/responses/bitbucket/pullCommitsFactory.ts:4:97 - error TS2503: Cannot find namespace 'Bitbucket'. 4 export const bitbucketPullCommitsResponseFactory = (params?: Partial): 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 => { ~~~~~~~~~ src/test/factories/responses/bitbucket/repoCommitsResponseFactory.ts:4:97 - error TS2503: Cannot find namespace 'Bitbucket'. 4 export const bitbucketRepoCommitsResponseFactory = (params?: Partial): Bitbucket.Schema.Commit => { ~~~~~~~~~ Found 71 errors. error Command failed with exit code 1.
MunifTanjim commented 4 years ago

Hello @prokopsimek

Can you please try v2.0.1 and see if the problem still exists. There were some buggy TypeScript types declaration in the previous release.

prokopsimek commented 4 years ago

@MunifTanjim v2.0.1 is still broken. There are some changes in exports, probably?

See my PR https://github.com/DXHeroes/dx-scanner/pull/237 and Travis job.

MunifTanjim commented 4 years ago

Well, the library seems to be fixed. Now you'll have to update the internal types you consumed from the bitbucket@1.

The exported types have changed in v2

prokopsimek commented 4 years ago

@MunifTanjim I understand. This issue is about adding update guide v2 to understand breaking changes.

MunifTanjim commented 4 years ago

Many things have changed since v1.

Here are some major differences between v1 and v2

bitbucket@1

import Bitbucket from 'bitbucket'

type Client = Bitbucket;
type Params = Bitbucket.Params;
type Schema = Bitbucket.Schema;
type Response = Bitbucket.Response;

// Pre GDPR: `username` param key

/**
 * AUTHENTICATION
 */

const client = new Bitbucket({})

client.authenticate({ type: '', username: '', password: '' })
// or
client.authenticate({ type: '', token: '' })

bitbucket@2

import { Bitbucket } from 'bitbucket';

type Client = import('bitbucket').APIClient;
type Params = import('bitbucket').Params;
type Schema = import('bitbucket').Schema;
type Response<T> = import('bitbucket/src/request/types').Response<T>;

// Post GDPR: `workspace` param key instead of `username`

/**
 * AUTHENTICATION
 */

let client = Bitbucket({})

client = Bitbucket({ auth: { username: '', password: '' } })
// or
client = Bitbucket({ auth: { token: '' } })

These are everything that comes to mind right now.

For the rest, you have to dig through the errors TypeScript provides.

prokopsimek commented 4 years ago

@MunifTanjim We've updated all to v2 but we're missing export of Response or AsyncResponse. Could you export it from the library to be able to use it manually to override e.g. createComment response? (before we had: Bitbucket.Response<Bitbucket.Schema.Commit> - now the reponse is not exported)

prokopsimek commented 4 years ago

The same Auth interface from v1.

MunifTanjim commented 4 years ago

we're missing export of Response

The previous comment included it:

type Response<T> = import('bitbucket/src/request/types').Response<T>;
prokopsimek commented 4 years ago

Ohh sorry, will try it.

MunifTanjim commented 4 years ago

The same Auth interface from v1.

Try importing from bitbucket/src/plugins/auth/types. The signatures are a bit different.

prokopsimek commented 4 years ago

@MunifTanjim Thanks for your help. We've just updated the bitbucket to v2. šŸŽ‰ https://github.com/DXHeroes/dx-scanner/pull/237/

prokopsimek commented 4 years ago

@MunifTanjim Is it possible to disable the BITBUCKET CLOUD API warnings?

BITBUCKET CLOUD API CHANGING NOTICE:  https://developer.atlassian.com/cloud/bitbucket/bitbucket-api-changes-gdpr 
 BITBUCKET CLOUD API MIGRATION GUIDE:  https://developer.atlassian.com/cloud/bitbucket/bbc-gdpr-api-migration-guide 
 BITBUCKET CLOUD API REPO URL CHANGE:  https://developer.atlassian.com/cloud/bitbucket/bitbucket-api-changes-workspaces 
MunifTanjim commented 4 years ago

Try passing notice: false in client options.

prokopsimek commented 4 years ago

@MunifTanjim Thanks! It has changed from hideNotice: true to notice: false. šŸ™‚