export type ProjectIdType = number ; export type MergeResuestIidType = number ; export type NoteIdType = number ; export type DiscussionIdType = number ; import rp from "request-promise" ; export type MergeRequestResource = { iid : MergeResuestIidType ; description : string ; web_url : string ; } ; export type CommitResource = { id : string ; } ; export type NoteResouce = { id : NoteIdType ; body : string ; } ; export type DiscussionResource = { id : DiscussionIdType ; notes : NoteResouce [ ] ; } ; export type GetMergeRequestsParams = { project_id : ProjectIdType ; } ; export type PutMergeRequestParams = { project_id : ProjectIdType ; iid : MergeResuestIidType ; description ? : string ; } ; export type GetMergeRequestCommitsParams = { project_id : ProjectIdType ; merge_request_iid : MergeResuestIidType ; } ; export type GetMergeRequestNotesParams = { project_id : ProjectIdType ; merge_request_iid : MergeResuestIidType ; } ; export type PostMergeRequestNoteParams = { project_id : ProjectIdType ; merge_request_iid : MergeResuestIidType ; body : string ; } ; export type PutMergeRequestNoteParams = { project_id : ProjectIdType ; merge_request_iid : MergeResuestIidType ; note_id : NoteIdType ; body : string ; } ; export type PostMergeRequestDiscussionParams = { project_id : ProjectIdType ; merge_request_iid : MergeResuestIidType ; body : string ; } ; export interface GitLabApiClient { getMergeRequests ( params ) : Promise < MergeRequestResource [ ] > ; putMergeRequest ( params ) : Promise < MergeRequestResource > ; getMergeRequestCommits ( params ) : Promise < CommitResource [ ] > ; getMergeRequestNotes ( params ) : Promise < NoteResouce [ ] > ; postMergeRequestNote ( params ) : Promise < NoteResouce > ; putMergeRequestNote ( params ) : Promise < NoteResouce > ; postMergeRequestDiscussion ( params ) : Promise < DiscussionResource > ; } export class DefaultGitLabApiClient implements GitLabApiClient { constructor ( private _urlPrefix , private _token ) { } getMergeRequests ( params ) { const reqParam = { method : "GET" , url : `${ this . _urlPrefix }/api/v4/projects/${ params . project_id }/merge_requests?state=opened` , json : true , headers : { "Private-Token" : this . _token , } , } ; return rp ( reqParam ) as any as Promise < MergeRequestResource [ ] > ; } putMergeRequest ( params ) { const reqParam = { method : "PUT" , url : `${ this . _urlPrefix }/api/v4/projects/${ params . project_id }/merge_requests/${ params . iid }` , json : true , headers : { "Private-Token" : this . _token , } , body : params , } ; return rp ( reqParam ) as any as Promise < MergeRequestResource > ; } getMergeRequestCommits ( params ) { const reqParam = { method : "GET" , url : `${ this . _urlPrefix }/api/v4/projects/${ params . project_id }/merge_requests/${ params . merge_request_iid }/commits` , json : true , headers : { "Private-Token" : this . _token , } , } ; return rp ( reqParam ) as any as Promise < CommitResource [ ] > ; } getMergeRequestNotes ( params ) { const reqParam = { method : "GET" , url : `${ this . _urlPrefix }/api/v4/projects/${ params . project_id }/merge_requests/${ params . merge_request_iid }/notes` , json : true , headers : { "Private-Token" : this . _token , } , } ; return rp ( reqParam ) as any as Promise < NoteResouce [ ] > ; } postMergeRequestNote ( params ) { const reqParam = { method : "POST" , url : `${ this . _urlPrefix }/api/v4/projects/${ params . project_id }/merge_requests/${ params . merge_request_iid }/notes` , json : true , headers : { "Private-Token" : this . _token , } , body : { body : params . body , } , } ; return rp ( reqParam ) as any as Promise < NoteResouce > ; } putMergeRequestNote ( params ) { const reqParam = { method : "PUT" , url : `${ this . _urlPrefix }/api/v4/projects/${ params . project_id }/merge_requests/${ params . merge_request_iid }/notes/${ params . note_id }` , json : true , headers : { "Private-Token" : this . _token , } , body : { body : params . body , } , } ; return rp ( reqParam ) as any as Promise < NoteResouce > ; } postMergeRequestDiscussion ( params ) { const reqParam = { method : "POST" , url : `${ this . _urlPrefix }/api/v4/projects/${ params . project_id }/merge_requests/${ params . merge_request_iid }/discussions` , json : true , headers : { "Private-Token" : this . _token , } , body : { body : params . body , } , } ; return rp ( reqParam ) as any as Promise < DiscussionResource > ; } }