(opts = {})
| 561 | } |
| 562 | |
| 563 | async request(opts = {}) { |
| 564 | const { token } = this; |
| 565 | const { endpoint, method = 'GET', body, raw } = opts; |
| 566 | let { url } = opts; |
| 567 | |
| 568 | if (endpoint) { |
| 569 | url = `${await this.repoBase()}/api/${API_VER}${endpoint}`; |
| 570 | } |
| 571 | if (!url) throw new Error('Gitlab API endpoint not found'); |
| 572 | |
| 573 | logger.debug(`Gitlab API request, method: ${method}, url: "${url}"`); |
| 574 | |
| 575 | const headers = { 'PRIVATE-TOKEN': token, Accept: 'application/json' }; |
| 576 | const response = await fetch(url, { |
| 577 | method, |
| 578 | headers, |
| 579 | body, |
| 580 | agent: new ProxyAgent() |
| 581 | }); |
| 582 | if (!response.ok) { |
| 583 | logger.debug(`Response status is ${response.status}`); |
| 584 | throw new Error(response.statusText); |
| 585 | } |
| 586 | if (raw) return response; |
| 587 | |
| 588 | return await response.json(); |
| 589 | } |
| 590 | |
| 591 | warn(message) { |
| 592 | logger.warn(message); |
no test coverage detected