Skip to content

Time tracking #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
34 changes: 22 additions & 12 deletions lib/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright(c) repo-utils and other contributors.
* MIT Licensed
*
* Authors:
* Authors:
* fengmk2 <m@fengmk2.com> (http://fengmk2.com)
*/

Expand All @@ -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',
Expand All @@ -52,25 +57,30 @@ var properties = {
'listNotes',
'createNote',
'getNote',
'updateNote'
'updateNote',
'timeEstimate',
'resetTimeEstimate',
'addSpentTime',
'resetSpentTime',
'timeStats'
],
projects: [
'getByPath',
'listEvents',
'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;
24 changes: 22 additions & 2 deletions lib/resources/issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright(c) repo-utils and other contributors.
* MIT Licensed
*
* Authors:
* Authors:
* fengmk2 <m@fengmk2.com> (http://fengmk2.com)
*/

Expand All @@ -14,7 +14,7 @@
* Module dependencies.
*/

var util = require('util');
var util = require('util');
var RESTFulResource = require('restful-client').RESTFulResource;

module.exports = Issue;
Expand All @@ -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);
};
24 changes: 22 additions & 2 deletions lib/resources/merge_request.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var util = require('util');
var util = require('util');
var RESTFulResource = require('restful-client').RESTFulResource;

module.exports = MergeRequest;
Expand Down Expand Up @@ -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);
};
70 changes: 55 additions & 15 deletions test/issue.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
});
});

});