summaryrefslogtreecommitdiff
path: root/source/github-helpers/api.ts
diff options
context:
space:
mode:
authorGravatar yakov116 <16872793+yakov116@users.noreply.github.com> 2021-08-14 09:21:34 -0400
committerGravatar GitHub <noreply@github.com> 2021-08-14 20:21:34 +0700
commitac8de6bd0ef0a6016732a69556e4eb9c014cfd38 (patch)
treec91eb73907b2d1443b9cc216116c9347ef499097 /source/github-helpers/api.ts
parent5ec0ec56dae43b328141453957dd9e53c69dd71e (diff)
downloadrefined-github-ac8de6bd0ef0a6016732a69556e4eb9c014cfd38.tar.gz
refined-github-ac8de6bd0ef0a6016732a69556e4eb9c014cfd38.tar.zst
refined-github-ac8de6bd0ef0a6016732a69556e4eb9c014cfd38.zip
Meta: Log API calls and other fetches (#4656)21.8.14
Diffstat (limited to 'source/github-helpers/api.ts')
-rw-r--r--source/github-helpers/api.ts12
1 files changed, 12 insertions, 0 deletions
diff --git a/source/github-helpers/api.ts b/source/github-helpers/api.ts
index 386156ac..45860893 100644
--- a/source/github-helpers/api.ts
+++ b/source/github-helpers/api.ts
@@ -48,6 +48,13 @@ interface RestResponse extends AnyObject {
ok: boolean;
}
+export async function log(message: string): Promise<void> {
+ const {logAPI} = (await optionsStorage.getAll());
+ if (logAPI) {
+ console.log(message);
+ }
+}
+
export const escapeKey = (value: string | number): string => '_' + String(value).replace(/[ ./-]/g, '_');
export class RefinedGitHubAPIError extends Error {
@@ -118,6 +125,7 @@ export const v3 = mem(async (
}
const url = new URL(query, api3);
+ void log(String(url));
const response = await fetch(url.href, {
method,
body: body && JSON.stringify(body),
@@ -174,6 +182,10 @@ export const v4 = mem(async (
query = query.replace('repository() {', () => `repository(owner: "${getRepo()!.owner}", name: "${getRepo()!.name}") {`);
+ void log(`{
+ ${query}
+ }`);
+
const response = await fetch(api4, {
headers: {
'User-Agent': 'Refined GitHub',