-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (35 loc) · 1.36 KB
/
index.js
File metadata and controls
39 lines (35 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const axios = require("axios");
const fs = require("fs");
(async () => {
const username = "ovasylenko";
const userUrl = `https://api.github.com/users/${username}/repos`;
const regex = /FROM\s+node\:\w+/gm;
const fileName = ".Dockerfile";
const searchingString = "node:";
try {
const response = await axios.get(userUrl);
const repos = response.data.map((it) => it.name);
for (let i = 0; i < repos.length; i += 1) {
const filteredFiles = `https://api.github.com/search/code?q=${searchingString}+in:file+filename:${fileName}+repo:${username}/${repos[i]}`;
const filteredFilesResponse = await axios.get(filteredFiles);
const dataArray = filteredFilesResponse.data.items;
const mappedFile = dataArray.map((it) => it.url);
for (let k = 0; k < mappedFile.length; k++) {
const fileResponse = await axios.get(mappedFile[k]);
const content = fileResponse.data.content;
const buff = Buffer.from(content, "base64");
const decoded = buff.toString("ascii");
const resultArr = decoded.match(regex);
const result = resultArr.join(" \n") + `\n ${repos[i]} \n`;
console.log(result);
fs.appendFile("./results/results.txt", result, (err) => {
if (err) {
console.log("ERROR: ", err);
}
});
}
}
} catch (err) {
console.log(err);
}
})();