diff --git a/src/lib/crypto.ts b/src/lib/crypto.ts index 218910d..685edcc 100644 --- a/src/lib/crypto.ts +++ b/src/lib/crypto.ts @@ -13,6 +13,7 @@ async function hash(namespace: string) { const relevant_hash = "Qa4xy8yRPnBsQf8U2UUE7tse2u4Fi/Aqxbt" + "6aq56m5ofcmCkTi8PbgMBF1OtHC6qkXDF2tz2qKprYCIAMzTSQQ=="; + Deno.test("encode_namespace", async () => { const namespace = "CHANGEME"; const base64 = await hash(namespace); diff --git a/src/okimeter.ts b/src/okimeter.ts index a336742..4312aae 100755 --- a/src/okimeter.ts +++ b/src/okimeter.ts @@ -12,7 +12,7 @@ async function main() { if (token === undefined) token = prompt_args(); const client = new ApiClient("gitlab.cri.epita.fr", token); const merge_requests = await get_all_merge_requests(client); - const total = sum(await parallel(merge_requests, (mr) => count_in_mr(mr, client))); + const total = sum(await parallel(merge_requests, (mr) => count_in_merge_request(mr, client))); console.log("Total", total, "oki"); } @@ -35,17 +35,17 @@ ${gr("> xxxxxxxxxxxxxxxxxxxx")} return result.trim(); } -async function get_all_merge_requests(client: ApiClient): Promise { +async function get_all_merge_requests(client: ApiClient) { return await client.fetch_parse_paginated(`api/v4/merge_requests`, merge_request_parser); } -async function count_in_mr(mr: MergeRequest, client: ApiClient) { +async function count_in_merge_request(merge_request: MergeRequest, client: ApiClient) { let total = 0; - const mr_path = `api/v4/projects/${mr.project_id}/merge_requests/${mr.iid}`; - const all_notes = await client.fetch_parse_paginated(`${mr_path}/notes`, note_parser); - for (const c of all_notes) { - if (!await is_relevant(c.author.username)) continue; - if (c.body.toLowerCase().includes("oki")) total += 1; + const merge_request_path = `api/v4/projects/${merge_request.project_id}/merge_requests/${merge_request.iid}`; + const all_notes = await client.fetch_parse_paginated(`${merge_request_path}/notes`, note_parser); + for (const note of all_notes) { + if (!await is_relevant(note.author.username)) continue; + if (note.body.toLowerCase().includes("oki")) total += 1; } return total; }