Skip to content

Commit 712a700

Browse files
authored
Merge pull request #16 from Leko/add-more-logging
Fetch files recursively
2 parents 6e3c53b + 47fae9b commit 712a700

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publishConfig": {
44
"access": "public"
55
},
6-
"version": "0.0.5",
6+
"version": "0.0.6-0",
77
"description": "A reg-suit plugin to publish reports on GitHub pages",
88
"repository": "Leko/reg-publish-github-pages-plugin",
99
"author": "Leko <[email protected]>",

src/git.ts

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@ export class GitUtil {
4949
this._token = token;
5050
this._logger = logger;
5151

52-
this._octokit = new Octokit({ auth: token });
52+
this._octokit = new Octokit({
53+
auth: token,
54+
log: {
55+
debug: msg => logger.verbose(msg),
56+
info: msg => logger.info(msg),
57+
warn: msg => logger.warn(msg),
58+
error: msg => logger.error(msg),
59+
},
60+
});
5361
}
5462

5563
async clone({ distDir }: { distDir: string }) {
@@ -88,19 +96,30 @@ export class GitUtil {
8896

8997
async listRemoteFiles({ prefix }: { prefix: string }): Promise<ObjectListResult> {
9098
try {
91-
const res = await this._octokit.request("GET /repos/{owner}/{repo}/contents/{path}", {
92-
owner: this._owner,
93-
repo: this._repo,
94-
ref: this._branchName,
95-
path: prefix,
96-
});
97-
if (!Array.isArray(res.data)) {
98-
throw new Error(`${prefix} must be a directory`);
99+
const open: string[] = [prefix];
100+
const result = [];
101+
while (open.length) {
102+
const prefix = open.pop()!;
103+
this._logger.verbose(`${prefix}: Visit`);
104+
const res = await this._octokit.request("GET /repos/{owner}/{repo}/contents/{path}", {
105+
owner: this._owner,
106+
repo: this._repo,
107+
ref: this._branchName,
108+
path: prefix,
109+
});
110+
if (!Array.isArray(res.data)) {
111+
throw new Error(`${prefix} must be a directory`);
112+
}
113+
const nextPaths = res.data.filter(f => f.type === "dir").map(f => f.path);
114+
const files = res.data.filter(f => f.type === "file");
115+
this._logger.verbose(`${prefix}: ${files.length} files and ${nextPaths} folders are found`);
116+
open.push(...nextPaths);
117+
result.push(...files);
99118
}
100119

101120
return {
102121
isTruncated: false,
103-
contents: res.data
122+
contents: result
104123
.filter(f => f.type === "file")
105124
.map(f => ({
106125
key: f.path,

src/github-pages-publisher-plugin.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ export class GithubPagesPublisherPlugin extends AbstractPublisher implements Pub
106106

107107
protected async listItems(_lastKey: string, prefix: string): Promise<ObjectListResult> {
108108
this.logger.verbose(
109-
`Listing files on the repository: ${this._pluginConfig.repository} (${this._pluginConfig.branchName})`,
109+
`Listing files on the repository: ${this._pluginConfig.repository} (${
110+
this._pluginConfig.branchName
111+
}), prefix=${JSON.stringify(prefix)}`,
110112
);
111113
const result = await this._gitUtil.listRemoteFiles({
112114
prefix,

0 commit comments

Comments
 (0)