diff --git a/chart/chart.html b/chart/chart.html index 196225d..1810e21 100644 --- a/chart/chart.html +++ b/chart/chart.html @@ -3,6 +3,7 @@ + @@ -26,7 +27,7 @@ return Services.ChartsService.getService().then(async function(chartService){ consoleLog("Starting to create chart"); var $container = $('#Chart-Container'); - var $title = $('h2.title'); + var $title = $('h2.ghazdo-title'); const webContext = VSS.getWebContext(); const project = webContext.project; @@ -46,7 +47,9 @@ let repoName let repoId - if (data && data.repo) { + // init empty object first + let alertTrendLines = {secretAlertTrend: [], dependencyAlertTrend: [], codeAlertsTrend: []}; + if (data && data.repo && data.repo !== "") { repoName = data.repo; repoId = data.repoId; consoleLog('loaded repoName from widgetSettings: ' + repoName); @@ -54,13 +57,17 @@ $title.text(`Advanced Security Alerts Trend`) $container.text(`${data.repo}`) - // load the alerts for the selected repo try { - alerts = await getAlerts(organization, projectName, repoId); - consoleLog('alerts: ' + JSON.stringify(alerts)); + // get the trend data for alerts first + alertTrendLines = await getAlertsTrendLines(organization, projectName, repoId) + consoleLog('Dependencies AlertTrend: ' + JSON.stringify(alertTrendLines.dependencyAlertsTrend)); + consoleLog('Code scanning AlertTrend: ' + JSON.stringify(alertTrendLines.codeAlertsTrend)); + consoleLog('Secrets AlertTrend: ' + JSON.stringify(alertTrendLines.secretAlertsTrend)); + + createChart($container, chartService, alertTrendLines); } catch (err) { - consoleLog(`Error loading the grouped alerts: ${err}`); + consoleLog(`Error loading the alerts trend: ${err}`); } } else { @@ -69,56 +76,6 @@ $title.text(`Configure the widget to get Advanced Security alerts trend information`); } - // init empty object first - let alertTrendLines = {secretAlertTrend: [], dependencyAlertTrend: [], codeAlertsTrend: []}; - try { - // get the trend data for alerts first - alertTrendLines = await getAlertsTrendLines(organization, projectName, repoId) - consoleLog('Dependencies AlertTrend: ' + JSON.stringify(alertTrendLines.dependencyAlertsTrend)); - consoleLog('Code scanning AlertTrend: ' + JSON.stringify(alertTrendLines.codeAlertsTrend)); - consoleLog('Secrets AlertTrend: ' + JSON.stringify(alertTrendLines.secretAlertsTrend)); - } - catch (err) { - consoleLog(`Error loading the alerts trend: ${err}`); - } - - const datePoints = getDatePoints(); - var chartOptions = { - "hostOptions": { - "height": "290", - "width": "300" - }, - "chartType": "line", - "series": - [ - { - "name": "Dependencies", - "data": alertTrendLines.dependencyAlertsTrend - }, - { - "name": "Code scanning", - "data": alertTrendLines.codeAlertsTrend - }, - { - "name": "Secrets", - "data": alertTrendLines.secretAlertsTrend - } - ], - "xAxis": { - "labelValues": datePoints, - "labelFormatMode": "dateTime", // format is 2023-09-17 - }, - "specializedOptions": { - "includeMarkers": "true" - } - }; - - try { - chartService.createChart($container, chartOptions); - } - catch (err) { - console.log(`Error creating chart: ${err}`); - } return WidgetHelpers.WidgetStatusHelper.Success(); }); } @@ -133,7 +90,7 @@
-

Chart Widget

+

GHAzDo Chart Widget

diff --git a/chart/chart.js b/chart/chart.js new file mode 100644 index 0000000..aca6de8 --- /dev/null +++ b/chart/chart.js @@ -0,0 +1,40 @@ +async function createChart($container, chartService, alertTrendLines){ + + const datePoints = getDatePoints(); + var chartOptions = { + "hostOptions": { + "height": "290", + "width": "300" + }, + "chartType": "line", + "series": + [ + { + "name": "Dependencies", + "data": alertTrendLines.dependencyAlertsTrend + }, + { + "name": "Code scanning", + "data": alertTrendLines.codeAlertsTrend + }, + { + "name": "Secrets", + "data": alertTrendLines.secretAlertsTrend + } + ], + "xAxis": { + "labelValues": datePoints, + "labelFormatMode": "dateTime", // format is 2023-09-17 + }, + "specializedOptions": { + "includeMarkers": "true" + } + }; + + try { + chartService.createChart($container, chartOptions); + } + catch (err) { + console.log(`Error creating chart: ${err}`); + } +} \ No newline at end of file diff --git a/chart/configuration_2x2.html b/chart/configuration_2x2.html index 004c4e3..c623624 100644 --- a/chart/configuration_2x2.html +++ b/chart/configuration_2x2.html @@ -40,6 +40,8 @@ const repos = await getRepos(); // add all repos as selection options to the dropdown if (repos) { + // add a top option to select no repo + $repoDropdown.append(``); // sort the repo alphabetically repos.sort((a, b) => a.name.localeCompare(b.name)); repos.forEach(r => { diff --git a/styles.css b/styles.css index c409d7f..f3cc3ca 100644 --- a/styles.css +++ b/styles.css @@ -20,10 +20,11 @@ text-decoration: none !important; } -.title { +.ghazdo-title { font-size: 1rem; text-align: left; text-wrap: balance; + margin: 0 0 10px; } .alertValue { diff --git a/vss-extension-dev.json b/vss-extension-dev.json index f4713a9..827bc55 100644 --- a/vss-extension-dev.json +++ b/vss-extension-dev.json @@ -1,7 +1,7 @@ { "manifestVersion": 1, "id": "GHAzDoWidget-DEV", - "version": "0.0.1.67", + "version": "0.0.1.73", "public": false, "name": "Advanced Security dashboard Widgets [DEV]", "description": "[DEV] GitHub Advanced Security for Azure DevOps dashboard widgets", diff --git a/vss-extension.json b/vss-extension.json index 1f1f211..f81b723 100644 --- a/vss-extension.json +++ b/vss-extension.json @@ -1,7 +1,7 @@ { "manifestVersion": 1, "id": "GHAzDoWidget", - "version": "0.0.1.5", + "version": "0.0.1.6", "public": true, "name": "Advanced Security dashboard Widgets", "description": "GitHub Advanced Security for Azure DevOps dashboard widgets", diff --git a/widget_1x1/configuration_1x1.html b/widget_1x1/configuration_1x1.html index 439e672..d1ae96b 100644 --- a/widget_1x1/configuration_1x1.html +++ b/widget_1x1/configuration_1x1.html @@ -60,6 +60,8 @@ const repos = await getRepos(); // add all repos as selection options to the dropdown if (repos) { + // add a top option to select no repo + $repoDropdown.append(``); // sort the repo alphabetically repos.sort((a, b) => a.name.localeCompare(b.name)); repos.forEach(r => { diff --git a/widget_1x1/widget_1x1.html b/widget_1x1/widget_1x1.html index 1298b90..1475e7c 100644 --- a/widget_1x1/widget_1x1.html +++ b/widget_1x1/widget_1x1.html @@ -48,7 +48,7 @@ consoleLog('loaded repoName from widgetSettings_1x1: ' + repoName); // set the tile - var title = $('h2.title'); + var title = $('h2.ghazdo-title'); title.text(`${repoName}`); alerts = await getAlerts(organization, projectName, repoId); consoleLog('alerts: ' + JSON.stringify(alerts)); @@ -138,7 +138,7 @@
-

GitHub Advanced Security Alerts

+

GitHub Advanced Security Alerts

diff --git a/widget_2x1/configuration_2x1.html b/widget_2x1/configuration_2x1.html index 8a579ce..e109202 100644 --- a/widget_2x1/configuration_2x1.html +++ b/widget_2x1/configuration_2x1.html @@ -40,6 +40,8 @@ const repos = await getRepos(); // add all repos as selection options to the dropdown if (repos) { + // add a top option to select no repo + $repoDropdown.append(``); // sort the repo alphabetically repos.sort((a, b) => a.name.localeCompare(b.name)); repos.forEach(r => { diff --git a/widget_2x1/widget_2x1.html b/widget_2x1/widget_2x1.html index b0a1768..6bc8de4 100644 --- a/widget_2x1/widget_2x1.html +++ b/widget_2x1/widget_2x1.html @@ -48,7 +48,7 @@ consoleLog('loaded repoName from widgetSettings: ' + repoName); // set the tile - var title = $('h2.title'); + var title = $('h2.ghazdo-title'); title.text(`Security Alerts for ${repoName}`); alerts = await getAlerts(organization, projectName, repoId); consoleLog('alerts: ' + JSON.stringify(alerts)); @@ -108,7 +108,7 @@