Skip to content

Commit

Permalink
#233 ajust database to enable access to reviewThreads and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
maerzman committed Jul 2, 2024
1 parent e9bafed commit 75ec413
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 0 deletions.
11 changes: 11 additions & 0 deletions binocular-frontend/src/database/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ export default class Database {
}
}

/**
* COMMENTS
*/
static async getCommentData(commentRequestSpan, significantSpan) {
if (await this.checkBackendConnection()) {
return ServerDB.getCommentData(commentRequestSpan, significantSpan);
} else {
return LocalDB.getCommentData(commentRequestSpan, significantSpan);
}
}

/**
* MILESTONES
*/
Expand Down
5 changes: 5 additions & 0 deletions binocular-frontend/src/database/localDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import modules from '../../db_export/modules.json';
import stakeholders from '../../db_export/stakeholders.json';
import mergeRequests from '../../db_export/mergeRequests.json';
import milestones from '../../db_export/milestones.json';
import Comments from './serverDB/comments';

const collections = { branches, builds, commits, files, issues, modules, stakeholders, mergeRequests, milestones };

Expand Down Expand Up @@ -213,6 +214,10 @@ export default class LocalDB {
return Issues.getCodeHotspotsIssueData(db, tripleStore, file);
}

static getCommentData(commentSpan, significantSpan) {
return Comments.getCommentData(commentSpan, significantSpan);
}

static getDatabase() {
const database = collections;

Expand Down
16 changes: 16 additions & 0 deletions binocular-frontend/src/database/localDB/comments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

import { findAll } from './utils';

export default class Comments {
static getIssueData(db, relations, issueSpan, significantSpan) {
return findAll(db, 'comments').then((res) => {
res.docs = res.docs
.sort((a, b) => {
return new Date(a.createdAt) - new Date(b.createdAt);
})
.filter((c) => new Date(c.createdAt) >= new Date(significantSpan[0]) && new Date(c.createdAt) <= new Date(significantSpan[1]));
return res.docs;
});
}
}
16 changes: 16 additions & 0 deletions binocular-frontend/src/database/localDB/reviewThreads.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

import { findAll } from './utils';

export default class ReviewThreads {
static getIssueData(db, relations, issueSpan, significantSpan) {
return findAll(db, 'reviewThreads').then((res) => {
res.docs = res.docs
.sort((a, b) => {
return new Date(a.createdAt) - new Date(b.createdAt);
})
.filter((rt) => new Date(rt.createdAt) >= new Date(significantSpan[0]) && new Date(rt.createdAt) <= new Date(significantSpan[1]));
return res.docs;
});
}
}
5 changes: 5 additions & 0 deletions binocular-frontend/src/database/serverDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Files from './serverDB/files';
import Branches from './serverDB/branches';
import Modules from './serverDB/modules';
import Stakeholders from './serverDB/stakeholders';
import Comments from './serverDB/comments';

export default class ServerDB {
static getBounds() {
Expand Down Expand Up @@ -116,6 +117,10 @@ export default class ServerDB {
return Issues.getCodeHotspotsIssueData(file);
}

static getCommentData(commentSpan, significantSpan) {
return Comments.getCommentData(commentSpan, significantSpan);
}

static getDatabase() {
const xhr = new XMLHttpRequest();
xhr.open('GET', window.location.protocol + '//' + window.location.hostname + ':48763/api/db-export', false);
Expand Down
56 changes: 56 additions & 0 deletions binocular-frontend/src/database/serverDB/comments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use strict';

import { graphQl, traversePages } from '../../utils';
import _ from 'lodash';

export default class Comments {
static getCommentData(commentSpan, significantSpan) {
const commentList = [];
const getCommentsPage = (since, until) => (page, perPage) => {
return graphQl
.query(
`
query($page: Int, $perPage: Int, $since: Timestamp, $until: Timestamp) {
comments(page: $page, perPage: $perPage, since: $since, until: $until) {
count
page
perPage
count
data {
id
author{
login
name
}
createdAt
updatedAt
lastEditedAt
path
bodyText
comments {
id
author {
login
name
}
createdAt
updatedAt
lastEditedAt
path
bodyText
}
}
}
}`,
{ page, perPage, since, until },
)
.then((resp) => resp.comments);
};

return traversePages(getCommentsPage(significantSpan[0], significantSpan[1]), (comment) => {
commentList.push(comment);
}).then(function () {
return commentList;
});
}
}

0 comments on commit 75ec413

Please sign in to comment.