* @param {string} token * @param {string} path * @param {Object=} data * @param {Object=} options * @return {!Promise }
(token, path, data, options = {})
| 118 | * @return {!Promise<Object>} |
| 119 | */ |
| 120 | async function requestGithub(token, path, data, options = {}) { |
| 121 | const {body, res} = await httpsRequest( |
| 122 | `https://api.github.com/${path.replace(/^\//, '')}`, |
| 123 | { |
| 124 | ...options, |
| 125 | method: options.method || 'GET', |
| 126 | headers: { |
| 127 | ...options.headers, |
| 128 | 'Authorization': `token ${token}`, |
| 129 | 'Content-Type': 'application/json', |
| 130 | 'User-Agent': 'amphtml', |
| 131 | 'Accept': 'application/vnd.github.v3+json', |
| 132 | }, |
| 133 | }, |
| 134 | data ? JSON.stringify(data) : undefined |
| 135 | ); |
| 136 | |
| 137 | if (res.statusCode < 200 || res.statusCode > 299) { |
| 138 | console./*OK*/ error(body); |
| 139 | throw new Error(res.statusCode); |
| 140 | } |
| 141 | |
| 142 | return JSON.parse(body); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * @param {string} token |
no test coverage detected