|
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"); |
4 | 4 | const core = require('@actions/core'); |
5 | 5 | const github = require('@actions/github'); |
6 | | -const dir = path.join(__dirname, '..', '..', '..', 'public', 'directory'); |
| 6 | +const dir = path.join(__dirname, "..", "..", "..", "public", "directory"); |
7 | 7 | const files = fs.readdirSync(dir); |
8 | 8 |
|
9 | 9 | const gh = github.getOctokit(core.getInput('GITHUB_TOKEN', { required: true })); |
10 | 10 | const nameDb = []; |
11 | 11 |
|
12 | 12 | 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 }); |
16 | 16 |
|
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 | + } |
25 | 32 | } |
| 33 | + } |
26 | 34 | }; |
27 | 35 |
|
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