11const Request = require ( 'request-promise' ) ;
2+
23const { Groups, Projects, Issues, Runners, Users, Labels } = require ( './Models' ) ;
34
45function defaultRequestWithQS ( url , endpoint , headers , options ) {
@@ -19,6 +20,15 @@ function defaultRequestWithBody(url, endpoint, headers, options) {
1920 } ;
2021}
2122
23+ function defaultRequestWithFormData ( url , endpoint , headers , options ) {
24+ return {
25+ url : url + endpoint ,
26+ headers,
27+ json : true ,
28+ formData : options ,
29+ } ;
30+ }
31+
2232class API {
2333 constructor ( { url = 'https://gitlab.com' , token, oauthToken } ) {
2434 this . url = `${ url } /api/v4/` ;
@@ -48,6 +58,14 @@ class API {
4858 return Request . post ( defaultRequestWithBody ( this . url , endpoint , this . headers , options ) ) ;
4959 }
5060
61+ postForm ( endpoint , options ) {
62+ const formHeader = Object . assign ( this . headers , {
63+ 'content-type' : 'multipart/form-data' ,
64+ } ) ;
65+
66+ return Request . post ( defaultRequestWithFormData ( this . url , endpoint , formHeader , options ) ) ;
67+ }
68+
5169 put ( endpoint , options ) {
5270 return Request . put ( defaultRequestWithBody ( this . url , endpoint , this . headers , options ) ) ;
5371 }
0 commit comments