Merge pull request #195: Release 4.1

* chore(package): Update jest-extended to the latest version 🚀 0.9.0 (#191)
* chore(package): update lockfile package-lock.json
* feat: Re-add list all project members endpoint (#190, #141)
* feat: Adding markdown support #182 (#193)
* fixes: #188: `stream` option is lost in any `get` request that is streamable (#192)
* feat: Added user snippets API support (#189)
* chore(test): Added test for creating snippets
* feat: Added user edit support #186
This commit is contained in:
jdalrymple 2018-09-18 19:34:24 -04:00 committed by GitHub
commit 5cfa4ee9d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 160 additions and 59 deletions

View File

@ -61,6 +61,7 @@ NotificationSettings
PagesDomains
Search
SidekiqMetrics
Snippets
SystemHooks
Version
Wikis

126
package-lock.json generated
View File

@ -362,6 +362,7 @@
"resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz",
"integrity": "sha1-DNkKVhCT810KmSVsIrcGlDP60Rc=",
"dev": true,
"optional": true,
"requires": {
"kind-of": "3.2.2",
"longest": "1.0.1",
@ -373,6 +374,7 @@
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz",
"integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=",
"dev": true,
"optional": true,
"requires": {
"is-buffer": "1.1.6"
}
@ -2251,12 +2253,14 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -2271,17 +2275,20 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"core-util-is": {
"version": "1.0.2",
@ -2398,7 +2405,8 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"ini": {
"version": "1.3.5",
@ -2410,6 +2418,7 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@ -2424,6 +2433,7 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
@ -2431,12 +2441,14 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"minipass": {
"version": "2.2.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.1",
"yallist": "^3.0.0"
@ -2455,6 +2467,7 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
@ -2535,7 +2548,8 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"object-assign": {
"version": "4.1.1",
@ -2547,6 +2561,7 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"wrappy": "1"
}
@ -2668,6 +2683,7 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@ -3977,14 +3993,14 @@
}
},
"jest-extended": {
"version": "0.8.1",
"resolved": "https://registry.npmjs.org/jest-extended/-/jest-extended-0.8.1.tgz",
"integrity": "sha512-WhyYy9bNAxotiAlSQz0cXTnqP6aKPZw8iBzBbaDrsE3Yv+u1N7Uq05n+YszSnQUuLCyuF/hAszY2yzAgKdY8kw==",
"version": "0.9.0",
"resolved": "https://registry.npmjs.org/jest-extended/-/jest-extended-0.9.0.tgz",
"integrity": "sha512-e3FWQZwdQACRdrjbVZpar+LzEFWGtuq3KFO/dXWAwLyQYkEHSm38Y2NJnYCjrHyp3rZO4aPJGezC+WbSsJHpmw==",
"dev": true,
"requires": {
"expect": "22.4.3",
"jest-get-type": "22.4.3",
"jest-matcher-utils": "22.4.3"
"expect": "^22.1.0",
"jest-get-type": "^22.4.3",
"jest-matcher-utils": "^22.0.0"
},
"dependencies": {
"ansi-regex": {
@ -3999,7 +4015,7 @@
"integrity": "sha1-jzuCf5Vai9ZpaX5KQlasPOrjVs8=",
"dev": true,
"requires": {
"arr-flatten": "1.1.0"
"arr-flatten": "^1.0.1"
}
},
"array-unique": {
@ -4014,9 +4030,9 @@
"integrity": "sha1-uneWLhLf+WnWt2cR6RS3N4V79qc=",
"dev": true,
"requires": {
"expand-range": "1.8.2",
"preserve": "0.2.0",
"repeat-element": "1.1.2"
"expand-range": "^1.8.1",
"preserve": "^0.2.0",
"repeat-element": "^1.1.2"
}
},
"expand-brackets": {
@ -4025,7 +4041,7 @@
"integrity": "sha1-3wcoTjQqgHzXM6xa9yQR5YHRF3s=",
"dev": true,
"requires": {
"is-posix-bracket": "0.1.1"
"is-posix-bracket": "^0.1.0"
}
},
"expect": {
@ -4034,12 +4050,12 @@
"integrity": "sha512-XcNXEPehqn8b/jm8FYotdX0YrXn36qp4HWlrVT4ktwQas1l1LPxiVWncYnnL2eyMtKAmVIaG0XAp0QlrqJaxaA==",
"dev": true,
"requires": {
"ansi-styles": "3.2.1",
"jest-diff": "22.4.3",
"jest-get-type": "22.4.3",
"jest-matcher-utils": "22.4.3",
"jest-message-util": "22.4.3",
"jest-regex-util": "22.4.3"
"ansi-styles": "^3.2.0",
"jest-diff": "^22.4.3",
"jest-get-type": "^22.4.3",
"jest-matcher-utils": "^22.4.3",
"jest-message-util": "^22.4.3",
"jest-regex-util": "^22.4.3"
}
},
"extglob": {
@ -4048,7 +4064,7 @@
"integrity": "sha1-Lhj/PS9JqydlzskCPwEdqo2DSaE=",
"dev": true,
"requires": {
"is-extglob": "1.0.0"
"is-extglob": "^1.0.0"
}
},
"is-extglob": {
@ -4063,7 +4079,7 @@
"integrity": "sha1-0Jb5JqPe1WAPP9/ZEZjLCIjC2GM=",
"dev": true,
"requires": {
"is-extglob": "1.0.0"
"is-extglob": "^1.0.0"
}
},
"jest-diff": {
@ -4072,10 +4088,10 @@
"integrity": "sha512-/QqGvCDP5oZOF6PebDuLwrB2BMD8ffJv6TAGAdEVuDx1+uEgrHpSFrfrOiMRx2eJ1hgNjlQrOQEHetVwij90KA==",
"dev": true,
"requires": {
"chalk": "2.4.1",
"diff": "3.5.0",
"jest-get-type": "22.4.3",
"pretty-format": "22.4.3"
"chalk": "^2.0.1",
"diff": "^3.2.0",
"jest-get-type": "^22.4.3",
"pretty-format": "^22.4.3"
}
},
"jest-matcher-utils": {
@ -4084,9 +4100,9 @@
"integrity": "sha512-lsEHVaTnKzdAPR5t4B6OcxXo9Vy4K+kRRbG5gtddY8lBEC+Mlpvm1CJcsMESRjzUhzkz568exMV1hTB76nAKbA==",
"dev": true,
"requires": {
"chalk": "2.4.1",
"jest-get-type": "22.4.3",
"pretty-format": "22.4.3"
"chalk": "^2.0.1",
"jest-get-type": "^22.4.3",
"pretty-format": "^22.4.3"
}
},
"jest-message-util": {
@ -4095,11 +4111,11 @@
"integrity": "sha512-iAMeKxhB3Se5xkSjU0NndLLCHtP4n+GtCqV0bISKA5dmOXQfEbdEmYiu2qpnWBDCQdEafNDDU6Q+l6oBMd/+BA==",
"dev": true,
"requires": {
"@babel/code-frame": "7.0.0-rc.1",
"chalk": "2.4.1",
"micromatch": "2.3.11",
"slash": "1.0.0",
"stack-utils": "1.0.1"
"@babel/code-frame": "^7.0.0-beta.35",
"chalk": "^2.0.1",
"micromatch": "^2.3.11",
"slash": "^1.0.0",
"stack-utils": "^1.0.1"
}
},
"jest-regex-util": {
@ -4114,7 +4130,7 @@
"integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=",
"dev": true,
"requires": {
"is-buffer": "1.1.6"
"is-buffer": "^1.1.5"
}
},
"micromatch": {
@ -4123,19 +4139,19 @@
"integrity": "sha1-hmd8l9FyCzY0MdBNDRUpO9OMFWU=",
"dev": true,
"requires": {
"arr-diff": "2.0.0",
"array-unique": "0.2.1",
"braces": "1.8.5",
"expand-brackets": "0.1.5",
"extglob": "0.3.2",
"filename-regex": "2.0.1",
"is-extglob": "1.0.0",
"is-glob": "2.0.1",
"kind-of": "3.2.2",
"normalize-path": "2.1.1",
"object.omit": "2.0.1",
"parse-glob": "3.0.4",
"regex-cache": "0.4.4"
"arr-diff": "^2.0.0",
"array-unique": "^0.2.1",
"braces": "^1.8.2",
"expand-brackets": "^0.1.4",
"extglob": "^0.3.1",
"filename-regex": "^2.0.0",
"is-extglob": "^1.0.0",
"is-glob": "^2.0.1",
"kind-of": "^3.0.2",
"normalize-path": "^2.0.1",
"object.omit": "^2.0.0",
"parse-glob": "^3.0.4",
"regex-cache": "^0.4.2"
}
},
"normalize-path": {
@ -4144,7 +4160,7 @@
"integrity": "sha1-GrKLVW4Zg2Oowab35vogE3/mrtk=",
"dev": true,
"requires": {
"remove-trailing-separator": "1.1.0"
"remove-trailing-separator": "^1.0.1"
}
},
"pretty-format": {
@ -4153,8 +4169,8 @@
"integrity": "sha512-S4oT9/sT6MN7/3COoOy+ZJeA92VmOnveLHgrwBE3Z1W5N9S2A1QGNYiE1z75DAENbJrXXUb+OWXhpJcg05QKQQ==",
"dev": true,
"requires": {
"ansi-regex": "3.0.0",
"ansi-styles": "3.2.1"
"ansi-regex": "^3.0.0",
"ansi-styles": "^3.2.0"
}
}
}

View File

@ -62,7 +62,7 @@
"husky": "^0.14.3",
"cz-conventional-changelog": "^2.1.0",
"jest": "^23.5.0",
"jest-extended": "^0.8.1",
"jest-extended": "^0.9.0",
"jest-tap-reporter": "^1.9.0",
"ts-jest": "^23.1.4",
"tslint": "^5.11.0",

View File

@ -177,7 +177,7 @@ class RequestHelper {
}
static get(service, endpoint, options = {}, { stream = false } = {}) {
return RequestHelper.request('get', service, endpoint, options, stream);
return RequestHelper.request('get', service, endpoint, options, false, stream);
}
static post(service, endpoint, options = {}, form = false) {

9
src/services/Markdown.ts Normal file
View File

@ -0,0 +1,9 @@
import { BaseService, RequestHelper } from '../infrastructure';
class Markdown extends BaseService {
render(text, options) {
return RequestHelper.post(this, 'markdown', { text, ...options });
}
}
export default Markdown;

50
src/services/Snippets.ts Normal file
View File

@ -0,0 +1,50 @@
import { BaseService, RequestHelper } from '../infrastructure';
class Snippets extends BaseService {
all(options = { public: false }) {
const url = options.public ? 'snippets/public' : 'snippets';
return RequestHelper.get(this, url, options);
}
content(snippetId) {
const sId = encodeURIComponent(snippetId);
return RequestHelper.get(this, `snippets/${sId}/raw`);
}
create(title, fileName, content, visibility, options = {}) {
return RequestHelper.post(this, 'snippets', {
title,
fileName,
content,
visibility,
...options,
});
}
edit(snippetId, options) {
const sId = encodeURIComponent(snippetId);
return RequestHelper.put(this, `snippets/${sId}`, options);
}
remove(snippetId) {
const sId = encodeURIComponent(snippetId);
return RequestHelper.delete(this, `snippets/${sId}`);
}
show(snippetId) {
const sId = encodeURIComponent(snippetId);
return RequestHelper.get(this, `snippets/${sId}`);
}
userAgentDetails(snippetId) {
const sId = encodeURIComponent(snippetId);
return RequestHelper.get(this, `snippets/${sId}/user_agent_detail`);
}
}
export default Snippets;

View File

@ -30,6 +30,12 @@ class Users extends BaseService {
return RequestHelper.get(this, 'user');
}
edit(userId, options) {
const uId = encodeURIComponent(userId);
return RequestHelper.put(this, `users/${uId}`, options);
}
events(userId, options) {
validateEventOptions(options.action, options.targetType);

View File

@ -79,9 +79,11 @@ export { default as LicenceTemplates } from './LicenceTemplates';
export { default as Lint } from './Lint';
export { default as Namespaces } from './Namespaces';
export { default as NotificationSettings } from './NotificationSettings';
export { default as Markdown } from './Markdown';
export { default as PagesDomains } from './PagesDomains';
export { default as Search } from './Search';
export { default as SidekiqMetrics } from './SidekiqMetrics';
export { default as Snippets } from './Snippets';
export { default as SystemHooks } from './SystemHooks';
export { default as Version } from './Version';
export { default as Wikis } from './Wikis';

View File

@ -8,10 +8,12 @@ class ResourceMembers extends BaseService {
this.url = URLJoin(this.url, resourceType);
}
all(resourceId) {
all(resourceId, includeInherited = false, options = {}) {
const rId = encodeURIComponent(resourceId);
return RequestHelper.get(this, `${rId}/members`);
const url = includeInherited ? `${rId}/members/all` : `${rId}/members`;
return RequestHelper.get(this, url, { options });
}
add(resourceId, userId, accessLevel, options) {

View File

@ -0,0 +1,15 @@
import { Snippets } from '../../../src';
describe('Snippets', () => {
it('should create snippet', async () => {
const service = new Snippets({
url: process.env.GITLAB_URL,
token: process.env.PERSONAL_ACCESS_TOKEN,
});
const result = await service.create('This is a snippet', 'test.txt', 'Hello world', 'internal', { 'description': 'Hello World snippet' });
expect(result).toBeInstanceOf(Object);
expect(result.title).toEqual('This is a snippet');
});
});