From 201c64f4d8a89d5d2ae5cfe498b3c392d88a74a7 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sat, 21 Oct 2023 14:22:34 +0200 Subject: [PATCH] Logging cleanup --- vss-extension-dev.json | 2 +- widgets/library.js | 45 +++++++++++---------- widgets/widgets/testing_widget/testing.html | 6 ++- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/vss-extension-dev.json b/vss-extension-dev.json index 8386ff7..650be09 100644 --- a/vss-extension-dev.json +++ b/vss-extension-dev.json @@ -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", diff --git a/widgets/library.js b/widgets/library.js index 665d190..3d92abe 100644 --- a/widgets/library.js +++ b/widgets/library.js @@ -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 { @@ -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; @@ -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`); diff --git a/widgets/widgets/testing_widget/testing.html b/widgets/widgets/testing_widget/testing.html index 6c4e5c8..937d347 100644 --- a/widgets/widgets/testing_widget/testing.html +++ b/widgets/widgets/testing_widget/testing.html @@ -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(`
  • ${project.name}
  • \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) ); } @@ -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) }