See Changelog:

This commit is contained in:
Justin Dalrymple 2017-07-20 15:29:57 -04:00
parent 9341972d97
commit af4eb6955f
27 changed files with 446 additions and 396 deletions

View File

@ -1,11 +1,17 @@
{
"parser": "babel-eslint",
"env": {
"browser": true,
"node": true
},
"extends": "airbnb",
rules:{
arrow-body-style: [2, "as-needed"]
}
"parser": "babel-eslint",
"env":
{
"browser": true,
"node": true
},
"extends": "airbnb",
"rules": {
"arrow-body-style": [2, "as-needed"],
"no-param-reassign": [
"error", {
"props": false
}
]
}
}

View File

@ -87,6 +87,14 @@ MIT
Changelog
=========
[1.0.11](https://github.com/jdalrymple/node-gitlab-api/commit/) (2017-07-20)
------------------
- Fixing the problem where Id was used instead of IId's for Project issues
- Fixing the naming convention for Project Issues
- Standadized the use of parseInt in the codebase
- Removed instances of duplicate code found by code climate
[1.0.10](https://github.com/jdalrymple/node-gitlab-api/commit/c4a55aba89d83fda1552b3d5688b090b0c2b60aa) (2017-07-13)
------------------
- Fixing Issues #1, #2, and #3

View File

@ -21,7 +21,7 @@
"devDependencies": {
"babel-eslint": "^7.1.1",
"babel-preset-latest": "^6.16.0",
"eslint": "^3.14.0",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^14.0.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^3.0.2",

View File

@ -1,17 +1,35 @@
const Request = require('request-promise');
const { Groups, Projects, Issues, Runners, Users, Labels } = require('./Models');
function defaultRequestWithQS(url, endpoint, headers, options) {
return {
url: url + endpoint,
headers,
json: true,
qs: options,
};
}
function defaultRequestWithBody(url, endpoint, headers, options) {
return {
url: url + endpoint,
headers,
json: true,
body: options,
};
}
class API {
constructor({ url = 'https://gitlab.com', token, oauthToken }) {
this.url = `${url}/api/v4/`;
this.headers = {}
this.headers = {};
if (oauthToken) {
this.headers.Authorization = `Bearer ${oauthToken}`;
} else if (token) {
this.headers['private-token'] = token;
} else {
throw "`token` (private-token) or `oauth_token` is mandatory"
throw new Error('`token` (private-token) or `oauth_token` is mandatory');
}
this.groups = new Groups(this);
@ -39,22 +57,4 @@ class API {
}
}
function defaultRequestWithQS(url, endpoint, headers, options) {
return {
url: url + endpoint,
headers: headers,
json: true,
qs: options
}
}
function defaultRequestWithBody(url, endpoint, headers, options) {
return {
url: url + endpoint,
headers: headers,
json: true,
body: options
}
}
module.exports = API;
module.exports = API;

View File

@ -1,21 +1,21 @@
class BaseModel {
constructor(APIClient){
constructor(APIClient) {
this.client = APIClient;
}
get(endpoint, options){
get(endpoint, options) {
return this.client.get(endpoint, options);
}
post(endpoint, options){
post(endpoint, options) {
return this.client.post(endpoint, options);
}
put(endpoint, options){
put(endpoint, options) {
return this.client.put(endpoint, options);
}
delete(endpoint, options){
delete(endpoint, options) {
return this.client.delete(endpoint, options);
}
}

View File

@ -1,104 +1,105 @@
const BaseModel = require('../BaseModel');
const Utils = require('utils');
const Utils = require('../Utils');
class Groups extends BaseModel {
constructor(...args){
super(...args);
this.access_levels = {
GUEST: 10,
REPORTER: 20,
DEVELOPER: 30,
MASTER: 40,
OWNER: 50
}
}
all(options = {}) {
Utils.defaultPaging(options);
return this.get("groups", options);
}
show(groupId) {
groupId = Utils.parse(groupId);
return this.get(`groups/${groupId}`);
}
listMembers(groupId) {
groupId = Utils.parse(groupId);
return this.get(`groups/${groupId}/members`);
}
addMember(groupId, userId, accessLevel) {
hasAccess.call(this);
[groupId,userId] = [groupId,userId].map(Utils.parse);
return this.post(`groups/${groupId}/members`, {
user_id: userId,
access_level: accessLevel
});
}
editMember(groupId, userId, accessLevel) {
hasAccess.call(this);
[groupId,userId] = [groupId,userId].map(Utils.parse);
return this.put(`groups/${groupId}/members/${userId}`, {
access_level: accessLevel
});
}
removeMember(groupId, userId) {
[groupId,userId] = Array.from(arguments).map(Utils.parse);
return this.delete(`groups/${groupId}/members/${userId}`);
}
create(options = {}) {
return this.post("groups", options);
}
listProjects(groupId) {
groupId = Utils.parse(groupId);
return this.get(`groups/${groupId}/projects`);
}
addProject(groupId, projectId) {
[groupId,projectId] = Array.from(arguments).map(Utils.parse);
return this.post(`groups/${groupId}/projects/${projectId}`);
}
deleteGroup(groupId) {
groupId = Utils.parse(groupId);
return this.delete(`groups/${groupId}`);
}
search(nameOrPath) {
return this.get("groups", options, {
search: nameOrPath
});
}
}
function hasAccess(){
function hasAccess() {
let access_level;
let hasAccess;
for (let k in this.access_levels) {
access_level = this.access_levels[k];
if (accessLevel === access_level) {
hasAccess = true;
if (accessLevel === access_level) {
hasAccess = true;
}
}
if (!hasAccess) throw `\`accessLevel\` must be one of ${JSON.stringify(this.access_levels)}`;
}
class Groups extends BaseModel {
constructor(...args) {
super(...args);
this.access_levels = {
GUEST: 10,
REPORTER: 20,
DEVELOPER: 30,
MASTER: 40,
OWNER: 50,
};
}
all(options = {}) {
Utils.defaultPaging(options);
return this.get('groups', options);
}
show(groupId) {
const gId = Utils.parse(groupId);
return this.get(`groups/${gId}`);
}
listMembers(groupId) {
const gId = Utils.parse(groupId);
return this.get(`groups/${gId}/members`);
}
addMember(groupId, userId, accessLevel) {
const [gId, uId] = [groupId, userId].map(Utils.parse);
hasAccess.call(this);
return this.post(`groups/${gId}/members`, {
user_id: uId,
access_level: accessLevel,
});
}
editMember(groupId, userId, accessLevel) {
const [gId, uId] = [groupId, userId].map(Utils.parse);
hasAccess.call(this);
return this.put(`groups/${gId}/members/${uId}`, {
access_level: accessLevel,
});
}
removeMember(groupId, userId) {
const [gId, uId] = [groupId, userId].map(Utils.parse);
return this.delete(`groups/${gId}/members/${uId}`);
}
create(options = {}) {
return this.post('groups', options);
}
listProjects(groupId) {
const gId = Utils.parse(groupId);
return this.get(`groups/${gId}/projects`);
}
addProject(groupId, projectId) {
const [gId, pId] = [groupId, projectId].map(Utils.parse);
return this.post(`groups/${gId}/projects/${pId}`);
}
deleteGroup(groupId) {
const gId = Utils.parse(groupId);
return this.delete(`groups/${gId}`);
}
search(nameOrPath) {
return this.get('groups', {
search: nameOrPath,
});
}
}
module.exports = Groups;

View File

@ -2,16 +2,11 @@ const BaseModel = require('../BaseModel');
const Utils = require('../Utils');
class Issues extends BaseModel {
constructor(...args) {
super(...args);
}
all(options = {}) {
Utils.defaultPaging(options);
return this.get("issues", options);
return this.get('issues', options);
}
}
module.exports = Issues;

View File

@ -2,47 +2,44 @@ const BaseModel = require('../BaseModel');
const Utils = require('../Utils');
class Labels extends BaseModel {
constructor(...args) {
super(...args);
}
all(projectId, options = {}) {
const pId = Utils.parse(projectId);
Utils.defaultPaging(options);
projectId = Utils.parse(projectId);
return this.get(`projects/${projectId}/labels`, options);
return this.get(`projects/${pId}/labels`, options);
}
create(projectId, options = {}) {
projectId = Utils.parse(projectId);
const pId = Utils.parse(projectId);
return this.post(`projects/${projectId}/labels`, options);
return this.post(`projects/${pId}/labels`, options);
}
edit(projectId, labelName, options = {}) {
projectId = Utils.parse(projectId);
options.name = labelName
const pId = Utils.parse(projectId);
return this.put(`projects/${projectId}/labels`, options);
options.name = labelName;
return this.put(`projects/${pId}/labels`, options);
}
remove(projectId, labelName) {
projectId = Utils.parse(projectId);
const pId = Utils.parse(projectId);
return this.delete(`projects/${projectId}/labels`, { name: labelName });
return this.delete(`projects/${pId}/labels`, { name: labelName });
}
subscribe(projectId, labelId, options = {}) {
[projectId, labelId] = [projectId, labelId].map(Utils.parse);
const [pId, lId] = [projectId, labelId].map(Utils.parse);
return this.post(`projects/${projectId}/issues/${labelId}/subscribe`, options);
return this.post(`projects/${pId}/issues/${lId}/subscribe`, options);
}
unsubscribe(projectId, labelId) {
[projectId, labelId] = [projectId, labelId].map(Utils.parse);
const [pId, lId] = [projectId, labelId].map(Utils.parse);
return this.delete(`projects/${projectId}/issues/${labelId}/unsubscribe`);
return this.delete(`projects/${pId}/issues/${lId}/unsubscribe`);
}
}

View File

@ -2,27 +2,23 @@ const BaseModel = require('../BaseModel');
const Utils = require('../Utils');
class ProjectKeys extends BaseModel {
constructor(...args) {
super(...args);
}
listKeys(projectId) {
projectId = Utils.parse(projectId);
const pId = Utils.parse(projectId);
return this.get(`projects/${projectId}/deploy_keys`);
return this.get(`projects/${pId}/deploy_keys`);
}
getKey(projectId, keyId) {
[groupId, keyId] = Array.from(arguments).map(Utils.parse);
const [pId, kId] = [projectId, keyId].map(Utils.parse);
return this.get(`projects/${projectId}/deploy_keys/${keyId}`);
return this.get(`projects/${pId}/deploy_keys/${kId}`);
}
addKey(projectId, options = {}) {
projectId = Utils.parse(projectId);
const pId = Utils.parse(projectId);
return this.post(`projects/${projectId}/deploy_keys`, options);
return this.post(`projects/${pId}/deploy_keys`, options);
}
}
module.exports = ProjectKeys;
module.exports = ProjectKeys;

View File

@ -2,42 +2,36 @@ const BaseModel = require('../BaseModel');
const Utils = require('../Utils');
class ProjectHooks extends BaseModel {
constructor(...args) {
super(...args);
}
list(projectId) {
projectId = Utils.parse(projectId);
const pId = Utils.parse(projectId);
return this.get(`projects/${projectId}/hooks`);
return this.get(`projects/${pId}/hooks`);
}
show(projectId, hookId) {
[projectId, hookId] = Array.from(arguments).map(Utils.parse);
const [pId, hId] = [projectId, hookId].map(Utils.parse);
return this.get(`projects/${projectId}/hooks/${hookId}`);
return this.get(`projects/${pId}/hooks/${hId}`);
}
add(projectId, options) {
if (typeof options === 'string') options = { url: options };
projectId = Utils.parse(projectId);
add(projectId, url, options = {}) {
options.url = url;
const pId = Utils.parse(projectId);
return this.post(`projects/${projectId}/hooks`, options);
return this.post(`projects/${pId}/hooks`, options);
}
edit(projectId, hookId, url) {
[projectId, hookId] = [projectId, hookId].map(Utils.parse);
edit(projectId, hookId, url, options) {
const [pId, hId] = [projectId, hookId].map(Utils.parse);
return this.put(`projects/${projectId}/hooks/${hookId}`, {
access_level: parseInt(accessLevel)
});
return this.put(`projects/${pId}/hooks/${hId}`, options);
}
remove(projectId, hookId) {
[projectId, hookId] = Array.from(arguments).map(Utils.parse);
const [pId, hId] = [projectId, hookId].map(Utils.parse);
return this.delete(`projects/${projectId}/hooks/${hookId}`);
return this.delete(`projects/${pId}/hooks/${hId}`);
}
}
module.exports = ProjectHooks;
module.exports = ProjectHooks;

View File

@ -1,45 +1,42 @@
const BaseModel = require('../BaseModel');
const Utils = require('../Utils');
class ProjectNotes extends BaseModel {
constructor(...args) {
super(...args);
}
class ProjectIssueNotes extends BaseModel {
all(projectId, issueIId, options = {}) {
const [pId, iIId] = [projectId, issueIId].map(Utils.parse);
all(projectId, issueId, options = {}) {
Utils.defaultPaging(options);
[projectId, issueId] = [projectId, issueId].map(Utils.parse);
return this.get(`projects/${projectId}/issues/${issueId}/notes`, options);
return this.get(`projects/${pId}/issues/${iIId}/notes`, options);
}
create(projectId, issueId, options = {}) {
if(!options.body) throw new Error('Missing required property: body');
create(projectId, issueIId, options = {}) {
if (!options.body) throw new Error('Missing required property: body');
[projectId, issueId] = [projectId, issueId].map(Utils.parse);
const [pId, iIId] = [projectId, issueIId].map(Utils.parse);
return this.post(`projects/${projectId}/issues/${issueId}/notes`, options);
return this.post(`projects/${pId}/issues/${iIId}/notes`, options);
}
edit(projectId, issueId, noteId, options = {}) {
if(!options.body) throw new Error('Missing required property: body');
edit(projectId, issueIId, noteId, options = {}) {
if (!options.body) throw new Error('Missing required property: body');
[projectId, issueId, noteId] = [projectId, issueId, noteId].map(Utils.parse)
const [pId, iIId, nId] = [projectId, issueIId, noteId].map(Utils.parse);
return this.put(`projects/${projectId}/issues/${issueId}/notes/${noteId}`, options);
return this.put(`projects/${pId}/issues/${iIId}/notes/${nId}`, options);
}
remove(projectId, issueId, nodeId) {
[projectId, issueId, noteId] = Array.from(arguments).map(Utils.parse)
remove(projectId, issueIId, noteId) {
const [pId, iIId, nId] = [projectId, issueIId, noteId].map(Utils.parse);
return this.delete(`projects/${projectId}/issues/${issueId}/notes/${noteId}`);
return this.delete(`projects/${pId}/issues/${iIId}/notes/${nId}`);
}
show(projectId, issueId, noteId) {
[projectId, issueId, noteId] = Array.from(arguments).map(Utils.parse)
show(projectId, issueIId, noteId) {
const [pId, iIId, nId] = [projectId, issueIId, noteId].map(Utils.parse);
return this.get(`projects/${projectId}/issues/${issueId}/notes/${noteId}`);
return this.get(`projects/${pId}/issues/${iIId}/notes/${nId}`);
}
}
module.exports = ProjectNotes;
module.exports = ProjectIssueNotes;

View File

@ -6,53 +6,51 @@ class ProjectIssues extends BaseModel {
constructor(...args) {
super(...args);
this.notes = ProjectIssueNotes;
this.notes = new ProjectIssueNotes(...args);
}
all(projectId, options = {}) {
const pId = Utils.parse(projectId);
Utils.defaultPaging(options);
projectId = Utils.parse(projectId);
return this.get(`projects/${projectId}/issues`, options);
return this.get(`projects/${pId}/issues`, options);
}
create(projectId, options = {}) {
projectId = Utils.parse(projectId);
const pId = Utils.parse(projectId);
return this.post(`projects/${projectId}/issues`, options);
return this.post(`projects/${pId}/issues`, options);
}
edit(projectId, issueId, options = {}) {
[projectId, issueId] = [projectId, issueId].map(Utils.parse)
const [pId, iId] = [projectId, issueId].map(Utils.parse);
return this.put(`projects/${projectId}/issues/${issueId}`, options);
return this.put(`projects/${pId}/issues/${iId}`, options);
}
remove(projectId, issueId) {
[projectId, issueId] = Array.from(arguments).map(Utils.parse)
const [pId, iId] = [projectId, issueId].map(Utils.parse);
return this.delete(`projects/${projectId}/issues/${issueId}`);
return this.delete(`projects/${pId}/issues/${iId}`);
}
show(projectId, issueId) {
[projectId, issueId] = Array.from(arguments).map(Utils.parse)
const [pId, iId] = [projectId, issueId].map(Utils.parse);
return this.get(`projects/${projectId}/issues/${issueId}`);
return this.get(`projects/${pId}/issues/${iId}`);
}
subscribe(projectId, issueId, options = {}) {
[projectId, issueId] = Array.from(arguments).map(Utils.parse)
const [pId, iId] = [projectId, issueId].map(Utils.parse);
return this.post(`projects/${projectId}/issues/${issueId}/subscribe`, options);
return this.post(`projects/${pId}/issues/${iId}/subscribe`, options);
}
unsubscribe(projectId, issueId) {
[projectId, issueId] = Array.from(arguments).map(Utils.parse)
const [pId, iId] = [projectId, issueId].map(Utils.parse);
return this.delete(`projects/${projectId}/issues/${issueId}/unsubscribe`);
return this.delete(`projects/${pId}/issues/${iId}/unsubscribe`);
}
}

View File

@ -2,15 +2,12 @@ const BaseModel = require('../BaseModel');
const Utils = require('../Utils');
class ProjectLabels extends BaseModel {
constructor(...args) {
super(...args);
}
all(projectId, options = {}) {
Utils.defaultPaging(options);
projectId = Utils.parse(projectId);
const pId = Utils.parse(projectId);
return this.get(`projects/${projectId}/labels`, options);
Utils.defaultPaging(options);
return this.get(`projects/${pId}/labels`, options);
}
}

View File

@ -2,44 +2,40 @@ const BaseModel = require('../BaseModel');
const Utils = require('../Utils');
class ProjectMembers extends BaseModel {
constructor(...args) {
super(...args);
}
list(projectId) {
projectId = Utils.parse(projectId);
const pId = Utils.parse(projectId);
return this.get(`projects/${projectId}/members`);
return this.get(`projects/${pId}/members`);
}
show(projectId, userId) {
[projectId, userId] = Array.from(arguments).map(Utils.parse)
const [pId, uId] = [projectId, userId].map(Utils.parse);
return this.get(`projects/${projectId}/members/${userId}`);
return this.get(`projects/${pId}/members/${uId}`);
}
add(projectId, userId, accessLevel = 30) {
[projectId, userId] = [projectId, userId].map(Utils.parse)
const [pId, uId] = [projectId, userId].map(Utils.parse);
return this.post(`projects/${projectId}/members`, {
user_id: userId,
access_level: parseInt(accessLevel)
return this.post(`projects/${pId}/members`, {
user_id: uId,
access_level: parseInt(accessLevel, 10),
});
}
edit(projectId, userId, accessLevel = 30) {
[projectId, userId] = [projectId, userId].map(Utils.parse)
const [pId, uId] = [projectId, userId].map(Utils.parse);
return this.put(`projects/${projectId}/members/${userId}`, {
access_level: parseInt(accessLevel)
return this.put(`projects/${pId}/members/${uId}`, {
access_level: parseInt(accessLevel, 10),
});
}
remove(projectId, userId) {
[projectId, issueId] = Array.from(arguments).map(Utils.parse)
const [pId, uId] = [projectId, userId].map(Utils.parse);
return this.delete(`projects/${projectId}/members/${userId}`);
return this.delete(`projects/${pId}/members/${uId}`);
}
}
module.exports = ProjectMembers;
module.exports = ProjectMembers;

View File

@ -2,57 +2,51 @@ const BaseModel = require('../BaseModel');
const Utils = require('../Utils');
class ProjectMergeRequests extends BaseModel {
constructor(...args) {
super(...args);
}
list(projectId, options = {}) {
const pId = Utils.parse(projectId);
Utils.defaultPaging(options);
projectId = Utils.parse(projectId);
return this.get(`projects/${Utils.parse(projectId)}/merge_requests`, options);
return this.get(`projects/${pId}/merge_requests`, options);
}
show(projectId, mergeRequestId) {
[projectId, hookId] = Array.from(arguments).map(Utils.parse);
show(projectId, mergerequestId) {
const [pId, mId] = [projectId, mergerequestId].map(Utils.parse);
return this.get(`projects/${projectId}/merge_requests/${mergerequestId}`);
return this.get(`projects/${pId}/merge_requests/${mId}`);
}
add(projectId, sourceBranch, targetBranch, assigneeId, title) {
[projectId, assigneeId] = [projectId, assigneeId].map(Utils.parse);
const [pId, aId] = [projectId, assigneeId].map(Utils.parse);
let options = {
id: projectId,
const options = {
id: pId,
source_branch: sourceBranch,
target_branch: targetBranch,
title
title,
};
if (assigneeId !== undefined) options.assigneeId = assigneeId;
if (assigneeId !== undefined) options.assigneeId = aId;
return this.post(`projects/${projectId}/merge_requests`, options);
return this.post(`projects/${pId}/merge_requests`, options);
}
update(projectId, mergerequestId, options = {}) {
[projectId, mergerequestId] = [projectId, mergerequestId].map(Utils.parse);
const [pId, mId] = [projectId, mergerequestId].map(Utils.parse);
options.id = projectId;
options.merge_request_id = mergerequestId;
options.id = pId;
options.merge_request_id = mId;
return this.put(`projects/${projectId}/merge_requests/${mergerequestId}`, options);
return this.put(`projects/${pId}/merge_requests/${mId}`, options);
}
comment(projectId, mergerequestId, note) {
[projectId, mergerequestId] = [projectId, mergerequestId].map(Utils.parse);
const [pId, mId] = [projectId, mergerequestId].map(Utils.parse);
return this.post(`projects/${projectId}/merge_requests/${mergerequestId}/comments`, {
id: projectId,
merge_request_id: mergerequestId,
note
return this.post(`projects/${pId}/merge_requests/${mId}/comments`, {
body: note,
});
}
}
module.exports = ProjectMergeRequests;
module.exports = ProjectMergeRequests;

View File

@ -2,36 +2,38 @@ const BaseModel = require('../BaseModel');
const Utils = require('../Utils');
class ProjectMilestones extends BaseModel {
constructor(...args) {
super(...args);
}
all(projectId, options = {}) {
const pId = Utils.parse(projectId);
Utils.defaultPaging(options);
return this.get(`projects/${Utils.parse(projectId)}/milestones`, options);
return this.get(`projects/${pId}/milestones`, options);
}
show(projectId, milestoneId) {
return this.get(`projects/${Utils.parse(projectId)}/milestones/${parseInt(milestoneId)}`);
const [pId, mId] = [projectId, milestoneId].map(Utils.parse);
return this.get(`projects/${pId}/milestones/${mId}`);
}
add(projectId, title, { description, due_date }) {
return this.post(`projects/${Utils.parse(projectId)}/milestones`, {
id: Utils.parse(projectId),
const pId = Utils.parse(projectId);
return this.post(`projects/${pId}/milestones`, {
title,
description,
due_date
due_date,
});
}
update(projectId, milestoneId, { title, description, due_date, state_event }) {
return this.put(`projects/${Utils.parse(projectId)}/milestones/${parseInt(milestoneId)}`, {
id: Utils.parse(projectId),
const [pId, mId] = [projectId, milestoneId].map(Utils.parse);
return this.put(`projects/${pId}/milestones/${mId}`, {
title,
description,
due_date,
state_event
state_event,
});
}
}

View File

@ -2,13 +2,11 @@ const BaseModel = require('../BaseModel');
const Utils = require('../Utils');
class Pipelines extends BaseModel {
constructor(...args) {
super(...args);
}
all(projectId) {
return this.get(`projects/${Utils.parse(projectId)}/pipelines`);
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}/pipelines`);
}
}
module.exports = Pipelines
module.exports = Pipelines;

View File

@ -2,84 +2,118 @@ const BaseModel = require('../BaseModel');
const Utils = require('../Utils');
class ProjectRepository extends BaseModel {
constructor(...args) {
super(...args);
}
listBranches(projectId) {
return this.get(`projects/${Utils.parse(projectId)}/repository/branches`);
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}/repository/branches`);
}
showBranch(projectId, branchId) {
return this.get(`projects/${Utils.parse(projectId)}/repository/branches/${encodeURI(branchId)}`);
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}/repository/branches/${encodeURI(branchId)}`);
}
protectBranch(projectId, branchId) {
return this.put(`projects/${Utils.parse(projectId)}/repository/branches/${encodeURI(branchId)}/protect`);
const pId = Utils.parse(projectId);
return this.put(`projects/${pId}/repository/branches/${encodeURI(branchId)}/protect`);
}
unprotectBranch(projectId, branchId) {
return this.put(`projects/${Utils.parse(projectId)}/repository/branches/${encodeURI(branchId)}/unprotect`);
const pId = Utils.parse(projectId);
return this.put(`projects/${pId}/repository/branches/${encodeURI(branchId)}/unprotect`);
}
createBranch(options = {}) {
return this.post(`projects/${Utils.parse(options.projectId)}/repository/branches`, options);
createBranch(projectId, options = {}) {
const pId = Utils.parse(projectId);
return this.post(`projects/${pId}/repository/branches`, options);
}
deleteBranch(projectId, branchId) {
return this.delete(`projects/${Utils.parse(projectId)}/repository/branches/${encodeURI(branchId)}`);
}
const pId = Utils.parse(projectId);
addTag(options = {}) {
return this.post(`projects/${Utils.parse(options.id)}/repository/tags`, options);
return this.delete(`projects/${pId}/repository/branches/${encodeURI(branchId)}`);
}
addTag(projectId, options = {}) {
const pId = Utils.parse(projectId);
return this.post(`projects/${pId}/repository/tags`, options);
}
deleteTag(projectId, tagName) {
return this.delete(`projects/${Utils.parse(projectId)}/repository/tags/${encodeURI(tagName)}`);
const pId = Utils.parse(projectId);
return this.delete(`projects/${pId}/repository/tags/${encodeURI(tagName)}`);
}
showTag(projectId, tagName) {
return this.get(`projects/${Utils.parse(projectId)}/repository/tags/${encodeURI(tagName)}`);
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}/repository/tags/${encodeURI(tagName)}`);
}
listTags(projectId) {
return this.get(`projects/${Utils.parse(projectId)}/repository/tags`);
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}/repository/tags`);
}
listCommits(projectId) {
return this.get(`projects/${Utils.parse(projectId)}/repository/commits`);
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}/repository/commits`);
}
showCommit(projectId, sha) {
return this.get(`projects/${Utils.parse(projectId)}/repository/commits/${sha}`);
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}/repository/commits/${sha}`);
}
diffCommit(projectId, sha) {
return this.get(`projects/${Utils.parse(projectId)}/repository/commits/${sha}/diff`);
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}/repository/commits/${sha}/diff`);
}
listTree(projectId, options = {}) {
return this.get(`projects/${Utils.parse(projectId)}/repository/tree`, options);
listTree(projectId, options = {}) {
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}/repository/tree`, options);
}
showFile(projectId, options = {}) {
const pId = Utils.parse(projectId);
if (options.file_path && options.ref) {
return this.get(`projects/${Utils.parse(projectId)}/repository/files`, options);
return this.get(`projects/${pId}/repository/files`, options);
} else if (options.file_path && options.file_id) {
return this.get(`projects/${Utils.parse(projectId)}/repository/raw_blobs/` + options.file_id, options);
return this.get(`projects/${pId}/repository/raw_blobs/{options.file_id}`, options);
}
return null;
}
createFile(projectId, options = {}) {
return this.post(`projects/${Utils.parse(projectId)}/repository/files`, options);
const pId = Utils.parse(projectId);
return this.post(`projects/${pId}/repository/files`, options);
}
updateFile(projectId, options = {}) {
return this.put(`projects/${Utils.parse(projectId)}/repository/files`, options);
const pId = Utils.parse(projectId);
return this.put(`projects/${pId}/repository/files`, options);
}
compare(projectId, options = {}) {
return this.get(`projects/${Utils.parse(projectId)}/repository/compare`, options);
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}/repository/compare`, options);
}
}

View File

@ -2,26 +2,28 @@ const BaseModel = require('../BaseModel');
const Utils = require('../Utils');
class ProjectRunners extends BaseModel {
constructor(...args) {
super(...args);
}
all(projectId, options = {}) {
const pId = Utils.parse(projectId);
if (projectId != null) {
return this.get(`projects/${Utils.parse(projectId)}/runners`, options);
} else {
return this.get("runners", options);
return this.get(`projects/${pId}/runners`, options);
}
return this.get('runners', options);
}
enable(projectId, runnerId) {
return this.post(`projects/${Utils.parse(projectId)}/runners`, {
runner_id: parseInt(runnerId)
const [pId, rId] = [projectId, runnerId].map(Utils.parse);
return this.post(`projects/${pId}/runners`, {
runner_id: rId,
});
}
disable(projectId, runnerId) {
return this.delete(`projects/${Utils.parse(projectId)}/runners/${parseInt(runnerId)}`);
const [pId, rId] = [projectId, runnerId].map(Utils.parse);
return this.delete(`projects/${pId}/runners/${rId}`);
}
}

View File

@ -2,20 +2,22 @@ const BaseModel = require('../BaseModel');
const Utils = require('../Utils');
class ProjectServices extends BaseModel {
constructor(...args) {
super(...args);
}
show(projectId, serviceName) {
return this.get(`projects/${Utils.parse(projectId)}/services/${serviceName}`);
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}/services/${serviceName}`);
}
update(projectId, serviceName, params = {}) {
return this.put(`projects/${Utils.parse(projectId)}/services/${serviceName}`, params);
update(projectId, serviceName, options = {}) {
const pId = Utils.parse(projectId);
return this.put(`projects/${pId}/services/${serviceName}`, options);
}
remove(projectId, serviceName) {
return this.delete(`projects/${Utils.parse(projectId)}/services/${serviceName}`);
const pId = Utils.parse(projectId);
return this.delete(`projects/${pId}/services/${serviceName}`);
}
}

View File

@ -2,28 +2,34 @@ const BaseModel = require('../BaseModel');
const Utils = require('../Utils');
class ProjectTriggers extends BaseModel {
constructor(...args) {
super(...args);
}
add(projectId, options = {}) {
return this.post(`projects/${Utils.parse(projectId)}/triggers`, options);
const pId = Utils.parse(projectId);
return this.post(`projects/${pId}/triggers`, options);
}
edit(projectId, triggerId, options = {}) {
return this.put(`projects/${Utils.parse(projectId)}/triggers/${Utils.parse(triggerId)}`, options);
const [pId, tId] = [projectId, triggerId].map(Utils.parse);
return this.put(`projects/${pId}/triggers/${tId}`, options);
}
list(projectId) {
return this.get(`projects/${Utils.parse(projectId)}/triggers`);
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}/triggers`);
}
remove(projectId, triggerId) {
return this.delete(`projects/${Utils.parse(projectId)}/triggers/${Utils.parse(triggerId)}`);
const [pId, tId] = [projectId, triggerId].map(Utils.parse);
return this.delete(`projects/${pId}/triggers/${tId}`);
}
show(projectId, triggerId) {
return this.get(`projects/${Utils.parse(projectId)}/triggers/${Utils.parse(triggerId)}`);
const [pId, tId] = [projectId, triggerId].map(Utils.parse);
return this.get(`projects/${pId}/triggers/${tId}`);
}
}

View File

@ -12,8 +12,6 @@ const ProjectServices = require('./ProjectServices');
const ProjectTriggers = require('./ProjectTriggers');
const ProjectRunners = require('./ProjectRunners');
const ProjectPipelines = require('./ProjectPipelines');
const Runners = require('./Runners');
class Projects extends BaseModel {
constructor(...args) {
@ -36,63 +34,81 @@ class Projects extends BaseModel {
all(options = {}) {
Utils.defaultPaging(options);
return this.get("projects", options);
return this.get('projects', options);
}
allAdmin(options = {}) {
Utils.defaultPaging(options);
return this.get("projects/all", options);
return this.get('projects/all', options);
}
create(options = {}) {
if(options.userId){
return this.post(`projects/user/${userId}`, options);
} else {
return this.post("projects", options);
if (options.userId) {
const uId = Utils.parse(options.userId);
return this.post(`projects/user/${uId}`, options);
}
return this.post('projects', options);
}
edit(projectId, options = {}) {
return this.put(`projects/${Utils.parse(projectId)}`, options);
const pId = Utils.parse(projectId);
return this.put(`projects/${pId}`, options);
}
fork(projectId, options = {}) {
return this.post(`projects/${projectId}/fork`, options);
const pId = Utils.parse(projectId);
return this.post(`projects/${pId}/fork`, options);
}
remove(projectId) {
return this.delete(`projects/${Utils.parse(projectId)}`);
const pId = Utils.parse(projectId);
return this.delete(`projects/${pId}`);
}
search(projectName) {
return this.get(`projects`, { search: projectName });
return this.get('projects', { search: projectName });
}
share(projectId, groupId, groupAccess, options) {
if(!groupId || !groupAccess) throw new Error("Missing required arguments");
const pId = Utils.parse(projectId);
if (!groupId || !groupAccess) throw new Error('Missing required arguments');
options.group_id = groupId;
options.groupAccess = groupAccess;
return this.post(`projects/${Utils.parse(projectId)}/share`, options);
return this.post(`projects/${pId}/share`, options);
}
show(projectId) {
return this.get(`projects/${Utils.parse(projectId)}`);
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}`);
}
star(projectId) {
return this.post(`projects/${Utils.parse(projectId)}/star`);
const pId = Utils.parse(projectId);
return this.post(`projects/${pId}/star`);
}
unstar(projectId) {
return this.post(`projects/${Utils.parse(projectId)}/unstar`);
const pId = Utils.parse(projectId);
return this.post(`projects/${pId}/unstar`);
}
upload(projectId, filePath) {
return this.post(`projects/${Utils.parse(projectId)}/uploads`, {
file: filePath
const pId = Utils.parse(projectId);
return this.post(`projects/${pId}/uploads`, {
file: filePath,
});
}
}

View File

@ -2,20 +2,26 @@ const BaseModel = require('../BaseModel');
const Utils = require('../Utils');
class Runners extends BaseModel {
constructor(...args) {
super(...args);
all(options = {}) {
return this.get('runners/all', options);
}
show(runnerId) {
return this.get(`runners/${parseInt(runnerId)}`);
const rId = Utils.parse(runnerId);
return this.get(`runners/${rId}`);
}
update(runnerId, attributes) {
return this.put(`runners/${parseInt(runnerId)}`, attributes);
const rId = Utils.parse(runnerId);
return this.put(`runners/${rId}`, attributes);
}
remove(runnerId, projectId, enable) {
return this.delete(`runners/${parseInt(runnerId)}`);
remove(runnerId) {
const rId = Utils.parse(runnerId);
return this.delete(`runners/${rId}`);
}
}

View File

@ -1,18 +1,19 @@
const BaseModel = require('../BaseModel');
const Utils = require('../Utils');
class UserKeys extends BaseModel {
constructor(...args) {
super(...args);
}
all(userId) {
return this.get(`users/${parseInt(userId)}/keys`);
const uId = Utils.parse(userId);
return this.get(`users/${uId}/keys`);
}
addKey(userId, title, key) {
return this.post(`users/${userId}/keys`, {
const uId = Utils.parse(userId);
return this.post(`users/${uId}/keys`, {
title,
key
key,
});
}
}

View File

@ -1,5 +1,6 @@
const BaseModel = require('../BaseModel');
const UserKeys = require('./UserKeys');
const Utils = require('../Utils');
class Users extends BaseModel {
constructor(...args) {
@ -11,31 +12,33 @@ class Users extends BaseModel {
all(options = {}) {
Utils.defaultPaging(options);
return this.get("users", options);
return this.get('users', options);
}
current() {
return this.get("user");
return this.get('user');
}
show(userId) {
return this.get(`users/${parseInt(userId)}`);
const uId = Utils.parse(userId);
return this.get(`users/${uId}`);
}
create(options = {}) {
return this.post("users", options);
return this.post('users', options);
}
session(email, password) {
return this.post("session", {
return this.post('session', {
email,
password
password,
});
}
search(emailOrUsername) {
return this.get("users", {
search: emailOrUsername
return this.get('users', {
search: emailOrUsername,
});
}
}

View File

@ -5,4 +5,4 @@ const Users = require('./Users');
const Labels = require('./Labels');
const Runners = require('./Runners');
module.exports = {Groups, Projects, Runners, Issues, Users, Labels}
module.exports = { Groups, Projects, Runners, Issues, Users, Labels };

View File

@ -1,15 +1,16 @@
function parse(value){
if (typeof value === "number") return value;
else if (value.toString().includes("/")) return encodeURIComponent(value);
else return parseInt(value,10);
function parse(value) {
if (typeof value === 'number') return value;
else if (value.toString().includes('/')) return encodeURIComponent(value);
return parseInt(value, 10);
}
function defaultPaging(options){
options.page = options.page || 1;
options.per_page = options.per_page || 100;
function defaultPaging(options) {
options.page = options.page || 1;
options.per_page = options.per_page || 100;
}
module.exports = {
parse,
defaultPaging
}
parse,
defaultPaging,
};