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"\nimport { RequestOptions } from \"https\"\nimport { IncomingMessage, ClientRequest } from \"http\"\nimport { addTimeOutHandler } from \"./httpRequest\"\nimport { Promise as BluebirdPromise } from \"bluebird\"\nimport { tsAwaiter } from \"./awaiter\"\n\nconst __awaiter = tsAwaiter\nArray.isArray(__awaiter)\n\nexport function gitHubRequest<T>(path: string, token: string, data: { [name: string]: any; } = null, method: string = \"GET\"): BluebirdPromise<T> {\n const options: any = {\n hostname: \"api.github.com\",\n path: path,\n method: method,\n headers: {\n Accept: \"application/vnd.github.v3+json\",\n \"User-Agent\": \"electron-complete-builder\",\n }\n }\n\n const encodedData = data == null ? null : new Buffer(JSON.stringify(data))\n if (encodedData != null) {\n options.method = \"post\"\n options.headers[\"Content-Type\"] = \"application/json\"\n options.headers[\"Content-Length\"] = encodedData.length\n }\n return doGitHubRequest<T>(options, token, it => it.end(encodedData))\n}\n\nexport function doGitHubRequest<T>(options: RequestOptions, token: string, requestProcessor: (request: ClientRequest, reject: (error: Error) => void) => void): BluebirdPromise<T> {\n if (token != null) {\n (<any>options.headers).authorization = \"token \" + token\n }\n\n return new BluebirdPromise<T>((resolve, reject, onCancel) => {\n const request = https.request(options, (response: IncomingMessage) => {\n try {\n if (response.statusCode === 404) {\n // error is clear, we don't need to read detailed error description\n reject(new HttpError(response))\n return\n }\n else if (response.statusCode === 204) {\n // on DELETE request\n resolve()\n return\n }\n\n let data = \"\"\n response.setEncoding(\"utf8\")\n response.on(\"data\", (chunk: string) => {\n data += chunk\n })\n\n response.on(\"end\", () => {\n try {\n if (response.statusCode >= 400) {\n if (response.headers[\"content-type\"].includes(\"json\")) {\n reject(new HttpError(response, JSON.parse(data)))\n }\n else {\n reject(new HttpError(response))\n }\n }\n else {\n resolve(data.length === 0 ? null : JSON.parse(data))\n }\n }\n catch (e) {\n reject(e)\n }\n })\n }\n catch (e) {\n reject(e)\n }\n })\n addTimeOutHandler(request, reject)\n request.on(\"error\", reject)\n requestProcessor(request, reject)\n onCancel(() => request.abort())\n })\n}\n\nexport class HttpError extends Error {\n constructor(public response: IncomingMessage, public description: any = null) {\n super(response.statusCode + \" \" + response.statusMessage + (description == null ? \"\" : (\"\\n\" + JSON.stringify(description, null, \" \"))) + \"\\nHeaders: \" + JSON.stringify(response.headers, null, \" \"))\n }\n}"]}
\No newline at end of file