Skip to content

Commit

Permalink
πŸ”€ Merge pull request #4 from aynp/fix-depth-flag-1
Browse files Browse the repository at this point in the history
πŸ› Fix `depth` behaviour
  • Loading branch information
aynp authored Oct 23, 2022
2 parents f19a8d5 + 6dcac38 commit 3f37499
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions parse.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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) {
Expand Down

0 comments on commit 3f37499

Please sign in to comment.