Skip to content

Commit

Permalink
Updates for Extendability to other schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
ishaan812 committed Nov 5, 2023
1 parent 1c35d65 commit 067cc92
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 38 deletions.
18 changes: 12 additions & 6 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { fileURLToPath } from 'url';
import path from 'path';
import Converter from 'openapi-to-postmanv2';
import { makePostmanCollection } from './utils.js';
import { openAPIQueryBuilder } from './searchtools/openAPISearchUtils.js';


const CustomOctokit = Octokit.plugin(throttling as any, retry as any);
Expand Down Expand Up @@ -44,12 +45,14 @@ const octokit = new CustomOctokit({
const esHost = process.env.ES_HOST || 'localhost';
const esClient = new es.Client({
host: 'http://' + esHost + ':9200',
// uncomment for debugging
// log: 'trace',
});

const app = express();
app.set('view engine', 'pug');
app.set('views', path.join(rootDir, 'templates'));

app.get('/search', async (_req, _res) => {
const query = _req.query.q as string;
const results = await passiveSearch(query);
Expand All @@ -62,12 +65,16 @@ app.post('/openapi', async (_req, _res) => {
const User = _req.query.user as string;
const Prompt = _req.query.prompt as string;
const RootQuery = _req.query.rootquery as string;
const query = await openAPIQueryBuilder(
Prompt,
Repository,
Organisation,
User,
RootQuery,
);
const results = await activeSearch(
Prompt as string,
Repository as string,
Organisation as string,
User as string,
RootQuery as string,
query as string,
'openapi'
);
_res.send(results);
});
Expand All @@ -82,7 +89,6 @@ app.use('/ping', async (_req, _res) => {
_res.send(response);
});


app.get('/openapi/:id', async (_req, _res) => {
const id = _req.params.id;
GetDocumentWithId(id).then((response) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function getFileContents(
return response;
}

export async function queryBuilder(
export async function openAPIQueryBuilder(
prompt: string,
repo: string,
organisation: string,
Expand Down Expand Up @@ -73,7 +73,7 @@ export async function queryBuilder(
return query;
}

export async function ValidateandStoreFiles(files: any[]): Promise<any> {
export async function openAPIValidateandStoreFiles(files: any[]): Promise<any> {
if (files.length == 0) {
return;
}
Expand Down
58 changes: 28 additions & 30 deletions src/searchtools/search.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
import { queryBuilder, ValidateandStoreFiles } from './searchutils.js';
import { openAPIValidateandStoreFiles } from './openAPISearchUtils.js';
import { octokit, esClient } from '../app.js';

let processCount = 0;
let finishedCount = 0;

export async function activeSearch(
prompt: string,
repo: string,
organisation: string,
username: string,
rootquery: string,
query: string,
type: string,
): Promise<any> {
const query = await queryBuilder(
prompt,
repo,
organisation,
username,
rootquery,
);
console.log(type)
console.info('Query: ' + query);
let files = [];
let validFiles = [];
console.info('Query: ' + query);
await octokit.paginate(
octokit.rest.search.code,
{
Expand All @@ -34,15 +25,19 @@ export async function activeSearch(
console.info(
'ValidateandStoreFiles Process Number ' + processCount + ' Started',
);
ValidateandStoreFiles(files).then((validatedFiles) => {
validFiles = validFiles.concat(validatedFiles);
finishedCount++;
console.info(
'ValidateandStoreFiles Process Number ' +
finishedCount +
' Finished',
);
});
switch (type) {
case 'openapi':
openAPIValidateandStoreFiles(files).then((validatedFiles) => {
validFiles = validFiles.concat(validatedFiles);
finishedCount++;
console.info(
'ValidateandStoreFiles Process Number ' +
finishedCount +
' Finished',
);
});
break;
}
files = [];
}
},
Expand All @@ -52,13 +47,16 @@ export async function activeSearch(
console.info(
'ValidateandStoreFiles Process Number ' + processCount + ' Started',
);
ValidateandStoreFiles(files).then((validatedFiles) => {
validFiles = validFiles.concat(validatedFiles);
console.info(
'ValidateandStoreFiles Process Number ' + finishedCount + ' Finished',
);
finishedCount++;
});
switch (type) {
case 'openapi':
openAPIValidateandStoreFiles(files).then((validatedFiles) => {
validFiles = validFiles.concat(validatedFiles);
console.info(
'ValidateandStoreFiles Process Number ' + finishedCount + ' Finished',
);
finishedCount++;
});
}
while (processCount > finishedCount) {
await new Promise((r) => setTimeout(r, 5000));
console.info(
Expand Down

0 comments on commit 067cc92

Please sign in to comment.