Skip to content

Commit cab9467

Browse files
selvagszfengmk2
authored andcommitted
Adds support for MR notes (#20)
* Adds CRUD for MR's notes * Add docs for MR * Accept MR * Fix issue in Merge
1 parent 7ce6dff commit cab9467

File tree

4 files changed

+168
-6
lines changed

4 files changed

+168
-6
lines changed

README.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,134 @@ Parameters:
826826
- note_id (required) - The ID of a note
827827
- body (required) - The content of a note
828828

829+
---
830+
831+
### Merge Requests
832+
833+
https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/merge_requests.md
834+
835+
https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/notes.md#merge-requests
836+
837+
838+
#### client.mergeRequests.list({id})
839+
840+
Get all merge requests for the project. This function accepts pagination parameters page and per_page to return the list of merge requests.
841+
842+
Parameters:
843+
844+
- id (required) - The ID of a project
845+
- iid (optional) - Return the request having the given iid
846+
- state (optional) - Return all requests or just those that are merged, opened or closed
847+
- order_by (optional) - Return requests ordered by created_at or updated_at fields. Default is created_at
848+
- sort (optional) - Return requests sorted in asc or desc order. Default is desc
849+
850+
#### client.mergeRequests.get({id, merge_request_id})
851+
852+
Gets a single project merge request.
853+
854+
Parameters:
855+
856+
- id (required) - The ID of a project
857+
- merge_request_id (required) - The ID of MR
858+
859+
860+
#### client.mergeRequests.create({id, source_branch, target_branch, title})
861+
862+
Creates a new merge request.
863+
864+
Parameters:
865+
866+
- id (required) - The ID of a project
867+
- source_branch (required) - The source branch
868+
- target_branch (required) - The target branch
869+
- assignee_id (optional) - Assignee user ID
870+
- title (required) - Title of MR
871+
- description (optional) - Description of MR
872+
- target_project_id (optional) - The target project (numeric id)
873+
- labels (optional) - Labels for MR as a comma-separated list
874+
- milestone_id (optional) - Milestone ID
875+
876+
877+
If the operation is successful, 200 and the newly created merge request is returned. If an error occurs, an error number and a message explaining the reason is returned.
878+
879+
#### client.mergeRequests.update({id, merge_request_id})
880+
881+
Updates an existing merge request. You can change the target branch, title, or even close the MR.
882+
883+
Parameters:
884+
885+
- id (required) - The ID of a project
886+
- merge_request_id (required) - ID of MR
887+
- target_branch - The target branch
888+
- assignee_id - Assignee user ID
889+
- title - Title of MR
890+
- description - Description of MR
891+
- state_event - New state (close|reopen|merge)
892+
- labels (optional) - Labels for MR as a comma-separated list
893+
- milestone_id (optional) - Milestone ID
894+
895+
If the operation is successful, 200 and the updated merge request is returned. If an error occurs, an error number and a message explaining the reason is returned.
896+
897+
#### client.mergeRequests.merge({id, merge_request_id})
898+
899+
Merge changes submitted with MR using this API.
900+
901+
Parameters:
902+
903+
- id (required) - The ID of a project
904+
- merge_request_id (required) - ID of MR
905+
- merge_commit_message (optional) - Custom merge commit message
906+
- should_remove_source_branch (optional) - if true removes the source branch
907+
- merged_when_build_succeeds (optional) - if true the MR is merge when the build succeeds
908+
909+
If merge success you get 200 OK.
910+
If it has some conflicts and can not be merged - you get 405 and error message 'Branch cannot be merged'.
911+
If merge request is already merged or closed - you get 405 and error message 'Method Not Allowed'
912+
If you don't have permissions to accept this merge request - you'll get a 401
913+
914+
#### client.mergeRequests.listNotes({id, merge_request_id})
915+
916+
Gets a list of all notes/comments for a single merge request.
917+
918+
Parameters:
919+
920+
- id (required) - The ID of a project
921+
- merge_request_id (required) - The ID of a project merge request
922+
923+
924+
#### client.mergeRequests.getNote({id, merge_request_id, note_id})
925+
926+
Returns a single note for a given merge request.
927+
928+
Parameters:
929+
930+
- id (required) - The ID of a project
931+
- merge_request_id (required) - The ID of a project merge request
932+
- note_id (required) - The ID of a merge request note
933+
934+
#### client.mergeRequests.createNote({id, merge_request_id})
935+
936+
Creates a new note for a single merge request.
937+
938+
Parameters:
939+
940+
- id (required) - The ID of a project
941+
- merge_request_id (required) - The ID of a project merge request
942+
- body (required) - The content of a note
943+
944+
#### client.mergeRequests.updateNote({id, merge_request_id, note_id})
945+
946+
Modify existing note of a merge request.
947+
948+
Parameters:
949+
950+
- id (required) - The ID of a project
951+
- merge_request_id (required) - The ID of a project merge request
952+
- note_id (required) - The ID of a note
953+
- body (required) - The content of a note
954+
955+
---
956+
829957
### Milestones
830958

831959
https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/milestones.md

lib/properties.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ var properties = {
2424
hooks: [],
2525
globalHooks: [],
2626
users: [],
27-
mergeRequests: [],
27+
mergeRequests: [
28+
'listNotes',
29+
'createNote',
30+
'getNote',
31+
'updateNote',
32+
'merge'
33+
],
2834
repositoryFiles: [],
2935
repositoryBranches: [
3036
'protect',
@@ -44,7 +50,7 @@ var properties = {
4450
'listNotes',
4551
'createNote',
4652
'getNote',
47-
'updateNote',
53+
'updateNote'
4854
],
4955
projects: [
5056
'getByPath',

lib/resources/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ module.exports = {
3030
resourcePath: '/projects/:id/repository/files'
3131
},
3232

33-
mergeRequests: {
34-
resourcePath: '/projects/:id/merge_request',
35-
idName: 'merge_request_id'
36-
},
33+
mergeRequests: require('./merge_request'),
3734

3835
users: {
3936
resourcePath: '/users',

lib/resources/merge_request.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
3+
var util = require('util');
4+
var RESTFulResource = require('restful-client').RESTFulResource;
5+
6+
module.exports = MergeRequest;
7+
8+
function MergeRequest(client) {
9+
this.constructor.super_.call(this, client, '/projects/:id/merge_requests', 'merge_request_id');
10+
}
11+
util.inherits(MergeRequest, RESTFulResource);
12+
13+
MergeRequest.prototype.listNotes = function (params, callback) {
14+
this.client.request('get', this.onePath + '/notes', params, callback);
15+
};
16+
17+
MergeRequest.prototype.createNote = function (params, callback) {
18+
this.client.request('post', this.onePath + '/notes', params, callback);
19+
};
20+
21+
MergeRequest.prototype.getNote = function (params, callback) {
22+
this.client.request('get', this.onePath + '/notes/:note_id', params, callback);
23+
};
24+
25+
MergeRequest.prototype.updateNote = function (params, callback) {
26+
this.client.request('put', this.onePath + '/notes/:note_id', params, callback);
27+
};
28+
29+
MergeRequest.prototype.merge = function (params, callback) {
30+
this.client.request('put', this.onePath + '/merge', params, callback);
31+
};

0 commit comments

Comments
 (0)