-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
181 lines (148 loc) · 6.99 KB
/
index.js
File metadata and controls
181 lines (148 loc) · 6.99 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
const mongoose = require('mongoose');
const { Octokit } = require('octokit');
const fs = require('fs');
const Project = require('./config/project');
const User = require('./config/user');
require('dotenv').config();
//Initialization
const octokit = new Octokit({ auth: process.env.GIT_TOKEN });
mongoose.connect(process.env.DB_STRING, () => { console.log("Connected to MongoDB.") });
//For adding projects to DB
const fetchAndAddProject = async(link) => {
const newLink = link.replace(/[\r\n]+/gm, "");
const resp = await octokit.request('GET /repos/{owner}/{repo}', {
owner: newLink.split('/')[3],
repo: newLink.split('/')[4]
})
const tc = [];
for (let topic of resp.data.topics) {
tc.push(topic);
}
await Project.create({
projectId: resp.data.id,
projectName: resp.data.name,
projectUrl: resp.data.html_url,
description: resp.data.description || "NA",
language: [resp.data.language],
topic: tc,
open_issues: resp.data.open_issues,
stars: resp.data.stargazers_url.length,
difficulty: "NA",
owner: {
ownerId: resp.data.owner.id,
ownerUsername: resp.data.owner.login,
avatar_url: resp.data.owner.avatar_url,
profile_url: resp.data.owner.html_url
},
repo_created_at: new Date(resp.data.created_at).toLocaleString('en-IN', { timeZone: 'Asia/Kolkata' }),
repo_updated_at: new Date(resp.data.updated_at).toLocaleString('en-IN', { timeZone: 'Asia/Kolkata' }),
repo_pushed_at: new Date(resp.data.pushed_at).toLocaleString('en-IN', { timeZone: 'Asia/Kolkata' }),
date: new Date().toLocaleString('en-IN', { timeZone: 'Asia/Kolkata' })
});
const project = await Project.find()
console.log(project.length)
}
// Tracks all projects in the DB
const track = async() => {
const d = new Date().toLocaleString('en-IN', { timeZone: 'Asia/Kolkata' });
fs.appendFileSync('track.log', `Tracked at ${d} \n`);
const projects = await Project.find();
for (let project of projects) {
const resp = await octokit.paginate('GET /repos/{owner}/{repo}/issues{?milestone,state,assignee,creator,mentioned,labels,sort,direction,since,per_page,page}', {
owner: project.owner.ownerUsername,
repo: project.projectName,
state: 'closed',
since: '2024-01-09T18:30:00.000Z',
per_page: '100'
});
for (let issue of resp) {
if (issue.pull_request == undefined) {
const isIWOC = issue.labels.find((element) => { return element.name.toLowerCase() === "iwoc2025" });
if (isIWOC) {
const assignees = issue.assignees;
for (let assignee of assignees) {
const user = await User.findOne({ userid: assignee.id });
if (user !== null) {
const recordExists = user.scoresRecord.find((element) => { return element.Issue_ID == issue.id });
if (!recordExists) {
let diffScore = 0;
let difficulty = "NA";
let labels = [];
for (let label of issue.labels) {
labels.push(label.name.toLowerCase());
switch (label.name.toLowerCase()) {
case "easy":
diffScore = 10;
difficulty = "easy";
break;
case "medium":
diffScore = 30;
difficulty = "medium";
break;
case "hard":
diffScore = 60;
difficulty = "hard";
break;
default:
break;
}
}
if (difficulty !== "NA") {
user.score += diffScore;
user.scoresRecord.push({
Issue_ID: issue.id,
projectId: project.projectId,
projectName: project.projectName,
score: diffScore,
Issue: {
Issue_ID: issue.id,
Issue_number: issue.number,
Issue_title: issue.title,
Issue_labels: labels,
Issue_difficulty: difficulty,
Issue_url: issue.html_url,
Issue_createdAt: issue.created_at,
Issue_updatedAt: issue.updated_at,
Issue_closedAt: issue.closed_at
},
author_association: issue.author_association,
DBdate: new Date().toLocaleString('en-IN', { timeZone: 'Asia/Kolkata' })
});
await user.save();
}
else {
fs.appendFileSync('IrregularTag.log', '--------------------------------------\n');
fs.appendFileSync('IrregularTag.log', `Difficulty tag not found in ${issue.html_url} \n`);
}
}
}
}
}
}
}
};
}
// startTrack() logs and calls track() after every 60 seconds
const startTrack = async() => {
fs.appendFileSync('track.log', '--------------------------------------\n');
await track();
await timeout(60);
await startTrack();
}
const timeout = async(ms) => {
return new Promise(resolve => setTimeout(resolve, 1000 * ms));
}
// For adding multiple projects
const addProjects = async(data) => {
for (let d of data) {
console.log(d);
await fetchAndAddProject(d);
}
}
// To start tracking projects
startTrack();
// To add projects from projectsData.csv
// Format of projectData.csv
// projectRepoLink1,projectRepoLink2,projectRepoLink3,projectRepoLink4
// const data = fs.readFileSync('projectsData.csv', 'utf8').split(',');
// addProjects(data);