MCPcopy Index your code
hub / github.com/github-tools/github / _request

Method _request

lib/Requestable.js:156–200  ·  view source on GitHub ↗

* Make a request. * @param {string} method - the method for the request (GET, PUT, POST, DELETE) * @param {string} path - the path for the request * @param {*} [data] - the data to send to the server. For HTTP methods that don't have a body the data * will be sent a

(method, path, data, cb, raw)

Source from the content-addressed store, hash-verified

154 * @return {Promise} - the Promise for the http request
155 */
156 _request(method, path, data, cb, raw) {
157 const url = this.__getURL(path);
158
159 const AcceptHeader = (data || {}).AcceptHeader;
160 if (AcceptHeader) {
161 delete data.AcceptHeader;
162 }
163 const headers = this.__getRequestHeaders(raw, AcceptHeader);
164
165 let queryParams = {};
166
167 const shouldUseDataAsParams = data && (typeof data === 'object') && methodHasNoBody(method);
168 if (shouldUseDataAsParams) {
169 queryParams = data;
170 data = undefined;
171 }
172
173 const config = {
174 url: url,
175 method: method,
176 headers: headers,
177 params: queryParams,
178 data: data,
179 responseType: raw ? 'text' : 'json',
180 };
181
182 log(`${config.method} to ${config.url}`);
183 const requestPromise = axios(config).catch(callbackErrorOrThrow(cb, path));
184
185 if (cb) {
186 requestPromise.then((response) => {
187 if (response.data && Object.keys(response.data).length > 0) {
188 // When data has results
189 cb(null, response.data, response);
190 } else if (config.method !== 'GET' && Object.keys(response.data).length < 1) {
191 // True when successful submit a request and receive a empty object
192 cb(null, (response.status < 300), response);
193 } else {
194 cb(null, response.data, response);
195 }
196 });
197 }
198
199 return requestPromise;
200 }
201
202 /**
203 * Make a request to an endpoint the returns 204 when true and 404 when false

Callers 15

_request204or404Method · 0.95
_requestAllPagesMethod · 0.95
createRepoMethod · 0.80
listMembersMethod · 0.80
createTeamMethod · 0.80
createProjectMethod · 0.80
readMethod · 0.80
createMethod · 0.80
deleteMethod · 0.80
forkMethod · 0.80
updateMethod · 0.80
starMethod · 0.80

Calls 4

__getURLMethod · 0.95
__getRequestHeadersMethod · 0.95
methodHasNoBodyFunction · 0.85
callbackErrorOrThrowFunction · 0.85

Tested by

no test coverage detected