-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditRegistryRepo.js
61 lines (58 loc) · 2.7 KB
/
editRegistryRepo.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const fs = require("fs");
const { Octokit } = require("@octokit/rest");
const octokit = new Octokit({
auth: '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'
});
async function x() {
let registry = JSON.parse(fs.readFileSync("registry.json", "utf-8"));
let popularity = JSON.parse(fs.readFileSync("popularity.json", "utf-8"));
console.log("number of registry extensions = ", Object.keys(registry).length);
let updateCount = 0, totalinValidRepos = 0, skipped = 0;
for (let registryKey of Object.keys(registry)) {
let registryEntry = registry[registryKey];
let repoURL = registry[registryKey].metadata.homepage;
let extensionPopularity = popularity[registryKey] || {};
let publishingOwner = registry[registryKey].owner.split(":")[1];
extensionPopularity.totalDownloads = registry[registryKey].totalDownloads || 0;
if(registryEntry.gihubStars){
skipped++;
continue; // we already did this
}
if(repoURL && repoURL.startsWith("http://github.com")){
repoURL = repoURL.replace("http://github.com", "https://github.com");
console.log("changed: ", repoURL)
}
if(repoURL && repoURL.startsWith("https://github.com")){
let repoURLSplit = repoURL.replace("https://github.com/","").split("/");
let owner = repoURLSplit[0], repoName = repoURLSplit[1];
if(publishingOwner.toLowerCase() !== owner.toLowerCase()){
console.log("publishing author is different, owner repo", publishingOwner, owner);
}
try{
console.log("fetching: ", repoURL);
let repoDetails = await octokit.request(`GET /repos/${owner}/${repoName}`, {
owner: 'OWNER',
repo: 'REPO'
});
extensionPopularity.gihubStars = repoDetails.data.stargazers_count;
registryEntry.gihubStars = repoDetails.data.stargazers_count;
registryEntry.ownerRepo = repoURL;
} catch(e){
console.log("error fetching repo: ", repoURL);
totalinValidRepos++;
}
}
popularity[registryKey] = extensionPopularity;
updateCount++;
if (updateCount === 2000) {
// trial run
break;
}
}
console.log("total processed: ", updateCount);
console.log("total skipped: ", skipped);
console.log("total invalid repos: ", totalinValidRepos);
fs.writeFileSync("registry.json", JSON.stringify(registry, null, 4), "utf-8");
fs.writeFileSync("popularity.json", JSON.stringify(popularity, null, 4), "utf-8");
}
x();