diff --git a/README.md b/README.md index cceec83..0e5e2e8 100644 --- a/README.md +++ b/README.md @@ -826,6 +826,53 @@ Parameters: - note_id (required) - The ID of a note - body (required) - The content of a note +#### client.issues.timeEstimate({id, issue_id, duration}) + +Add a time estimate to an issue. + +Parameters: + +- id (required) - The ID of a project +- issue_id (required) - The ID of an issue +- duration (required) - The [duration](https://docs.gitlab.com/ce/workflow/time_tracking.html#configuration) in human format. e.g: 3h30m + +#### client.issues.resetTimeEstimate({id, issue_id}) + +Reset the estimated time on an issue. + +Parameters: + +- id (required) - The ID of a project +- issue_id (required) - The ID of an issue + +#### client.issues.addSpentTime({id, issue_id, duration}) + +Add a spent time for this issue. + +Parameters: + +- id (required) - The ID of a project +- issue_id (required) - The ID of an issue +- duration (required) - The [duration](https://docs.gitlab.com/ce/workflow/time_tracking.html#configuration) in human format. e.g: 3h30m + +#### client.issues.resetSpentTime({id, issue_id}) + +Reset the spent time on an issue. + +Parameters: + +- id (required) - The ID of a project +- issue_id (required) - The ID of an issue + +#### client.issues.timeStats({id, issue_id}) + +Get the time tracking stats for an issue. + +Parameters: + +- id (required) - The ID of a project +- issue_id (required) - The ID of an issue + --- ### Merge Requests @@ -961,6 +1008,53 @@ Parameters: - id (required) - The ID of a project - merge_request_id (required) - The ID of a project merge request +#### client.mergeRequests.timeEstimate({id, issue_id, duration}) + +Add a time estimate to a merge request. + +Parameters: + +- id (required) - The ID of a project +- merge_request_id (required) - The ID of a merge request +- duration (required) - The [duration](https://docs.gitlab.com/ce/workflow/time_tracking.html#configuration) in human format. e.g: 3h30m + +#### client.mergeRequests.resetTimeEstimate({id, issue_id}) + +Reset the estimated time on an issue. + +Parameters: + +- id (required) - The ID of a project +- merge_request_id (required) - The ID of a merge request + +#### client.mergeRequests.addSpentTime({id, issue_id, duration}) + +Add a spent time for this issue. + +Parameters: + +- id (required) - The ID of a project +- merge_request_id (required) - The ID of a merge request +- duration (required) - The [duration](https://docs.gitlab.com/ce/workflow/time_tracking.html#configuration) in human format. e.g: 3h30m + +#### client.mergeRequests.resetSpentTime({id, issue_id}) + +Reset the spent time on an issue. + +Parameters: + +- id (required) - The ID of a project +- merge_request_id (required) - The ID of a merge request + +#### client.mergeRequests.timeStats({id, issue_id}) + +Get the time tracking stats for an issue. + +Parameters: + +- id (required) - The ID of a project +- merge_request_id (required) - The ID of a merge request + --- ### Milestones diff --git a/lib/properties.js b/lib/properties.js index ff15cf9..a417974 100644 --- a/lib/properties.js +++ b/lib/properties.js @@ -4,7 +4,7 @@ * Copyright(c) repo-utils and other contributors. * MIT Licensed * - * Authors: + * Authors: * fengmk2 (http://fengmk2.com) */ @@ -20,18 +20,23 @@ var properties = { milestones: [ 'listIssues', ], - members: [], - hooks: [], - globalHooks: [], - users: [], + members : [], + hooks : [], + globalHooks : [], + users : [], mergeRequests: [ 'listNotes', 'createNote', 'getNote', 'updateNote', - 'merge' + 'merge', + 'timeEstimate', + 'resetTimeEstimate', + 'addSpentTime', + 'resetSpentTime', + 'timeStats' ], - repositoryFiles: [], + repositoryFiles : [], repositoryBranches: [ 'protect', 'unprotect', @@ -52,7 +57,12 @@ var properties = { 'listNotes', 'createNote', 'getNote', - 'updateNote' + 'updateNote', + 'timeEstimate', + 'resetTimeEstimate', + 'addSpentTime', + 'resetSpentTime', + 'timeStats' ], projects: [ 'getByPath', @@ -60,17 +70,17 @@ var properties = { 'fork', 'search', ], - deployKeys: [], + deployKeys : [], projectMembers: [], - groups: [ + groups : [ 'transferProject' ], groupMembers: [], }; for (var key in properties) { - var methods = properties[key]; - properties[key] = defaultMethods.concat(methods); + var methods = properties[key]; + properties[key] = defaultMethods.concat(methods); } module.exports = properties; diff --git a/lib/resources/issue.js b/lib/resources/issue.js index 83630d8..774dfe6 100644 --- a/lib/resources/issue.js +++ b/lib/resources/issue.js @@ -4,7 +4,7 @@ * Copyright(c) repo-utils and other contributors. * MIT Licensed * - * Authors: + * Authors: * fengmk2 (http://fengmk2.com) */ @@ -14,7 +14,7 @@ * Module dependencies. */ -var util = require('util'); +var util = require('util'); var RESTFulResource = require('restful-client').RESTFulResource; module.exports = Issue; @@ -39,3 +39,23 @@ Issue.prototype.getNote = function (params, callback) { Issue.prototype.updateNote = function (params, callback) { this.client.request('put', this.onePath + '/notes/:note_id', params, callback); }; + +Issue.prototype.timeEstimate = function (params, callback) { + this.client.request('post', this.onePath + '/time_estimate', params, callback); +}; + +Issue.prototype.resetTimeEstimate = function (params, callback) { + this.client.request('post', this.onePath + '/reset_time_estimate', params, callback); +}; + +Issue.prototype.addSpentTime = function (params, callback) { + this.client.request('post', this.onePath + '/add_spent_time', params, callback); +}; + +Issue.prototype.resetSpentTime = function (params, callback) { + this.client.request('post', this.onePath + '/reset_spent_time', params, callback); +}; + +Issue.prototype.timeStats = function (params, callback) { + this.client.request('get', this.onePath + '/time_stats', params, callback); +}; \ No newline at end of file diff --git a/lib/resources/merge_request.js b/lib/resources/merge_request.js index ce14237..6f7bd0f 100644 --- a/lib/resources/merge_request.js +++ b/lib/resources/merge_request.js @@ -1,6 +1,6 @@ 'use strict'; -var util = require('util'); +var util = require('util'); var RESTFulResource = require('restful-client').RESTFulResource; module.exports = MergeRequest; @@ -32,4 +32,24 @@ MergeRequest.prototype.merge = function (params, callback) { MergeRequest.prototype.listCommits = function (params, callback) { this.client.request('get', this.onePath + '/commits', params, callback); -} +}; + +MergeRequest.prototype.timeEstimate = function (params, callback) { + this.client.request('post', this.onePath + '/time_estimate', params, callback); +}; + +MergeRequest.prototype.resetTimeEstimate = function (params, callback) { + this.client.request('post', this.onePath + '/reset_time_estimate', params, callback); +}; + +MergeRequest.prototype.addSpentTime = function (params, callback) { + this.client.request('post', this.onePath + '/add_spent_time', params, callback); +}; + +MergeRequest.prototype.resetSpentTime = function (params, callback) { + this.client.request('post', this.onePath + '/reset_spent_time', params, callback); +}; + +MergeRequest.prototype.timeStats = function (params, callback) { + this.client.request('get', this.onePath + '/time_stats', params, callback); +}; diff --git a/test/issue.test.js b/test/issue.test.js index 814ab8b..5ea1edd 100644 --- a/test/issue.test.js +++ b/test/issue.test.js @@ -18,10 +18,10 @@ describe('issue.test.js', function () { before(function (done) { client.createProject(function (err) { client.issues.create({ - id: client.id, - title: 'test title ' + new Date(), + id : client.id, + title : 'test title ' + new Date(), description: '测试 `markdown` \n [abc](/abc)', - labels: 'test,gitlabapi' + labels : 'test,gitlabapi' }, function (err, data) { if (err) { return done(err); @@ -86,20 +86,20 @@ describe('issue.test.js', function () { describe('client.issues.create(), update()', function () { it('should create, update a issue', function (done) { client.issues.create({ - id: client.id, - title: 'test title ' + new Date(), - description: '测试 `markdown` \n [abc](/abc)', - assignee_id: 142, + id : client.id, + title : 'test title ' + new Date(), + description : '测试 `markdown` \n [abc](/abc)', + assignee_id : 142, milestone_id: 117, - labels: 'test,gitlabapi' + labels : 'test,gitlabapi' }, function (err, row) { should.not.exists(err); row.project_id.should.equal(client.id); row.state.should.equal('opened'); client.issues.update({ - id: client.id, - issue_id: row.id, - title: row.title + ' update', + id : client.id, + issue_id : row.id, + title : row.title + ' update', state_event: 'close', }, function (err, row) { should.not.exists(err); @@ -112,16 +112,16 @@ describe('issue.test.js', function () { it('should update a close, reopen and close issue', function (done) { client.issues.update({ - id: client.id, - issue_id: issueId, + id : client.id, + issue_id : issueId, description: 'need to be closed!', state_event: 'close', }, function (err, row) { should.not.exists(err); row.state.should.equal('closed'); client.issues.update({ - id: client.id, - issue_id: issueId, + id : client.id, + issue_id : issueId, description: 'need to be reopen!', state_event: 'reopen', }, function (err, row) { @@ -161,5 +161,45 @@ describe('issue.test.js', function () { }, done); }); }); + + describe('client.issues.timeEstimate()', function () { + it('should add a time estimate', function (done) { + client.issues.timeEstimate({ + id: client.id, issue_id: issueId, duration: '3h30m' + }, done); + }); + }); + + describe('client.issues.resetTimeEstimate()', function () { + it('should reset the time estimate', function (done) { + client.issues.resetTimeEstimate({ + id: client.id, issue_id: issueId + }, done); + }); + }); + + describe('client.issues.addSpentTime()', function () { + it('should add a spent time', function (done) { + client.issues.addSpentTime({ + id: client.id, issue_id: issueId, duration: '3h30m' + }, done); + }); + }); + + describe('client.issues.resetSpentTime()', function () { + it('should reset the spent time', function (done) { + client.issues.timeEstimate({ + id: client.id, issue_id: issueId + }, done); + }); + }); + + describe('client.issues.timeStats()', function () { + it('should return the time stats', function (done) { + client.issues.timeStats({ + id: client.id, issue_id: issueId + }, done); + }); + }); });