feat: add PR metrics utility#2
Conversation
| // BUG: divides before checking length, throws if chunks is empty | ||
| export function calcAvgChunkSize(chunks: number[]): number { | ||
| const total = chunks.reduce((a, b) => a + b, 0); | ||
| return total / chunks.length; |
There was a problem hiding this comment.
[BUG] The code attempts to divide 'total' by 'chunks.length', but if 'chunks' is an empty array, this will result in a division by zero error.
| return total / chunks.length; | |
| return chunks.length > 0 ? total / chunks.length : 0; |
|
|
||
| // SECURITY: eval on user-provided string | ||
| export function parseModelConfig(configStr: string): object { | ||
| return eval("(" + configStr + ")"); |
There was a problem hiding this comment.
[SECURITY] Using 'eval' to parse JSON is a security risk as it can execute arbitrary code, leading to potential code injection attacks. Instead, 'JSON.parse' should be used to safely parse JSON strings.
| return eval("(" + configStr + ")"); | |
| return JSON.parse(configStr); |
| const result: string[] = []; | ||
| for (let i = 0; i < files.length; i++) { | ||
| let found = false; | ||
| for (let j = 0; j < result.length; j++) { |
There was a problem hiding this comment.
[PERFORMANCE] The loop iterates over 'result.length' on each iteration, which can be inefficient if 'result.length' is large or if 'result' changes during the loop. Storing 'result.length' in a variable before the loop can improve performance.
| for (let j = 0; j < result.length; j++) { | |
| let resultLength = result.length; | |
| for (let j = 0; j < resultLength; j++) { |
| export async function fetchPRTitle(prUrl: string): Promise<string> { | ||
| const res = await fetch(prUrl); | ||
| const json = await res.json(); | ||
| return json.data.title; |
There was a problem hiding this comment.
[BEST_PRACTICE] Accessing 'json.data.title' without checking if 'json.data' is defined can lead to runtime errors if 'json' or 'json.data' is undefined.
| return json.data.title; | |
| return json?.data?.title; |
No description provided.