1 | [![version:@latest](https://img.shields.io/npm/v/bitbucket.svg?style=for-the-badge)](https://www.npmjs.com/package/bitbucket)
|
2 | [![Documentation](https://img.shields.io/badge/docs-bitbucket.js-blue.svg?style=for-the-badge)](https://bitbucketjs.netlify.app)
|
3 | [![License](https://img.shields.io/github/license/MunifTanjim/node-bitbucket.svg?style=for-the-badge)](https://github.com/MunifTanjim/node-bitbucket/blob/master/LICENSE)
|
4 |
|
5 | # Bitbucket.js
|
6 |
|
7 | Bitbucket API client for Browser and Node.js
|
8 |
|
9 | Bitbucket API docs: [https://api.bitbucket.org](https://api.bitbucket.org)
|
10 |
|
11 | ---
|
12 |
|
13 | **BITBUCKET CLOUD API LATEST UPDATES**: [https://developer.atlassian.com/cloud/bitbucket](https://developer.atlassian.com/cloud/bitbucket)
|
14 |
|
15 | ---
|
16 |
|
17 | ## Installation
|
18 |
|
19 | via **npm**:
|
20 |
|
21 | ```sh
|
22 | $ npm install --save bitbucket
|
23 | ```
|
24 |
|
25 | via **yarn**:
|
26 |
|
27 | ```sh
|
28 | $ yarn add bitbucket
|
29 | ```
|
30 |
|
31 | ## Usage
|
32 |
|
33 | ### Browser
|
34 |
|
35 | ```html
|
36 | <script src="https://unpkg.com/bitbucket/lib/index.umd.js"></script>
|
37 | <script>
|
38 | const bitbucket = new Bitbucket()
|
39 | </script>
|
40 | ```
|
41 |
|
42 | ### Node
|
43 |
|
44 | ```js
|
45 | const { Bitbucket } = require('bitbucket')
|
46 |
|
47 | const bitbucket = new Bitbucket()
|
48 | ```
|
49 |
|
50 | #### Client Options
|
51 |
|
52 | You can set the APIs' `baseUrl` and modify some behaviors (e.g. request timeout etc.) by passing a clientOptions object to the `Bitbucket` constructor.
|
53 |
|
54 | ```js
|
55 | const clientOptions = {
|
56 | baseUrl: 'https://api.bitbucket.org/2.0',
|
57 | request: {
|
58 | timeout: 10,
|
59 | },
|
60 | }
|
61 |
|
62 | const bitbucket = new Bitbucket(clientOptions)
|
63 | ```
|
64 |
|
65 | #### Authentication
|
66 |
|
67 | **Using `username` and `password`**:
|
68 |
|
69 | ```js
|
70 | const clientOptions = {
|
71 | auth: {
|
72 | username: 'username',
|
73 | password: 'password',
|
74 | },
|
75 | }
|
76 |
|
77 | const bitbucket = new Bitbucket(clientOptions)
|
78 | ```
|
79 |
|
80 | **Using `token`**:
|
81 |
|
82 | ```js
|
83 | const clientOptions = {
|
84 | auth: {
|
85 | token: 'abcdef123456',
|
86 | },
|
87 | }
|
88 |
|
89 | const bitbucket = new Bitbucket(clientOptions)
|
90 | ```
|
91 |
|
92 | #### API Methods
|
93 |
|
94 | **async/await**
|
95 |
|
96 | ```js
|
97 | try {
|
98 | const { data, headers, status, url } = await bitbucket.<namespace>.<api>({ ...params })
|
99 | } catch (err) {
|
100 | const { message, error, headers, request, status } = err
|
101 | }
|
102 | ```
|
103 |
|
104 | **Promise**
|
105 |
|
106 | ```js
|
107 | bitbucket.<namespace>
|
108 | .<api>({ ...params })
|
109 | .then(({ data, headers, status, url }) => {})
|
110 | .catch(({ message, error, headers, request, status }) => {})
|
111 | ```
|
112 |
|
113 | Notes:
|
114 |
|
115 | - `<namespace>` is one of the _Namespace Names_
|
116 | - `<api>` is one of the _API Names_
|
117 |
|
118 | #### Namespace Names
|
119 |
|
120 | `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`
|
121 |
|
122 | #### API Names
|
123 |
|
124 | Check API client docs: [https://bitbucketjs.netlify.com](https://bitbucketjs.netlify.com)
|
125 |
|
126 | ##### Examples
|
127 |
|
128 | ```js
|
129 | bitbucket.repositories
|
130 | .listGlobal({})
|
131 | .then(({ data }) => console.log(data.values))
|
132 | .catch((err) => console.error(err))
|
133 | ```
|
134 |
|
135 | ## Acknowledgement
|
136 |
|
137 | This API client is heavily inspired by the **[`octokit/rest.js`](https://github.com/octokit/rest.js/)** and a lot of ideas are taken from there. So, thanks goes to the maintainer [Gregor Martynus](https://github.com/gr2m) and all the [awesome contributors](https://github.com/octokit/rest.js/graphs/contributors) of `octokit/rest.js`.
|
138 |
|
139 | ## License
|
140 |
|
141 | Licensed under the MIT License. Check the [LICENSE](https://github.com/MunifTanjim/node-bitbucket/blob/master/LICENSE) file for details.
|