Skip to content

Commit

Permalink
Adding issue links and file upload
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalrymple committed Jul 30, 2017
1 parent 93aa534 commit 6f77ee0
Show file tree
Hide file tree
Showing 23 changed files with 55 additions and 22 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ MIT

Changelog
=========

[1.0.12](https://github.com/jdalrymple/node-gitlab-api/commit/) (2017-07-30)
------------------
- Added issue links (for related issues)
- Fixed project file upload

[1.0.11](https://github.com/jdalrymple/node-gitlab-api/commit/af4eb6955f583b5be4a4032d2d532d81bb2cf54d) (2017-07-20)
------------------
- Fixing the problem where Id was used instead of IId's for Project issues
Expand Down
18 changes: 18 additions & 0 deletions src/API.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Request = require('request-promise');

const { Groups, Projects, Issues, Runners, Users, Labels } = require('./Models');

function defaultRequestWithQS(url, endpoint, headers, options) {
Expand All @@ -19,6 +20,15 @@ function defaultRequestWithBody(url, endpoint, headers, options) {
};
}

function defaultRequestWithFormData(url, endpoint, headers, options) {
return {
url: url + endpoint,
headers,
json: true,
formData: options,
};
}

class API {
constructor({ url = 'https://gitlab.com', token, oauthToken }) {
this.url = `${url}/api/v4/`;
Expand Down Expand Up @@ -48,6 +58,14 @@ class API {
return Request.post(defaultRequestWithBody(this.url, endpoint, this.headers, options));
}

postForm(endpoint, options) {
const formHeader = Object.assign(this.headers, {
'content-type': 'multipart/form-data',
});

return Request.post(defaultRequestWithFormData(this.url, endpoint, formHeader, options));
}

put(endpoint, options) {
return Request.put(defaultRequestWithBody(this.url, endpoint, this.headers, options));
}
Expand Down
4 changes: 4 additions & 0 deletions src/BaseModel.js → src/Models/BaseModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class BaseModel {
return this.client.post(endpoint, options);
}

postForm(endpoint, options) {
return this.client.postForm(endpoint, options);
}

put(endpoint, options) {
return this.client.put(endpoint, options);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Groups.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BaseModel = require('../BaseModel');
const BaseModel = require('./BaseModel');
const Utils = require('../Utils');

const ACCESS_LEVELS = {
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Issues.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BaseModel = require('../BaseModel');
const BaseModel = require('./BaseModel');
const Utils = require('../Utils');

class Issues extends BaseModel {
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Labels.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BaseModel = require('../BaseModel');
const BaseModel = require('./BaseModel');
const Utils = require('../Utils');

class Labels extends BaseModel {
Expand Down
2 changes: 1 addition & 1 deletion src/Models/ProjectDeployKeys.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BaseModel = require('../BaseModel');
const BaseModel = require('./BaseModel');
const Utils = require('../Utils');

class ProjectKeys extends BaseModel {
Expand Down
2 changes: 1 addition & 1 deletion src/Models/ProjectHooks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BaseModel = require('../BaseModel');
const BaseModel = require('./BaseModel');
const Utils = require('../Utils');

class ProjectHooks extends BaseModel {
Expand Down
2 changes: 1 addition & 1 deletion src/Models/ProjectIssueNotes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BaseModel = require('../BaseModel');
const BaseModel = require('./BaseModel');
const Utils = require('../Utils');

class ProjectIssueNotes extends BaseModel {
Expand Down
2 changes: 1 addition & 1 deletion src/Models/ProjectIssues.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BaseModel = require('../BaseModel');
const BaseModel = require('./BaseModel');
const Utils = require('../Utils');
const ProjectIssueNotes = require('./ProjectIssueNotes');

Expand Down
2 changes: 1 addition & 1 deletion src/Models/ProjectLabels.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BaseModel = require('../BaseModel');
const BaseModel = require('./BaseModel');
const Utils = require('../Utils');

class ProjectLabels extends BaseModel {
Expand Down
2 changes: 1 addition & 1 deletion src/Models/ProjectMembers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BaseModel = require('../BaseModel');
const BaseModel = require('./BaseModel');
const Utils = require('../Utils');

class ProjectMembers extends BaseModel {
Expand Down
2 changes: 1 addition & 1 deletion src/Models/ProjectMergeRequests.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BaseModel = require('../BaseModel');
const BaseModel = require('./BaseModel');
const Utils = require('../Utils');

class ProjectMergeRequests extends BaseModel {
Expand Down
2 changes: 1 addition & 1 deletion src/Models/ProjectMilestones.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BaseModel = require('../BaseModel');
const BaseModel = require('./BaseModel');
const Utils = require('../Utils');

class ProjectMilestones extends BaseModel {
Expand Down
2 changes: 1 addition & 1 deletion src/Models/ProjectPipelines.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BaseModel = require('../BaseModel');
const BaseModel = require('./BaseModel');
const Utils = require('../Utils');

class Pipelines extends BaseModel {
Expand Down
2 changes: 1 addition & 1 deletion src/Models/ProjectRepository.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BaseModel = require('../BaseModel');
const BaseModel = require('./BaseModel');
const Utils = require('../Utils');

class ProjectRepository extends BaseModel {
Expand Down
2 changes: 1 addition & 1 deletion src/Models/ProjectRunners.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BaseModel = require('../BaseModel');
const BaseModel = require('./BaseModel');
const Utils = require('../Utils');

class ProjectRunners extends BaseModel {
Expand Down
2 changes: 1 addition & 1 deletion src/Models/ProjectServices.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BaseModel = require('../BaseModel');
const BaseModel = require('./BaseModel');
const Utils = require('../Utils');

class ProjectServices extends BaseModel {
Expand Down
2 changes: 1 addition & 1 deletion src/Models/ProjectTriggers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BaseModel = require('../BaseModel');
const BaseModel = require('./BaseModel');
const Utils = require('../Utils');

class ProjectTriggers extends BaseModel {
Expand Down
11 changes: 8 additions & 3 deletions src/Models/Projects.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const BaseModel = require('../BaseModel');
const BaseModel = require('./BaseModel');
const Fs = require('fs');
const Utils = require('../Utils');
const ProjectMembers = require('./ProjectMembers');
const ProjectHooks = require('./ProjectHooks');
Expand Down Expand Up @@ -106,9 +107,13 @@ class Projects extends BaseModel {

upload(projectId, filePath) {
const pId = Utils.parse(projectId);
const file = Fs.readFileSync(filePath);

return this.post(`projects/${pId}/uploads`, {
file: filePath,
return this.postForm(`projects/${pId}/uploads`, {
file: {
value: file,
contentType: 'application/octet-stream',
},
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Runners.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BaseModel = require('../BaseModel');
const BaseModel = require('./BaseModel');
const Utils = require('../Utils');

class Runners extends BaseModel {
Expand Down
2 changes: 1 addition & 1 deletion src/Models/UserKeys.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BaseModel = require('../BaseModel');
const BaseModel = require('./BaseModel');
const Utils = require('../Utils');

class UserKeys extends BaseModel {
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Users.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BaseModel = require('../BaseModel');
const BaseModel = require('./BaseModel');
const UserKeys = require('./UserKeys');
const Utils = require('../Utils');

Expand Down

0 comments on commit 6f77ee0

Please sign in to comment.