Skip to content

Commit

Permalink
Logging cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rajbos committed Oct 21, 2023
1 parent 0d2a8d3 commit 201c64f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion vss-extension-dev.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifestVersion": 1,
"id": "GHAzDoWidget-DEV",
"version": "0.2.174",
"version": "0.2.176",
"public": false,
"name": "Advanced Security dashboard Widgets [DEV]",
"description": "[DEV] GitHub Advanced Security for Azure DevOps dashboard widgets",
Expand Down
45 changes: 24 additions & 21 deletions widgets/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ async function getProjects(VSS, Service, CoreRestClient) {
id: project.id
}
});
consoleLog(`Converted projects to: ${JSON.stringify(projects)}`);
//consoleLog(`Converted projects to: ${JSON.stringify(projects)}`);

// save the repos to the document store for next time
// try {
Expand All @@ -310,7 +310,7 @@ async function getProjects(VSS, Service, CoreRestClient) {
}
}

async function getRepos(VSS, Service, GitWebApi, projectName) {
async function getRepos(VSS, Service, GitWebApi, projectName, useCache = true) {

const webContext = VSS.getWebContext();
const project = webContext.project;
Expand All @@ -323,27 +323,30 @@ async function getRepos(VSS, Service, GitWebApi, projectName) {
// needed to clean up
//removeDocument(VSS, documentCollection, documentId);

try {
const document = await getSavedDocument(VSS, documentCollection, documentId);
consoleLog(`document inside getRepos: ${JSON.stringify(document)}`);
if (document || document.data.length > 0) {
consoleLog(`Loaded repos from document store. Last updated [${document.lastUpdated}]`);
// get the data type of lastUpdated
consoleLog(`typeof document.lastUpdated: ${typeof document.lastUpdated}`)
// if data.lastUpdated is older then 1 hour, then refresh the repos
const diff = new Date() - new Date(document.lastUpdated);
const diffHours = Math.floor(diff / 1000 / 60 / 60);
if (diffHours < 4) {
consoleLog(`Repos are less then 1 hour old, so using the cached version. diffHours [${diffHours}]`);
return document.data;
}
else {
consoleLog(`Repos are older then 1 hour, so refreshing the repo list is needed. diffHours [${diffHours}]`);
if (useCache) {
try {
const document = await getSavedDocument(VSS, documentCollection, documentId);
consoleLog(`document inside getRepos: ${JSON.stringify(document)}`);
if (document || document.data.length > 0) {
consoleLog(`Loaded repos from document store. Last updated [${document.lastUpdated}]`);
// get the data type of lastUpdated
consoleLog(`typeof document.lastUpdated: ${typeof document.lastUpdated}`)
// if data.lastUpdated is older then 1 hour, then refresh the repos
const diff = new Date() - new Date(document.lastUpdated);
const diffHours = Math.floor(diff / 1000 / 60 / 60);
const cacheDuration = 4;
if (diffHours < cacheDuration) {
consoleLog(`Repos are less then ${cacheDuration} hour old, so using the cached version. diffHours [${diffHours}]`);
return document.data;
}
else {
consoleLog(`Repos are older then ${cacheDuration} hour, so refreshing the repo list is needed. diffHours [${diffHours}]`);
}
}
}
}
catch (err) {
console.log(`Error loading the available repos from document store: ${err}`);
catch (err) {
console.log(`Error loading the available repos from document store: ${err}`);
}
}

consoleLog(`Loading repositories from the API`);
Expand Down
6 changes: 4 additions & 2 deletions widgets/widgets/testing_widget/testing.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@

for (let index in projects) {
const project = projects[index];
consoleLog(`Checking project: [${JSON.stringify(project)}]`);
//consoleLog(`Checking project: [${JSON.stringify(project)}]`);
$queryinfocontainer.append(`<li id="${project.id}">${project.name}</li>\n`);
// load the repos for this project:
try {
getRepos(VSS, Service, GitWebApi, project.name).then(
getRepos(VSS, Service, GitWebApi, project.name, false).then(
repos => showRepoInfo(repos, project, organization)
);
}
Expand Down Expand Up @@ -161,6 +161,8 @@

const projects = await getProjects(VSS, Service, RestClient);
consoleLog(`Found [${projects?.length}] projects`);
// sort the projects based on the name
projects.sort((a, b) => (a.name > b.name) ? 1 : -1);

showProjectInfo(VSS, Service, GitWebApi, organization, projects)
}
Expand Down

0 comments on commit 201c64f

Please sign in to comment.