Skip to content

Commit 3f37499

Browse files
authored
πŸ”€ Merge pull request #4 from aynp/fix-depth-flag-1
πŸ› Fix `depth` behaviour
2 parents f19a8d5 + 6dcac38 commit 3f37499

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

β€Žparse.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import { Octokit } from '@octokit/core';
22
import fs from 'fs';
33

4-
async function rec(octokit, url) {
4+
async function rec(octokit, url, depth) {
55
const result = [];
66

7+
if (depth <= 0) return result;
8+
79
const data = (await octokit.request(`GET ${url}`, {})).data;
810

911
for (let i = 0; i < data.length; i++) {
1012
const item = data[i];
1113
if (item.type === 'dir') {
12-
const temp = await rec(octokit, item.url);
14+
const temp = await rec(octokit, item.url, depth - 1);
1315
result.push({ ...item, contents: temp });
1416
} else {
1517
result.push(item);
@@ -27,7 +29,7 @@ async function parseGH(input, { depth = Infinity, token, output }) {
2729
auth: token,
2830
});
2931

30-
const result = await rec(octokit, url);
32+
const result = await rec(octokit, url, depth);
3133

3234
if (output) {
3335
fs.writeFile(output, JSON.stringify(result), function (err) {

0 commit comments

Comments
Β (0)