Skip to content

Commit e271f00

Browse files
authored
fix: handle errors in nameDb creation to skip invalid files
2 parents ef9c2fa + bc05360 commit e271f00

File tree

1 file changed

+34
-20
lines changed

1 file changed

+34
-20
lines changed

.github/actions/buildDB/buildDB.js

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,46 @@
1-
require('dotenv').config();
2-
const fs = require('fs');
3-
const path = require('path');
1+
require("dotenv").config();
2+
const fs = require("fs");
3+
const path = require("path");
44
const core = require('@actions/core');
55
const github = require('@actions/github');
6-
const dir = path.join(__dirname, '..', '..', '..', 'public', 'directory');
6+
const dir = path.join(__dirname, "..", "..", "..", "public", "directory");
77
const files = fs.readdirSync(dir);
88

99
const gh = github.getOctokit(core.getInput('GITHUB_TOKEN', { required: true }));
1010
const nameDb = [];
1111

1212
const build = async () => {
13-
for (let i = 0; i < files.length; i++) {
14-
const file = files[i];
15-
console.log({ i, file });
13+
for (let i = 0; i < files.length; i++) {
14+
const file = files[i];
15+
console.log({ i, file });
1616

17-
if (file.endsWith('.json')) {
18-
const data = require(path.join(dir, file));
19-
20-
await gh.users.getByUsername({username: data.githubId}).then(prof => {
21-
data.avatar_url = prof.data.avatar_url;
22-
nameDb.push(data);
23-
}).catch(console.log);
24-
}
17+
if (file.endsWith(".json")) {
18+
try {
19+
const data = require(path.join(dir, file));
20+
21+
nameDb.push(data);
22+
23+
await gh.users
24+
.getByUsername({ username: data.githubId })
25+
.then((prof) => {
26+
data.avatar_url = prof.data.avatar_url;
27+
});
28+
29+
} catch (e) {
30+
console.log(e);
31+
}
2532
}
33+
}
2634
};
2735

28-
build().then(() => {
29-
fs.writeFileSync(path.join(__dirname, '..', '..', '..', 'public', 'nameDB.json'), JSON.stringify(nameDb));
30-
}).catch(e => {
31-
core.setFailed(`Failed to compile a DB, \n${e.message} `);
32-
})
36+
build()
37+
.then(() => {
38+
fs.writeFileSync(
39+
path.join(__dirname, "..", "..", "..", "public", "nameDB.json"),
40+
JSON.stringify(nameDb)
41+
);
42+
})
43+
.catch((e) => {
44+
// core.setFailed(`Failed to compile a DB, \n${e.message} `);
45+
console.log(e);
46+
});

0 commit comments

Comments
 (0)