|
| 1 | +const axios = require('axios'); |
| 2 | +const mongoose = require('mongoose'); |
| 3 | +const passportLocalMongoose = require('passport-local-mongoose'); |
| 4 | +const fs = require('fs'); |
| 5 | +const session = require('express-session'); |
| 6 | +const MongoStore = require('connect-mongo') |
| 7 | +const express = require('express'); |
| 8 | +const jwt = require('jsonwebtoken'); |
| 9 | +const connectEnsureLogin = require('connect-ensure-login'); |
| 10 | +// Custom requires |
| 11 | +const WebDataHandler = require('./backendsrc/webDataHandler') |
| 12 | +const TeamsDataHandler = require('./backendsrc/teamsDataHandler') |
| 13 | +// Get config |
| 14 | +const config = fs.existsSync('./config.js') ? require('./config') : require('./defaultconfig'); |
| 15 | + |
| 16 | +// Configure Vue Specific set up |
| 17 | +const app = express(); |
| 18 | +app.use(express.static(__dirname + "/dist")); |
| 19 | + |
| 20 | +// Set up Dev or Production |
| 21 | +let mongooseConnectionString = ''; |
| 22 | +let hostPort = 3000; |
| 23 | + |
| 24 | +if (process.env.NODE_ENV == 'production') { |
| 25 | + mongooseConnectionString = process.env.prodMongoDBConnectionString; |
| 26 | + config.secret = process.env.secret; |
| 27 | + config.sessionSecret = process.env.sessionSecret; |
| 28 | + config.ghToken = process.env.ghToken; |
| 29 | + config.pineconeAPIKey = process.env.pineconeAPIKey; |
| 30 | + config.azureOpenAIAPIKey = process.env.azureOpenAIAPIKey; |
| 31 | + config.azureEndpointURL = process.env.azureEndpointURL; |
| 32 | + config.debugDisableEmbeddings = false; |
| 33 | + hostPort = process.env.PORT ? process.env.PORT : 8080; |
| 34 | +} else { |
| 35 | + mongooseConnectionString = config.devMongoDBConnectionString; |
| 36 | + hostPort = 3000; |
| 37 | +} |
| 38 | + |
| 39 | +// Set up Mongoose connection |
| 40 | +const Schema = mongoose.Schema; |
| 41 | +const RepoInfo = new Schema({ |
| 42 | + lastIssuesCompleteUpdate: Date, |
| 43 | + lastIssuesUpdateStart: Date, |
| 44 | + lastIssuesUpdateProgress: Date, |
| 45 | + issuesUpdating: Boolean, |
| 46 | + lastCommentsCompleteUpdate: Date, |
| 47 | + lastCommentsUpdateStart: Date, |
| 48 | + lastCommentsUpdateProgress: Date, |
| 49 | + commentsUpdating: Boolean, |
| 50 | + url: String, |
| 51 | + shortURL: String, |
| 52 | +}, { toJSON: { virtuals: true }, collation: { locale: "en_US", strength: 2 } }); |
| 53 | + |
| 54 | +RepoInfo.virtual('userList', { |
| 55 | + ref: 'userInfo', |
| 56 | + localField: '_id', |
| 57 | + foreignField: 'repos' |
| 58 | +}); |
| 59 | + |
| 60 | +RepoInfo.virtual('updating').get(function () { |
| 61 | + return (this.issuesUpdating || this.commentsUpdating); |
| 62 | +}); |
| 63 | + |
| 64 | +const labelSchema = new Schema({ |
| 65 | + id: Number, |
| 66 | + node_id: String, |
| 67 | + url: String, |
| 68 | + name: String, |
| 69 | + description: String, |
| 70 | + color: String, |
| 71 | + default: Boolean, |
| 72 | +}); |
| 73 | + |
| 74 | +const GHUserSchema = new Schema({ |
| 75 | + login: String, |
| 76 | + id: Number, |
| 77 | + node_id: String, |
| 78 | + avatar_url: String, |
| 79 | + gravatar_id: String, |
| 80 | + url: String, |
| 81 | + html_url: String, |
| 82 | +}) |
| 83 | + |
| 84 | +const issueReadDetail = new Schema({ |
| 85 | + readAt: Date, |
| 86 | + userRef: { type: Schema.Types.ObjectId, ref: 'userInfo' }, |
| 87 | + issueRef: { type: Schema.Types.ObjectId, ref: 'issueInfo' }, |
| 88 | + repoRef: { type: Schema.Types.ObjectId, ref: 'repoInfo' }, |
| 89 | +}) |
| 90 | + |
| 91 | +issueReadDetail.index({ 'userRef': -1 }); |
| 92 | +issueReadDetail.index({ 'issueRef': -1 }); |
| 93 | +issueReadDetail.index({ 'repoRef': -1 }); |
| 94 | + |
| 95 | +const IssueCommentMentionDetail = new Schema({ |
| 96 | + commentRef: { type: Schema.Types.ObjectId, ref: 'issueCommentInfo' }, |
| 97 | + userRef: { type: Schema.Types.ObjectId, ref: 'userInfo' }, |
| 98 | + issueRef: { type: Schema.Types.ObjectId, ref: 'issueInfo' }, |
| 99 | + repoRef: { type: Schema.Types.ObjectId, ref: 'repoInfo' }, |
| 100 | + mentionedAt: Date, |
| 101 | + html_url: String, |
| 102 | + mentionAuthor: String, |
| 103 | +}); |
| 104 | + |
| 105 | +IssueCommentMentionDetail.index({ 'commentRef': 1 }); |
| 106 | +IssueCommentMentionDetail.index({ 'userRef': -1 }); |
| 107 | +IssueCommentMentionDetail.index({ 'issueRef': -1 }); |
| 108 | +IssueCommentMentionDetail.index({ 'repoRef': -1 }); |
| 109 | +IssueCommentMentionDetail.index({ 'mentionedAt': 1, type: -1 }); |
| 110 | + |
| 111 | +const IssueCommentDetail = new Schema({ |
| 112 | + repoRef: { type: Schema.Types.ObjectId, ref: 'repoInfo' }, |
| 113 | + issueRef: { type: Schema.Types.ObjectId, ref: 'issueInfo' }, |
| 114 | + mentionStrings: [String], |
| 115 | + author_association: String, |
| 116 | + body: String, |
| 117 | + created_at: Date, |
| 118 | + html_url: String, |
| 119 | + comment_id: Number, |
| 120 | + issue_url: String, |
| 121 | + node_id: String, |
| 122 | + reactions: Object, |
| 123 | + updated_at: Date, |
| 124 | + url: String, |
| 125 | + user: GHUserSchema, |
| 126 | +}); |
| 127 | + |
| 128 | +IssueCommentDetail.index({ 'updated_at': 1, type: -1 }); |
| 129 | +IssueCommentDetail.index({ 'created_at': 1, type: -1 }); |
| 130 | +IssueCommentDetail.index({ 'repoRef': 1 }); |
| 131 | +IssueCommentDetail.index({ 'comment_id': -1 }); |
| 132 | +IssueCommentDetail.index({ 'user.login': -1 }); |
| 133 | +IssueCommentDetail.index({ 'issueRef': -1 }); |
| 134 | + |
| 135 | +const IssueInfo = new Schema({ |
| 136 | + // siteIssueLabels: [{ type: Schema.Types.ObjectId, ref: 'siteIssueLabelInfo' }], |
| 137 | + repoRef: { type: Schema.Types.ObjectId, ref: 'repoInfo' }, |
| 138 | + created_at: { type: Date, index: true }, |
| 139 | + updated_at: { type: Date, index: true }, |
| 140 | + title: String, |
| 141 | + user: GHUserSchema, |
| 142 | + number: Number, |
| 143 | + url: String, |
| 144 | + html_url: String, |
| 145 | + repository_url: String, |
| 146 | + labels_url: String, |
| 147 | + comments_url: String, |
| 148 | + labels: [labelSchema], |
| 149 | + state: String, |
| 150 | + locked: Boolean, |
| 151 | + assignee: GHUserSchema, |
| 152 | + assignees: [GHUserSchema], |
| 153 | + milestone: Object, |
| 154 | + comments: Number, |
| 155 | + reactions: Object, |
| 156 | + closed_at: Date, |
| 157 | + closed_by: GHUserSchema, |
| 158 | + body: String, |
| 159 | + userMentionsList: [String], |
| 160 | + userCommentsList: [String], |
| 161 | +}, { toJSON: { virtuals: true }, collation: { locale: "en_US", strength: 2 } }); |
| 162 | + |
| 163 | +IssueInfo.index({ 'repository_url': 1 }); |
| 164 | +IssueInfo.index({ 'state': 1 }); |
| 165 | +IssueInfo.index({ 'number': 1 }); |
| 166 | +IssueInfo.index({ 'repoRef': 1 }); |
| 167 | + |
| 168 | +IssueInfo.virtual('issueCommentsArray', { |
| 169 | + ref: 'issueCommentInfo', |
| 170 | + localField: '_id', |
| 171 | + foreignField: 'issueRef' |
| 172 | +}); |
| 173 | + |
| 174 | +IssueInfo.virtual('siteIssueLabels', { |
| 175 | + ref: 'siteIssueLabelInfo', |
| 176 | + localField: '_id', |
| 177 | + foreignField: 'issueList' |
| 178 | +}); |
| 179 | + |
| 180 | +IssueInfo.virtual('readByArray', { |
| 181 | + ref: 'issueReadInfo', |
| 182 | + localField: '_id', |
| 183 | + foreignField: 'issueRef' |
| 184 | +}); |
| 185 | + |
| 186 | +IssueInfo.virtual('linkToThisIssueArray', { |
| 187 | + ref: 'issueLinkInfo', |
| 188 | + localField: '_id', |
| 189 | + foreignField: 'toIssue' |
| 190 | +}); |
| 191 | + |
| 192 | +IssueInfo.virtual('linkFromThisIssueArray', { |
| 193 | + ref: 'issueLinkInfo', |
| 194 | + localField: '_id', |
| 195 | + foreignField: 'fromIssue' |
| 196 | +}); |
| 197 | + |
| 198 | +const siteIssueLabelDetail = new Schema({ |
| 199 | + name: String, |
| 200 | + issueList: [{ type: Schema.Types.ObjectId, ref: 'issueInfo' }], |
| 201 | + owner: { type: Schema.Types.ObjectId, ref: 'userInfo' }, |
| 202 | +}); |
| 203 | + |
| 204 | +siteIssueLabelDetail.index({ 'issueList': 1 }); |
| 205 | +siteIssueLabelDetail.index({ 'owner': 1 }); |
| 206 | + |
| 207 | +const mentionQueryDetail = new Schema({ |
| 208 | + title: String, |
| 209 | + state: String, |
| 210 | + sort: String, |
| 211 | + limit: Number, |
| 212 | + creator: String, |
| 213 | + assignee: String, |
| 214 | + labels: String, |
| 215 | + repos: String, |
| 216 | + siteLabels: String, |
| 217 | + commentedAliases: String, |
| 218 | + read: String, |
| 219 | + milestones: String, |
| 220 | + userRef: { type: Schema.Types.ObjectId, ref: 'userInfo' }, |
| 221 | +}); |
| 222 | + |
| 223 | +const searchQueryDetail = new Schema({ |
| 224 | + title: String, |
| 225 | + state: String, |
| 226 | + sort: String, |
| 227 | + limit: Number, |
| 228 | + creator: String, |
| 229 | + assignee: String, |
| 230 | + labels: String, |
| 231 | + repos: String, |
| 232 | + siteLabels: String, |
| 233 | + commentedAliases: String, |
| 234 | + read: String, |
| 235 | + milestones: String, |
| 236 | + userRef: { type: Schema.Types.ObjectId, ref: 'userInfo' }, |
| 237 | +}); |
| 238 | + |
| 239 | +const UserDetail = new Schema({ |
| 240 | + username: { type: String, index: true }, |
| 241 | + githubUsername: { type: String, index: true }, |
| 242 | + password: String, |
| 243 | + email: String, |
| 244 | + repos: [{ type: Schema.Types.ObjectId, ref: 'repoInfo' }], |
| 245 | + lastLoginDate: Date, |
| 246 | +}, { collection: 'usercollection' }); |
| 247 | + |
| 248 | +UserDetail.virtual('issueLabels', { |
| 249 | + ref: 'siteIssueLabelInfo', |
| 250 | + localField: '_id', |
| 251 | + foreignField: 'owner' |
| 252 | +}); |
| 253 | + |
| 254 | +UserDetail.virtual('mentionArray', { |
| 255 | + ref: 'issueCommentMentionInfo', |
| 256 | + localField: '_id', |
| 257 | + foreignField: 'userRef' |
| 258 | +}); |
| 259 | + |
| 260 | +UserDetail.virtual('manageMentionQueries', { |
| 261 | + ref: 'mentionQueryInfo', |
| 262 | + localField: '_id', |
| 263 | + foreignField: 'userRef' |
| 264 | +}); |
| 265 | + |
| 266 | +UserDetail.virtual('manageIssueSearchQueries', { |
| 267 | + ref: 'searchQueryInfo', |
| 268 | + localField: '_id', |
| 269 | + foreignField: 'userRef' |
| 270 | +}); |
| 271 | + |
| 272 | +UserDetail.virtual('teams', { |
| 273 | + ref: 'teamInfo', |
| 274 | + localField: '_id', |
| 275 | + foreignField: 'users' |
| 276 | +}); |
| 277 | + |
| 278 | +const TeamDetail = new Schema({ |
| 279 | + name: String, |
| 280 | + repos: [{ type: Schema.Types.ObjectId, ref: 'repoInfo' }], |
| 281 | + users: [{ type: Schema.Types.ObjectId, ref: 'userInfo' }], |
| 282 | + owner: { type: Schema.Types.ObjectId, ref: 'userInfo' }, |
| 283 | + triageSettings: Object, |
| 284 | +}, { toJSON: { virtuals: true } }); |
| 285 | + |
| 286 | +TeamDetail.index({ 'repos': 1 }); |
| 287 | +TeamDetail.index({ 'users': 1 }); |
| 288 | +TeamDetail.index({ 'owner': 1 }); |
| 289 | + |
| 290 | +TeamDetail.virtual('triageList', { |
| 291 | + ref: 'teamTriageInfo', |
| 292 | + localField: '_id', |
| 293 | + foreignField: 'team' |
| 294 | +}); |
| 295 | + |
| 296 | +const TeamTriageDetail = new Schema({ |
| 297 | + team: { type: Schema.Types.ObjectId, ref: 'teamInfo' }, |
| 298 | + participants: [{ |
| 299 | + user: { type: Schema.Types.ObjectId, ref: 'userInfo' }, |
| 300 | + issueList: [{ type: Schema.Types.ObjectId, ref: 'issueInfo' }], |
| 301 | + }], |
| 302 | + active: Boolean, |
| 303 | + startDate: Date, |
| 304 | + endDate: Date, |
| 305 | +}); |
| 306 | + |
| 307 | +const IssueLinkDetail = new Schema({ |
| 308 | + fromIssue: { type: Schema.Types.ObjectId, ref: 'issueInfo' }, |
| 309 | + toIssue: { type: Schema.Types.ObjectId, ref: 'issueInfo' }, |
| 310 | + repoRef: { type: Schema.Types.ObjectId, ref: 'repoRef' }, |
| 311 | + linkDate: Date, |
| 312 | +}, { toJSON: { virtuals: true } }); |
| 313 | + |
| 314 | +IssueLinkDetail.index({ 'repoRef': 1 }); |
| 315 | +IssueLinkDetail.index({ 'fromIssue': 1 }); |
| 316 | +IssueLinkDetail.index({ 'toIssue': 1 }); |
| 317 | + |
| 318 | +mongoose.connect(mongooseConnectionString, { useNewUrlParser: true, useUnifiedTopology: true }); |
| 319 | + |
| 320 | +UserDetail.plugin(passportLocalMongoose); |
| 321 | +const RepoDetails = mongoose.model('repoInfo', RepoInfo, 'repoInfo'); |
| 322 | +const IssueDetails = mongoose.model('issueInfo', IssueInfo, 'issueInfo'); |
| 323 | +const UserDetails = mongoose.model('userInfo', UserDetail, 'userInfo'); |
| 324 | +const SearchQueryDetails = mongoose.model('searchQueryInfo', searchQueryDetail, 'searchQueryInfo'); |
| 325 | +const MentionQueryDetails = mongoose.model('mentionQueryInfo', mentionQueryDetail, 'mentionQueryInfo'); |
| 326 | +const siteIssueLabelDetails = mongoose.model('siteIssueLabelInfo', siteIssueLabelDetail, 'siteIssueLabelInfo'); |
| 327 | +const IssueCommentDetails = mongoose.model('issueCommentInfo', IssueCommentDetail, 'issueCommentInfo'); |
| 328 | +const IssueCommentMentionDetails = mongoose.model('issueCommentMentionInfo', IssueCommentMentionDetail, 'issueCommentMentionInfo'); |
| 329 | +const IssueReadDetails = mongoose.model('issueReadInfo', issueReadDetail, 'issueReadInfo'); |
| 330 | +const TeamDetails = mongoose.model('teamInfo', TeamDetail, 'teamInfo'); |
| 331 | +const TeamTriageDetails = mongoose.model('teamTriageInfo', TeamTriageDetail, 'teamTriageInfo'); |
| 332 | +const IssueLinkDetails = mongoose.model('issueLinkInfo', IssueLinkDetail, 'issueLinkInfo'); |
| 333 | + |
| 334 | +const JWTTimeout = 4 * 604800; // 28 Days |
| 335 | + |
| 336 | +const dataHandler = new WebDataHandler(RepoDetails, IssueDetails, UserDetails, siteIssueLabelDetails, IssueCommentDetails, IssueCommentMentionDetails, |
| 337 | + IssueReadDetails, SearchQueryDetails, MentionQueryDetails, config, IssueLinkDetails); |
| 338 | + |
| 339 | +const teamDataHandler = new TeamsDataHandler(RepoDetails, IssueDetails, UserDetails, siteIssueLabelDetails, IssueCommentDetails, IssueCommentMentionDetails, |
| 340 | + IssueReadDetails, SearchQueryDetails, MentionQueryDetails, config.ghToken, TeamDetails, TeamTriageDetails, dataHandler); |
| 341 | + |
| 342 | +async function main() { |
| 343 | + let inputDate = new Date('2024-05-01'); |
| 344 | + let response = await RepoDetails.updateMany({}, { lastIssuesCompleteUpdate: inputDate }); |
| 345 | + let response2 = await RepoDetails.updateMany({}, { lastCommentsCompleteUpdate: inputDate }); |
| 346 | + |
| 347 | + console.log(response); |
| 348 | +} |
| 349 | + |
| 350 | +main() |
0 commit comments