bitbucket-v2 0.6.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +33 -5
- package/.prettierrc +5 -0
- package/.vscode/settings.example.json +7 -0
- package/CHANGELOG.md +12 -1
- package/README.md +61 -20
- package/dist/constants.d.ts +11 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +13 -0
- package/dist/constants.js.map +1 -0
- package/dist/helpers.d.ts +5 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +10 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +90 -0
- package/dist/index.js.map +1 -0
- package/dist/repositories.d.ts +18 -0
- package/dist/repositories.d.ts.map +1 -0
- package/dist/repositories.js +82 -0
- package/dist/repositories.js.map +1 -0
- package/dist/request.d.ts +30 -0
- package/dist/request.d.ts.map +1 -0
- package/dist/request.js +202 -0
- package/dist/request.js.map +1 -0
- package/dist/types.d.ts +183 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/user.d.ts +6 -0
- package/dist/user.d.ts.map +1 -0
- package/dist/user.js +9 -0
- package/dist/user.js.map +1 -0
- package/dist/workspaces.d.ts +6 -0
- package/dist/workspaces.d.ts.map +1 -0
- package/dist/workspaces.js +9 -0
- package/dist/workspaces.js.map +1 -0
- package/package.json +28 -20
- package/src/constants.ts +11 -0
- package/src/helpers.ts +11 -0
- package/src/index.ts +249 -0
- package/{bitbucket/repositories.js → src/repositories.ts} +75 -57
- package/src/request.ts +294 -0
- package/src/types.ts +183 -0
- package/src/user.ts +14 -0
- package/src/workspaces.ts +14 -0
- package/tsconfig.json +32 -0
- package/bitbucket/constants.js +0 -9
- package/bitbucket/helpers.js +0 -9
- package/bitbucket/index.js +0 -147
- package/bitbucket/request.js +0 -256
- package/bitbucket/user.js +0 -11
- package/bitbucket/workspaces.js +0 -12
package/.eslintrc.js
CHANGED
|
@@ -1,15 +1,43 @@
|
|
|
1
|
+
/* eslint-disable quote-props */
|
|
1
2
|
module.exports = {
|
|
2
|
-
'
|
|
3
|
-
'
|
|
4
|
-
'
|
|
3
|
+
'parser': '@typescript-eslint/parser',
|
|
4
|
+
'extends': [
|
|
5
|
+
'airbnb-base',
|
|
6
|
+
'plugin:@typescript-eslint/recommended',
|
|
7
|
+
'prettier'
|
|
5
8
|
],
|
|
9
|
+
'plugins': ['@typescript-eslint'],
|
|
6
10
|
'rules': {
|
|
7
11
|
'arrow-parens': [2, 'always'],
|
|
8
|
-
'brace-style': [2, '
|
|
12
|
+
'brace-style': [2, '1tbs', { 'allowSingleLine': true }],
|
|
9
13
|
'camelcase': 0,
|
|
10
14
|
'comma-dangle': [2, 'never'],
|
|
11
15
|
'linebreak-style': 0,
|
|
12
16
|
'max-len': [2, { code: 120 }],
|
|
13
|
-
'new-cap': [2, { 'capIsNewExceptions': ['AbstractApi', 'Repositories', 'Request', 'Teams', 'User'] }]
|
|
17
|
+
'new-cap': [2, { 'capIsNewExceptions': ['AbstractApi', 'Repositories', 'Request', 'Teams', 'User'] }],
|
|
18
|
+
'import/extensions': ['error', 'ignorePackages', { 'ts': 'never' }],
|
|
19
|
+
'import/no-unresolved': 'off',
|
|
20
|
+
'import/prefer-default-export': 'off',
|
|
21
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
22
|
+
'no-use-before-define': 'off',
|
|
23
|
+
'@typescript-eslint/no-use-before-define': ['error', { 'typedefs': false }]
|
|
24
|
+
},
|
|
25
|
+
'parserOptions': {
|
|
26
|
+
'ecmaVersion': 2024
|
|
27
|
+
},
|
|
28
|
+
'overrides': [
|
|
29
|
+
{
|
|
30
|
+
'files': ['*.ts'],
|
|
31
|
+
'parserOptions': {
|
|
32
|
+
'project': './tsconfig.json'
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
'settings': {
|
|
37
|
+
'import/resolver': {
|
|
38
|
+
'node': {
|
|
39
|
+
'extensions': ['.js', '.ts']
|
|
40
|
+
}
|
|
41
|
+
}
|
|
14
42
|
}
|
|
15
43
|
};
|
package/.prettierrc
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# CHANGELOG
|
|
2
|
+
|
|
3
|
+
## 1.0.1
|
|
4
|
+
- Fixed `BitbucketWorkspace` type to document what is returned by the new `.worspaces.get` function.
|
|
5
|
+
|
|
6
|
+
## 1.0.0
|
|
7
|
+
- **BREAKING CHANGE**: Node 7.6 is no longer supported; only Node 22 and up is now supported.
|
|
8
|
+
- **BREAKING CHANGE**: Module export changed: use `require('bitbucket-v2').default` in CommonJS (was `require('bitbucket-v2')`).
|
|
9
|
+
- **BREAKING CHANGE**: Constructor is now a function call, not a class - use `Bitbucket(options)` instead of `new Bitbucket(options)`
|
|
10
|
+
- **BREAKING CHANGE**: Moved `.workspaces.get` off of deprecated `/workspaces` route and onto new `/user/workspaces` route. The return value has changed and your existing usage will need to be adjusted.
|
|
11
|
+
- Transferred ownership of the repository to the "GitKraken" GitHub organization.
|
|
12
|
+
- Converted entire codebase to Typescript. The types for API responses have been defined according to current usage within the author's workplace, and will be missing _many_ properties. If you encounter a problem, please open a pull request with expanded type definitions.
|
|
2
13
|
|
|
3
14
|
## 0.6.0
|
|
4
15
|
Thanks to [@andrewyalung](https://github.com/andrewyalung/) for authoring most of this version!
|
package/README.md
CHANGED
|
@@ -1,12 +1,38 @@
|
|
|
1
1
|
# node-bitbucket-v2
|
|
2
2
|
node.js library to access the Bitbucket API v2
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
**Note:** This library is now written in TypeScript and includes full type definitions!
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install bitbucket-v2
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
### JavaScript (CommonJS)
|
|
15
|
+
|
|
16
|
+
```javascript
|
|
17
|
+
const Bitbucket = require('bitbucket-v2').default;
|
|
18
|
+
const bitbucketApi = Bitbucket(options);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### TypeScript
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import Bitbucket, { type BitbucketConstructorOptions } from 'bitbucket-v2';
|
|
25
|
+
|
|
26
|
+
const options: BitbucketConstructorOptions = {
|
|
27
|
+
// your options here
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const bitbucketApi = Bitbucket(options);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Authentication and request
|
|
6
34
|
|
|
7
35
|
```
|
|
8
|
-
const Bitbucket = require('node-bitbucket-v2');
|
|
9
|
-
const bitbucketApi = new Bitbucket(options);
|
|
10
36
|
bitbucketApi.authenticateOAuth2(accessTokenString);
|
|
11
37
|
|
|
12
38
|
bitbucketApi.user.get().then(({ body }) => {
|
|
@@ -14,25 +40,40 @@ bitbucketApi.user.get().then(({ body }) => {
|
|
|
14
40
|
});
|
|
15
41
|
```
|
|
16
42
|
|
|
17
|
-
|
|
43
|
+
## Options
|
|
44
|
+
|
|
18
45
|
It is not necessary to provide any options at all (`Bitbucket` can be constructed with no argument).
|
|
19
|
-
- `requesterFn` (`(options) => Promise<any>`): If provided, requests will be made using the function you provide. This is allows you to use your preferred http client. The `options` provided are `{ headers, hostname, method, path, query, url, body? }`. `body` is only provided on `POST` methods. In the case of `getNextPage`, `getPreviousPage`, `getForksFromResponse` and `getParentFromResponse`, only `{ headers, method, url }` are provided in the options. Example:
|
|
20
|
-
```
|
|
21
|
-
const axios = require('axios');
|
|
22
|
-
const Bitbucket = require('node-bitbucket-v2');
|
|
23
46
|
|
|
24
|
-
|
|
25
|
-
|
|
47
|
+
- `requesterFn` (`(options: RequesterOptions) => Promise<BitbucketResponse>`): If provided, requests will be made using the function you provide. This allows you to use your preferred http client. The `options` provided are `{ headers, hostname, method, path, query, url, body? }`. `body` is only provided on `POST` methods. In the case of `getNextPage`, `getPreviousPage`, `getForksFromResponse` and `getParentFromResponse`, only `{ headers, method, url }` are provided in the options. Example:
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import axios from 'axios';
|
|
51
|
+
import Bitbucket from 'bitbucket-v2';
|
|
26
52
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
53
|
+
const requesterFn = (options) => {
|
|
54
|
+
const { url, method, body } = options;
|
|
30
55
|
|
|
31
|
-
|
|
32
|
-
|
|
56
|
+
if (method === 'POST') {
|
|
57
|
+
return axios.post(url, body);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return axios.get(url);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const bitbucketApi = Bitbucket({ requesterFn });
|
|
64
|
+
```
|
|
33
65
|
|
|
34
|
-
|
|
35
|
-
```
|
|
36
|
-
- `proxy` (`String`): Defines a proxy to make requests against, instead of `api.bitbucket.org:443`. This option is _ignored_ when `requesterFn` is provided.
|
|
66
|
+
- `proxy` (`string`): Defines a proxy to make requests against, instead of `api.bitbucket.org:443`. This option is _ignored_ when `requesterFn` is provided.
|
|
37
67
|
|
|
38
|
-
|
|
68
|
+
|
|
69
|
+
## Development
|
|
70
|
+
|
|
71
|
+
Build the TypeScript code:
|
|
72
|
+
```bash
|
|
73
|
+
npm run build
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Run linting:
|
|
77
|
+
```bash
|
|
78
|
+
npm run lint
|
|
79
|
+
```
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const constants: {
|
|
2
|
+
pullRequest: {
|
|
3
|
+
states: {
|
|
4
|
+
DECLINED: "DECLINED";
|
|
5
|
+
MERGED: "MERGED";
|
|
6
|
+
OPEN: "OPEN";
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export type PullRequestState = (typeof constants.pullRequest.states)[keyof typeof constants.pullRequest.states];
|
|
11
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;;;;;;;;CAQrB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,MAAM,OAAO,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.constants = void 0;
|
|
4
|
+
exports.constants = {
|
|
5
|
+
pullRequest: {
|
|
6
|
+
states: {
|
|
7
|
+
DECLINED: 'DECLINED',
|
|
8
|
+
MERGED: 'MERGED',
|
|
9
|
+
OPEN: 'OPEN'
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG;IACvB,WAAW,EAAE;QACX,MAAM,EAAE;YACN,QAAQ,EAAE,UAAmB;YAC7B,MAAM,EAAE,QAAiB;YACzB,IAAI,EAAE,MAAe;SACtB;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ApiResponse } from './types';
|
|
2
|
+
type ExtractedBodyIfAble<R> = R extends ApiResponse<infer T> ? T : R;
|
|
3
|
+
export declare function extractResponseBody<R extends object | null | undefined>(response: R): ExtractedBodyIfAble<R>;
|
|
4
|
+
export {};
|
|
5
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,KAAK,mBAAmB,CAAC,CAAC,IAAI,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAErE,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,QAAQ,EAAE,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAM5G"}
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractResponseBody = extractResponseBody;
|
|
4
|
+
function extractResponseBody(response) {
|
|
5
|
+
if (!response || !('body' in response && 'statusCode' in response)) {
|
|
6
|
+
return response;
|
|
7
|
+
}
|
|
8
|
+
return response.body;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;AAIA,kDAMC;AAND,SAAgB,mBAAmB,CAAsC,QAAW;IAClF,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC,MAAM,IAAI,QAAQ,IAAI,YAAY,IAAI,QAAQ,CAAC,EAAE,CAAC;QACnE,OAAO,QAAkC,CAAC;IAC5C,CAAC;IAED,OAAQ,QAAwB,CAAC,IAAI,CAAC;AACxC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { constants } from './constants';
|
|
2
|
+
import buildRepositoriesApi from './repositories';
|
|
3
|
+
import { Request } from './request';
|
|
4
|
+
import buildUserApi from './user';
|
|
5
|
+
import buildWorkspacesApi from './workspaces';
|
|
6
|
+
import { BitbucketConstructorOptions, ApiResponse, PaginatedResponse } from './types';
|
|
7
|
+
export interface ApiModel {
|
|
8
|
+
$proxy_host?: string;
|
|
9
|
+
$proxy_port?: string;
|
|
10
|
+
constants: typeof constants;
|
|
11
|
+
repositories: ReturnType<typeof buildRepositoriesApi>;
|
|
12
|
+
request: Request;
|
|
13
|
+
user: ReturnType<typeof buildUserApi>;
|
|
14
|
+
workspaces: ReturnType<typeof buildWorkspacesApi>;
|
|
15
|
+
authenticateOAuth2(accessToken: string): ApiModel;
|
|
16
|
+
deAuthenticate(): ApiModel;
|
|
17
|
+
get(route: string, parameters?: Record<string, any>, requestOptions?: any): Promise<ApiResponse>;
|
|
18
|
+
delete(route: string, parameters?: Record<string, any>, requestOptions?: any): Promise<ApiResponse>;
|
|
19
|
+
post(route: string, parameters?: Record<string, any>, requestOptions?: any): Promise<ApiResponse>;
|
|
20
|
+
hasNextPage(response: ApiResponse | PaginatedResponse | any): boolean;
|
|
21
|
+
hasPreviousPage(response: ApiResponse | PaginatedResponse | any): boolean;
|
|
22
|
+
getNextPage(response: ApiResponse | PaginatedResponse | any): Promise<ApiResponse>;
|
|
23
|
+
getPreviousPage(response: ApiResponse | PaginatedResponse | any): Promise<ApiResponse>;
|
|
24
|
+
}
|
|
25
|
+
export default function Bitbucket(options?: BitbucketConstructorOptions): ApiModel;
|
|
26
|
+
export * from './types';
|
|
27
|
+
export { constants } from './constants';
|
|
28
|
+
export type { PullRequestState } from './constants';
|
|
29
|
+
export type { Request } from './request';
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,oBAAoB,MAAM,gBAAgB,CAAC;AAClD,OAAqB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,YAAY,MAAM,QAAQ,CA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AE,WAAW,GAAG,iBAAiB,GAAG,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAQnF,eAAe,CAAC,QAAQ,EAAE,WAAW,GAAG,iBAAiB,GAAG,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CACxF;AAED,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,OAAO,GAAE,2BAAgC,GAAG,QAAQ,CA+IrF;AAGD,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,YAAY,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.constants = void 0;
|
|
21
|
+
exports.default = Bitbucket;
|
|
22
|
+
const constants_1 = require("./constants");
|
|
23
|
+
const repositories_1 = __importDefault(require("./repositories"));
|
|
24
|
+
const request_1 = __importDefault(require("./request"));
|
|
25
|
+
const user_1 = __importDefault(require("./user"));
|
|
26
|
+
const workspaces_1 = __importDefault(require("./workspaces"));
|
|
27
|
+
const helpers_1 = require("./helpers");
|
|
28
|
+
function Bitbucket(options = {}) {
|
|
29
|
+
const { proxy, requesterFn } = options;
|
|
30
|
+
let $proxy_host;
|
|
31
|
+
let $proxy_port;
|
|
32
|
+
if (proxy) {
|
|
33
|
+
[$proxy_host, $proxy_port] = proxy.split(':');
|
|
34
|
+
}
|
|
35
|
+
const apiModel = {
|
|
36
|
+
$proxy_host,
|
|
37
|
+
$proxy_port,
|
|
38
|
+
constants: constants_1.constants,
|
|
39
|
+
repositories: undefined,
|
|
40
|
+
request: undefined,
|
|
41
|
+
user: undefined,
|
|
42
|
+
workspaces: undefined,
|
|
43
|
+
authenticateOAuth2: (accessToken) => {
|
|
44
|
+
apiModel.request.setOption('login_type', 'oauth2').setOption('oauth_access_token', accessToken);
|
|
45
|
+
return apiModel;
|
|
46
|
+
},
|
|
47
|
+
deAuthenticate: () => {
|
|
48
|
+
apiModel.request.setOption('login_type', 'none');
|
|
49
|
+
return apiModel;
|
|
50
|
+
},
|
|
51
|
+
get: (route, parameters, requestOptions) => apiModel.request.get(route, parameters || {}, requestOptions),
|
|
52
|
+
delete: (route, parameters, requestOptions) => apiModel.request.delete(route, parameters, requestOptions),
|
|
53
|
+
post: (route, parameters, requestOptions) => apiModel.request.post(route, parameters || {}, requestOptions),
|
|
54
|
+
hasNextPage: (response) => {
|
|
55
|
+
const body = (0, helpers_1.extractResponseBody)(response);
|
|
56
|
+
return Boolean(body.next);
|
|
57
|
+
},
|
|
58
|
+
hasPreviousPage: (response) => {
|
|
59
|
+
const body = (0, helpers_1.extractResponseBody)(response);
|
|
60
|
+
return Boolean(body.previous);
|
|
61
|
+
},
|
|
62
|
+
getNextPage: (response) => {
|
|
63
|
+
if (!apiModel.hasNextPage(response)) {
|
|
64
|
+
throw new Error('getNextPage: argument has no next page url. Call hasNextPage first to guard this method call.');
|
|
65
|
+
}
|
|
66
|
+
const body = (0, helpers_1.extractResponseBody)(response);
|
|
67
|
+
return apiModel.request.doPrebuiltSend(body.next);
|
|
68
|
+
},
|
|
69
|
+
getPreviousPage: (response) => {
|
|
70
|
+
if (!apiModel.hasPreviousPage(response)) {
|
|
71
|
+
throw new Error('getPreviousPage: argument has no next page url. Call hasPreviousPage first to guard this method call.');
|
|
72
|
+
}
|
|
73
|
+
const body = (0, helpers_1.extractResponseBody)(response);
|
|
74
|
+
return apiModel.request.doPrebuiltSend(body.previous);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
apiModel.repositories = (0, repositories_1.default)(apiModel);
|
|
78
|
+
apiModel.request = (0, request_1.default)({
|
|
79
|
+
proxy_host: $proxy_host,
|
|
80
|
+
proxy_port: $proxy_port ? parseInt($proxy_port, 10) : null,
|
|
81
|
+
requester_fn: requesterFn || null
|
|
82
|
+
});
|
|
83
|
+
apiModel.user = (0, user_1.default)(apiModel);
|
|
84
|
+
apiModel.workspaces = (0, workspaces_1.default)(apiModel);
|
|
85
|
+
return apiModel;
|
|
86
|
+
}
|
|
87
|
+
__exportStar(require("./types"), exports);
|
|
88
|
+
var constants_2 = require("./constants");
|
|
89
|
+
Object.defineProperty(exports, "constants", { enumerable: true, get: function () { return constants_2.constants; } });
|
|
90
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAmGA,4BA+IC;AAlPD,2CAAwC;AACxC,kEAAkD;AAClD,wDAAkD;AAClD,kDAAkC;AAClC,8DAA8C;AAC9C,uCAAgD;AA8FhD,SAAwB,SAAS,CAAC,UAAuC,EAAE;IACzE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,GA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QAC1D,YAAY,EAAE,WAAW,IAAI,IAAI;KAClC,CAAC,CAAC;IACH,QAAQ,CAAC,IAAI,GAAG,IAAA,cAAY,EAAC,QAAQ,CAAC,CAAC;IACvC,QAAQ,CAAC,UAAU,GAAG,IAAA,oBAAkB,EAAC,QAAQ,CAAC,CAAC;IAEnD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAGD,0CAAwB;AACxB,yCAAwC;AAA/B,sGAAA,SAAS,OAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PullRequestState } from './constants';
|
|
2
|
+
import { ApiModel } from './index';
|
|
3
|
+
import { ApiResponse, Repository, PullRequest, GetPullRequestsOptions, BitbucketRepository, BitbucketBranch, BitbucketPullRequest, PaginatedResponse } from './types';
|
|
4
|
+
export default function buildRepositoriesApi(api: ApiModel): {
|
|
5
|
+
create: (workspace: string, repo: Repository) => Promise<ApiResponse<BitbucketRepository>>;
|
|
6
|
+
createPullRequest: (workspace: string, repoSlug: string, pullRequest: PullRequest) => Promise<ApiResponse<BitbucketPullRequest>>;
|
|
7
|
+
get: (workspace: string, repoSlug: string) => Promise<ApiResponse<BitbucketRepository>>;
|
|
8
|
+
getBranches: (workspace: string, repoSlug: string) => Promise<ApiResponse<PaginatedResponse<BitbucketBranch>>>;
|
|
9
|
+
getCommit: (workspace: string, repoSlug: string, sha: string) => Promise<ApiResponse<any>>;
|
|
10
|
+
getPullRequests: (workspace: string, repoSlug: string, state?: PullRequestState | PullRequestState[]) => Promise<ApiResponse<PaginatedResponse<BitbucketPullRequest>>>;
|
|
11
|
+
getPullRequestsWithFields: (workspace: string, repoSlug: string, options?: GetPullRequestsOptions) => Promise<ApiResponse<PaginatedResponse<BitbucketPullRequest>>>;
|
|
12
|
+
getByWorkspace: (workspace: string) => Promise<ApiResponse<PaginatedResponse<BitbucketRepository>>>;
|
|
13
|
+
getForks: (workspace: string, repoSlug: string) => Promise<ApiResponse<PaginatedResponse<BitbucketRepository>>>;
|
|
14
|
+
getForksFromResponse: (response: BitbucketRepository) => Promise<ApiResponse<PaginatedResponse<BitbucketRepository>>>;
|
|
15
|
+
getParentFromResponse: (response: BitbucketRepository) => Promise<ApiResponse<BitbucketRepository>>;
|
|
16
|
+
hasParent: (response: ApiResponse<BitbucketRepository> | BitbucketRepository) => boolean;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=repositories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repositories.d.ts","sourceRoot":"","sources":["../src/repositories.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE1D,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EACL,WAAW,EACX,UAAU,EACV,WAAW,EACX,sBAAsB,EACtB,mBAAmB,EACnB,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAMjB,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,GAAG,EAAE,QAAQ;wBASlC,MAAM,QAAQ,UAAU,KAAG,OAAO,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC;mCAkC3E,MAAM,YACP,MAAM,eACH,WAAW,KACvB,OAAO,CAAC,WAAW,CAAC,oBAAoB,CAAC,CAAC;qBAS5B,MAAM,YAAY,MAAM,KAAG,OAAO,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC;6BAS5D,MAAM,YAAY,MAAM,KAAG,OAAO,CAAC,WAAW,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAAC,CAAC;2BASrF,MAAM,YAAY,MAAM,OAAO,MAAM,KAAG,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;iCAW3E,MAAM,YACP,MAAM,UACR,gBAAgB,GAAG,gBAAgB,EAAE,KAC5C,OAAO,CAAC,WAAW,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,CAAC,CAAC;2CA6BnD,MAAM,YACP,MAAM,YACP,sBAAsB,KAC9B,OAAO,CAAC,WAAW,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,CAAC,CAAC;gCAkCpC,MAAM,KAAG,OAAO,CAAC,WAAW,CAAC,iBAAiB,CAAC,mBAAmB,CAAC,CAAC,CAAC;0BAS3E,MAAM,YAAY,MAAM,KAAG,OAAO,CAAC,WAAW,CAAC,iBAAiB,CAAC,mBAAmB,CAAC,CAAC,CAAC;qCASjG,mBAAmB,KAC5B,OAAO,CAAC,WAAW,CAAC,iBAAiB,CAAC,mBAAmB,CAAC,CAAC,CAAC;sCAiB7B,mBAAmB,KAAG,OAAO,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC;0BAmB3E,WAAW,CAAC,mBAAmB,CAAC,GAAG,mBAAmB,KAAG,OAAO;EAGzF"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = buildRepositoriesApi;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
|
+
function buildRepositoriesApi(api) {
|
|
7
|
+
return {
|
|
8
|
+
create: (workspace, repo) => {
|
|
9
|
+
if (!repo || typeof repo.is_private !== 'boolean' || typeof repo.name !== 'string') {
|
|
10
|
+
throw new Error('Repo must be initialized with a booelan privacy setting and a string name');
|
|
11
|
+
}
|
|
12
|
+
const repoSlug = repo.name
|
|
13
|
+
.replace(/['"]/g, '')
|
|
14
|
+
.replace(/\W/g, '-')
|
|
15
|
+
.replace(/--+/g, '-')
|
|
16
|
+
.replace(/^-/, '')
|
|
17
|
+
.replace(/-$/, '')
|
|
18
|
+
.toLowerCase();
|
|
19
|
+
return api.post(`repositories/${encodeURI(workspace)}/${encodeURI(repoSlug)}`, repo);
|
|
20
|
+
},
|
|
21
|
+
createPullRequest: (workspace, repoSlug, pullRequest) => api.post(`repositories/${encodeURI(workspace)}/${encodeURI(repoSlug)}/pullrequests`, pullRequest),
|
|
22
|
+
get: (workspace, repoSlug) => api.get(`repositories/${encodeURI(workspace)}/${encodeURI(repoSlug)}`),
|
|
23
|
+
getBranches: (workspace, repoSlug) => api.get(`repositories/${encodeURI(workspace)}/${encodeURI(repoSlug)}/refs/branches`),
|
|
24
|
+
getCommit: (workspace, repoSlug, sha) => api.get(`repositories/${encodeURI(workspace)}/${encodeURI(repoSlug)}/commit/${sha}`),
|
|
25
|
+
getPullRequests: (workspace, repoSlug, state) => {
|
|
26
|
+
let stateArray = [constants_1.constants.pullRequest.states.OPEN];
|
|
27
|
+
if (state) {
|
|
28
|
+
stateArray = Array.isArray(state) ? state : [state];
|
|
29
|
+
}
|
|
30
|
+
const hasInvalidState = stateArray.find((stateElement) => !Object.values(constants_1.constants.pullRequest.states).includes(stateElement));
|
|
31
|
+
if (hasInvalidState) {
|
|
32
|
+
stateArray = [constants_1.constants.pullRequest.states.OPEN];
|
|
33
|
+
}
|
|
34
|
+
const apiParameters = {
|
|
35
|
+
state: stateArray.join(',')
|
|
36
|
+
};
|
|
37
|
+
return api.get(`repositories/${encodeURI(workspace)}/${encodeURI(repoSlug)}/pullrequests`, apiParameters);
|
|
38
|
+
},
|
|
39
|
+
getPullRequestsWithFields: (workspace, repoSlug, options = {}) => {
|
|
40
|
+
const { state, fields } = options;
|
|
41
|
+
if (!Array.isArray(fields) || fields.length < 1) {
|
|
42
|
+
throw new Error("getPullRequestsWithFields: options argument missing or has missing/empty 'fields' array.");
|
|
43
|
+
}
|
|
44
|
+
let stateArray = [constants_1.constants.pullRequest.states.OPEN];
|
|
45
|
+
if (state) {
|
|
46
|
+
stateArray = Array.isArray(state) ? state : [state];
|
|
47
|
+
}
|
|
48
|
+
const hasInvalidState = stateArray.find((stateElement) => !Object.values(constants_1.constants.pullRequest.states).includes(stateElement));
|
|
49
|
+
if (hasInvalidState) {
|
|
50
|
+
stateArray = [constants_1.constants.pullRequest.states.OPEN];
|
|
51
|
+
}
|
|
52
|
+
const apiParameters = {
|
|
53
|
+
state: stateArray.join(',')
|
|
54
|
+
};
|
|
55
|
+
const fieldsWithEncodedPlus = fields.map((field) => `+${field}`);
|
|
56
|
+
apiParameters.fields = fieldsWithEncodedPlus.join(',');
|
|
57
|
+
return api.get(`repositories/${encodeURI(workspace)}/${encodeURI(repoSlug)}/pullrequests`, apiParameters);
|
|
58
|
+
},
|
|
59
|
+
getByWorkspace: (workspace) => api.get(`repositories/${encodeURI(workspace)}`),
|
|
60
|
+
getForks: (workspace, repoSlug) => api.get(`repositories/${encodeURI(workspace)}/${encodeURI(repoSlug)}/forks`),
|
|
61
|
+
getForksFromResponse: (response) => {
|
|
62
|
+
var _a, _b;
|
|
63
|
+
const body = (0, helpers_1.extractResponseBody)(response);
|
|
64
|
+
const prebuiltURL = (_b = (_a = body === null || body === void 0 ? void 0 : body.links) === null || _a === void 0 ? void 0 : _a.forks) === null || _b === void 0 ? void 0 : _b.href;
|
|
65
|
+
if (!prebuiltURL) {
|
|
66
|
+
throw new Error("getForksFromResponse: argument has no 'forks' url.");
|
|
67
|
+
}
|
|
68
|
+
return api.request.doPrebuiltSend(prebuiltURL);
|
|
69
|
+
},
|
|
70
|
+
getParentFromResponse: (response) => {
|
|
71
|
+
var _a, _b, _c;
|
|
72
|
+
const body = (0, helpers_1.extractResponseBody)(response);
|
|
73
|
+
const prebuiltURL = (_c = (_b = (_a = body === null || body === void 0 ? void 0 : body.parent) === null || _a === void 0 ? void 0 : _a.links) === null || _b === void 0 ? void 0 : _b.self) === null || _c === void 0 ? void 0 : _c.href;
|
|
74
|
+
if (!prebuiltURL) {
|
|
75
|
+
throw new Error("getForksFromResponse: argument has no 'parent' info. Call hasParent first to guard this method call.");
|
|
76
|
+
}
|
|
77
|
+
return api.request.doPrebuiltSend(prebuiltURL);
|
|
78
|
+
},
|
|
79
|
+
hasParent: (response) => Boolean((0, helpers_1.extractResponseBody)(response).parent)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=repositories.js.map
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,QAAQ,CAAC,CAAC,MAAM,CAAC;KAChD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { RequestOptions, ApiResponse } from './types';
|
|
2
|
+
interface HttpsRequestOptions {
|
|
3
|
+
headers: Record<string, string>;
|
|
4
|
+
hostname: string;
|
|
5
|
+
method: string;
|
|
6
|
+
path: string;
|
|
7
|
+
port: number;
|
|
8
|
+
}
|
|
9
|
+
interface PrepRequestResult {
|
|
10
|
+
headers: Record<string, string>;
|
|
11
|
+
hostname: string;
|
|
12
|
+
port: number;
|
|
13
|
+
}
|
|
14
|
+
export interface Request {
|
|
15
|
+
$defaults: RequestOptions;
|
|
16
|
+
$options: RequestOptions;
|
|
17
|
+
setOption(name: string, value: any): Request;
|
|
18
|
+
getOption(name: string, defaultValue?: any): any;
|
|
19
|
+
get(apiPath: string, parameters?: Record<string, any>, options?: RequestOptions): Promise<ApiResponse>;
|
|
20
|
+
post(apiPath: string, parameters?: Record<string, any>, options?: RequestOptions): Promise<ApiResponse>;
|
|
21
|
+
delete(apiPath: string, parameters?: Record<string, any>, options?: RequestOptions): Promise<ApiResponse>;
|
|
22
|
+
doPrebuiltSend(prebuiltURL: string): Promise<ApiResponse>;
|
|
23
|
+
doSend(apiPath: string, parameters: Record<string, any>, httpMethod?: string, options?: RequestOptions): Promise<ApiResponse>;
|
|
24
|
+
decodeResponse(response: string): any;
|
|
25
|
+
prepRequest(options: RequestOptions): PrepRequestResult;
|
|
26
|
+
sendHttpsRequest(httpsOptions: HttpsRequestOptions, query?: string): Promise<ApiResponse>;
|
|
27
|
+
}
|
|
28
|
+
export default function buildRequest(_options?: RequestOptions): Request;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAA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