From 6dcac38ee86ff5ff2dc4457deddbca4c31b51008 Mon Sep 17 00:00:00 2001 From: Aryan Date: Sun, 23 Oct 2022 21:05:02 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20`depth`=20behaviour?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `--depth` or `-d` flag is now respected. --- parse.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/parse.js b/parse.js index 8c97f13..fc4572b 100644 --- a/parse.js +++ b/parse.js @@ -1,15 +1,17 @@ import { Octokit } from '@octokit/core'; import fs from 'fs'; -async function rec(octokit, url) { +async function rec(octokit, url, depth) { const result = []; + if (depth <= 0) return result; + const data = (await octokit.request(`GET ${url}`, {})).data; for (let i = 0; i < data.length; i++) { const item = data[i]; if (item.type === 'dir') { - const temp = await rec(octokit, item.url); + const temp = await rec(octokit, item.url, depth - 1); result.push({ ...item, contents: temp }); } else { result.push(item); @@ -27,7 +29,7 @@ async function parseGH(input, { depth = Infinity, token, output }) { auth: token, }); - const result = await rec(octokit, url); + const result = await rec(octokit, url, depth); if (output) { fs.writeFile(output, JSON.stringify(result), function (err) {